Search in sources :

Example 56 with Entry

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

the class LineChart method drawAdditional.

/**
     * draws the circle value indicators
     */
@Override
protected void drawAdditional() {
    mRenderPaint.setStyle(Paint.Style.FILL);
    ArrayList<LineDataSet> dataSets = mData.getDataSets();
    for (int i = 0; i < mData.getDataSetCount(); i++) {
        LineDataSet dataSet = dataSets.get(i);
        // if drawing circles is enabled for this dataset
        if (dataSet.isDrawCirclesEnabled()) {
            ArrayList<Entry> entries = dataSet.getYVals();
            float[] positions = mTrans.generateTransformedValuesLineScatter(entries, mPhaseY);
            for (int j = 0; j < positions.length * mPhaseX; j += 2) {
                // Set the color for the currently drawn value. If the index
                // is
                // out of bounds, reuse colors.
                mRenderPaint.setColor(dataSet.getCircleColor(j / 2));
                if (isOffContentRight(positions[j]))
                    break;
                // bounds
                if (isOffContentLeft(positions[j]) || isOffContentTop(positions[j + 1]) || isOffContentBottom(positions[j + 1]))
                    continue;
                mDrawCanvas.drawCircle(positions[j], positions[j + 1], dataSet.getCircleSize(), mRenderPaint);
                mDrawCanvas.drawCircle(positions[j], positions[j + 1], dataSet.getCircleSize() / 2f, mCirclePaintInner);
            }
        }
    // else do nothing
    }
}
Also used : Entry(com.github.mikephil.charting.data.Entry) LineDataSet(com.github.mikephil.charting.data.LineDataSet) Paint(android.graphics.Paint)

Example 57 with Entry

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

the class LineChart method drawValues.

@Override
protected void drawValues() {
    // if values are drawn
    if (mDrawYValues && mData.getYValCount() < mMaxVisibleCount * mTrans.getScaleX()) {
        ArrayList<LineDataSet> dataSets = mData.getDataSets();
        for (int i = 0; i < mData.getDataSetCount(); i++) {
            LineDataSet dataSet = dataSets.get(i);
            // make sure the values do not interfear with the circles
            int valOffset = (int) (dataSet.getCircleSize() * 1.75f);
            if (!dataSet.isDrawCirclesEnabled())
                valOffset = valOffset / 2;
            ArrayList<Entry> entries = dataSet.getYVals();
            float[] positions = mTrans.generateTransformedValuesLineScatter(entries, mPhaseY);
            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] - valOffset, mValuePaint);
                } else {
                    mDrawCanvas.drawText(mValueFormatter.getFormattedValue(val), positions[j], positions[j + 1] - valOffset, mValuePaint);
                }
            }
        }
    }
}
Also used : Entry(com.github.mikephil.charting.data.Entry) LineDataSet(com.github.mikephil.charting.data.LineDataSet) Paint(android.graphics.Paint)

Example 58 with Entry

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

the class PieChart method drawData.

@Override
protected void drawData() {
    float angle = mRotationAngle;
    ArrayList<PieDataSet> dataSets = mData.getDataSets();
    int cnt = 0;
    for (int i = 0; i < mData.getDataSetCount(); i++) {
        PieDataSet dataSet = dataSets.get(i);
        ArrayList<Entry> entries = dataSet.getYVals();
        for (int j = 0; j < entries.size(); j++) {
            float newangle = mDrawAngles[cnt];
            float sliceSpace = dataSet.getSliceSpace();
            Entry e = entries.get(j);
            // draw only if the value is greater than zero
            if ((Math.abs(e.getVal()) > 0.000001)) {
                if (!needsHighlight(e.getXIndex(), i)) {
                    mRenderPaint.setColor(dataSet.getColor(j));
                    mDrawCanvas.drawArc(mCircleBox, angle + sliceSpace / 2f, newangle * mPhaseY - sliceSpace / 2f, true, mRenderPaint);
                }
            // if(sliceSpace > 0f) {
            //
            // PointF outer = getPosition(c, radius, angle);
            // PointF inner = getPosition(c, radius * mHoleRadiusPercent
            // / 100f, angle);
            // }
            }
            angle += newangle * mPhaseX;
            cnt++;
        }
    }
}
Also used : Entry(com.github.mikephil.charting.data.Entry) PieDataSet(com.github.mikephil.charting.data.PieDataSet) Paint(android.graphics.Paint)

Example 59 with Entry

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

the class PieChart method drawValues.

