Search in sources :

Example 1 with LimitLine

use of com.github.mikephil.charting.utils.LimitLine in project carat by amplab.

the class BarLineChartBase method drawLimitLines.

/**
     * Draws the limit lines if there are one.
     */
private void drawLimitLines() {
    ArrayList<LimitLine> limitLines = mData.getLimitLines();
    if (limitLines == null)
        return;
    float[] pts = new float[4];
    for (int i = 0; i < limitLines.size(); i++) {
        LimitLine l = limitLines.get(i);
        pts[1] = l.getLimit();
        pts[3] = l.getLimit();
        mTrans.pointValuesToPixel(pts);
        pts[0] = 0;
        pts[2] = getWidth();
        mLimitLinePaint.setColor(l.getLineColor());
        mLimitLinePaint.setPathEffect(l.getDashPathEffect());
        mLimitLinePaint.setStrokeWidth(l.getLineWidth());
        mDrawCanvas.drawLines(pts, mLimitLinePaint);
        // if drawing the limit-value is enabled
        if (l.isDrawValueEnabled()) {
            PointF pos = getPosition(new Entry(l.getLimit(), 0));
            // save text align
            Align align = mValuePaint.getTextAlign();
            float xOffset = Utils.convertDpToPixel(4f);
            float yOffset = l.getLineWidth() + xOffset;
            String label = mValueFormatter.getFormattedValue(l.getLimit());
            if (mDrawUnitInChart)
                label += mUnit;
            if (l.getLabelPosition() == LimitLabelPosition.RIGHT) {
                mValuePaint.setTextAlign(Align.RIGHT);
                mDrawCanvas.drawText(label, getWidth() - mOffsetRight - xOffset, pos.y - yOffset, mValuePaint);
            } else {
                mValuePaint.setTextAlign(Align.LEFT);
                mDrawCanvas.drawText(label, mOffsetLeft + xOffset, pos.y - yOffset, mValuePaint);
            }
            mValuePaint.setTextAlign(align);
        }
    }
}
Also used : Entry(com.github.mikephil.charting.data.Entry) Align(android.graphics.Paint.Align) PointF(android.graphics.PointF) LimitLine(com.github.mikephil.charting.utils.LimitLine) SuppressLint(android.annotation.SuppressLint) Paint(android.graphics.Paint)

Example 2 with LimitLine

use of com.github.mikephil.charting.utils.LimitLine in project carat by amplab.

the class RadarChart method drawLimitLines.

/**
     * Draws the limit lines if there are one.
     */
private void drawLimitLines() {
    ArrayList<LimitLine> limitLines = mData.getLimitLines();
    if (limitLines == null)
        return;
    float sliceangle = getSliceAngle();
    // calculate the factor that is needed for transforming the value to
    // pixels
    float factor = getFactor();
    PointF c = getCenterOffsets();
    for (int i = 0; i < limitLines.size(); i++) {
        LimitLine l = limitLines.get(i);
        mLimitLinePaint.setColor(l.getLineColor());
        mLimitLinePaint.setPathEffect(l.getDashPathEffect());
        mLimitLinePaint.setStrokeWidth(l.getLineWidth());
        float r = l.getLimit() * factor;
        Path limitPath = new Path();
        for (int j = 0; j < mData.getXValCount(); j++) {
            PointF p = getPosition(c, r, sliceangle * j + mRotationAngle);
            if (j == 0)
                limitPath.moveTo(p.x, p.y);
            else
                limitPath.lineTo(p.x, p.y);
        }
        limitPath.close();
        mDrawCanvas.drawPath(limitPath, mLimitLinePaint);
    }
}
Also used : Path(android.graphics.Path) PointF(android.graphics.PointF) LimitLine(com.github.mikephil.charting.utils.LimitLine) Paint(android.graphics.Paint)

Aggregations

Paint (android.graphics.Paint)2 PointF (android.graphics.PointF)2 LimitLine (com.github.mikephil.charting.utils.LimitLine)2 SuppressLint (android.annotation.SuppressLint)1 Align (android.graphics.Paint.Align)1 Path (android.graphics.Path)1 Entry (com.github.mikephil.charting.data.Entry)1