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

more style abstraction work

parent 6501cb85
No related branches found
No related tags found
No related merge requests found
...@@ -144,7 +144,7 @@ public class Axis implements IChartPart { ...@@ -144,7 +144,7 @@ public class Axis implements IChartPart {
if (axisPair.chart.getStyleManager().isxAxisTitleVisible()) { if (axisPair.chart.getStyleManager().isxAxisTitleVisible()) {
TextLayout textLayout = new TextLayout(axisTitle.getText(), axisTick.axis.axisPair.chart.getStyleManager().getAxisTitleFont(), new FontRenderContext(null, true, false)); TextLayout textLayout = new TextLayout(axisTitle.getText(), axisTick.axis.axisPair.chart.getStyleManager().getAxisTitleFont(), new FontRenderContext(null, true, false));
Rectangle rectangle = textLayout.getPixelBounds(null, 0, 0); Rectangle rectangle = textLayout.getPixelBounds(null, 0, 0);
titleHeight = rectangle.getHeight() + AxisTitle.AXIS_TITLE_PADDING; titleHeight = rectangle.getHeight() + axisTick.axis.axisPair.chart.getStyleManager().getAxisTitlePadding();
} }
// Axis tick labels // Axis tick labels
...@@ -152,7 +152,8 @@ public class Axis implements IChartPart { ...@@ -152,7 +152,8 @@ public class Axis implements IChartPart {
if (axisPair.chart.getStyleManager().isxAxisTicksVisible()) { if (axisPair.chart.getStyleManager().isxAxisTicksVisible()) {
TextLayout textLayout = new TextLayout("0", axisTick.axis.axisPair.chart.getStyleManager().getAxisTicksFont(), new FontRenderContext(null, true, false)); TextLayout textLayout = new TextLayout("0", axisTick.axis.axisPair.chart.getStyleManager().getAxisTicksFont(), new FontRenderContext(null, true, false));
Rectangle rectangle = textLayout.getPixelBounds(null, 0, 0); Rectangle rectangle = textLayout.getPixelBounds(null, 0, 0);
axisTickLabelsHeight = rectangle.getHeight() + AxisTick.AXIS_TICK_PADDING + AxisTickMarks.TICK_LENGTH + Plot.PLOT_PADDING; axisTickLabelsHeight = rectangle.getHeight() + axisPair.chart.getStyleManager().getAxisTickPadding() + axisPair.chart.getStyleManager().getAxisTickMarkLength()
+ axisPair.chart.getStyleManager().getPlotPadding();
} }
return (int) (titleHeight + axisTickLabelsHeight); return (int) (titleHeight + axisTickLabelsHeight);
} else { // Y-Axis } else { // Y-Axis
...@@ -202,8 +203,8 @@ public class Axis implements IChartPart { ...@@ -202,8 +203,8 @@ public class Axis implements IChartPart {
// calculate paint zone // calculate paint zone
// |____________________| // |____________________|
int xOffset = (int) (axisPair.yAxis.getBounds().getWidth() + (axisPair.chart.getStyleManager().isyAxisTicksVisible() ? Plot.PLOT_PADDING : 0) + axisPair.chart.getStyleManager() int xOffset = (int) (axisPair.yAxis.getBounds().getWidth() + (axisPair.chart.getStyleManager().isyAxisTicksVisible() ? axisPair.chart.getStyleManager().getPlotPadding() : 0) + axisPair.chart
.getChartPadding()); .getStyleManager().getChartPadding());
int yOffset = (int) (axisPair.yAxis.getBounds().getY() + axisPair.yAxis.getBounds().getHeight()); int yOffset = (int) (axisPair.yAxis.getBounds().getY() + axisPair.yAxis.getBounds().getHeight());
int width = (int) (axisPair.chart.width - axisPair.yAxis.getBounds().getWidth() - axisPair.getChartLegendBounds().getWidth() - (axisPair.chart.getStyleManager().isLegendVisible() ? 3 : 2) int width = (int) (axisPair.chart.width - axisPair.yAxis.getBounds().getWidth() - axisPair.getChartLegendBounds().getWidth() - (axisPair.chart.getStyleManager().isLegendVisible() ? 3 : 2)
* axisPair.chart.getStyleManager().getChartPadding()); * axisPair.chart.getStyleManager().getChartPadding());
......
...@@ -30,7 +30,7 @@ import com.xeiam.xchart.internal.interfaces.IHideable; ...@@ -30,7 +30,7 @@ import com.xeiam.xchart.internal.interfaces.IHideable;
import com.xeiam.xchart.internal.misc.AxisValueFormatterUtil; import com.xeiam.xchart.internal.misc.AxisValueFormatterUtil;
/** /**
* An axis tick. * An axis tick
*/ */
public class AxisTick implements IChartPart, IHideable { public class AxisTick implements IChartPart, IHideable {
...@@ -40,9 +40,6 @@ public class AxisTick implements IChartPart, IHideable { ...@@ -40,9 +40,6 @@ public class AxisTick implements IChartPart, IHideable {
/** the default tick mark step hint for y axis */ /** the default tick mark step hint for y axis */
private static final int DEFAULT_TICK_MARK_STEP_HINT_Y = 44; private static final int DEFAULT_TICK_MARK_STEP_HINT_Y = 44;
/** the padding between the tick labels and the tick marks */
protected final static int AXIS_TICK_PADDING = 4;
/** parent */ /** parent */
protected Axis axis; protected Axis axis;
...@@ -123,14 +120,14 @@ public class AxisTick implements IChartPart, IHideable { ...@@ -123,14 +120,14 @@ public class AxisTick implements IChartPart, IHideable {
axisTickMarks.paint(g); axisTickMarks.paint(g);
if (axis.direction == Axis.Direction.Y) { if (axis.direction == Axis.Direction.Y) {
bounds = new Rectangle((int) axisTickLabels.getBounds().getX(), (int) (axisTickLabels.getBounds().getY()), (int) (axisTickLabels.getBounds().getWidth() + AXIS_TICK_PADDING + axisTickMarks bounds = new Rectangle((int) axisTickLabels.getBounds().getX(), (int) (axisTickLabels.getBounds().getY()), (int) (axisTickLabels.getBounds().getWidth()
.getBounds().getWidth()), (int) (axisTickMarks.getBounds().getHeight())); + axis.axisPair.chart.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 {
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()
+ AXIS_TICK_PADDING + axisTickLabels.getBounds().getHeight())); + axis.axisPair.chart.getStyleManager().getAxisTickPadding() + axisTickLabels.getBounds().getHeight()));
// g.setColor(Color.red); // g.setColor(Color.red);
// g.draw(bounds); // g.draw(bounds);
} }
......
...@@ -27,9 +27,6 @@ import com.xeiam.xchart.internal.interfaces.IChartPart; ...@@ -27,9 +27,6 @@ import com.xeiam.xchart.internal.interfaces.IChartPart;
*/ */
public class AxisTickMarks implements IChartPart { public class AxisTickMarks implements IChartPart {
/** the tick length */
public static final int TICK_LENGTH = 3;
/** parent */ /** parent */
private AxisTick axisTick; private AxisTick axisTick;
...@@ -64,7 +61,7 @@ public class AxisTickMarks implements IChartPart { ...@@ -64,7 +61,7 @@ public class AxisTickMarks implements IChartPart {
if (axisTick.axis.direction == Axis.Direction.Y) { // Y-Axis if (axisTick.axis.direction == Axis.Direction.Y) { // Y-Axis
int xOffset = (int) (axisTick.axisTickLabels.getBounds().getX() + axisTick.axisTickLabels.getBounds().getWidth() + AxisTick.AXIS_TICK_PADDING); int xOffset = (int) (axisTick.axisTickLabels.getBounds().getX() + axisTick.axisTickLabels.getBounds().getWidth() + axisTick.axis.axisPair.chart.getStyleManager().getAxisTickPadding());
int yOffset = (int) (axisTick.axis.getPaintZone().getY()); int yOffset = (int) (axisTick.axis.getPaintZone().getY());
// tick marks // tick marks
...@@ -75,21 +72,24 @@ public class AxisTickMarks implements IChartPart { ...@@ -75,21 +72,24 @@ public class AxisTickMarks implements IChartPart {
g.setColor(axisTick.axis.axisPair.chart.getStyleManager().getChartBordersColor()); g.setColor(axisTick.axis.axisPair.chart.getStyleManager().getChartBordersColor());
g.setStroke(stroke); g.setStroke(stroke);
g.drawLine(xOffset, yOffset + (int) (axisTick.axis.getPaintZone().getHeight() - tickLocation), xOffset + TICK_LENGTH, yOffset + (int) (axisTick.axis.getPaintZone().getHeight() - tickLocation)); g.drawLine(xOffset, yOffset + (int) (axisTick.axis.getPaintZone().getHeight() - tickLocation), xOffset + axisTick.axis.axisPair.chart.getStyleManager().getAxisTickMarkLength(), yOffset
+ (int) (axisTick.axis.getPaintZone().getHeight() - tickLocation));
} }
// Line // Line
g.drawLine(xOffset + TICK_LENGTH, yOffset, xOffset + TICK_LENGTH, yOffset + (int) axisTick.axis.getPaintZone().getHeight()); if (axisTick.axis.axisPair.chart.getStyleManager().isAxisTicksLineVisible()) {
g.drawLine(xOffset + axisTick.axis.axisPair.chart.getStyleManager().getAxisTickMarkLength(), yOffset, xOffset + axisTick.axis.axisPair.chart.getStyleManager().getAxisTickMarkLength(), yOffset
+ (int) axisTick.axis.getPaintZone().getHeight());
}
// bounds // bounds
bounds = new Rectangle(xOffset, yOffset, TICK_LENGTH, (int) axisTick.axis.getPaintZone().getHeight()); bounds = new Rectangle(xOffset, yOffset, axisTick.axis.axisPair.chart.getStyleManager().getAxisTickMarkLength(), (int) axisTick.axis.getPaintZone().getHeight());
// g.setColor(Color.yellow); // g.setColor(Color.yellow);
// g.draw(bounds); // g.draw(bounds);
} else { // X-Axis } else { // X-Axis
int xOffset = (int) (axisTick.axis.getPaintZone().getX()); int xOffset = (int) (axisTick.axis.getPaintZone().getX());
int yOffset = (int) (axisTick.axisTickLabels.getBounds().getY() - AxisTick.AXIS_TICK_PADDING); int yOffset = (int) (axisTick.axisTickLabels.getBounds().getY() - axisTick.axis.axisPair.chart.getStyleManager().getAxisTickPadding());
// tick marks // tick marks
for (int i = 0; i < axisTick.tickLabels.size(); i++) { for (int i = 0; i < axisTick.tickLabels.size(); i++) {
...@@ -99,13 +99,19 @@ public class AxisTickMarks implements IChartPart { ...@@ -99,13 +99,19 @@ public class AxisTickMarks implements IChartPart {
g.setColor(axisTick.axis.axisPair.chart.getStyleManager().getChartBordersColor()); g.setColor(axisTick.axis.axisPair.chart.getStyleManager().getChartBordersColor());
g.setStroke(stroke); g.setStroke(stroke);
g.drawLine(xOffset + tickLocation, yOffset, xOffset + tickLocation, yOffset - TICK_LENGTH); g.drawLine(xOffset + tickLocation, yOffset, xOffset + tickLocation, yOffset - axisTick.axis.axisPair.chart.getStyleManager().getAxisTickMarkLength());
} }
// Line // Line
g.drawLine(xOffset, yOffset - TICK_LENGTH, xOffset + (int) axisTick.axis.getPaintZone().getWidth(), yOffset - TICK_LENGTH); if (axisTick.axis.axisPair.chart.getStyleManager().isAxisTicksLineVisible()) {
g.drawLine(xOffset, yOffset - axisTick.axis.axisPair.chart.getStyleManager().getAxisTickMarkLength(), xOffset + (int) axisTick.axis.getPaintZone().getWidth(), yOffset
- axisTick.axis.axisPair.chart.getStyleManager().getAxisTickMarkLength());
}
// bounds // bounds
bounds = new Rectangle(xOffset, yOffset - TICK_LENGTH, (int) axisTick.axis.getPaintZone().getWidth(), TICK_LENGTH); bounds = new Rectangle(xOffset, yOffset - axisTick.axis.axisPair.chart.getStyleManager().getAxisTickMarkLength(), (int) axisTick.axis.getPaintZone().getWidth(), axisTick.axis.axisPair.chart
.getStyleManager().getAxisTickMarkLength());
// g.setColor(Color.yellow); // g.setColor(Color.yellow);
// g.draw(bounds); // g.draw(bounds);
} }
......
...@@ -29,8 +29,6 @@ import com.xeiam.xchart.internal.interfaces.IHideable; ...@@ -29,8 +29,6 @@ import com.xeiam.xchart.internal.interfaces.IHideable;
*/ */
public class AxisTitle implements IChartPart, IHideable { public class AxisTitle implements IChartPart, IHideable {
protected final static int AXIS_TITLE_PADDING = 10;
/** parent */ /** parent */
private final Axis axis; private final Axis axis;
...@@ -111,8 +109,8 @@ public class AxisTitle implements IChartPart, IHideable { ...@@ -111,8 +109,8 @@ public class AxisTitle implements IChartPart, IHideable {
g.setTransform(orig); g.setTransform(orig);
// bounds // bounds
bounds = new Rectangle((int) (xOffset - nonRotatedRectangle.getHeight()), (int) (yOffset - nonRotatedRectangle.getWidth()), (int) nonRotatedRectangle.getHeight() + AXIS_TITLE_PADDING, bounds = new Rectangle((int) (xOffset - nonRotatedRectangle.getHeight()), (int) (yOffset - nonRotatedRectangle.getWidth()), (int) nonRotatedRectangle.getHeight()
(int) nonRotatedRectangle.getWidth()); + axis.axisPair.chart.getStyleManager().getAxisTitlePadding(), (int) nonRotatedRectangle.getWidth());
// g.setColor(Color.blue); // g.setColor(Color.blue);
// g.draw(bounds); // g.draw(bounds);
} else { } else {
...@@ -133,7 +131,8 @@ public class AxisTitle implements IChartPart, IHideable { ...@@ -133,7 +131,8 @@ public class AxisTitle implements IChartPart, IHideable {
textLayout.draw(g, xOffset, (float) (yOffset - rectangle.getY())); textLayout.draw(g, xOffset, (float) (yOffset - rectangle.getY()));
bounds = new Rectangle(xOffset, yOffset - AXIS_TITLE_PADDING, (int) rectangle.getWidth(), (int) rectangle.getHeight() + AXIS_TITLE_PADDING); bounds = new Rectangle(xOffset, yOffset - axis.axisPair.chart.getStyleManager().getAxisTitlePadding(), (int) rectangle.getWidth(), (int) rectangle.getHeight()
+ axis.axisPair.chart.getStyleManager().getAxisTitlePadding());
// g.setColor(Color.blue); // g.setColor(Color.blue);
// g.draw(bounds); // g.draw(bounds);
......
...@@ -33,8 +33,6 @@ public class Plot implements IChartPart { ...@@ -33,8 +33,6 @@ public class Plot implements IChartPart {
protected PlotContent plotContent; protected PlotContent plotContent;
public static final int PLOT_PADDING = 3;
/** the bounds */ /** the bounds */
private Rectangle bounds; private Rectangle bounds;
...@@ -57,7 +55,8 @@ public class Plot implements IChartPart { ...@@ -57,7 +55,8 @@ public class Plot implements IChartPart {
bounds = new Rectangle(); bounds = new Rectangle();
// calculate bounds // calculate bounds
int xOffset = (int) (chart.axisPair.yAxis.getBounds().getX() + chart.axisPair.yAxis.getBounds().getWidth() + (chart.getStyleManager().isyAxisTicksVisible() ? (Plot.PLOT_PADDING + 1) : 0)); int xOffset = (int) (chart.axisPair.yAxis.getBounds().getX() + chart.axisPair.yAxis.getBounds().getWidth() + (chart.getStyleManager().isyAxisTicksVisible() ? (chart.getStyleManager()
.getPlotPadding() + 1) : 0));
int yOffset = (int) (chart.axisPair.yAxis.getBounds().getY()); int yOffset = (int) (chart.axisPair.yAxis.getBounds().getY());
int width = (int) chart.axisPair.xAxis.getBounds().getWidth(); int width = (int) chart.axisPair.xAxis.getBounds().getWidth();
int height = (int) chart.axisPair.yAxis.getBounds().getHeight(); int height = (int) chart.axisPair.yAxis.getBounds().getHeight();
......
...@@ -54,6 +54,11 @@ public class StyleManager { ...@@ -54,6 +54,11 @@ public class StyleManager {
private boolean xAxisTicksVisible; private boolean xAxisTicksVisible;
private boolean yAxisTicksVisible; private boolean yAxisTicksVisible;
private Font axisTicksFont; private Font axisTicksFont;
private int axisTickMarkLength;
private int axisTickPadding;
private boolean isAxisTicksLineVisible;
private int plotPadding;
private int axisTitlePadding;
/** /**
* Constructor * Constructor
...@@ -85,6 +90,11 @@ public class StyleManager { ...@@ -85,6 +90,11 @@ public class StyleManager {
xAxisTicksVisible = theme.isXAxisTicksVisible(); xAxisTicksVisible = theme.isXAxisTicksVisible();
yAxisTicksVisible = theme.isYAxisTicksVisible(); yAxisTicksVisible = theme.isYAxisTicksVisible();
axisTicksFont = theme.getAxisTicksFont(); axisTicksFont = theme.getAxisTicksFont();
axisTickMarkLength = theme.getAxisTickMarkLength();
axisTickPadding = theme.getAxisTickPadding();
isAxisTicksLineVisible = theme.isAxisTicksLineVisible();
plotPadding = theme.getPlotPadding();
axisTitlePadding = theme.getAxisTitlePadding();
} }
/** /**
...@@ -372,4 +382,78 @@ public class StyleManager { ...@@ -372,4 +382,78 @@ public class StyleManager {
return axisTicksFont; return axisTicksFont;
} }
/**
* set the axis tick mark length
*
* @param axisTickMarkLength
*/
public void setAxisTickMarkLength(int axisTickMarkLength) {
this.axisTickMarkLength = axisTickMarkLength;
}
public int getAxisTickMarkLength() {
return axisTickMarkLength;
}
/**
* the padding between the tick labels and the tick marks
*
* @param axisTickPadding
*/
public void setAxisTickPadding(int axisTickPadding) {
this.axisTickPadding = axisTickPadding;
}
public int getAxisTickPadding() {
return axisTickPadding;
}
/**
* sets the visibility of the line parallel to the plot edges that go along with the tick marks
*
* @param isAxisTicksLineVisible
*/
public void setAxisTicksLineVisible(boolean isAxisTicksLineVisible) {
this.isAxisTicksLineVisible = isAxisTicksLineVisible;
}
public boolean isAxisTicksLineVisible() {
return isAxisTicksLineVisible;
}
/**
* sets the pading between the tick marks and the plot area
*
* @param plotPadding
*/
public void setPlotPadding(int plotPadding) {
this.plotPadding = plotPadding;
}
public int getPlotPadding() {
return plotPadding;
}
/**
* sets the padding between the axis title and the tick labels
*
* @param axisTitlePadding
*/
public void setAxisTitlePadding(int axisTitlePadding) {
this.axisTitlePadding = axisTitlePadding;
}
public int getAxisTitlePadding() {
return axisTitlePadding;
}
} }
...@@ -69,4 +69,14 @@ public interface Theme { ...@@ -69,4 +69,14 @@ public interface Theme {
public Font getAxisTicksFont(); public Font getAxisTicksFont();
public int getAxisTickMarkLength();
public int getAxisTickPadding();
public boolean isAxisTicksLineVisible();
public int getAxisTitlePadding();
public int getPlotPadding();
} }
...@@ -133,4 +133,33 @@ public class XChartTheme implements Theme { ...@@ -133,4 +133,33 @@ public class XChartTheme implements Theme {
return new Font(Font.SANS_SERIF, Font.BOLD, 12); return new Font(Font.SANS_SERIF, Font.BOLD, 12);
} }
@Override
public int getAxisTickMarkLength() {
return 3;
}
@Override
public int getAxisTickPadding() {
return 4;
}
@Override
public boolean isAxisTicksLineVisible() {
return true;
}
@Override
public int getPlotPadding() {
return 3;
}
@Override
public int getAxisTitlePadding() {
return 10;
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment