Search in sources :

Example 1 with MPPointD

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

the class BarLineChartBase method zoomAndCenterAnimated.

/**
     * Zooms by the specified scale factor to the specified values on the specified axis.
     *
     * @param scaleX
     * @param scaleY
     * @param xValue
     * @param yValue
     * @param axis
     * @param duration
     */
@TargetApi(11)
public void zoomAndCenterAnimated(float scaleX, float scaleY, float xValue, float yValue, AxisDependency axis, long duration) {
    if (android.os.Build.VERSION.SDK_INT >= 11) {
        MPPointD origin = getValuesByTouchPoint(mViewPortHandler.contentLeft(), mViewPortHandler.contentTop(), axis);
        Runnable job = AnimatedZoomJob.getInstance(mViewPortHandler, this, getTransformer(axis), getAxis(axis), mXAxis.mAxisRange, scaleX, scaleY, mViewPortHandler.getScaleX(), mViewPortHandler.getScaleY(), xValue, yValue, (float) origin.x, (float) origin.y, duration);
        addViewportJob(job);
        MPPointD.recycleInstance(origin);
    } else {
        Log.e(LOG_TAG, "Unable to execute zoomAndCenterAnimated(...) on API level < 11");
    }
}
Also used : MPPointD(com.github.mikephil.charting.utils.MPPointD) TargetApi(android.annotation.TargetApi)

Example 2 with MPPointD

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

the class BarHighlighter method getStackedHighlight.

/**
     * This method creates the Highlight object that also indicates which value of a stacked BarEntry has been
     * selected.
     *
     * @param high the Highlight to work with looking for stacked values
     * @param set
     * @param xVal
     * @param yVal
     * @return
     */
public Highlight getStackedHighlight(Highlight high, IBarDataSet set, float xVal, float yVal) {
    BarEntry entry = set.getEntryForXValue(xVal, yVal);
    if (entry == null)
        return null;
    // not stacked
    if (entry.getYVals() == null) {
        return high;
    } else {
        Range[] ranges = entry.getRanges();
        if (ranges.length > 0) {
            int stackIndex = getClosestStackIndex(ranges, yVal);
            MPPointD pixels = mChart.getTransformer(set.getAxisDependency()).getPixelForValues(high.getX(), ranges[stackIndex].to);
            Highlight stackedHigh = new Highlight(entry.getX(), entry.getY(), (float) pixels.x, (float) pixels.y, high.getDataSetIndex(), stackIndex, high.getAxis());
            MPPointD.recycleInstance(pixels);
            return stackedHigh;
        }
    }
    return null;
}
Also used : MPPointD(com.github.mikephil.charting.utils.MPPointD) BarEntry(com.github.mikephil.charting.data.BarEntry)

Example 3 with MPPointD

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

the class ChartHighlighter method getHighlight.

@Override
public Highlight getHighlight(float x, float y) {
    MPPointD pos = getValsForTouch(x, y);
    float xVal = (float) pos.x;
    MPPointD.recycleInstance(pos);
    Highlight high = getHighlightForX(xVal, x, y);
    return high;
}
Also used : MPPointD(com.github.mikephil.charting.utils.MPPointD)

Example 4 with MPPointD

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

the class HorizontalBarHighlighter method buildHighlights.

@Override
protected List<Highlight> buildHighlights(IDataSet set, int dataSetIndex, float xVal, DataSet.Rounding rounding) {
    ArrayList<Highlight> highlights = new ArrayList<>();
    //noinspection unchecked
    List<Entry> entries = set.getEntriesForXValue(xVal);
    if (entries.size() == 0) {
        // Try to find closest x-value and take all entries for that x-value
        final Entry closest = set.getEntryForXValue(xVal, Float.NaN, rounding);
        if (closest != null) {
            //noinspection unchecked
            entries = set.getEntriesForXValue(closest.getX());
        }
    }
    if (entries.size() == 0)
        return highlights;
    for (Entry e : entries) {
        MPPointD pixels = mChart.getTransformer(set.getAxisDependency()).getPixelForValues(e.getY(), e.getX());
        highlights.add(new Highlight(e.getX(), e.getY(), (float) pixels.x, (float) pixels.y, dataSetIndex, set.getAxisDependency()));
    }
    return highlights;
}
Also used : Entry(com.github.mikephil.charting.data.Entry) ArrayList(java.util.ArrayList) MPPointD(com.github.mikephil.charting.utils.MPPointD)

Example 5 with MPPointD

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

the class HorizontalBarHighlighter method getHighlight.

@Override
public Highlight getHighlight(float x, float y) {
    BarData barData = mChart.getBarData();
    MPPointD pos = getValsForTouch(y, x);
    Highlight high = getHighlightForX((float) pos.y, y, x);
    if (high == null)
        return null;
    IBarDataSet set = barData.getDataSetByIndex(high.getDataSetIndex());
    if (set.isStacked()) {
        return getStackedHighlight(high, set, (float) pos.y, (float) pos.x);
    }
    MPPointD.recycleInstance(pos);
    return high;
}
Also used : BarData(com.github.mikephil.charting.data.BarData) IBarDataSet(com.github.mikephil.charting.interfaces.datasets.IBarDataSet) 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