use of org.eazegraph.lib.models.BarModel 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.BarModel in project EazeGraph by blackfizz.
the class BarChart 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 (BarModel model : mData) {
RectF bounds = model.getBarBounds();
mGraphPaint.setColor(model.getColor());
_Canvas.drawRect(bounds.left, bounds.bottom - (bounds.height() * mRevealValue), bounds.right, bounds.bottom, mGraphPaint);
if (mShowValues) {
_Canvas.drawText(Utils.getFloatString(model.getValue(), mShowDecimal), model.getLegendBounds().centerX(), bounds.bottom - (bounds.height() * mRevealValue) - mValueDistance, mValuePaint);
}
}
}
use of org.eazegraph.lib.models.BarModel in project EazeGraph by blackfizz.
the class BarChart 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) {
float maxValue = 0;
int last = 0;
for (BarModel model : mData) {
if (model.getValue() > maxValue) {
maxValue = model.getValue();
}
}
int valuePadding = mShowValues ? (int) mValuePaint.getTextSize() + mValueDistance : 0;
float heightMultiplier = (mGraphHeight - valuePadding) / maxValue;
for (BarModel model : mData) {
float height = model.getValue() * heightMultiplier;
last += _Margin / 2;
model.setBarBounds(new RectF(last, mGraphHeight - height, last + _Width, mGraphHeight));
model.setLegendBounds(new RectF(last, 0, last + _Width, mLegendHeight));
last += _Width + (_Margin / 2);
}
Utils.calculateLegendInformation(mData, 0, mContentRect.width(), mLegendPaint);
}
use of org.eazegraph.lib.models.BarModel in project EazeGraph by blackfizz.
the class BarChart 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<>();
mValuePaint = new Paint(mLegendPaint);
mValuePaint.setTextAlign(Paint.Align.CENTER);
if (this.isInEditMode()) {
addBar(new BarModel(2.3f));
addBar(new BarModel(2.f));
addBar(new BarModel(3.3f));
addBar(new BarModel(1.1f));
addBar(new BarModel(2.7f));
addBar(new BarModel(2.3f));
addBar(new BarModel(2.f));
addBar(new BarModel(3.3f));
addBar(new BarModel(1.1f));
addBar(new BarModel(2.7f));
}
}
use of org.eazegraph.lib.models.BarModel 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;
}
}
}
}
Aggregations