double inset = defaultInsets;
// Add legend size if it's on this edge
if (legend != null) {
if (legend.getPosition() == edges[i]) {
PreciseRectangle bbox = legend.getBBox();
if (isVertical) {
inset += bbox.getWidth() + inset;
} else {
inset += bbox.getHeight() + inset;
}
}
}
// Add axis size if there's one on this edge
if (axis != null) {
PreciseRectangle bbox = axis.getBBox();
if (isVertical) {
inset += bbox.getWidth();
} else {
inset += bbox.getHeight();
}
}
insets.put(edges[i], inset);
}
// Build the chart bbox based on the collected inset values
bbox.setX(insets.get(Position.LEFT));
bbox.setY(insets.get(Position.TOP));
bbox.setWidth(currentWidth - insets.get(Position.LEFT) - insets.get(Position.RIGHT));
bbox.setHeight(currentHeight - insets.get(Position.TOP) - insets.get(Position.BOTTOM));
// Go back through each axis and set its length and position based on the
// corresponding edge of the chartBBox
for (Axis<M, ?> ax : this.axes.values()) {
if (ax instanceof CartesianAxis) {
CartesianAxis<M, ?> axis = (CartesianAxis<M, ?>) ax;
Position pos = axis.getPosition();
boolean isVertical = (pos == Position.LEFT || pos == Position.RIGHT);
axis.setX((pos == Position.RIGHT) ? (bbox.getX() + bbox.getWidth()) : (bbox.getX()));
axis.setY((pos == Position.TOP) ? (bbox.getY()) : (bbox.getY() + bbox.getHeight()));
axis.setDepth(isVertical ? bbox.getWidth() : bbox.getHeight());
axis.setLength(isVertical ? bbox.getHeight() : bbox.getWidth());
}
}
}