Search in sources :

Example 1 with Range

use of com.github.mikephil.charting.highlight.Range in project MPAndroidChart by PhilJay.

the class BarChartRenderer method drawHighlighted.

@Override
public void drawHighlighted(Canvas c, Highlight[] indices) {
    BarData barData = mChart.getBarData();
    for (Highlight high : indices) {
        IBarDataSet set = barData.getDataSetByIndex(high.getDataSetIndex());
        if (set == null || !set.isHighlightEnabled())
            continue;
        BarEntry e = set.getEntryForXValue(high.getX(), high.getY());
        if (!isInBoundsX(e, set))
            continue;
        Transformer trans = mChart.getTransformer(set.getAxisDependency());
        mHighlightPaint.setColor(set.getHighLightColor());
        mHighlightPaint.setAlpha(set.getHighLightAlpha());
        boolean isStack = (high.getStackIndex() >= 0 && e.isStacked()) ? true : false;
        final float y1;
        final float y2;
        if (isStack) {
            if (mChart.isHighlightFullBarEnabled()) {
                y1 = e.getPositiveSum();
                y2 = -e.getNegativeSum();
            } else {
                Range range = e.getRanges()[high.getStackIndex()];
                y1 = range.from;
                y2 = range.to;
            }
        } else {
            y1 = e.getY();
            y2 = 0.f;
        }
        prepareBarHighlight(e.getX(), y1, y2, barData.getBarWidth() / 2f, trans);
        setHighlightDrawPos(high, mBarRect);
        c.drawRect(mBarRect, mHighlightPaint);
    }
}
Also used : Highlight(com.github.mikephil.charting.highlight.Highlight) Transformer(com.github.mikephil.charting.utils.Transformer) BarData(com.github.mikephil.charting.data.BarData) IBarDataSet(com.github.mikephil.charting.interfaces.datasets.IBarDataSet) Range(com.github.mikephil.charting.highlight.Range) BarEntry(com.github.mikephil.charting.data.BarEntry)

Example 2 with Range

use of com.github.mikephil.charting.highlight.Range in project MPAndroidChart by PhilJay.

the class BarEntry method calcRanges.

protected void calcRanges() {
    float[] values = getYVals();
    if (values == null || values.length == 0)
        return;
    mRanges = new Range[values.length];
    float negRemain = -getNegativeSum();
    float posRemain = 0f;
    for (int i = 0; i < mRanges.length; i++) {
        float value = values[i];
        if (value < 0) {
            mRanges[i] = new Range(negRemain, negRemain - value);
            negRemain -= value;
        } else {
            mRanges[i] = new Range(posRemain, posRemain + value);
            posRemain += value;
        }
    }
}
Also used : Range(com.github.mikephil.charting.highlight.Range) SuppressLint(android.annotation.SuppressLint)

Aggregations

Range (com.github.mikephil.charting.highlight.Range)2 SuppressLint (android.annotation.SuppressLint)1 BarData (com.github.mikephil.charting.data.BarData)1 BarEntry (com.github.mikephil.charting.data.BarEntry)1 Highlight (com.github.mikephil.charting.highlight.Highlight)1 IBarDataSet (com.github.mikephil.charting.interfaces.datasets.IBarDataSet)1 Transformer (com.github.mikephil.charting.utils.Transformer)1