Search in sources :

Example 16 with Transformer

use of com.github.mikephil.charting.utils.Transformer in project MPAndroidChart by PhilJay.

the class LineChartRenderer method drawCircles.

protected void drawCircles(Canvas c) {
    mRenderPaint.setStyle(Paint.Style.FILL);
    float phaseY = mAnimator.getPhaseY();
    mCirclesBuffer[0] = 0;
    mCirclesBuffer[1] = 0;
    List<ILineDataSet> dataSets = mChart.getLineData().getDataSets();
    for (int i = 0; i < dataSets.size(); i++) {
        ILineDataSet dataSet = dataSets.get(i);
        if (!dataSet.isVisible() || !dataSet.isDrawCirclesEnabled() || dataSet.getEntryCount() == 0)
            continue;
        mCirclePaintInner.setColor(dataSet.getCircleHoleColor());
        Transformer trans = mChart.getTransformer(dataSet.getAxisDependency());
        mXBounds.set(mChart, dataSet);
        float circleRadius = dataSet.getCircleRadius();
        float circleHoleRadius = dataSet.getCircleHoleRadius();
        boolean drawCircleHole = dataSet.isDrawCircleHoleEnabled() && circleHoleRadius < circleRadius && circleHoleRadius > 0.f;
        boolean drawTransparentCircleHole = drawCircleHole && dataSet.getCircleHoleColor() == ColorTemplate.COLOR_NONE;
        DataSetImageCache imageCache;
        if (mImageCaches.containsKey(dataSet)) {
            imageCache = mImageCaches.get(dataSet);
        } else {
            imageCache = new DataSetImageCache();
            mImageCaches.put(dataSet, imageCache);
        }
        boolean changeRequired = imageCache.init(dataSet);
        // only fill the cache with new bitmaps if a change is required
        if (changeRequired) {
            imageCache.fill(dataSet, drawCircleHole, drawTransparentCircleHole);
        }
        int boundsRangeCount = mXBounds.range + mXBounds.min;
        for (int j = mXBounds.min; j <= boundsRangeCount; j++) {
            Entry e = dataSet.getEntryForIndex(j);
            if (e == null)
                break;
            mCirclesBuffer[0] = e.getX();
            mCirclesBuffer[1] = e.getY() * phaseY;
            trans.pointValuesToPixel(mCirclesBuffer);
            if (!mViewPortHandler.isInBoundsRight(mCirclesBuffer[0]))
                break;
            if (!mViewPortHandler.isInBoundsLeft(mCirclesBuffer[0]) || !mViewPortHandler.isInBoundsY(mCirclesBuffer[1]))
                continue;
            Bitmap circleBitmap = imageCache.getBitmap(j);
            if (circleBitmap != null) {
                c.drawBitmap(circleBitmap, mCirclesBuffer[0] - circleRadius, mCirclesBuffer[1] - circleRadius, null);
            }
        }
    }
}
Also used : Entry(com.github.mikephil.charting.data.Entry) Bitmap(android.graphics.Bitmap) ILineDataSet(com.github.mikephil.charting.interfaces.datasets.ILineDataSet) Transformer(com.github.mikephil.charting.utils.Transformer) Paint(android.graphics.Paint)

Aggregations

Transformer (com.github.mikephil.charting.utils.Transformer)16 Paint (android.graphics.Paint)10 Entry (com.github.mikephil.charting.data.Entry)6 BarEntry (com.github.mikephil.charting.data.BarEntry)5 Drawable (android.graphics.drawable.Drawable)4 BarBuffer (com.github.mikephil.charting.buffer.BarBuffer)4 MPPointF (com.github.mikephil.charting.utils.MPPointF)4 BarData (com.github.mikephil.charting.data.BarData)3 IBarDataSet (com.github.mikephil.charting.interfaces.datasets.IBarDataSet)3 HorizontalBarBuffer (com.github.mikephil.charting.buffer.HorizontalBarBuffer)2 BubbleEntry (com.github.mikephil.charting.data.BubbleEntry)2 CandleEntry (com.github.mikephil.charting.data.CandleEntry)2 Highlight (com.github.mikephil.charting.highlight.Highlight)2 ILineDataSet (com.github.mikephil.charting.interfaces.datasets.ILineDataSet)2 Bitmap (android.graphics.Bitmap)1 Canvas (android.graphics.Canvas)1 YAxis (com.github.mikephil.charting.components.YAxis)1 BubbleData (com.github.mikephil.charting.data.BubbleData)1 IValueFormatter (com.github.mikephil.charting.formatter.IValueFormatter)1 ChartHighlighter (com.github.mikephil.charting.highlight.ChartHighlighter)1