From 5ee97f6385eab6f7e3386863514c246dfc36fc31 Mon Sep 17 00:00:00 2001 From: Tim Molter <tim.molter@gmail.com> Date: Tue, 28 Oct 2014 15:06:05 +0100 Subject: [PATCH] bugfix for issue #84 - The bar chart doesn't show the title in the version 2.4.1 --- .../xchart/internal/chartpart/ChartTitle.java | 15 +++++++-------- .../com/xeiam/xchart/internal/chartpart/Plot.java | 9 ++++----- .../internal/chartpart/PlotContentBarChart.java | 9 ++++++++- 3 files changed, 19 insertions(+), 14 deletions(-) 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 973ff52a..adb3ff43 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 @@ -39,7 +39,7 @@ public class ChartTitle implements ChartPart { /** * Constructor - * + * * @param chartPainter */ public ChartTitle(ChartPainter chartPainter) { @@ -49,7 +49,7 @@ public class ChartTitle implements ChartPart { /** * set the chart title's text - * + * * @param text */ public void setText(String text) { @@ -65,7 +65,7 @@ public class ChartTitle implements ChartPart { /** * get the height of the chart title including the chart padding - * + * * @return */ protected int getSizeHint() { @@ -94,8 +94,8 @@ public class ChartTitle implements ChartPart { TextLayout textLayout = new TextLayout(text, chartPainter.getStyleManager().getChartTitleFont(), frc); Rectangle2D rectangle = textLayout.getBounds(); - int xOffset = (int) chartPainter.getPlot().getBounds().getX(); - int yOffset = chartPainter.getStyleManager().getChartPadding(); + double xOffset = (int) chartPainter.getPlot().getBounds().getX(); + double yOffset = chartPainter.getStyleManager().getChartPadding(); if (chartPainter.getStyleManager().isChartTitleBoxVisible()) { @@ -109,12 +109,11 @@ public class ChartTitle implements ChartPart { g.fill(rect); g.setColor(chartPainter.getStyleManager().getChartTitleBoxBorderColor()); g.draw(rect); - } // paint title - xOffset = (int) (chartPainter.getPlot().getBounds().getX() + (chartPainter.getPlot().getBounds().getWidth() - rectangle.getWidth()) / 2.0); - yOffset = (int) (chartPainter.getStyleManager().getChartPadding() - rectangle.getY() + chartPainter.getStyleManager().getChartTitlePadding()); + xOffset = chartPainter.getPlot().getBounds().getX() + (chartPainter.getPlot().getBounds().getWidth() - rectangle.getWidth()) / 2.0; + yOffset = chartPainter.getStyleManager().getChartPadding() - rectangle.getY() + chartPainter.getStyleManager().getChartTitlePadding(); bounds = new Rectangle2D.Double(xOffset, yOffset + rectangle.getY(), rectangle.getWidth(), rectangle.getHeight()); // g.setColor(Color.green); diff --git a/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/Plot.java b/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/Plot.java index 59be2c9f..be45c59a 100644 --- a/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/Plot.java +++ b/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/Plot.java @@ -37,14 +37,13 @@ public class Plot implements ChartPart { /** * Constructor - * + * * @param chartPainter */ public Plot(ChartPainter chartPainter) { this.chartPainter = chartPainter; this.plotSurface = new PlotSurface(this); - } @Override @@ -61,11 +60,11 @@ public class Plot implements ChartPart { // calculate bounds double xOffset = chartPainter.getAxisPair().getYAxis().getBounds().getX() - + chartPainter.getAxisPair().getYAxis().getBounds().getWidth() + + chartPainter.getAxisPair().getYAxis().getBounds().getWidth() - + (chartPainter.getStyleManager().isYAxisTicksVisible() ? (chartPainter.getStyleManager().getPlotPadding()) : 0) + + (chartPainter.getStyleManager().isYAxisTicksVisible() ? (chartPainter.getStyleManager().getPlotPadding()) : 0) - ; + ; double yOffset = chartPainter.getAxisPair().getYAxis().getBounds().getY(); double width = chartPainter.getAxisPair().getXAxis().getBounds().getWidth(); diff --git a/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/PlotContentBarChart.java b/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/PlotContentBarChart.java index 197a8002..6ee673bd 100644 --- a/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/PlotContentBarChart.java +++ b/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/PlotContentBarChart.java @@ -45,10 +45,17 @@ public class PlotContentBarChart extends PlotContent { public void paint(Graphics2D g) { Rectangle2D bounds = plot.getBounds(); + // g.setStroke(new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL)); + // g.setColor(Color.red); + // g.draw(bounds); + StyleManager styleManager = plot.getChartPainter().getStyleManager(); // this is for preventing the series to be drawn outside the plot area if min and max is overridden to fall inside the data range Rectangle rectangle = new Rectangle(0, 0, getChartPainter().getWidth(), getChartPainter().getHeight()); + // g.setStroke(new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL)); + // g.setColor(Color.green); + // g.draw(rectangle); g.setClip(bounds.createIntersection(rectangle)); // X-Axis @@ -206,7 +213,7 @@ public class PlotContentBarChart extends PlotContent { } seriesCounter++; } - + g.setClip(null); } @Override -- GitLab