Search in sources :

Example 16 with MPPointF

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

the class RadarHighlighter method getHighlightsAtIndex.

/**
     * Returns an array of Highlight objects for the given index. The Highlight
     * objects give information about the value at the selected index and the
     * DataSet it belongs to. INFORMATION: This method does calculations at
     * runtime. Do not over-use in performance critical situations.
     *
     * @param index
     * @return
     */
protected List<Highlight> getHighlightsAtIndex(int index) {
    mHighlightBuffer.clear();
    float phaseX = mChart.getAnimator().getPhaseX();
    float phaseY = mChart.getAnimator().getPhaseY();
    float sliceangle = mChart.getSliceAngle();
    float factor = mChart.getFactor();
    MPPointF pOut = MPPointF.getInstance(0, 0);
    for (int i = 0; i < mChart.getData().getDataSetCount(); i++) {
        IDataSet<?> dataSet = mChart.getData().getDataSetByIndex(i);
        final Entry entry = dataSet.getEntryForIndex(index);
        float y = (entry.getY() - mChart.getYChartMin());
        Utils.getPosition(mChart.getCenterOffsets(), y * factor * phaseY, sliceangle * index * phaseX + mChart.getRotationAngle(), pOut);
        mHighlightBuffer.add(new Highlight(index, entry.getY(), pOut.x, pOut.y, i, dataSet.getAxisDependency()));
    }
    return mHighlightBuffer;
}
Also used : Entry(com.github.mikephil.charting.data.Entry) MPPointF(com.github.mikephil.charting.utils.MPPointF)

Example 17 with MPPointF

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

the class XAxisRendererHorizontalBarChart method renderAxisLabels.

@Override
public void renderAxisLabels(Canvas c) {
    if (!mXAxis.isEnabled() || !mXAxis.isDrawLabelsEnabled())
        return;
    float xoffset = mXAxis.getXOffset();
    mAxisLabelPaint.setTypeface(mXAxis.getTypeface());
    mAxisLabelPaint.setTextSize(mXAxis.getTextSize());
    mAxisLabelPaint.setColor(mXAxis.getTextColor());
    MPPointF pointF = MPPointF.getInstance(0, 0);
    if (mXAxis.getPosition() == XAxisPosition.TOP) {
        pointF.x = 0.0f;
        pointF.y = 0.5f;
        drawLabels(c, mViewPortHandler.contentRight() + xoffset, pointF);
    } else if (mXAxis.getPosition() == XAxisPosition.TOP_INSIDE) {
        pointF.x = 1.0f;
        pointF.y = 0.5f;
        drawLabels(c, mViewPortHandler.contentRight() - xoffset, pointF);
    } else if (mXAxis.getPosition() == XAxisPosition.BOTTOM) {
        pointF.x = 1.0f;
        pointF.y = 0.5f;
        drawLabels(c, mViewPortHandler.contentLeft() - xoffset, pointF);
    } else if (mXAxis.getPosition() == XAxisPosition.BOTTOM_INSIDE) {
        pointF.x = 1.0f;
        pointF.y = 0.5f;
        drawLabels(c, mViewPortHandler.contentLeft() + xoffset, pointF);
    } else {
        // BOTH SIDED
        pointF.x = 0.0f;
        pointF.y = 0.5f;
        drawLabels(c, mViewPortHandler.contentRight() + xoffset, pointF);
        pointF.x = 1.0f;
        pointF.y = 0.5f;
        drawLabels(c, mViewPortHandler.contentLeft() - xoffset, pointF);
    }
    MPPointF.recycleInstance(pointF);
}
Also used : MPPointF(com.github.mikephil.charting.utils.MPPointF)

Example 18 with MPPointF

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

the class XAxisRendererRadarChart method renderAxisLabels.

@Override
public void renderAxisLabels(Canvas c) {
    if (!mXAxis.isEnabled() || !mXAxis.isDrawLabelsEnabled())
        return;
    final float labelRotationAngleDegrees = mXAxis.getLabelRotationAngle();
    final MPPointF drawLabelAnchor = MPPointF.getInstance(0.5f, 0.25f);
    mAxisLabelPaint.setTypeface(mXAxis.getTypeface());
    mAxisLabelPaint.setTextSize(mXAxis.getTextSize());
    mAxisLabelPaint.setColor(mXAxis.getTextColor());
    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 < mChart.getData().getMaxEntryCountSet().getEntryCount(); i++) {
        String label = mXAxis.getValueFormatter().getFormattedValue(i, mXAxis);
        float angle = (sliceangle * i + mChart.getRotationAngle()) % 360f;
        Utils.getPosition(center, mChart.getYRange() * factor + mXAxis.mLabelRotatedWidth / 2f, angle, pOut);
        drawLabel(c, label, pOut.x, pOut.y - mXAxis.mLabelRotatedHeight / 2.f, drawLabelAnchor, labelRotationAngleDegrees);
    }
    MPPointF.recycleInstance(center);
    MPPointF.recycleInstance(pOut);
    MPPointF.recycleInstance(drawLabelAnchor);
}
Also used : MPPointF(com.github.mikephil.charting.utils.MPPointF)

