diff --git a/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/line/LineChart03.java b/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/line/LineChart03.java index 4c45430f2a080a7d56a6d16f2921743266941493..5dc34019aa4f7bf39bb258dfe6a5d11dae092759 100644 --- a/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/line/LineChart03.java +++ b/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/line/LineChart03.java @@ -31,8 +31,8 @@ import com.xeiam.xchart.Series; import com.xeiam.xchart.SeriesColor; import com.xeiam.xchart.SeriesLineStyle; import com.xeiam.xchart.SeriesMarker; -import com.xeiam.xchart.SwingWrapper; import com.xeiam.xchart.StyleManager.LegendPosition; +import com.xeiam.xchart.SwingWrapper; import com.xeiam.xchart.demo.charts.ExampleChart; /** @@ -79,7 +79,9 @@ public class LineChart03 implements ExampleChart { chart.getStyleManager().setChartBackgroundColor(Color.WHITE); chart.getStyleManager().setLegendBackgroundColor(Color.PINK); chart.getStyleManager().setChartFontColor(Color.MAGENTA); - chart.getStyleManager().setChartTitleBackgroundColor(new Color(0, 222, 0)); + chart.getStyleManager().setChartTitleBoxBackgroundColor(new Color(0, 222, 0)); + chart.getStyleManager().setChartTitleBoxVisible(true); + chart.getStyleManager().setChartTitleBoxBorderColor(Color.BLACK); chart.getStyleManager().setPlotGridLinesVisible(false); chart.getStyleManager().setAxisTickPadding(20); chart.getStyleManager().setAxisTickMarkLength(15); @@ -101,5 +103,4 @@ public class LineChart03 implements ExampleChart { return chart; } - } diff --git a/xchart/src/main/java/com/xeiam/xchart/StyleManager.java b/xchart/src/main/java/com/xeiam/xchart/StyleManager.java index 12c53692674bc9a94b8e74c7fdac06205df92431..d712b24f37fed4e659083b8583df8325f2fdd514 100644 --- a/xchart/src/main/java/com/xeiam/xchart/StyleManager.java +++ b/xchart/src/main/java/com/xeiam/xchart/StyleManager.java @@ -63,8 +63,9 @@ public class StyleManager { // Chart Title /////////////////////////////// private Font chartTitleFont; private boolean isChartTitleVisible; - private Color chartTitleBackgroundColor; - private Color chartTitleBorderColor; + private boolean isChartTitleBoxVisible; + private Color chartTitleBoxBackgroundColor; + private Color chartTitleBoxBorderColor; private int chartTitlePadding; // Chart Legend /////////////////////////////// @@ -134,8 +135,9 @@ public class StyleManager { // Chart Title /////////////////////////////// chartTitleFont = theme.getChartTitleFont(); isChartTitleVisible = theme.isChartTitleVisible(); - chartTitleBackgroundColor = theme.getChartTitleBackgroundColor(); - chartTitleBorderColor = theme.getChartTitleBorderColor(); + isChartTitleBoxVisible = theme.isChartTitleBoxVisible(); + chartTitleBoxBackgroundColor = theme.getChartTitleBoxBackgroundColor(); + chartTitleBoxBorderColor = theme.getChartTitleBoxBorderColor(); chartTitlePadding = theme.getChartTitlePadding(); // legend @@ -312,33 +314,48 @@ public class StyleManager { } /** - * set the chart title background color + * Set the chart title box visibility * - * @param chartTitleBackgroundColor + * @param isChartTitleBoxVisible */ - public void setChartTitleBackgroundColor(Color chartTitleBackgroundColor) { + public void setChartTitleBoxVisible(boolean isChartTitleBoxVisible) { - this.chartTitleBackgroundColor = chartTitleBackgroundColor; + this.isChartTitleBoxVisible = isChartTitleBoxVisible; } - public Color getChartTitleBackgroundColor() { + public boolean isChartTitleBoxVisible() { - return chartTitleBackgroundColor; + return isChartTitleBoxVisible; } /** - * set the chart title border color + * set the chart title box background color * - * @param chartTitleBorderColor + * @param chartTitleBoxBackgroundColor */ - public void setChartTitleBorderColor(Color chartTitleBorderColor) { + public void setChartTitleBoxBackgroundColor(Color chartTitleBoxBackgroundColor) { - this.chartTitleBorderColor = chartTitleBorderColor; + this.chartTitleBoxBackgroundColor = chartTitleBoxBackgroundColor; } - public Color getChartTitleBorderColor() { + public Color getChartTitleBoxBackgroundColor() { - return chartTitleBorderColor; + return chartTitleBoxBackgroundColor; + } + + /** + * set the chart title box border color + * + * @param chartTitleBoxBorderColor + */ + public void setChartTitleBoxBorderColor(Color chartTitleBoxBorderColor) { + + this.chartTitleBoxBorderColor = chartTitleBoxBorderColor; + } + + public Color getChartTitleBoxBorderColor() { + + return chartTitleBoxBorderColor; } /** diff --git a/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/ChartTitle.java b/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/ChartTitle.java index bc1ccbfa5a3fe16b3dd9a87393f66d100c8f7d9c..395e47aed3eb2fb37be0a4056889e872c8bad504 100644 --- a/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/ChartTitle.java +++ b/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/ChartTitle.java @@ -91,17 +91,21 @@ public class ChartTitle implements ChartPart { TextLayout textLayout = new TextLayout(text, chartPainter.getStyleManager().getChartTitleFont(), frc); Rectangle rectangle = textLayout.getPixelBounds(null, 0, 0); - // paint the chart title box - int chartTitleBoxWidth = (int) chartPainter.getPlot().getBounds().getWidth(); - int chartTitleBoxHeight = (int) (rectangle.getHeight() + 2 * chartPainter.getStyleManager().getChartTitlePadding()); int xOffset = (int) chartPainter.getPlot().getBounds().getX(); int yOffset = chartPainter.getStyleManager().getChartPadding(); - g.setStroke(new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL)); - g.setColor(chartPainter.getStyleManager().getChartTitleBorderColor()); - g.drawRect(xOffset - 1, yOffset, chartTitleBoxWidth - 1, chartTitleBoxHeight - 1); - g.setColor(chartPainter.getStyleManager().getChartTitleBackgroundColor()); - g.fillRect(xOffset - 1, yOffset + 1, chartTitleBoxWidth, chartTitleBoxHeight - 1); + if (chartPainter.getStyleManager().isChartTitleBoxVisible()) { + + // paint the chart title box + int chartTitleBoxWidth = (int) chartPainter.getPlot().getBounds().getWidth(); + int chartTitleBoxHeight = (int) (rectangle.getHeight() + 2 * chartPainter.getStyleManager().getChartTitlePadding()); + + g.setStroke(new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL)); + g.setColor(chartPainter.getStyleManager().getChartTitleBoxBorderColor()); + g.drawRect(xOffset - 1, yOffset, chartTitleBoxWidth, chartTitleBoxHeight); + g.setColor(chartPainter.getStyleManager().getChartTitleBoxBackgroundColor()); + g.fillRect(xOffset, yOffset + 1, chartTitleBoxWidth - 1, chartTitleBoxHeight - 1); + } // paint title xOffset = (int) (chartPainter.getPlot().getBounds().getX() + (chartPainter.getPlot().getBounds().getWidth() - rectangle.getWidth()) / 2.0); diff --git a/xchart/src/main/java/com/xeiam/xchart/internal/style/GGPlot2Theme.java b/xchart/src/main/java/com/xeiam/xchart/internal/style/GGPlot2Theme.java index ead2c0ad3556771452a82bafba8f9c902af4c237..207d55be598fb1db51875a8be76ea6f55b74807e 100644 --- a/xchart/src/main/java/com/xeiam/xchart/internal/style/GGPlot2Theme.java +++ b/xchart/src/main/java/com/xeiam/xchart/internal/style/GGPlot2Theme.java @@ -69,13 +69,19 @@ public class GGPlot2Theme implements Theme { } @Override - public Color getChartTitleBackgroundColor() { + public boolean isChartTitleBoxVisible() { + + return true; + } + + @Override + public Color getChartTitleBoxBackgroundColor() { return ChartColor.getAWTColor(ChartColor.GREY); } @Override - public Color getChartTitleBorderColor() { + public Color getChartTitleBoxBorderColor() { return ChartColor.getAWTColor(ChartColor.GREY); } diff --git a/xchart/src/main/java/com/xeiam/xchart/internal/style/Theme.java b/xchart/src/main/java/com/xeiam/xchart/internal/style/Theme.java index 85edec3e23a17f8f7ab555544ee04900bdb76358..c6fdc4f0732b61f516b4fbc8d021002655fc7375 100644 --- a/xchart/src/main/java/com/xeiam/xchart/internal/style/Theme.java +++ b/xchart/src/main/java/com/xeiam/xchart/internal/style/Theme.java @@ -46,9 +46,11 @@ public interface Theme { public boolean isChartTitleVisible(); - public Color getChartTitleBackgroundColor(); + public boolean isChartTitleBoxVisible(); - public Color getChartTitleBorderColor(); + public Color getChartTitleBoxBackgroundColor(); + + public Color getChartTitleBoxBorderColor(); public int getChartTitlePadding(); diff --git a/xchart/src/main/java/com/xeiam/xchart/internal/style/XChartTheme.java b/xchart/src/main/java/com/xeiam/xchart/internal/style/XChartTheme.java index d660fdf266e2d8341703426a16bc4fc830d35e4c..5d9b542b073313a464759abf599004f88c10393c 100644 --- a/xchart/src/main/java/com/xeiam/xchart/internal/style/XChartTheme.java +++ b/xchart/src/main/java/com/xeiam/xchart/internal/style/XChartTheme.java @@ -69,13 +69,19 @@ public class XChartTheme implements Theme { } @Override - public Color getChartTitleBackgroundColor() { + public boolean isChartTitleBoxVisible() { + + return false; + } + + @Override + public Color getChartTitleBoxBackgroundColor() { return ChartColor.getAWTColor(ChartColor.GREY); } @Override - public Color getChartTitleBorderColor() { + public Color getChartTitleBoxBorderColor() { return ChartColor.getAWTColor(ChartColor.GREY); }