public double calculateBarWidth(final CategoryPlot plot,
final Rectangle dataArea, final int rendererIndex) {
// calculate the bar width
final CategoryAxis xAxis = plot.getDomainAxisForDataset(rendererIndex);
final CategoryDataset data = plot.getDataset(rendererIndex);
if (data != null) {
final PlotOrientation orientation = plot.getOrientation();
double space = 0.0;
if (orientation == PlotOrientation.HORIZONTAL) {
space = dataArea.height;
} else if (orientation == PlotOrientation.VERTICAL) {
space = dataArea.width;
}
final double maxWidth = this.calculateMaxBarWidth(plot, dataArea,
rendererIndex);
final int groups = this.seriesToGroupMap.getGroupCount();
final int categories = data.getColumnCount();
final int columns = groups * categories;
double categoryMargin = 0.0;
double itemMargin = 0.0;
if (categories > 1) {
categoryMargin = xAxis.getCategoryMargin();