Search in sources :

Example 51 with Entry

use of com.github.mikephil.charting.data.Entry in project carat by amplab.

the class RadarChart method drawHighlights.

@Override
protected void drawHighlights() {
    // if there are values to highlight and highlighnting is enabled, do it
    if (mHighlightEnabled && valuesToHighlight()) {
        float sliceangle = getSliceAngle();
        float factor = getFactor();
        PointF c = getCenterOffsets();
        for (int i = 0; i < mIndicesToHightlight.length; i++) {
            RadarDataSet set = mData.getDataSetByIndex(mIndicesToHightlight[i].getDataSetIndex());
            if (set == null)
                continue;
            mHighlightPaint.setColor(set.getHighLightColor());
            // get the index to highlight
            int xIndex = mIndicesToHightlight[i].getXIndex();
            Entry e = set.getEntryForXIndex(xIndex);
            int j = set.getEntryPosition(e);
            float y = e.getVal();
            PointF p = getPosition(c, y * factor, sliceangle * j + mRotationAngle);
            float[] pts = new float[] { p.x, 0, p.x, getHeight(), 0, p.y, getWidth(), p.y };
            mDrawCanvas.drawLines(pts, mHighlightPaint);
        }
    }
}
Also used : RadarDataSet(com.github.mikephil.charting.data.RadarDataSet) Entry(com.github.mikephil.charting.data.Entry) PointF(android.graphics.PointF) Paint(android.graphics.Paint)

Example 52 with Entry

use of com.github.mikephil.charting.data.Entry in project carat by amplab.

the class RadarChart method drawData.

@Override
protected void drawData() {
    ArrayList<RadarDataSet> dataSets = mData.getDataSets();
    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 < mData.getDataSetCount(); i++) {
        RadarDataSet dataSet = dataSets.get(i);
        ArrayList<Entry> entries = dataSet.getYVals();
        Path surface = new Path();
        for (int j = 0; j < entries.size(); j++) {
            mRenderPaint.setColor(dataSet.getColor(j));
            Entry e = entries.get(j);
            PointF p = getPosition(c, e.getVal() * factor, sliceangle * j + mRotationAngle);
            if (j == 0)
                surface.moveTo(p.x, p.y);
            else
                surface.lineTo(p.x, p.y);
        }
        surface.close();
        // draw filled
        if (dataSet.isDrawFilledEnabled()) {
            mRenderPaint.setStyle(Paint.Style.FILL);
            mRenderPaint.setAlpha(dataSet.getFillAlpha());
            mDrawCanvas.drawPath(surface, mRenderPaint);
            mRenderPaint.setAlpha(255);
        }
        mRenderPaint.setStrokeWidth(dataSet.getLineWidth());
        mRenderPaint.setStyle(Paint.Style.STROKE);
        // draw the line (only if filled is disabled or alpha is below 255)
        if (!dataSet.isDrawFilledEnabled() || dataSet.getFillAlpha() < 255)
            mDrawCanvas.drawPath(surface, mRenderPaint);
    }
}
Also used : Path(android.graphics.Path) RadarDataSet(com.github.mikephil.charting.data.RadarDataSet) Entry(com.github.mikephil.charting.data.Entry) PointF(android.graphics.PointF) Paint(android.graphics.Paint)

Example 53 with Entry

use of com.github.mikephil.charting.data.Entry in project carat by amplab.

the class RadarChart method drawValues.

@Override
protected void drawValues() {
    // if values are drawn
    if (mDrawYValues) {
        float sliceangle = getSliceAngle();
        // calculate the factor that is needed for transforming the value to
        // pixels
        float factor = getFactor();
        PointF c = getCenterOffsets();
        float yoffset = Utils.convertDpToPixel(5f);
        for (int i = 0; i < mData.getDataSetCount(); i++) {
            RadarDataSet dataSet = mData.getDataSetByIndex(i);
            ArrayList<Entry> entries = dataSet.getYVals();
            for (int j = 0; j < entries.size(); j++) {
                Entry e = entries.get(j);
                PointF p = getPosition(c, e.getVal() * factor, sliceangle * j + mRotationAngle);
                if (mDrawUnitInChart)
                    mDrawCanvas.drawText(mValueFormatter.getFormattedValue(e.getVal()) + mUnit, p.x, p.y - yoffset, mValuePaint);
                else
                    mDrawCanvas.drawText(mValueFormatter.getFormattedValue(e.getVal()), p.x, p.y - yoffset, mValuePaint);
            }
        }
    }
}
Also used : RadarDataSet(com.github.mikephil.charting.data.RadarDataSet) Entry(com.github.mikephil.charting.data.Entry) PointF(android.graphics.PointF) Paint(android.graphics.Paint)

Example 54 with Entry

use of com.github.mikephil.charting.data.Entry in project carat by amplab.

the class ScatterChart method drawValues.

