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);
}
}
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;
}
}
}
Aggregations