use of org.eazegraph.lib.models.StackedBarModel in project EazeGraph by blackfizz.
the class StackedBarChartFragment method loadData.
private void loadData() {
StackedBarModel s1 = new StackedBarModel("12.4");
s1.addBar(new BarModel(2.3f, 0xFF63CBB0));
s1.addBar(new BarModel(2.3f, 0xFF56B7F1));
s1.addBar(new BarModel(2.3f, 0xFFCDA67F));
StackedBarModel s2 = new StackedBarModel("13.4");
s2.addBar(new BarModel(1.1f, 0xFF63CBB0));
s2.addBar(new BarModel(2.7f, 0xFF56B7F1));
s2.addBar(new BarModel(0.7f, 0xFFCDA67F));
StackedBarModel s3 = new StackedBarModel("14.4");
s3.addBar(new BarModel(2.3f, 0xFF63CBB0));
s3.addBar(new BarModel(2.f, 0xFF56B7F1));
s3.addBar(new BarModel(3.3f, 0xFFCDA67F));
StackedBarModel s4 = new StackedBarModel("15.4");
s4.addBar(new BarModel(1.f, 0xFF63CBB0));
s4.addBar(new BarModel(4.2f, 0xFF56B7F1));
s4.addBar(new BarModel(2.1f, 0xFFCDA67F));
StackedBarModel s5 = new StackedBarModel("16.4");
s5.addBar(new BarModel(32.3f, 0xFF63CBB0));
s5.addBar(new BarModel(12.f, 0xFF56B7F1));
s5.addBar(new BarModel(22.3f, 0xFFCDA67F));
StackedBarModel s6 = new StackedBarModel("17.4");
s6.addBar(new BarModel(3.f, 0xFF63CBB0));
s6.addBar(new BarModel(.7f, 0xFF56B7F1));
s6.addBar(new BarModel(1.7f, 0xFFCDA67F));
StackedBarModel s7 = new StackedBarModel("18.4");
s7.addBar(new BarModel(2.3f, 0xFF63CBB0));
s7.addBar(new BarModel(2.f, 0xFF56B7F1));
s7.addBar(new BarModel(3.3f, 0xFFCDA67F));
StackedBarModel s8 = new StackedBarModel("19.4");
s8.addBar(new BarModel(5.4f, 0xFF63CBB0));
s8.addBar(new BarModel(2.7f, 0xFF56B7F1));
s8.addBar(new BarModel(3.4f, 0xFFCDA67F));
mStackedBarChart.addBar(s1);
mStackedBarChart.addBar(s2);
mStackedBarChart.addBar(s3);
mStackedBarChart.addBar(s4);
mStackedBarChart.addBar(s5);
mStackedBarChart.addBar(s6);
mStackedBarChart.addBar(s7);
mStackedBarChart.addBar(s8);
}
use of org.eazegraph.lib.models.StackedBarModel in project EazeGraph by blackfizz.
the class StackedBarChart method drawBars.
/**
* Callback method for drawing the bars in the child classes.
* @param _Canvas The canvas object of the graph view.
*/
protected void drawBars(Canvas _Canvas) {
for (StackedBarModel model : mData) {
float lastTop;
float lastBottom = mGraphHeight;
for (int index = 0; index < model.getBars().size(); index++) {
BarModel barModel = model.getBars().get(index);
RectF bounds = barModel.getBarBounds();
mGraphPaint.setColor(barModel.getColor());
float height = (bounds.height() * mRevealValue);
lastTop = lastBottom - height;
_Canvas.drawRect(bounds.left, lastTop, bounds.right, lastBottom, mGraphPaint);
if (mShowValues && barModel.isShowValue()) {
_Canvas.drawText(String.valueOf(barModel.getValue()), bounds.centerX(), (lastTop + height / 2) + barModel.getValueBounds().height() / 2, mTextPaint);
}
lastBottom = lastTop;
if (mShowSeparators && index < model.getBars().size() - 1) {
lastBottom -= mSeparatorWidth;
}
}
}
}
use of org.eazegraph.lib.models.StackedBarModel in project EazeGraph by blackfizz.
the class StackedBarChart method initializeGraph.
/**
* This is the main entry point after the graph has been inflated. Used to initialize the graph
* and its corresponding members.
*/
@Override
protected void initializeGraph() {
super.initializeGraph();
mData = new ArrayList<>();
mSeperatorPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mSeperatorPaint.setStyle(Paint.Style.FILL_AND_STROKE);
mSeperatorPaint.setStrokeWidth(mSeparatorWidth);
mSeperatorPaint.setColor(0xFFFFFFFF);
mTextPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mTextPaint.setTextSize(mTextSize);
mTextPaint.setTextAlign(Paint.Align.CENTER);
mTextPaint.setColor(0xFFFFFFFF);
if (this.isInEditMode()) {
StackedBarModel s1 = new StackedBarModel();
s1.addBar(new BarModel(2.3f, 0xFF123456));
s1.addBar(new BarModel(2.f, 0xFF1EF556));
s1.addBar(new BarModel(3.3f, 0xFF1BA4E6));
StackedBarModel s2 = new StackedBarModel();
s2.addBar(new BarModel(1.1f, 0xFF123456));
s2.addBar(new BarModel(2.7f, 0xFF1EF556));
s2.addBar(new BarModel(0.7f, 0xFF1BA4E6));
addBar(s1);
addBar(s2);
}
}
use of org.eazegraph.lib.models.StackedBarModel in project EazeGraph by blackfizz.
the class StackedBarChart method calculateBounds.
/**
* Calculates the bar boundaries based on the bar width and bar margin.
* @param _Width Calculated bar width
* @param _Margin Calculated bar margin
*/
protected void calculateBounds(float _Width, float _Margin) {
int last = 0;
for (StackedBarModel model : mData) {
float lastY = 0;
float cumulatedValues = 0;
// used if seperators are enabled, to prevent information loss
int usableGraphHeight = mGraphHeight - (int) (mSeparatorWidth * (model.getBars().size() - 1));
for (BarModel barModel : model.getBars()) {
cumulatedValues += barModel.getValue();
}
last += _Margin / 2;
for (BarModel barModel : model.getBars()) {
// calculate topX for the StackedBarModel part
float newY = ((barModel.getValue() * usableGraphHeight) / cumulatedValues) + lastY;
float height = newY - lastY;
Rect textBounds = new Rect();
String value = String.valueOf(barModel.getValue());
mTextPaint.getTextBounds(value, 0, value.length(), textBounds);
if (textBounds.height() * 1.5f < height && textBounds.width() * 1.1f < _Width) {
barModel.setShowValue(true);
barModel.setValueBounds(textBounds);
}
barModel.setBarBounds(new RectF(last, lastY, last + _Width, newY));
lastY = newY;
}
model.setLegendBounds(new RectF(last, 0, last + _Width, mLegendHeight));
last += _Width + (_Margin / 2);
}
Utils.calculateLegendInformation(mData, 0, mContentRect.width(), mLegendPaint);
}
Aggregations