Search in sources :

Example 36 with MPPointF

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

the class PieChart method calculateOffsets.

@Override
public void calculateOffsets() {
    super.calculateOffsets();
    // prevent nullpointer when no data set
    if (mData == null)
        return;
    float diameter = getDiameter();
    float radius = diameter / 2f;
    MPPointF c = getCenterOffsets();
    float shift = mData.getDataSet().getSelectionShift();
    // create the circle box that will contain the pie-chart (the bounds of
    // the pie-chart)
    mCircleBox.set(c.x - radius + shift, c.y - radius + shift, c.x + radius - shift, c.y + radius - shift);
    MPPointF.recycleInstance(c);
}
Also used : MPPointF(com.github.mikephil.charting.utils.MPPointF)

Example 37 with MPPointF

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

the class PieRadarChartBase method getAngleForPoint.

/**
     * returns the angle relative to the chart center for the given point on the
     * chart in degrees. The angle is always between 0 and 360°, 0° is NORTH,
     * 90° is EAST, ...
     *
     * @param x
     * @param y
     * @return
     */
public float getAngleForPoint(float x, float y) {
    MPPointF c = getCenterOffsets();
    double tx = x - c.x, ty = y - c.y;
    double length = Math.sqrt(tx * tx + ty * ty);
    double r = Math.acos(ty / length);
    float angle = (float) Math.toDegrees(r);
    if (x > c.x)
        angle = 360f - angle;
    // add 90° because chart starts EAST
    angle = angle + 90f;
    // neutralize overflow
    if (angle > 360f)
        angle = angle - 360f;
    MPPointF.recycleInstance(c);
    return angle;
}
Also used : MPPointF(com.github.mikephil.charting.utils.MPPointF)

Example 38 with MPPointF

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

the class PieRadarChartBase method getPosition.

/**
     * Returns a recyclable MPPointF instance.
     * Calculates the position around a center point, depending on the distance
     * from the center, and the angle of the position around the center.
     *
     * @param center
     * @param dist
     * @param angle  in degrees, converted to radians internally
     * @return
     */
public MPPointF getPosition(MPPointF center, float dist, float angle) {
    MPPointF p = MPPointF.getInstance(0, 0);
    getPosition(center, dist, angle, p);
    return p;
}
Also used : MPPointF(com.github.mikephil.charting.utils.MPPointF)

Example 39 with MPPointF

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

the class PieRadarChartBase method distanceToCenter.

/**
     * Returns the distance of a certain point on the chart to the center of the
     * chart.
     *
     * @param x
     * @param y
     * @return
     */
public float distanceToCenter(float x, float y) {
    MPPointF c = getCenterOffsets();
    float dist = 0f;
    float xDist = 0f;
    float yDist = 0f;
    if (x > c.x) {
        xDist = x - c.x;
    } else {
        xDist = c.x - x;
    }
    if (y > c.y) {
        yDist = y - c.y;
    } else {
        yDist = c.y - y;
    }
    // pythagoras
    dist = (float) Math.sqrt(Math.pow(xDist, 2.0) + Math.pow(yDist, 2.0));
    MPPointF.recycleInstance(c);
    return dist;
}
Also used : MPPointF(com.github.mikephil.charting.utils.MPPointF)

Example 40 with MPPointF

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

the class BarLineChartTouchListener method onDoubleTap.

@Override
public boolean onDoubleTap(MotionEvent e) {
    mLastGesture = ChartGesture.DOUBLE_TAP;
    OnChartGestureListener l = mChart.getOnChartGestureListener();
    if (l != null) {
        l.onChartDoubleTapped(e);
    }
    // check if double-tap zooming is enabled
    if (mChart.isDoubleTapToZoomEnabled() && mChart.getData().getEntryCount() > 0) {
        MPPointF trans = getTrans(e.getX(), e.getY());
        mChart.zoom(mChart.isScaleXEnabled() ? 1.4f : 1f, mChart.isScaleYEnabled() ? 1.4f : 1f, trans.x, trans.y);
        if (mChart.isLogEnabled())
            Log.i("BarlineChartTouch", "Double-Tap, Zooming In, x: " + trans.x + ", y: " + trans.y);
        MPPointF.recycleInstance(trans);
    }
    return super.onDoubleTap(e);
}
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