private void calculateBounds() {
ListStore<M> store = chart.getCurrentStore();
double barWidth = getBarGirth();
double groupGutter = this.groupGutter / 100;
groupBarsLength = yFields.size();
PreciseRectangle chartBBox = chart.getBBox();
calculateBBox(false);
// skip excluded series
groupBarsLength -= exclude.size();
axis = chart.getAxis(yAxisPosition);
if (axis != null) {
minY = axis.getFrom();
maxY = axis.getTo();
} else if (yFields.size() > 0) {
NumericAxis<M> numAxis = new NumericAxis<M>();
numAxis.setChart(chart);
for (int i = 0; i < yFields.size(); i++) {
numAxis.addField(yFields.get(i));
}
numAxis.calcEnds();
minY = numAxis.getFrom();
maxY = numAxis.getTo();
}
axis = chart.getAxis(xAxisPosition);
if (axis != null) {
minY = axis.getFrom();
maxY = axis.getTo();
}
scale = (column ? chartBBox.getHeight() - yPadding * 2 : chartBBox.getWidth() - xPadding * 2)
/ (Math.abs(maxY - minY));
groupBarWidth = barWidth / ((stacked ? 1 : groupBarsLength) * (groupGutter + 1) - groupGutter);
zero = column ? chartBBox.getY() + chartBBox.getHeight() - yPadding : chartBBox.getX() + xPadding;
List<Double> totalPositive = new ArrayList<Double>();
List<Double> totalNegative = new ArrayList<Double>();
if (stacked) {
for (int i = 0; i < store.size(); i++) {
M model = store.get(i);
totalPositive.add(0.0);
totalNegative.add(0.0);
for (int j = 0; j < yFields.size(); j++) {
if (exclude.contains(j)) {
continue;
}
double value = yFields.get(j).getValue(model).doubleValue();
if (value > 0) {
totalPositive.set(i, totalPositive.get(i) + value);
} else {
totalNegative.set(i, totalNegative.get(i) + Math.abs(value));
}
}
}
if (maxY > 0) {
totalPositive.add(maxY);
} else {
totalNegative.add(Math.abs(maxY));
}
if (minY > 0) {
totalPositive.add(minY);
} else {
totalNegative.add(Math.abs(minY));
}
double minus = 0;
double plus = 0;
for (int i = 0; i < totalNegative.size(); i++) {
minus = Math.max(minus, totalNegative.get(i));
}
for (int i = 0; i < totalPositive.size(); i++) {
plus = Math.max(plus, totalPositive.get(i));
}
scale = (column ? bbox.getHeight() - yPadding * 2 : bbox.getWidth() - xPadding * 2) / (plus + minus);
zero = zero + minus * scale * (column ? -1 : 1);
} else if (minY < 0) {
if (column) {
zero = chartBBox.getY();
} else {
zero = chartBBox.getX() + chartBBox.getWidth();
}
}
}