Search in sources :

Example 6 with MPPointD

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

the class YAxisRendererHorizontalBarChart method computeAxis.

/**
     * Computes the axis values.
     *
     * @param yMin - the minimum y-value in the data object for this axis
     * @param yMax - the maximum y-value in the data object for this axis
     */
@Override
public void computeAxis(float yMin, float yMax, boolean inverted) {
    // zoom / contentrect bounds)
    if (mViewPortHandler.contentHeight() > 10 && !mViewPortHandler.isFullyZoomedOutX()) {
        MPPointD p1 = mTrans.getValuesByTouchPoint(mViewPortHandler.contentLeft(), mViewPortHandler.contentTop());
        MPPointD p2 = mTrans.getValuesByTouchPoint(mViewPortHandler.contentRight(), mViewPortHandler.contentTop());
        if (!inverted) {
            yMin = (float) p1.x;
            yMax = (float) p2.x;
        } else {
            yMin = (float) p2.x;
            yMax = (float) p1.x;
        }
        MPPointD.recycleInstance(p1);
        MPPointD.recycleInstance(p2);
    }
    computeAxisValues(yMin, yMax);
}
Also used : MPPointD(com.github.mikephil.charting.utils.MPPointD)

Example 7 with MPPointD

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

the class BarLineChartBase method centerViewToAnimated.

/**
     * This will move the center of the current viewport to the specified
     * x and y value animated.
     *
     * @param xValue
     * @param yValue
     * @param axis
     * @param duration the duration of the animation in milliseconds
     */
@TargetApi(11)
public void centerViewToAnimated(float xValue, float yValue, AxisDependency axis, long duration) {
    if (android.os.Build.VERSION.SDK_INT >= 11) {
        MPPointD bounds = getValuesByTouchPoint(mViewPortHandler.contentLeft(), mViewPortHandler.contentTop(), axis);
        float yInView = getAxisRange(axis) / mViewPortHandler.getScaleY();
        float xInView = getXAxis().mAxisRange / mViewPortHandler.getScaleX();
        Runnable job = AnimatedMoveViewJob.getInstance(mViewPortHandler, xValue - xInView / 2f, yValue + yInView / 2f, getTransformer(axis), this, (float) bounds.x, (float) bounds.y, duration);
        addViewportJob(job);
        MPPointD.recycleInstance(bounds);
    } else {
        Log.e(LOG_TAG, "Unable to execute centerViewToAnimated(...) on API level < 11");
    }
}
Also used : MPPointD(com.github.mikephil.charting.utils.MPPointD) TargetApi(android.annotation.TargetApi)

Example 8 with MPPointD

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

the class BarLineChartBase method getValuesByTouchPoint.

/**
     * Returns a recyclable MPPointD instance
     * Returns the x and y values in the chart at the given touch point
     * (encapsulated in a MPPointD). This method transforms pixel coordinates to
     * coordinates / values in the chart. This is the opposite method to
     * getPixelForValues(...).
     *
     * @param x
     * @param y
     * @return
     */
public MPPointD getValuesByTouchPoint(float x, float y, AxisDependency axis) {
    MPPointD result = MPPointD.getInstance(0, 0);
    getValuesByTouchPoint(x, y, axis, result);
    return result;
}
Also used : MPPointD(com.github.mikephil.charting.utils.MPPointD)

Example 9 with MPPointD

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

the class BarLineChartBase method moveViewToAnimated.

/**
     * This will move the left side of the current viewport to the specified x-value
     * and center the viewport to the y value animated.
     * This also refreshes the chart by calling invalidate().
     *
     * @param xValue
     * @param yValue
     * @param axis
     * @param duration the duration of the animation in milliseconds
     */
@TargetApi(11)
public void moveViewToAnimated(float xValue, float yValue, AxisDependency axis, long duration) {
    if (android.os.Build.VERSION.SDK_INT >= 11) {
        MPPointD bounds = getValuesByTouchPoint(mViewPortHandler.contentLeft(), mViewPortHandler.contentTop(), axis);
        float yInView = getAxisRange(axis) / mViewPortHandler.getScaleY();
        Runnable job = AnimatedMoveViewJob.getInstance(mViewPortHandler, xValue, yValue + yInView / 2f, getTransformer(axis), this, (float) bounds.x, (float) bounds.y, duration);
        addViewportJob(job);
        MPPointD.recycleInstance(bounds);
    } else {
        Log.e(LOG_TAG, "Unable to execute moveViewToAnimated(...) on API level < 11");
    }
}
Also used : MPPointD(com.github.mikephil.charting.utils.MPPointD) TargetApi(android.annotation.TargetApi)

Example 10 with MPPointD

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

the class CandleStickChartRenderer method drawHighlighted.

@Override
public void drawHighlighted(Canvas c, Highlight[] indices) {
    CandleData candleData = mChart.getCandleData();
    for (Highlight high : indices) {
        ICandleDataSet set = candleData.getDataSetByIndex(high.getDataSetIndex());
        if (set == null || !set.isHighlightEnabled())
            continue;
        CandleEntry e = set.getEntryForXValue(high.getX(), high.getY());
        if (!isInBoundsX(e, set))
            continue;
        float lowValue = e.getLow() * mAnimator.getPhaseY();
        float highValue = e.getHigh() * mAnimator.getPhaseY();
        float y = (lowValue + highValue) / 2f;
        MPPointD pix = mChart.getTransformer(set.getAxisDependency()).getPixelForValues(e.getX(), y);
        high.setDraw((float) pix.x, (float) pix.y);
        // draw the lines
        drawHighlightLines(c, (float) pix.x, (float) pix.y, set);
    }
}
Also used : Highlight(com.github.mikephil.charting.highlight.Highlight) ICandleDataSet(com.github.mikephil.charting.interfaces.datasets.ICandleDataSet) CandleEntry(com.github.mikephil.charting.data.CandleEntry) CandleData(com.github.mikephil.charting.data.CandleData) MPPointD(com.github.mikephil.charting.utils.MPPointD)

Aggregations

MPPointD (com.github.mikephil.charting.utils.MPPointD)19 Entry (com.github.mikephil.charting.data.Entry)4 TargetApi (android.annotation.TargetApi)3 Highlight (com.github.mikephil.charting.highlight.Highlight)3 Paint (android.graphics.Paint)2 Path (android.graphics.Path)2 BarData (com.github.mikephil.charting.data.BarData)2 IBarDataSet (com.github.mikephil.charting.interfaces.datasets.IBarDataSet)2 ArrayList (java.util.ArrayList)2 BarEntry (com.github.mikephil.charting.data.BarEntry)1 CandleData (com.github.mikephil.charting.data.CandleData)1 CandleEntry (com.github.mikephil.charting.data.CandleEntry)1 LineData (com.github.mikephil.charting.data.LineData)1 ScatterData (com.github.mikephil.charting.data.ScatterData)1 ICandleDataSet (com.github.mikephil.charting.interfaces.datasets.ICandleDataSet)1 ILineDataSet (com.github.mikephil.charting.interfaces.datasets.ILineDataSet)1 IScatterDataSet (com.github.mikephil.charting.interfaces.datasets.IScatterDataSet)1