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

added bar thickness to style manager

parent d7997d2a
No related branches found
No related tags found
No related merge requests found
Showing
with 60 additions and 11 deletions
......@@ -48,11 +48,12 @@ 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(1000), 11, -30, 30);
chart.addSeries("histogram 2", getGaussianData(1000), 11, -30, 30);
chart.addSeries("histogram 1", getGaussianData(10000), 10, -30, 30);
chart.addSeries("histogram 2", getGaussianData(10000), 10, -30, 30);
// Customize Chart
chart.getStyleManager().setLegendPosition(LegendPosition.InsideNW);
chart.getStyleManager().setBarWidthPercentage(.99);
return chart;
}
......@@ -62,8 +63,8 @@ public class BarChart06 implements ExampleChart {
List<Double> data = new ArrayList<Double>(count);
Random r = new Random();
for (int i = 0; i < count; i++) {
// data.add(r.nextGaussian() * 10);
data.add(r.nextDouble() * 60 - 30);
data.add(r.nextGaussian() * 10);
// data.add(r.nextDouble() * 60 - 30);
}
return data;
}
......
......@@ -38,7 +38,7 @@ public class StyleManager {
*/
public enum ChartType {
Line, Scatter, Area, Bar, Histogram
Line, Scatter, Area, Bar
}
public enum LegendPosition {
......@@ -126,6 +126,7 @@ public class StyleManager {
private boolean isPlotTicksMarksVisible;
private Color plotGridLinesColor;
private Stroke plotGridLinesStroke;
private double barWidthPercentage;
// Error Bars ///////////////////////////////
private Color errorBarsColor;
......@@ -204,6 +205,7 @@ public class StyleManager {
isPlotTicksMarksVisible = theme.isPlotTicksMarksVisible();
plotGridLinesColor = theme.getPlotGridLinesColor();
plotGridLinesStroke = theme.getPlotGridLinesStroke();
barWidthPercentage = theme.getBarWidthPercentage();
// Error Bars ///////////////////////////////
errorBarsColor = theme.getErrorBarsColor();
......@@ -966,6 +968,23 @@ public class StyleManager {
return plotGridLinesStroke;
}
// Bar Charts ///////////////////////////////
/**
* set the width of a single bar in a bar chart. full width is 100%, i.e. 1.0
*
* @param barWidthPercentage
*/
public void setBarWidthPercentage(double barWidthPercentage) {
this.barWidthPercentage = barWidthPercentage;
}
public double getBarWidthPercentage() {
return barWidthPercentage;
}
// Error Bars ///////////////////////////////
/**
......
......@@ -99,7 +99,7 @@ public class AxisTickBarChartCalculator extends AxisTickCalculator {
tickLocations.add(tickLabelPosition);
}
}
else if (categories.size() < 13) { // Number or Date and 12 or less categories
else if (categories.size() < 13) { // Number or Date and 12 or less categories. give each category a tick label
double gridStep = (tickSpace / (double) categories.size());
double firstPosition = gridStep / 2.0;
......@@ -130,7 +130,7 @@ public class AxisTickBarChartCalculator extends AxisTickCalculator {
tickLocations.add(tickLabelPosition);
}
}
else { // Number or Date
else { // Number or Date and more than 12 categories. divide up the axis tick space according to normal number axis layout
double gridStep = getNumericalGridStep(tickSpace);
double firstPosition = getFirstPosition(gridStep);
......
......@@ -167,8 +167,9 @@ public class PlotContentBarChart extends PlotContent {
double zeroOffset = bounds.getY() + zeroTransform;
// paint bar
double barWidth = gridStep / getChartPainter().getAxisPair().getSeriesMap().size() / 1.1;
double barMargin = gridStep * .05;
double barWidthPercentage = getChartPainter().getStyleManager().getBarWidthPercentage();
double barWidth = gridStep / getChartPainter().getAxisPair().getSeriesMap().size() * barWidthPercentage;
double barMargin = gridStep * (1 - barWidthPercentage) / 2;
double xOffset = bounds.getX() + xLeftMargin + gridStep * barCounter++ + seriesCounter * barWidth + barMargin;
g.setColor(series.getStrokeColor());
......
......@@ -185,7 +185,7 @@ public class PlotContentLineChart extends PlotContent {
if (previousX != Integer.MIN_VALUE && previousY != Integer.MIN_VALUE) {
g.setColor(series.getStrokeColor());
double yBottomOfArea = bounds.getY() + bounds.getHeight() - yTopMargin + 1;
double yBottomOfArea = bounds.getY() + bounds.getHeight() - yTopMargin;
if (path == null) {
path = new Path2D.Double();
......@@ -264,7 +264,7 @@ public class PlotContentLineChart extends PlotContent {
private void closePath(Graphics2D g, Path2D.Double path, double previousX, Rectangle2D bounds, double yTopMargin) {
if (path != null) {
double yBottomOfArea = bounds.getY() + bounds.getHeight() - yTopMargin + 1;
double yBottomOfArea = bounds.getY() + bounds.getHeight() - yTopMargin;
path.lineTo(previousX, yBottomOfArea);
path.closePath();
g.fill(path);
......
......@@ -279,6 +279,14 @@ public class GGPlot2Theme implements Theme {
return new BasicStroke(1.5f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL);
}
// Bar Charts ///////////////////////////////
@Override
public double getBarWidthPercentage() {
return 0.9;
}
// Error Bars ///////////////////////////////
@Override
......
......@@ -280,6 +280,14 @@ public class MatlabTheme implements Theme {
}
// Bar Charts ///////////////////////////////
@Override
public double getBarWidthPercentage() {
return 0.9;
}
// Error Bars ///////////////////////////////
@Override
......
......@@ -116,6 +116,10 @@ public interface Theme {
public boolean isPlotTicksMarksVisible();
// Bar Charts ///////////////////////////////
public double getBarWidthPercentage();
// Error Bars ///////////////////////////////
public Color getErrorBarsColor();
......
......@@ -279,6 +279,14 @@ public class XChartTheme implements Theme {
return new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 10.0f, new float[] { 3.0f, 3.0f }, 0.0f);
}
// Bar Charts ///////////////////////////////
@Override
public double getBarWidthPercentage() {
return 0.9;
}
// Error Bars ///////////////////////////////
@Override
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment