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

bug fixes - taxis ticks could not be hidden, plot area width was falsely calculated.

parent b76d2694
No related branches found
No related tags found
No related merge requests found
Showing
with 55 additions and 46 deletions
...@@ -51,6 +51,7 @@ public class AreaChart01 implements ExampleChart { ...@@ -51,6 +51,7 @@ public class AreaChart01 implements ExampleChart {
// Customize Chart // Customize Chart
chart.getStyleManager().setLegendPosition(LegendPosition.InsideNW); chart.getStyleManager().setLegendPosition(LegendPosition.InsideNW);
chart.getStyleManager().setAxisTitlesVisible(false);
return chart; return chart;
} }
......
...@@ -45,7 +45,7 @@ public class StyleManager { ...@@ -45,7 +45,7 @@ public class StyleManager {
public enum LegendPosition { public enum LegendPosition {
OutsideW, InsideNW, InsideNE, InsideSE, InsideSW OutsideE, InsideNW, InsideNE, InsideSE, InsideSW
} }
public enum ChartTheme { public enum ChartTheme {
...@@ -567,7 +567,6 @@ public class StyleManager { ...@@ -567,7 +567,6 @@ public class StyleManager {
this.xAxisTicksVisible = isVisible; this.xAxisTicksVisible = isVisible;
this.yAxisTicksVisible = isVisible; this.yAxisTicksVisible = isVisible;
} }
/** /**
......
...@@ -80,8 +80,8 @@ public class Axis implements ChartPart { ...@@ -80,8 +80,8 @@ public class Axis implements ChartPart {
this.axisPair = axisPair; this.axisPair = axisPair;
this.direction = direction; this.direction = direction;
axisTitle = new AxisTitle(this, direction == Direction.X ? getChartPainter().getStyleManager().isXAxisTitleVisible() : getChartPainter().getStyleManager().isYAxisTitleVisible()); axisTitle = new AxisTitle(this);
axisTick = new AxisTick(this, direction == Direction.X ? getChartPainter().getStyleManager().isXAxisTicksVisible() : getChartPainter().getStyleManager().isYAxisTicksVisible()); axisTick = new AxisTick(this);
} }
/** /**
...@@ -193,12 +193,13 @@ public class Axis implements ChartPart { ...@@ -193,12 +193,13 @@ public class Axis implements ChartPart {
int yOffset = (int) (axisPair.getyAxis().getBounds().getY() + axisPair.getyAxis().getBounds().getHeight()); int yOffset = (int) (axisPair.getyAxis().getBounds().getY() + axisPair.getyAxis().getBounds().getHeight());
int chartLegendWidth = 0; int chartLegendWidth = 0;
if (getChartPainter().getStyleManager().getLegendPosition() == LegendPosition.OutsideW) { if (getChartPainter().getStyleManager().getLegendPosition() == LegendPosition.OutsideE) {
chartLegendWidth = getChartPainter().getChartLegend().getSizeHint()[0]; chartLegendWidth = getChartPainter().getChartLegend().getSizeHint()[0];
} }
int width = (int) (getChartPainter().getWidth() - axisPair.getyAxis().getBounds().getWidth() - chartLegendWidth - (getChartPainter().getStyleManager().isLegendVisible() ? 3 : 2) int width = (int) (getChartPainter().getWidth() - axisPair.getyAxis().getBounds().getWidth() - chartLegendWidth - 2 * getChartPainter().getStyleManager().getChartPadding()
* getChartPainter().getStyleManager().getChartPadding() - getChartPainter().getStyleManager().getPlotPadding()); - getChartPainter().getStyleManager().getPlotPadding() - (getChartPainter().getStyleManager().getLegendPosition() == LegendPosition.OutsideE ? getChartPainter().getStyleManager()
.getChartPadding() : 0));
int height = this.getSizeHint(); int height = this.getSizeHint();
Rectangle xAxisRectangle = new Rectangle(xOffset, yOffset, width, height); Rectangle xAxisRectangle = new Rectangle(xOffset, yOffset, width, height);
this.paintZone = xAxisRectangle; this.paintZone = xAxisRectangle;
......
...@@ -38,7 +38,7 @@ public class AxisPair implements ChartPart { ...@@ -38,7 +38,7 @@ public class AxisPair implements ChartPart {
private Map<Integer, Series> seriesMap = new LinkedHashMap<Integer, Series>(); private Map<Integer, Series> seriesMap = new LinkedHashMap<Integer, Series>();
private int seriesCount; private int seriesCount = 0;
private Axis xAxis; private Axis xAxis;
private Axis yAxis; private Axis yAxis;
......
...@@ -37,10 +37,7 @@ public class AxisTick implements ChartPart { ...@@ -37,10 +37,7 @@ public class AxisTick implements ChartPart {
private AxisTickMarks axisTickMarks; private AxisTickMarks axisTickMarks;
/** the bounds */ /** the bounds */
private Rectangle bounds; private Rectangle bounds = new Rectangle();;
/** the visibility state of axistick */
private boolean isVisible = true; // default to true
AxisTickCalculator gridStep = null; AxisTickCalculator gridStep = null;
...@@ -48,12 +45,10 @@ public class AxisTick implements ChartPart { ...@@ -48,12 +45,10 @@ public class AxisTick implements ChartPart {
* Constructor * Constructor
* *
* @param axis * @param axis
* @param isVisible
*/ */
protected AxisTick(Axis axis, boolean isVisible) { protected AxisTick(Axis axis) {
this.axis = axis; this.axis = axis;
this.isVisible = isVisible;
axisTickLabels = new AxisTickLabels(this); axisTickLabels = new AxisTickLabels(this);
axisTickMarks = new AxisTickMarks(this); axisTickMarks = new AxisTickMarks(this);
} }
...@@ -67,13 +62,11 @@ public class AxisTick implements ChartPart { ...@@ -67,13 +62,11 @@ public class AxisTick implements ChartPart {
@Override @Override
public void paint(Graphics2D g) { public void paint(Graphics2D g) {
bounds = new Rectangle();
int workingSpace = 0; int workingSpace = 0;
if (axis.getDirection() == Axis.Direction.Y) { if (axis.getDirection() == Axis.Direction.Y) {
workingSpace = (int) axis.getPaintZone().getHeight(); // number of pixels the axis has to work with for drawing AxisTicks workingSpace = (int) axis.getPaintZone().getHeight(); // number of pixels the axis has to work with for drawing AxisTicks
// System.out.println("workingspace= " + workingSpace); // System.out.println("workingspace= " + workingSpace);
} else { } else if (axis.getDirection() == Axis.Direction.X) {
workingSpace = (int) axis.getPaintZone().getWidth(); // number of pixels the axis has to work with for drawing AxisTicks workingSpace = (int) axis.getPaintZone().getWidth(); // number of pixels the axis has to work with for drawing AxisTicks
// System.out.println("workingspace= " + workingSpace); // System.out.println("workingspace= " + workingSpace);
} }
...@@ -100,23 +93,37 @@ public class AxisTick implements ChartPart { ...@@ -100,23 +93,37 @@ public class AxisTick implements ChartPart {
} }
if (isVisible) { if (axis.getDirection() == Axis.Direction.Y && getChartPainter().getStyleManager().isYAxisTicksVisible()) {
axisTickLabels.paint(g); axisTickLabels.paint(g);
axisTickMarks.paint(g); axisTickMarks.paint(g);
if (axis.getDirection() == Axis.Direction.Y) { bounds = new Rectangle(
bounds = new Rectangle((int) axisTickLabels.getBounds().getX(), (int) (axisTickLabels.getBounds().getY()), (int) (axisTickLabels.getBounds().getWidth()
+ getChartPainter().getStyleManager().getAxisTickPadding() + axisTickMarks.getBounds().getWidth()), (int) (axisTickMarks.getBounds().getHeight())); (int) axisTickLabels.getBounds().getX(),
(int) (axisTickLabels.getBounds().getY()),
(int) (axisTickLabels.getBounds().getWidth() + getChartPainter().getStyleManager().getAxisTickPadding() + axisTickMarks.getBounds().getWidth()),
(int) (axisTickMarks.getBounds().getHeight())
);
// g.setColor(Color.red); // g.setColor(Color.red);
// g.draw(bounds); // g.draw(bounds);
} else {
} else if (axis.getDirection() == Axis.Direction.X && getChartPainter().getStyleManager().isXAxisTicksVisible()) {
axisTickLabels.paint(g);
axisTickMarks.paint(g);
bounds = new Rectangle((int) axisTickMarks.getBounds().getX(), (int) (axisTickMarks.getBounds().getY()), (int) axisTickLabels.getBounds().getWidth(), (int) (axisTickMarks.getBounds() bounds = new Rectangle((int) axisTickMarks.getBounds().getX(), (int) (axisTickMarks.getBounds().getY()), (int) axisTickLabels.getBounds().getWidth(), (int) (axisTickMarks.getBounds()
.getHeight() .getHeight()
+ getChartPainter().getStyleManager().getAxisTickPadding() + axisTickLabels.getBounds().getHeight())); + getChartPainter().getStyleManager().getAxisTickPadding() + axisTickLabels.getBounds().getHeight()));
// g.setColor(Color.red); // g.setColor(Color.red);
// g.draw(bounds); // g.draw(bounds);
}
} }
} }
......
...@@ -29,7 +29,7 @@ public class AxisTickLabels implements ChartPart { ...@@ -29,7 +29,7 @@ public class AxisTickLabels implements ChartPart {
private final AxisTick axisTick; private final AxisTick axisTick;
/** the bounds */ /** the bounds */
private Rectangle bounds; private Rectangle bounds = new Rectangle();
/** /**
* Constructor * Constructor
...@@ -50,12 +50,11 @@ public class AxisTickLabels implements ChartPart { ...@@ -50,12 +50,11 @@ public class AxisTickLabels implements ChartPart {
@Override @Override
public void paint(Graphics2D g) { public void paint(Graphics2D g) {
bounds = new Rectangle();
g.setFont(getChartPainter().getStyleManager().getAxisTickLabelsFont()); g.setFont(getChartPainter().getStyleManager().getAxisTickLabelsFont());
g.setColor(getChartPainter().getStyleManager().getAxisTickLabelsColor()); g.setColor(getChartPainter().getStyleManager().getAxisTickLabelsColor());
if (axisTick.getAxis().getDirection() == Axis.Direction.Y) { // Y-Axis if (axisTick.getAxis().getDirection() == Axis.Direction.Y && getChartPainter().getStyleManager().isYAxisTicksVisible()) { // Y-Axis
int xOffset = (int) (axisTick.getAxis().getAxisTitle().getBounds().getX() + axisTick.getAxis().getAxisTitle().getBounds().getWidth()); int xOffset = (int) (axisTick.getAxis().getAxisTitle().getBounds().getX() + axisTick.getAxis().getAxisTitle().getBounds().getWidth());
int yOffset = (int) (axisTick.getAxis().getPaintZone().getY()); int yOffset = (int) (axisTick.getAxis().getPaintZone().getY());
...@@ -84,7 +83,7 @@ public class AxisTickLabels implements ChartPart { ...@@ -84,7 +83,7 @@ public class AxisTickLabels implements ChartPart {
// g.setColor(Color.blue); // g.setColor(Color.blue);
// g.draw(bounds); // g.draw(bounds);
} else { // X-Axis } else if (axisTick.getAxis().getDirection() == Axis.Direction.X && getChartPainter().getStyleManager().isXAxisTicksVisible()) { // X-Axis
int xOffset = (int) (axisTick.getAxis().getPaintZone().getX()); int xOffset = (int) (axisTick.getAxis().getPaintZone().getX());
int yOffset = (int) (axisTick.getAxis().getAxisTitle().getBounds().getY()); int yOffset = (int) (axisTick.getAxis().getAxisTitle().getBounds().getY());
......
...@@ -27,7 +27,7 @@ public class AxisTickMarks implements ChartPart { ...@@ -27,7 +27,7 @@ public class AxisTickMarks implements ChartPart {
private AxisTick axisTick; private AxisTick axisTick;
/** the bounds */ /** the bounds */
private Rectangle bounds; private Rectangle bounds = new Rectangle();
/** /**
* Constructor * Constructor
...@@ -48,12 +48,10 @@ public class AxisTickMarks implements ChartPart { ...@@ -48,12 +48,10 @@ public class AxisTickMarks implements ChartPart {
@Override @Override
public void paint(Graphics2D g) { public void paint(Graphics2D g) {
bounds = new Rectangle();
g.setColor(getChartPainter().getStyleManager().getAxisTickMarksColor()); g.setColor(getChartPainter().getStyleManager().getAxisTickMarksColor());
g.setStroke(getChartPainter().getStyleManager().getAxisTickMarksStroke()); g.setStroke(getChartPainter().getStyleManager().getAxisTickMarksStroke());
if (axisTick.getAxis().getDirection() == Axis.Direction.Y) { // Y-Axis if (axisTick.getAxis().getDirection() == Axis.Direction.Y && getChartPainter().getStyleManager().isYAxisTicksVisible()) { // Y-Axis
int xOffset = (int) (axisTick.getAxisTickLabels().getBounds().getX() + axisTick.getAxisTickLabels().getBounds().getWidth() + getChartPainter().getStyleManager().getAxisTickPadding()); int xOffset = (int) (axisTick.getAxisTickLabels().getBounds().getX() + axisTick.getAxisTickLabels().getBounds().getWidth() + getChartPainter().getStyleManager().getAxisTickPadding());
int yOffset = (int) (axisTick.getAxis().getPaintZone().getY()); int yOffset = (int) (axisTick.getAxis().getPaintZone().getY());
...@@ -82,7 +80,7 @@ public class AxisTickMarks implements ChartPart { ...@@ -82,7 +80,7 @@ public class AxisTickMarks implements ChartPart {
// g.setColor(Color.yellow); // g.setColor(Color.yellow);
// g.draw(bounds); // g.draw(bounds);
} else { // X-Axis } else if (axisTick.getAxis().getDirection() == Axis.Direction.X && getChartPainter().getStyleManager().isXAxisTicksVisible()) { // X-Axis
int xOffset = (int) (axisTick.getAxis().getPaintZone().getX()); int xOffset = (int) (axisTick.getAxis().getPaintZone().getX());
// int yOffset = (int) (axisTick.getAxisTickLabels().getBounds().getY() - getChart().getStyleManager().getAxisTickPadding()); // int yOffset = (int) (axisTick.getAxisTickLabels().getBounds().getY() - getChart().getStyleManager().getAxisTickPadding());
......
...@@ -40,7 +40,7 @@ public class AxisTitle implements ChartPart { ...@@ -40,7 +40,7 @@ public class AxisTitle implements ChartPart {
* *
* @param axis the axis * @param axis the axis
*/ */
protected AxisTitle(Axis axis, boolean isVisible) { protected AxisTitle(Axis axis) {
this.axis = axis; this.axis = axis;
} }
......
...@@ -121,7 +121,7 @@ public class Legend implements ChartPart { ...@@ -121,7 +121,7 @@ public class Legend implements ChartPart {
int xOffset = 0; int xOffset = 0;
int yOffset = 0; int yOffset = 0;
switch (chartPainter.getStyleManager().getLegendPosition()) { switch (chartPainter.getStyleManager().getLegendPosition()) {
case OutsideW: case OutsideE:
xOffset = chartPainter.getWidth() - legendBoxWidth - chartPainter.getStyleManager().getChartPadding(); xOffset = chartPainter.getWidth() - legendBoxWidth - chartPainter.getStyleManager().getChartPadding();
yOffset = (int) (chartPainter.getPlot().getBounds().getY() + (chartPainter.getPlot().getBounds().getHeight() - legendBoxHeight) / 2.0); yOffset = (int) (chartPainter.getPlot().getBounds().getY() + (chartPainter.getPlot().getBounds().getHeight() - legendBoxHeight) / 2.0);
break; break;
......
...@@ -59,8 +59,12 @@ public class Plot implements ChartPart { ...@@ -59,8 +59,12 @@ public class Plot implements ChartPart {
bounds = new Rectangle(); bounds = new Rectangle();
// calculate bounds // calculate bounds
int xOffset = (int) (chartPainter.getAxisPair().getyAxis().getBounds().getX() + chartPainter.getAxisPair().getyAxis().getBounds().getWidth() + (chartPainter.getStyleManager() int xOffset = (int) (chartPainter.getAxisPair().getyAxis().getBounds().getX()
.isYAxisTicksVisible() ? (chartPainter.getStyleManager().getPlotPadding() + 1) : 0));
+ chartPainter.getAxisPair().getyAxis().getBounds().getWidth()
+ (chartPainter.getStyleManager().isYAxisTicksVisible() ? (chartPainter.getStyleManager().getPlotPadding() + 1) : 0));
int yOffset = (int) (chartPainter.getAxisPair().getyAxis().getBounds().getY()); int yOffset = (int) (chartPainter.getAxisPair().getyAxis().getBounds().getY());
int width = (int) chartPainter.getAxisPair().getxAxis().getBounds().getWidth(); int width = (int) chartPainter.getAxisPair().getxAxis().getBounds().getWidth();
int height = (int) chartPainter.getAxisPair().getyAxis().getBounds().getHeight(); int height = (int) chartPainter.getAxisPair().getyAxis().getBounds().getHeight();
......
...@@ -127,7 +127,7 @@ public class GGPlot2Theme implements Theme { ...@@ -127,7 +127,7 @@ public class GGPlot2Theme implements Theme {
@Override @Override
public LegendPosition getLegendPosition() { public LegendPosition getLegendPosition() {
return LegendPosition.OutsideW; return LegendPosition.OutsideE;
} }
// Chart Axes /////////////////////////////// // Chart Axes ///////////////////////////////
......
...@@ -128,7 +128,7 @@ public class XChartTheme implements Theme { ...@@ -128,7 +128,7 @@ public class XChartTheme implements Theme {
@Override @Override
public LegendPosition getLegendPosition() { public LegendPosition getLegendPosition() {
return LegendPosition.OutsideW; return LegendPosition.OutsideE;
} }
// Chart Axes /////////////////////////////// // Chart Axes ///////////////////////////////
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment