use of com.db.chart.model.Bar in project WilliamChart by diogobernardino.
the class StackBarChartView method defineRegions.
@Override
void defineRegions(ArrayList<ArrayList<Region>> regions, ArrayList<ChartSet> data) {
int dataSize = data.size();
int setSize = data.get(0).size();
float verticalOffset;
float currBottomY;
float negVerticalOffset;
float negCurrBottomY;
float y1;
float barSize;
BarSet barSet;
Bar bar;
float zeroPosition = this.getZeroPosition();
for (int i = 0; i < setSize; i++) {
// Vertical offset to keep drawing bars on top of the others
verticalOffset = 0;
negVerticalOffset = 0;
// Bottom of the next bar to be drawn
currBottomY = zeroPosition;
negCurrBottomY = zeroPosition;
for (int j = 0; j < dataSize; j++) {
barSet = (BarSet) data.get(j);
bar = (Bar) barSet.getEntry(i);
barSize = Math.abs(zeroPosition - bar.getY());
// Then no need to have region
if (!barSet.isVisible())
continue;
if (bar.getValue() > 0) {
y1 = zeroPosition - (barSize + verticalOffset);
regions.get(j).get(i).set((int) (bar.getX() - barWidth / 2), (int) y1, (int) (bar.getX() + barWidth / 2), (int) currBottomY);
currBottomY = y1;
verticalOffset += barSize + 2;
} else if (bar.getValue() < 0) {
y1 = zeroPosition + (barSize - negVerticalOffset);
regions.get(j).get(i).set((int) (bar.getX() - barWidth / 2), (int) negCurrBottomY, (int) (bar.getX() + barWidth / 2), (int) y1);
negCurrBottomY = y1;
negVerticalOffset -= barSize;
} else {
// If bar.getValue() == 0, force region to 1 pixel
y1 = zeroPosition - (1 + verticalOffset);
regions.get(j).get(i).set((int) (bar.getX() - barWidth / 2), (int) y1, (int) (bar.getX() + barWidth / 2), (int) currBottomY);
}
}
}
}
Aggregations