Search in sources :

Example 6 with LimitLine

use of com.github.mikephil.charting.components.LimitLine in project MPAndroidChart by PhilJay.

the class XAxisRendererHorizontalBarChart method renderLimitLines.

/**
	 * Draws the LimitLines associated with this axis to the screen.
	 * This is the standard YAxis renderer using the XAxis limit lines.
	 *
	 * @param c
	 */
@Override
public void renderLimitLines(Canvas c) {
    List<LimitLine> limitLines = mXAxis.getLimitLines();
    if (limitLines == null || limitLines.size() <= 0)
        return;
    float[] pts = mRenderLimitLinesBuffer;
    pts[0] = 0;
    pts[1] = 0;
    Path limitLinePath = mRenderLimitLinesPathBuffer;
    limitLinePath.reset();
    for (int i = 0; i < limitLines.size(); i++) {
        LimitLine l = limitLines.get(i);
        if (!l.isEnabled())
            continue;
        int clipRestoreCount = c.save();
        mLimitLineClippingRect.set(mViewPortHandler.getContentRect());
        mLimitLineClippingRect.inset(0.f, -l.getLineWidth());
        c.clipRect(mLimitLineClippingRect);
        mLimitLinePaint.setStyle(Paint.Style.STROKE);
        mLimitLinePaint.setColor(l.getLineColor());
        mLimitLinePaint.setStrokeWidth(l.getLineWidth());
        mLimitLinePaint.setPathEffect(l.getDashPathEffect());
        pts[1] = l.getLimit();
        mTrans.pointValuesToPixel(pts);
        limitLinePath.moveTo(mViewPortHandler.contentLeft(), pts[1]);
        limitLinePath.lineTo(mViewPortHandler.contentRight(), pts[1]);
        c.drawPath(limitLinePath, mLimitLinePaint);
        limitLinePath.reset();
        // c.drawLines(pts, mLimitLinePaint);
        String label = l.getLabel();
        // if drawing the limit-value label is enabled
        if (label != null && !label.equals("")) {
            mLimitLinePaint.setStyle(l.getTextStyle());
            mLimitLinePaint.setPathEffect(null);
            mLimitLinePaint.setColor(l.getTextColor());
            mLimitLinePaint.setStrokeWidth(0.5f);
            mLimitLinePaint.setTextSize(l.getTextSize());
            final float labelLineHeight = Utils.calcTextHeight(mLimitLinePaint, label);
            float xOffset = Utils.convertDpToPixel(4f) + l.getXOffset();
            float yOffset = l.getLineWidth() + labelLineHeight + l.getYOffset();
            final LimitLine.LimitLabelPosition position = l.getLabelPosition();
            if (position == LimitLine.LimitLabelPosition.RIGHT_TOP) {
                mLimitLinePaint.setTextAlign(Align.RIGHT);
                c.drawText(label, mViewPortHandler.contentRight() - xOffset, pts[1] - yOffset + labelLineHeight, mLimitLinePaint);
            } else if (position == LimitLine.LimitLabelPosition.RIGHT_BOTTOM) {
                mLimitLinePaint.setTextAlign(Align.RIGHT);
                c.drawText(label, mViewPortHandler.contentRight() - xOffset, pts[1] + yOffset, mLimitLinePaint);
            } else if (position == LimitLine.LimitLabelPosition.LEFT_TOP) {
                mLimitLinePaint.setTextAlign(Align.LEFT);
                c.drawText(label, mViewPortHandler.contentLeft() + xOffset, pts[1] - yOffset + labelLineHeight, mLimitLinePaint);
            } else {
                mLimitLinePaint.setTextAlign(Align.LEFT);
                c.drawText(label, mViewPortHandler.offsetLeft() + xOffset, pts[1] + yOffset, mLimitLinePaint);
            }
        }
        c.restoreToCount(clipRestoreCount);
    }
}
Also used : Path(android.graphics.Path) LimitLine(com.github.mikephil.charting.components.LimitLine) Paint(android.graphics.Paint)

Example 7 with LimitLine

use of com.github.mikephil.charting.components.LimitLine in project MPAndroidChart by PhilJay.

the class YAxisRendererRadarChart method renderLimitLines.

