use of com.jjoe64.graphview.series.BaseSeries in project GraphView by appsthatmatter.
the class CursorMode method drawLegend.
protected void drawLegend(Canvas canvas) {
mTextPaint.setTextSize(mStyles.textSize);
mTextPaint.setColor(mStyles.textColor);
int shapeSize = (int) (mStyles.textSize * 0.8d);
// width
int legendWidth = mStyles.width;
if (legendWidth == 0) {
// auto
legendWidth = cachedLegendWidth;
if (legendWidth == 0) {
Rect textBounds = new Rect();
for (Map.Entry<BaseSeries, DataPointInterface> entry : mCurrentSelection.entrySet()) {
String txt = getTextForSeries(entry.getKey(), entry.getValue());
mTextPaint.getTextBounds(txt, 0, txt.length(), textBounds);
legendWidth = Math.max(legendWidth, textBounds.width());
}
if (legendWidth == 0)
legendWidth = 1;
// add shape size
legendWidth += shapeSize + mStyles.padding * 2 + mStyles.spacing;
cachedLegendWidth = legendWidth;
}
}
float legendPosX = mPosX - mStyles.margin - legendWidth;
if (legendPosX < 0) {
legendPosX = 0;
}
// rect
float legendHeight = (mStyles.textSize + mStyles.spacing) * (mCurrentSelection.size() + 1) - mStyles.spacing;
float legendPosY = mPosY - legendHeight - 4.5f * mStyles.textSize;
if (legendPosY < 0) {
legendPosY = 0;
}
float lLeft;
float lTop;
lLeft = legendPosX;
lTop = legendPosY;
float lRight = lLeft + legendWidth;
float lBottom = lTop + legendHeight + 2 * mStyles.padding;
mRectPaint.setColor(mStyles.backgroundColor);
canvas.drawRoundRect(new RectF(lLeft, lTop, lRight, lBottom), 8, 8, mRectPaint);
mTextPaint.setFakeBoldText(true);
canvas.drawText(mGraphView.getGridLabelRenderer().getLabelFormatter().formatLabel(mCurrentSelectionX, true), lLeft + mStyles.padding, lTop + mStyles.padding / 2 + mStyles.textSize, mTextPaint);
mTextPaint.setFakeBoldText(false);
int i = 1;
for (Map.Entry<BaseSeries, DataPointInterface> entry : mCurrentSelection.entrySet()) {
mRectPaint.setColor(entry.getKey().getColor());
canvas.drawRect(new RectF(lLeft + mStyles.padding, lTop + mStyles.padding + (i * (mStyles.textSize + mStyles.spacing)), lLeft + mStyles.padding + shapeSize, lTop + mStyles.padding + (i * (mStyles.textSize + mStyles.spacing)) + shapeSize), mRectPaint);
canvas.drawText(getTextForSeries(entry.getKey(), entry.getValue()), lLeft + mStyles.padding + shapeSize + mStyles.spacing, lTop + mStyles.padding / 2 + mStyles.textSize + (i * (mStyles.textSize + mStyles.spacing)), mTextPaint);
i++;
}
}
use of com.jjoe64.graphview.series.BaseSeries in project GraphView by appsthatmatter.
the class GraphView method setCursorMode.
public void setCursorMode(boolean b) {
mIsCursorMode = b;
if (mIsCursorMode) {
if (mCursorMode == null) {
mCursorMode = new CursorMode(this);
}
} else {
mCursorMode = null;
invalidate();
}
for (Series series : mSeries) {
if (series instanceof BaseSeries) {
((BaseSeries) series).clearCursorModeCache();
}
}
}
use of com.jjoe64.graphview.series.BaseSeries in project GraphView by appsthatmatter.
the class CursorMode method findCurrentDataPoint.
private void findCurrentDataPoint() {
double selX = 0;
mCurrentSelection.clear();
for (Series series : mGraphView.getSeries()) {
if (series instanceof BaseSeries) {
DataPointInterface p = ((BaseSeries) series).findDataPointAtX(mPosX);
if (p != null) {
selX = p.getX();
mCurrentSelection.put((BaseSeries) series, p);
}
}
}
if (!mCurrentSelection.isEmpty()) {
mCurrentSelectionX = selX;
}
}
Aggregations