@Override
protected void drawValues() {
    // if values are drawn
    if (mDrawYValues && mData.getYValCount() < mMaxVisibleCount * mTrans.getScaleX()) {
        ArrayList<ScatterDataSet> dataSets = mData.getDataSets();
        for (int i = 0; i < mData.getDataSetCount(); i++) {
            ScatterDataSet dataSet = dataSets.get(i);
            ArrayList<Entry> entries = dataSet.getYVals();
            float[] positions = mTrans.generateTransformedValuesLineScatter(entries, mPhaseY);
            float shapeSize = dataSet.getScatterShapeSize();
            for (int j = 0; j < positions.length * mPhaseX; j += 2) {
                if (isOffContentRight(positions[j]))
                    break;
                if (isOffContentLeft(positions[j]) || isOffContentTop(positions[j + 1]) || isOffContentBottom(positions[j + 1]))
                    continue;
                float val = entries.get(j / 2).getVal();
                if (mDrawUnitInChart) {
                    mDrawCanvas.drawText(mValueFormatter.getFormattedValue(val) + mUnit, positions[j], positions[j + 1] - shapeSize, mValuePaint);
                } else {
                    mDrawCanvas.drawText(mValueFormatter.getFormattedValue(val), positions[j], positions[j + 1] - shapeSize, mValuePaint);
                }
            }
        }
    }
}
Also used : Entry(com.github.mikephil.charting.data.Entry) ScatterDataSet(com.github.mikephil.charting.data.ScatterDataSet)

Example 55 with Entry

use of com.github.mikephil.charting.data.Entry in project carat by amplab.

the class ScatterChart method drawData.

@Override
protected void drawData() {
    ArrayList<ScatterDataSet> dataSets = mData.getDataSets();
    for (int i = 0; i < mData.getDataSetCount(); i++) {
        ScatterDataSet dataSet = dataSets.get(i);
        ArrayList<Entry> entries = dataSet.getYVals();
        float shapeHalf = dataSet.getScatterShapeSize() / 2f;
        float[] valuePoints = mTrans.generateTransformedValuesLineScatter(entries, mPhaseY);
        ScatterShape shape = dataSet.getScatterShape();
        for (int j = 0; j < valuePoints.length * mPhaseX; j += 2) {
            if (isOffContentRight(valuePoints[j]))
                break;
            // make sure the lines don't do shitty things outside bounds
            if (j != 0 && isOffContentLeft(valuePoints[j - 1]) && isOffContentTop(valuePoints[j + 1]) && isOffContentBottom(valuePoints[j + 1]))
                continue;
            // Set the color for the currently drawn value. If the index is
            // out of bounds, reuse colors.
            mRenderPaint.setColor(dataSet.getColor(j));
            if (shape == ScatterShape.SQUARE) {
                mDrawCanvas.drawRect(valuePoints[j] - shapeHalf, valuePoints[j + 1] - shapeHalf, valuePoints[j] + shapeHalf, valuePoints[j + 1] + shapeHalf, mRenderPaint);
            } else if (shape == ScatterShape.CIRCLE) {
                mDrawCanvas.drawCircle(valuePoints[j], valuePoints[j + 1], shapeHalf, mRenderPaint);
            } else if (shape == ScatterShape.CROSS) {
                mDrawCanvas.drawLine(valuePoints[j] - shapeHalf, valuePoints[j + 1], valuePoints[j] + shapeHalf, valuePoints[j + 1], mRenderPaint);
                mDrawCanvas.drawLine(valuePoints[j], valuePoints[j + 1] - shapeHalf, valuePoints[j], valuePoints[j + 1] + shapeHalf, mRenderPaint);
            } else if (shape == ScatterShape.TRIANGLE) {
                // create a triangle path
                Path tri = new Path();
                tri.moveTo(valuePoints[j], valuePoints[j + 1] - shapeHalf);
                tri.lineTo(valuePoints[j] + shapeHalf, valuePoints[j + 1] + shapeHalf);
                tri.lineTo(valuePoints[j] - shapeHalf, valuePoints[j + 1] + shapeHalf);
                tri.close();
                mDrawCanvas.drawPath(tri, mRenderPaint);
            } else if (shape == ScatterShape.CUSTOM) {
                Path customShape = dataSet.getCustomScatterShape();
                if (customShape == null)
                    return;
                // transform the provided custom path
                mTrans.pathValueToPixel(customShape);
                mDrawCanvas.drawPath(customShape, mRenderPaint);
            }
        }
    }
}
Also used : Path(android.graphics.Path) Entry(com.github.mikephil.charting.data.Entry) ScatterDataSet(com.github.mikephil.charting.data.ScatterDataSet)

Aggregations

Entry (com.github.mikephil.charting.data.Entry)83 ArrayList (java.util.ArrayList)34 Paint (android.graphics.Paint)27 LineData (com.github.mikephil.charting.data.LineData)20 LineDataSet (com.github.mikephil.charting.data.LineDataSet)19 ILineDataSet (com.github.mikephil.charting.interfaces.datasets.ILineDataSet)17 BarEntry (com.github.mikephil.charting.data.BarEntry)13 ScatterDataSet (com.github.mikephil.charting.data.ScatterDataSet)10 Path (android.graphics.Path)7 PieEntry (com.github.mikephil.charting.data.PieEntry)7 IOException (java.io.IOException)6 PointF (android.graphics.PointF)5 CandleEntry (com.github.mikephil.charting.data.CandleEntry)5 PieDataSet (com.github.mikephil.charting.data.PieDataSet)5 ScatterData (com.github.mikephil.charting.data.ScatterData)5 Highlight (com.github.mikephil.charting.highlight.Highlight)5 Transformer (com.github.mikephil.charting.utils.Transformer)5 Test (org.junit.Test)5 MPPointF (com.github.mikephil.charting.utils.MPPointF)4 SuppressLint (android.annotation.SuppressLint)3