@Override
protected void drawValues() {
    // if neither xvals nor yvals are drawn, return
    if (!mDrawXVals && !mDrawYValues)
        return;
    PointF center = getCenterCircleBox();
    // get whole the radius
    float r = getRadius();
    float off = r / 2f;
    if (mDrawHole) {
        off = (r - (r / 100f * mHoleRadiusPercent)) / 2f;
    }
    // offset to keep things inside the chart
    r -= off;
    ArrayList<PieDataSet> dataSets = mData.getDataSets();
    int cnt = 0;
    for (int i = 0; i < mData.getDataSetCount(); i++) {
        PieDataSet dataSet = dataSets.get(i);
        ArrayList<Entry> entries = dataSet.getYVals();
        for (int j = 0; j < entries.size() * mPhaseX; j++) {
            // offset needed to center the drawn text in the slice
            float offset = mDrawAngles[cnt] / 2;
            // calculate the text position
            float x = (float) (r * Math.cos(Math.toRadians((mRotationAngle + mAbsoluteAngles[cnt] - offset) * mPhaseY)) + center.x);
            float y = (float) (r * Math.sin(Math.toRadians((mRotationAngle + mAbsoluteAngles[cnt] - offset) * mPhaseY)) + center.y);
            String val = "";
            float value = entries.get(j).getVal();
            if (mUsePercentValues)
                val = mValueFormatter.getFormattedValue(Math.abs(getPercentOfTotal(value))) + " %";
            else
                val = mValueFormatter.getFormattedValue(value);
            if (mDrawUnitInChart)
                val = val + mUnit;
            // draw everything, depending on settings
            if (mDrawXVals && mDrawYValues) {
                // use ascent and descent to calculate the new line
                // position,
                // 1.6f is the line spacing
                float lineHeight = (mValuePaint.ascent() + mValuePaint.descent()) * 1.6f;
                y -= lineHeight / 2;
                mDrawCanvas.drawText(val, x, y, mValuePaint);
                if (j < mData.getXValCount())
                    mDrawCanvas.drawText(mData.getXVals().get(j), x, y + lineHeight, mValuePaint);
            } else if (mDrawXVals && !mDrawYValues) {
                if (j < mData.getXValCount())
                    mDrawCanvas.drawText(mData.getXVals().get(j), x, y, mValuePaint);
            } else if (!mDrawXVals && mDrawYValues) {
                mDrawCanvas.drawText(val, x, y, mValuePaint);
            }
            cnt++;
        }
    }
}
Also used : Entry(com.github.mikephil.charting.data.Entry) PieDataSet(com.github.mikephil.charting.data.PieDataSet) PointF(android.graphics.PointF) Paint(android.graphics.Paint)

Example 60 with Entry

use of com.github.mikephil.charting.data.Entry in project Gadgetbridge by Freeyourgadget.

the class SleepChartFragment method refreshSleepAmounts.

private MySleepChartsData refreshSleepAmounts(GBDevice mGBDevice, List<? extends ActivitySample> samples) {
    ActivityAnalysis analysis = new ActivityAnalysis();
    ActivityAmounts amounts = analysis.calculateActivityAmounts(samples);
    PieData data = new PieData();
    List<PieEntry> entries = new ArrayList<>();
    List<Integer> colors = new ArrayList<>();
    //        int index = 0;
    long totalSeconds = 0;
    for (ActivityAmount amount : amounts.getAmounts()) {
        if ((amount.getActivityKind() & ActivityKind.TYPE_SLEEP) != 0) {
            long value = amount.getTotalSeconds();
            totalSeconds += value;
            //                entries.add(new PieEntry(value, index++));
            entries.add(new PieEntry(value, amount.getName(getActivity())));
            colors.add(getColorFor(amount.getActivityKind()));
        //                data.addXValue(amount.getName(getActivity()));
        }
    }
    String totalSleep = DateTimeUtils.formatDurationHoursMinutes(totalSeconds, TimeUnit.SECONDS);
    PieDataSet set = new PieDataSet(entries, "");
    set.setValueFormatter(new IValueFormatter() {

        @Override
        public String getFormattedValue(float value, Entry entry, int dataSetIndex, ViewPortHandler viewPortHandler) {
            return DateTimeUtils.formatDurationHoursMinutes((long) value, TimeUnit.SECONDS);
        }
    });
    set.setColors(colors);
    data.setDataSet(set);
    //setupLegend(pieChart);
    return new MySleepChartsData(totalSleep, data);
}
Also used : PieEntry(com.github.mikephil.charting.data.PieEntry) ArrayList(java.util.ArrayList) ActivityAmount(nodomain.freeyourgadget.gadgetbridge.model.ActivityAmount) ViewPortHandler(com.github.mikephil.charting.utils.ViewPortHandler) Entry(com.github.mikephil.charting.data.Entry) LegendEntry(com.github.mikephil.charting.components.LegendEntry) PieEntry(com.github.mikephil.charting.data.PieEntry) IValueFormatter(com.github.mikephil.charting.formatter.IValueFormatter) ActivityAmounts(nodomain.freeyourgadget.gadgetbridge.model.ActivityAmounts) PieDataSet(com.github.mikephil.charting.data.PieDataSet) PieData(com.github.mikephil.charting.data.PieData)

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