@Override
public void renderLimitLines(Canvas c) {
    List<LimitLine> limitLines = mYAxis.getLimitLines();
    if (limitLines == null)
        return;
    float sliceangle = mChart.getSliceAngle();
    // calculate the factor that is needed for transforming the value to
    // pixels
    float factor = mChart.getFactor();
    MPPointF center = mChart.getCenterOffsets();
    MPPointF pOut = MPPointF.getInstance(0, 0);
    for (int i = 0; i < limitLines.size(); i++) {
        LimitLine l = limitLines.get(i);
        if (!l.isEnabled())
            continue;
        mLimitLinePaint.setColor(l.getLineColor());
        mLimitLinePaint.setPathEffect(l.getDashPathEffect());
        mLimitLinePaint.setStrokeWidth(l.getLineWidth());
        float r = (l.getLimit() - mChart.getYChartMin()) * factor;
        Path limitPath = mRenderLimitLinesPathBuffer;
        limitPath.reset();
        for (int j = 0; j < mChart.getData().getMaxEntryCountSet().getEntryCount(); j++) {
            Utils.getPosition(center, r, sliceangle * j + mChart.getRotationAngle(), pOut);
            if (j == 0)
                limitPath.moveTo(pOut.x, pOut.y);
            else
                limitPath.lineTo(pOut.x, pOut.y);
        }
        limitPath.close();
        c.drawPath(limitPath, mLimitLinePaint);
    }
    MPPointF.recycleInstance(center);
    MPPointF.recycleInstance(pOut);
}
Also used : Path(android.graphics.Path) MPPointF(com.github.mikephil.charting.utils.MPPointF) LimitLine(com.github.mikephil.charting.components.LimitLine)

Example 8 with LimitLine

use of com.github.mikephil.charting.components.LimitLine in project Gadgetbridge by Freeyourgadget.

the class AbstractWeekChartFragment method refreshWeekBeforeData.

private DefaultChartsData<BarData> refreshWeekBeforeData(DBHandler db, BarChart barChart, Calendar day, GBDevice device) {
    // do not modify the caller's argument
    day = (Calendar) day.clone();
    day.add(Calendar.DATE, -7);
    List<BarEntry> entries = new ArrayList<>();
    ArrayList<String> labels = new ArrayList<String>();
    for (int counter = 0; counter < 7; counter++) {
        ActivityAmounts amounts = getActivityAmountsForDay(db, day, device);
        entries.add(new BarEntry(counter, getTotalsForActivityAmounts(amounts)));
        labels.add(day.getDisplayName(Calendar.DAY_OF_WEEK, Calendar.SHORT, mLocale));
        day.add(Calendar.DATE, 1);
    }
    BarDataSet set = new BarDataSet(entries, "");
    set.setColors(getColors());
    set.setValueFormatter(getBarValueFormatter());
    BarData barData = new BarData(set);
    //prevent tearing other graph elements with the black text. Another approach would be to hide the values cmpletely with data.setDrawValues(false);
    barData.setValueTextColor(Color.GRAY);
    LimitLine target = new LimitLine(mTargetValue);
    barChart.getAxisLeft().removeAllLimitLines();
    barChart.getAxisLeft().addLimitLine(target);
    return new DefaultChartsData(barData, new PreformattedXIndexLabelFormatter(labels));
}
Also used : BarDataSet(com.github.mikephil.charting.data.BarDataSet) ActivityAmounts(nodomain.freeyourgadget.gadgetbridge.model.ActivityAmounts) BarData(com.github.mikephil.charting.data.BarData) ArrayList(java.util.ArrayList) LimitLine(com.github.mikephil.charting.components.LimitLine) BarEntry(com.github.mikephil.charting.data.BarEntry)

Aggregations

LimitLine (com.github.mikephil.charting.components.LimitLine)8 Paint (android.graphics.Paint)5 Path (android.graphics.Path)4 YAxis (com.github.mikephil.charting.components.YAxis)2 BarEntry (com.github.mikephil.charting.data.BarEntry)2 Typeface (android.graphics.Typeface)1 Legend (com.github.mikephil.charting.components.Legend)1 XAxis (com.github.mikephil.charting.components.XAxis)1 BarData (com.github.mikephil.charting.data.BarData)1 BarDataSet (com.github.mikephil.charting.data.BarDataSet)1 ChartData (com.github.mikephil.charting.data.ChartData)1 Entry (com.github.mikephil.charting.data.Entry)1 MPPointF (com.github.mikephil.charting.utils.MPPointF)1 MyMarkerView (com.xxmassdeveloper.mpchartexample.custom.MyMarkerView)1 ArrayList (java.util.ArrayList)1 ActivityAmounts (nodomain.freeyourgadget.gadgetbridge.model.ActivityAmounts)1