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

addressed a chart title box issue

parent d7be0164
No related branches found
No related tags found
No related merge requests found
...@@ -31,8 +31,8 @@ import com.xeiam.xchart.Series; ...@@ -31,8 +31,8 @@ import com.xeiam.xchart.Series;
import com.xeiam.xchart.SeriesColor; import com.xeiam.xchart.SeriesColor;
import com.xeiam.xchart.SeriesLineStyle; import com.xeiam.xchart.SeriesLineStyle;
import com.xeiam.xchart.SeriesMarker; import com.xeiam.xchart.SeriesMarker;
import com.xeiam.xchart.SwingWrapper;
import com.xeiam.xchart.StyleManager.LegendPosition; import com.xeiam.xchart.StyleManager.LegendPosition;
import com.xeiam.xchart.SwingWrapper;
import com.xeiam.xchart.demo.charts.ExampleChart; import com.xeiam.xchart.demo.charts.ExampleChart;
/** /**
...@@ -79,7 +79,9 @@ public class LineChart03 implements ExampleChart { ...@@ -79,7 +79,9 @@ public class LineChart03 implements ExampleChart {
chart.getStyleManager().setChartBackgroundColor(Color.WHITE); chart.getStyleManager().setChartBackgroundColor(Color.WHITE);
chart.getStyleManager().setLegendBackgroundColor(Color.PINK); chart.getStyleManager().setLegendBackgroundColor(Color.PINK);
chart.getStyleManager().setChartFontColor(Color.MAGENTA); 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().setPlotGridLinesVisible(false);
chart.getStyleManager().setAxisTickPadding(20); chart.getStyleManager().setAxisTickPadding(20);
chart.getStyleManager().setAxisTickMarkLength(15); chart.getStyleManager().setAxisTickMarkLength(15);
...@@ -101,5 +103,4 @@ public class LineChart03 implements ExampleChart { ...@@ -101,5 +103,4 @@ public class LineChart03 implements ExampleChart {
return chart; return chart;
} }
} }
...@@ -63,8 +63,9 @@ public class StyleManager { ...@@ -63,8 +63,9 @@ public class StyleManager {
// Chart Title /////////////////////////////// // Chart Title ///////////////////////////////
private Font chartTitleFont; private Font chartTitleFont;
private boolean isChartTitleVisible; private boolean isChartTitleVisible;
private Color chartTitleBackgroundColor; private boolean isChartTitleBoxVisible;
private Color chartTitleBorderColor; private Color chartTitleBoxBackgroundColor;
private Color chartTitleBoxBorderColor;
private int chartTitlePadding; private int chartTitlePadding;
// Chart Legend /////////////////////////////// // Chart Legend ///////////////////////////////
...@@ -134,8 +135,9 @@ public class StyleManager { ...@@ -134,8 +135,9 @@ public class StyleManager {
// Chart Title /////////////////////////////// // Chart Title ///////////////////////////////
chartTitleFont = theme.getChartTitleFont(); chartTitleFont = theme.getChartTitleFont();
isChartTitleVisible = theme.isChartTitleVisible(); isChartTitleVisible = theme.isChartTitleVisible();
chartTitleBackgroundColor = theme.getChartTitleBackgroundColor(); isChartTitleBoxVisible = theme.isChartTitleBoxVisible();
chartTitleBorderColor = theme.getChartTitleBorderColor(); chartTitleBoxBackgroundColor = theme.getChartTitleBoxBackgroundColor();
chartTitleBoxBorderColor = theme.getChartTitleBoxBorderColor();
chartTitlePadding = theme.getChartTitlePadding(); chartTitlePadding = theme.getChartTitlePadding();
// legend // legend
...@@ -312,33 +314,48 @@ public class StyleManager { ...@@ -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;
} }
/** /**
......
...@@ -91,17 +91,21 @@ public class ChartTitle implements ChartPart { ...@@ -91,17 +91,21 @@ public class ChartTitle implements ChartPart {
TextLayout textLayout = new TextLayout(text, chartPainter.getStyleManager().getChartTitleFont(), frc); TextLayout textLayout = new TextLayout(text, chartPainter.getStyleManager().getChartTitleFont(), frc);
Rectangle rectangle = textLayout.getPixelBounds(null, 0, 0); Rectangle rectangle = textLayout.getPixelBounds(null, 0, 0);
int xOffset = (int) chartPainter.getPlot().getBounds().getX();
int yOffset = chartPainter.getStyleManager().getChartPadding();
if (chartPainter.getStyleManager().isChartTitleBoxVisible()) {
// paint the chart title box // paint the chart title box
int chartTitleBoxWidth = (int) chartPainter.getPlot().getBounds().getWidth(); int chartTitleBoxWidth = (int) chartPainter.getPlot().getBounds().getWidth();
int chartTitleBoxHeight = (int) (rectangle.getHeight() + 2 * chartPainter.getStyleManager().getChartTitlePadding()); 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.setStroke(new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL));
g.setColor(chartPainter.getStyleManager().getChartTitleBorderColor()); g.setColor(chartPainter.getStyleManager().getChartTitleBoxBorderColor());
g.drawRect(xOffset - 1, yOffset, chartTitleBoxWidth - 1, chartTitleBoxHeight - 1); g.drawRect(xOffset - 1, yOffset, chartTitleBoxWidth, chartTitleBoxHeight);
g.setColor(chartPainter.getStyleManager().getChartTitleBackgroundColor()); g.setColor(chartPainter.getStyleManager().getChartTitleBoxBackgroundColor());
g.fillRect(xOffset - 1, yOffset + 1, chartTitleBoxWidth, chartTitleBoxHeight - 1); g.fillRect(xOffset, yOffset + 1, chartTitleBoxWidth - 1, chartTitleBoxHeight - 1);
}
// paint title // paint title
xOffset = (int) (chartPainter.getPlot().getBounds().getX() + (chartPainter.getPlot().getBounds().getWidth() - rectangle.getWidth()) / 2.0); xOffset = (int) (chartPainter.getPlot().getBounds().getX() + (chartPainter.getPlot().getBounds().getWidth() - rectangle.getWidth()) / 2.0);
......
...@@ -69,13 +69,19 @@ public class GGPlot2Theme implements Theme { ...@@ -69,13 +69,19 @@ public class GGPlot2Theme implements Theme {
} }
@Override @Override
public Color getChartTitleBackgroundColor() { public boolean isChartTitleBoxVisible() {
return true;
}
@Override
public Color getChartTitleBoxBackgroundColor() {
return ChartColor.getAWTColor(ChartColor.GREY); return ChartColor.getAWTColor(ChartColor.GREY);
} }
@Override @Override
public Color getChartTitleBorderColor() { public Color getChartTitleBoxBorderColor() {
return ChartColor.getAWTColor(ChartColor.GREY); return ChartColor.getAWTColor(ChartColor.GREY);
} }
......
...@@ -46,9 +46,11 @@ public interface Theme { ...@@ -46,9 +46,11 @@ public interface Theme {
public boolean isChartTitleVisible(); public boolean isChartTitleVisible();
public Color getChartTitleBackgroundColor(); public boolean isChartTitleBoxVisible();
public Color getChartTitleBorderColor(); public Color getChartTitleBoxBackgroundColor();
public Color getChartTitleBoxBorderColor();
public int getChartTitlePadding(); public int getChartTitlePadding();
......
...@@ -69,13 +69,19 @@ public class XChartTheme implements Theme { ...@@ -69,13 +69,19 @@ public class XChartTheme implements Theme {
} }
@Override @Override
public Color getChartTitleBackgroundColor() { public boolean isChartTitleBoxVisible() {
return false;
}
@Override
public Color getChartTitleBoxBackgroundColor() {
return ChartColor.getAWTColor(ChartColor.GREY); return ChartColor.getAWTColor(ChartColor.GREY);
} }
@Override @Override
public Color getChartTitleBorderColor() { public Color getChartTitleBoxBorderColor() {
return ChartColor.getAWTColor(ChartColor.GREY); return ChartColor.getAWTColor(ChartColor.GREY);
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment