use of org.eazegraph.lib.models.BarModel 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.BarModel 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);
}
use of org.eazegraph.lib.models.BarModel in project EazeGraph by blackfizz.
the class VerticalBarChart 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;
float maxLegendWidth = 0;
if (mUseMaximumValue) {
maxValue = mMaximumValue;
} else {
for (BarModel model : mData) {
if (model.getValue() > maxValue) {
maxValue = model.getValue();
}
}
}
if (mShowBarLabel) {
float measuredText;
for (BarModel model : mData) {
measuredText = mValuePaint.measureText(model.getLegendLabel());
if (maxLegendWidth < measuredText) {
maxLegendWidth = measuredText;
}
}
}
float legendWidthDistance = mShowBarLabel ? maxLegendWidth + mValueDistance : 0;
float widthMultiplier = (mGraphWidth - legendWidthDistance) / maxValue;
for (BarModel model : mData) {
float width = model.getValue() * widthMultiplier;
last += _Margin / 2;
model.setBarBounds(new RectF(0, last, width, last + _Width));
model.setLegendBounds(new RectF(last, 0, last + _Width, mLegendHeight));
last += _Width + (_Margin / 2);
}
Utils.calculateLegendInformation(mData, 0, mContentRect.width(), mLegendPaint);
mMaxFontHeight = Utils.calculateMaxTextHeight(mValuePaint, "190");
}
use of org.eazegraph.lib.models.BarModel in project EazeGraph by blackfizz.
the class VerticalBarChart 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) {
RectF bounds;
String valueString;
float animatedRightOffset;
for (BarModel model : mData) {
bounds = model.getBarBounds();
valueString = Utils.getFloatString(model.getValue(), mShowDecimal) + mValueUnit;
animatedRightOffset = bounds.right * mRevealValue;
mGraphPaint.setColor(model.getColor());
_Canvas.drawRect(bounds.left, bounds.top, bounds.right * mRevealValue, bounds.bottom, mGraphPaint);
if (mShowValues && animatedRightOffset > mValuePaint.measureText(valueString)) {
mValuePaint.setColor(mLegendColor);
_Canvas.drawText(valueString, bounds.left + mValueDistance, bounds.centerY() + (mMaxFontHeight / 2), mValuePaint);
}
if (mShowBarLabel) {
mValuePaint.setColor(mBarLabelColor);
_Canvas.drawText(model.getLegendLabel(), animatedRightOffset + mValueDistance, bounds.centerY() + (mMaxFontHeight / 2), mValuePaint);
}
}
}
use of org.eazegraph.lib.models.BarModel in project EazeGraph by blackfizz.
the class VerticalBarChart 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);
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));
}
}
Aggregations