diff --git a/xchart/src/main/java/com/xeiam/xchart/BitmapEncoder.java b/xchart/src/main/java/com/xeiam/xchart/BitmapEncoder.java index 463f10d6c20df269fcdeb920066ec0ba5bf55e6a..eb8b29737ad72d3d76487b929f7459c180d030c8 100644 --- a/xchart/src/main/java/com/xeiam/xchart/BitmapEncoder.java +++ b/xchart/src/main/java/com/xeiam/xchart/BitmapEncoder.java @@ -53,7 +53,7 @@ public final class BitmapEncoder { */ public static void savePNG(Chart chart, String fileName) throws IOException { - BufferedImage bufferedImage = new BufferedImage(chart.width, chart.height, BufferedImage.TYPE_INT_RGB); + BufferedImage bufferedImage = new BufferedImage(chart.getWidth(), chart.getHeight(), BufferedImage.TYPE_INT_RGB); Graphics2D lGraphics2D = bufferedImage.createGraphics(); chart.paint(lGraphics2D); @@ -74,7 +74,7 @@ public final class BitmapEncoder { */ public static void saveJPG(Chart chart, String fileName, float quality) throws FileNotFoundException, IOException { - BufferedImage bufferedImage = new BufferedImage(chart.width, chart.height, BufferedImage.TYPE_INT_RGB); + BufferedImage bufferedImage = new BufferedImage(chart.getWidth(), chart.getHeight(), BufferedImage.TYPE_INT_RGB); Graphics2D lGraphics2D = bufferedImage.createGraphics(); chart.paint(lGraphics2D); diff --git a/xchart/src/main/java/com/xeiam/xchart/Chart.java b/xchart/src/main/java/com/xeiam/xchart/Chart.java index bfd2652dea00baaa11d40e33f04a74ec5571eb27..1a2e451af2b1534ea7428f2ae80ff83dcafb471c 100644 --- a/xchart/src/main/java/com/xeiam/xchart/Chart.java +++ b/xchart/src/main/java/com/xeiam/xchart/Chart.java @@ -37,8 +37,8 @@ import com.xeiam.xchart.style.theme.Theme; */ public abstract class Chart { - public int width; - public int height; + private int width; + private int height; private StyleManager styleManager = new StyleManager(); private ValueFormatter valueFormatter = new ValueFormatter(); @@ -285,7 +285,7 @@ public abstract class Chart { } /** - * for internal useage + * for internal usage * * @return */ @@ -295,7 +295,7 @@ public abstract class Chart { } /** - * for internal useage + * for internal usage * * @return */ @@ -305,7 +305,7 @@ public abstract class Chart { } /** - * for internal useage + * for internal usage * * @return */ @@ -315,7 +315,7 @@ public abstract class Chart { } /** - * for internal useage + * for internal usage * * @return */ @@ -324,4 +324,14 @@ public abstract class Chart { return plot; } + public int getWidth() { + + return width; + } + + public int getHeight() { + + return height; + } + } diff --git a/xchart/src/main/java/com/xeiam/xchart/XChartPanel.java b/xchart/src/main/java/com/xeiam/xchart/XChartPanel.java index 374d857a6f4cffa5d6307c120110aca1e62abc55..71a52c709b91f0ce94b34a685f645f4e5cd9601a 100644 --- a/xchart/src/main/java/com/xeiam/xchart/XChartPanel.java +++ b/xchart/src/main/java/com/xeiam/xchart/XChartPanel.java @@ -75,7 +75,7 @@ public class XChartPanel extends JPanel { @Override public Dimension getPreferredSize() { - return new Dimension(chart.width, chart.height); + return new Dimension(chart.getWidth(), chart.getHeight()); } private class SaveAction extends AbstractAction { diff --git a/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/Axis.java b/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/Axis.java index ff976312c91b99912956f603501a8f51e8a648b0..ee51100ddf1b94b33e4465621ba3ce26f42c8747 100644 --- a/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/Axis.java +++ b/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/Axis.java @@ -165,7 +165,7 @@ public class Axis implements ChartPart { int xOffset = getChart().getStyleManager().getChartPadding(); int yOffset = (int) (getChart().getChartTitle().getBounds().getY() + getChart().getChartTitle().getBounds().getHeight() + getChart().getStyleManager().getChartPadding()); int width = 80; // arbitrary, final width depends on Axis tick labels - int height = getChart().height - yOffset - axisPair.getxAxis().getSizeHint() - getChart().getStyleManager().getChartPadding(); + int height = getChart().getHeight() - yOffset - axisPair.getxAxis().getSizeHint() - getChart().getStyleManager().getChartPadding(); Rectangle yAxisRectangle = new Rectangle(xOffset, yOffset, width, height); this.paintZone = yAxisRectangle; // g.setColor(Color.green); @@ -191,7 +191,8 @@ public class Axis implements ChartPart { int xOffset = (int) (axisPair.getyAxis().getBounds().getWidth() + (getChart().getStyleManager().isyAxisTicksVisible() ? getChart().getStyleManager().getPlotPadding() : 0) + getChart() .getStyleManager().getChartPadding()); int yOffset = (int) (axisPair.getyAxis().getBounds().getY() + axisPair.getyAxis().getBounds().getHeight()); - int width = (int) (getChart().width - axisPair.getyAxis().getBounds().getWidth() - getChart().getChartLegend().getBounds().getWidth() - (getChart().getStyleManager().isLegendVisible() ? 3 : 2) + int width = (int) (getChart().getWidth() - axisPair.getyAxis().getBounds().getWidth() - getChart().getChartLegend().getBounds().getWidth() - (getChart().getStyleManager().isLegendVisible() ? 3 + : 2) * getChart().getStyleManager().getChartPadding()); int height = this.getSizeHint(); Rectangle xAxisRectangle = new Rectangle(xOffset, yOffset, width, height); 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 5add22405e3ded083ad0ecf7e1fd0e6e35df9d1f..22e3c75b379bc635278f09c99c7a1556761d1ee8 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 @@ -72,7 +72,7 @@ public class ChartTitle implements ChartPart { FontRenderContext frc = g.getFontRenderContext(); TextLayout textLayout = new TextLayout(text, chart.getStyleManager().getChartTitleFont(), frc); Rectangle rectangle = textLayout.getPixelBounds(null, 0, 0); - int xOffset = (int) ((chart.width - rectangle.getWidth()) / 2.0); + int xOffset = (int) ((chart.getWidth() - rectangle.getWidth()) / 2.0); int yOffset = (int) ((chart.getStyleManager().isChartTitleVisible() ? (chart.getStyleManager().getChartPadding() - rectangle.getY()) : 0)); bounds = new Rectangle(xOffset, yOffset + (chart.getStyleManager().isChartTitleVisible() ? (int) rectangle.getY() : 0), (int) rectangle.getWidth(), (int) (chart.getStyleManager() diff --git a/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/Legend.java b/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/Legend.java index 24d8739fb9834b2fed82894742a941a8980f53df..b3ac07c1fd61897e5c002b4b12c7113989e317e3 100644 --- a/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/Legend.java +++ b/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/Legend.java @@ -84,8 +84,8 @@ public class Legend implements ChartPart { // Draw Legend Box int legendBoxWidth = legendContentWidth + 2 * chart.getStyleManager().getLegendPadding(); int legendBoxHeight = legendContentHeight + 2 * chart.getStyleManager().getLegendPadding(); - int xOffset = chart.width - legendBoxWidth - chart.getStyleManager().getChartPadding(); - int yOffset = (int) ((chart.height - legendBoxHeight) / 2.0 + chart.getChartTitle().getBounds().getY() + chart.getChartTitle().getBounds().getHeight()); + int xOffset = chart.getWidth() - legendBoxWidth - chart.getStyleManager().getChartPadding(); + int yOffset = (int) ((chart.getHeight() - legendBoxHeight) / 2.0 + chart.getChartTitle().getBounds().getY() + chart.getChartTitle().getBounds().getHeight()); g.setColor(chart.getStyleManager().getChartBordersColor()); g.drawRect(xOffset, yOffset, legendBoxWidth, legendBoxHeight);