Search in sources :

Example 1 with BaseSeries

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++;
    }
}
Also used : RectF(android.graphics.RectF) Rect(android.graphics.Rect) BaseSeries(com.jjoe64.graphview.series.BaseSeries) DataPointInterface(com.jjoe64.graphview.series.DataPointInterface) HashMap(java.util.HashMap) Map(java.util.Map) Paint(android.graphics.Paint)

Example 2 with BaseSeries

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();
        }
    }
}
Also used : BaseSeries(com.jjoe64.graphview.series.BaseSeries) Series(com.jjoe64.graphview.series.Series) BaseSeries(com.jjoe64.graphview.series.BaseSeries)

Example 3 with BaseSeries

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;
    }
}
Also used : BaseSeries(com.jjoe64.graphview.series.BaseSeries) Series(com.jjoe64.graphview.series.Series) BaseSeries(com.jjoe64.graphview.series.BaseSeries) DataPointInterface(com.jjoe64.graphview.series.DataPointInterface)

Aggregations

BaseSeries (com.jjoe64.graphview.series.BaseSeries)3 DataPointInterface (com.jjoe64.graphview.series.DataPointInterface)2 Series (com.jjoe64.graphview.series.Series)2 Paint (android.graphics.Paint)1 Rect (android.graphics.Rect)1 RectF (android.graphics.RectF)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1