Example 19 with MPPointF

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

the class PieChart method getMarkerPosition.

@Override
protected float[] getMarkerPosition(Highlight highlight) {
    MPPointF center = getCenterCircleBox();
    float r = getRadius();
    float off = r / 10f * 3.6f;
    if (isDrawHoleEnabled()) {
        off = (r - (r / 100f * getHoleRadius())) / 2f;
    }
    // offset to keep things inside the chart
    r -= off;
    float rotationAngle = getRotationAngle();
    int entryIndex = (int) highlight.getX();
    // offset needed to center the drawn text in the slice
    float offset = mDrawAngles[entryIndex] / 2;
    // calculate the text position
    float x = (float) (r * Math.cos(Math.toRadians((rotationAngle + mAbsoluteAngles[entryIndex] - offset) * mAnimator.getPhaseY())) + center.x);
    float y = (float) (r * Math.sin(Math.toRadians((rotationAngle + mAbsoluteAngles[entryIndex] - offset) * mAnimator.getPhaseY())) + center.y);
    MPPointF.recycleInstance(center);
    return new float[] { x, y };
}
Also used : MPPointF(com.github.mikephil.charting.utils.MPPointF) Paint(android.graphics.Paint)

Example 20 with MPPointF

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

the class YAxisRendererRadarChart method renderAxisLabels.

@Override
public void renderAxisLabels(Canvas c) {
    if (!mYAxis.isEnabled() || !mYAxis.isDrawLabelsEnabled())
        return;
    mAxisLabelPaint.setTypeface(mYAxis.getTypeface());
    mAxisLabelPaint.setTextSize(mYAxis.getTextSize());
    mAxisLabelPaint.setColor(mYAxis.getTextColor());
    MPPointF center = mChart.getCenterOffsets();
    MPPointF pOut = MPPointF.getInstance(0, 0);
    float factor = mChart.getFactor();
    final int from = mYAxis.isDrawBottomYLabelEntryEnabled() ? 0 : 1;
    final int to = mYAxis.isDrawTopYLabelEntryEnabled() ? mYAxis.mEntryCount : (mYAxis.mEntryCount - 1);
    for (int j = from; j < to; j++) {
        float r = (mYAxis.mEntries[j] - mYAxis.mAxisMinimum) * factor;
        Utils.getPosition(center, r, mChart.getRotationAngle(), pOut);
        String label = mYAxis.getFormattedLabel(j);
        c.drawText(label, pOut.x + 10, pOut.y, mAxisLabelPaint);
    }
    MPPointF.recycleInstance(center);
    MPPointF.recycleInstance(pOut);
}
Also used : MPPointF(com.github.mikephil.charting.utils.MPPointF)

Aggregations

MPPointF (com.github.mikephil.charting.utils.MPPointF)43 Paint (android.graphics.Paint)13 Drawable (android.graphics.drawable.Drawable)9 RectF (android.graphics.RectF)5 TextPaint (android.text.TextPaint)5 Entry (com.github.mikephil.charting.data.Entry)5 PieEntry (com.github.mikephil.charting.data.PieEntry)4 Transformer (com.github.mikephil.charting.utils.Transformer)4 Path (android.graphics.Path)3 RadarEntry (com.github.mikephil.charting.data.RadarEntry)3 IPieDataSet (com.github.mikephil.charting.interfaces.datasets.IPieDataSet)3 SuppressLint (android.annotation.SuppressLint)2 BarBuffer (com.github.mikephil.charting.buffer.BarBuffer)2 Chart (com.github.mikephil.charting.charts.Chart)2 BarEntry (com.github.mikephil.charting.data.BarEntry)2 BubbleData (com.github.mikephil.charting.data.BubbleData)2 BubbleEntry (com.github.mikephil.charting.data.BubbleEntry)2 PieData (com.github.mikephil.charting.data.PieData)2 PieDataSet (com.github.mikephil.charting.data.PieDataSet)2 IValueFormatter (com.github.mikephil.charting.formatter.IValueFormatter)2