use of org.eazegraph.lib.models.BaseModel in project EazeGraph by blackfizz.
the class ValueLineChart method onLegendDraw.
@Override
protected void onLegendDraw(Canvas _Canvas) {
super.onLegendDraw(_Canvas);
mLegendPaint.setColor(mLegendColor);
mLegendPaint.setStrokeWidth(DEF_LEGEND_STROKE);
if (!mSeries.isEmpty()) {
_Canvas.translate(Utils.getTranslationX(mDrawMatrixValues), 0);
if (mUseCustomLegend) {
for (LegendModel model : mLegendList) {
RectF bounds = model.getLegendBounds();
_Canvas.drawText(model.getLegendLabel(), model.getLegendLabelPosition(), bounds.bottom - mMaxFontHeight, mLegendPaint);
_Canvas.drawLine(bounds.centerX(), bounds.bottom - mMaxFontHeight * 2 - mLegendTopPadding, bounds.centerX(), mLegendTopPadding, mLegendPaint);
}
} else {
List<? extends BaseModel> list = mSeries.get(0).getSeries();
for (BaseModel model : list) {
if (model.canShowLabel()) {
RectF bounds = model.getLegendBounds();
_Canvas.drawText(model.getLegendLabel(), model.getLegendLabelPosition(), bounds.bottom - mMaxFontHeight, mLegendPaint);
_Canvas.drawLine(bounds.centerX(), bounds.bottom - mMaxFontHeight * 2 - mLegendTopPadding, bounds.centerX(), mLegendTopPadding, mLegendPaint);
}
}
}
}
}
use of org.eazegraph.lib.models.BaseModel in project EazeGraph by blackfizz.
the class Utils method calculateLegendInformation.
/**
* Calculates the legend positions and which legend title should be displayed or not.
*
* Important: the LegendBounds in the _Models should be set and correctly calculated before this
* function is called!
* @param _Models The graph data which should have the BaseModel class as parent class.
* @param _StartX Left starting point on the screen. Should be the absolute pixel value!
* @param _Paint The correctly set Paint which will be used for the text painting in the later process
*/
public static void calculateLegendInformation(List<? extends BaseModel> _Models, float _StartX, float _EndX, Paint _Paint) {
float textMargin = Utils.dpToPx(10.f);
float lastX = _StartX;
// if not the label will not be shown
for (BaseModel model : _Models) {
if (!model.isIgnore()) {
Rect textBounds = new Rect();
RectF legendBounds = model.getLegendBounds();
_Paint.getTextBounds(model.getLegendLabel(), 0, model.getLegendLabel().length(), textBounds);
model.setTextBounds(textBounds);
float centerX = legendBounds.centerX();
float centeredTextPos = centerX - (textBounds.width() / 2);
float textStartPos = centeredTextPos - textMargin;
// check if the text is too big to fit on the screen
if (centeredTextPos + textBounds.width() > _EndX - textMargin) {
model.setShowLabel(false);
} else {
// If not the label will be shown and the label position is calculated
if (textStartPos < lastX) {
if (lastX + textMargin < legendBounds.left) {
model.setLegendLabelPosition((int) (lastX + textMargin));
model.setShowLabel(true);
lastX = lastX + textMargin + textBounds.width();
} else {
model.setShowLabel(false);
}
} else {
model.setShowLabel(true);
model.setLegendLabelPosition((int) centeredTextPos);
lastX = centerX + (textBounds.width() / 2);
}
}
}
}
}
use of org.eazegraph.lib.models.BaseModel in project EazeGraph by blackfizz.
the class BaseBarChart method onLegendDraw.
@Override
protected void onLegendDraw(Canvas _Canvas) {
super.onLegendDraw(_Canvas);
_Canvas.translate(-mCurrentViewport.left, 0);
for (BaseModel model : getLegendData()) {
if (model.canShowLabel()) {
RectF bounds = model.getLegendBounds();
_Canvas.drawText(model.getLegendLabel(), model.getLegendLabelPosition(), bounds.bottom - mMaxFontHeight, mLegendPaint);
_Canvas.drawLine(bounds.centerX(), bounds.bottom - mMaxFontHeight * 2 - mLegendTopPadding, bounds.centerX(), mLegendTopPadding, mLegendPaint);
}
}
}
Aggregations