Skip to content
Snippets Groups Projects
Commit 2201bc42 authored by Tim Molter's avatar Tim Molter
Browse files

added isOverlapped to style manager

parent f2327081
No related branches found
No related tags found
No related merge requests found
......@@ -48,13 +48,13 @@ public class BarChart06 implements ExampleChart {
// Create Chart
Chart chart = new ChartBuilder().chartType(ChartType.Bar).width(800).height(600).title("Score Histogram").xAxisTitle("Score").yAxisTitle("Count").build();
chart.addSeries("histogram 1", getGaussianData(10000), 10, -30, 30);
chart.addSeries("histogram 2", getGaussianData(10000), 10, -30, 30);
chart.addSeries("histogram 1", getGaussianData(10000), 30, -30, 30);
chart.addSeries("histogram 2", getGaussianData(5000), 30, -30, 30);
// Customize Chart
chart.getStyleManager().setLegendPosition(LegendPosition.InsideNW);
chart.getStyleManager().setBarWidthPercentage(.99);
chart.getStyleManager().setBarWidthPercentage(.96);
chart.getStyleManager().setOverlapped(false);
return chart;
}
......
......@@ -126,7 +126,10 @@ public class StyleManager {
private boolean isPlotTicksMarksVisible;
private Color plotGridLinesColor;
private Stroke plotGridLinesStroke;
// Bar Charts ///////////////////////////////
private double barWidthPercentage;
private boolean isOverlapped;
// Error Bars ///////////////////////////////
private Color errorBarsColor;
......@@ -205,7 +208,10 @@ public class StyleManager {
isPlotTicksMarksVisible = theme.isPlotTicksMarksVisible();
plotGridLinesColor = theme.getPlotGridLinesColor();
plotGridLinesStroke = theme.getPlotGridLinesStroke();
// Bar Charts ///////////////////////////////
barWidthPercentage = theme.getBarWidthPercentage();
isOverlapped = theme.isOverlapped();
// Error Bars ///////////////////////////////
errorBarsColor = theme.getErrorBarsColor();
......@@ -985,6 +991,21 @@ public class StyleManager {
return barWidthPercentage;
}
/**
* set whether or no bars are overlapped. Otherwise they are places side-by-side
*
* @param isOverlapped
*/
public void setOverlapped(boolean isOverlapped) {
this.isOverlapped = isOverlapped;
}
public boolean isOverlapped() {
return isOverlapped;
}
// Error Bars ///////////////////////////////
/**
......
......@@ -167,12 +167,23 @@ public class PlotContentBarChart extends PlotContent {
double zeroOffset = bounds.getY() + zeroTransform;
// paint bar
boolean isOverlap = true;
double xOffset;
double barWidth;
if (getChartPainter().getStyleManager().isOverlapped()) {
double barWidthPercentage = getChartPainter().getStyleManager().getBarWidthPercentage();
double barWidth = gridStep / getChartPainter().getAxisPair().getSeriesMap().size() * barWidthPercentage;
barWidth = gridStep * barWidthPercentage;
double barMargin = gridStep * (1 - barWidthPercentage) / 2;
double xOffset = bounds.getX() + xLeftMargin + gridStep * barCounter++ + seriesCounter * barWidth + barMargin;
xOffset = bounds.getX() + xLeftMargin + gridStep * barCounter++ + barMargin;
g.setColor(series.getStrokeColor());
}
else {
double barWidthPercentage = getChartPainter().getStyleManager().getBarWidthPercentage();
barWidth = gridStep / getChartPainter().getAxisPair().getSeriesMap().size() * barWidthPercentage;
double barMargin = gridStep * (1 - barWidthPercentage) / 2;
xOffset = bounds.getX() + xLeftMargin + gridStep * barCounter++ + seriesCounter * barWidth + barMargin;
g.setColor(series.getStrokeColor());
}
Path2D.Double path = new Path2D.Double();
path.moveTo(xOffset, yOffset);
path.lineTo(xOffset + barWidth, yOffset);
......
......@@ -287,6 +287,12 @@ public class GGPlot2Theme implements Theme {
return 0.9;
}
@Override
public boolean isOverlapped() {
return false;
}
// Error Bars ///////////////////////////////
@Override
......
......@@ -288,6 +288,12 @@ public class MatlabTheme implements Theme {
return 0.9;
}
@Override
public boolean isOverlapped() {
return false;
}
// Error Bars ///////////////////////////////
@Override
......
......@@ -120,6 +120,8 @@ public interface Theme {
public double getBarWidthPercentage();
public boolean isOverlapped();
// Error Bars ///////////////////////////////
public Color getErrorBarsColor();
......
......@@ -287,6 +287,12 @@ public class XChartTheme implements Theme {
return 0.9;
}
@Override
public boolean isOverlapped() {
return false;
}
// Error Bars ///////////////////////////////
@Override
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment