Search in sources :

Example 16 with MPPointD

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

the class AxisRenderer method computeAxis.

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

Example 17 with MPPointD

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

the class LineChartRenderer method drawHighlighted.

@Override
public void drawHighlighted(Canvas c, Highlight[] indices) {
    LineData lineData = mChart.getLineData();
    for (Highlight high : indices) {
        ILineDataSet set = lineData.getDataSetByIndex(high.getDataSetIndex());
        if (set == null || !set.isHighlightEnabled())
            continue;
        Entry e = set.getEntryForXValue(high.getX(), high.getY());
        if (!isInBoundsX(e, set))
            continue;
        MPPointD pix = mChart.getTransformer(set.getAxisDependency()).getPixelForValues(e.getX(), e.getY() * mAnimator.getPhaseY());
        high.setDraw((float) pix.x, (float) pix.y);
        // draw the lines
        drawHighlightLines(c, (float) pix.x, (float) pix.y, set);
    }
}
Also used : LineData(com.github.mikephil.charting.data.LineData) Entry(com.github.mikephil.charting.data.Entry) Highlight(com.github.mikephil.charting.highlight.Highlight) ILineDataSet(com.github.mikephil.charting.interfaces.datasets.ILineDataSet) MPPointD(com.github.mikephil.charting.utils.MPPointD)

Example 18 with MPPointD

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

the class BarHighlighter method getHighlight.

@Override
public Highlight getHighlight(float x, float y) {
    Highlight high = super.getHighlight(x, y);
    if (high == null) {
        return null;
    }
    MPPointD pos = getValsForTouch(x, y);
    BarData barData = mChart.getBarData();
    IBarDataSet set = barData.getDataSetByIndex(high.getDataSetIndex());
    if (set.isStacked()) {
        return getStackedHighlight(high, set, (float) pos.x, (float) pos.y);
    }
    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)

Example 19 with MPPointD

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

the class ChartHighlighter method buildHighlights.

/**
     * An array of `Highlight` objects corresponding to the selected xValue and dataSetIndex.
     *
     * @param set
     * @param dataSetIndex
     * @param xVal
     * @param rounding
     * @return
     */
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.getX(), e.getY());
        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)

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