From c0fe8e5699bc98ff526696310bdff5c72bbb421a Mon Sep 17 00:00:00 2001
From: Tim Molter <tim.molter@gmail.com>
Date: Sun, 10 Feb 2013 18:31:16 +0100
Subject: [PATCH] cleaned up Chart

---
 .../java/com/xeiam/xchart/BitmapEncoder.java  |  4 ++--
 .../src/main/java/com/xeiam/xchart/Chart.java | 22 ++++++++++++++-----
 .../java/com/xeiam/xchart/XChartPanel.java    |  2 +-
 .../xeiam/xchart/internal/chartpart/Axis.java |  5 +++--
 .../xchart/internal/chartpart/ChartTitle.java |  2 +-
 .../xchart/internal/chartpart/Legend.java     |  4 ++--
 6 files changed, 25 insertions(+), 14 deletions(-)

diff --git a/xchart/src/main/java/com/xeiam/xchart/BitmapEncoder.java b/xchart/src/main/java/com/xeiam/xchart/BitmapEncoder.java
index 463f10d6..eb8b2973 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 bfd2652d..1a2e451a 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 374d857a..71a52c70 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 ff976312..ee51100d 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 5add2240..22e3c75b 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 24d8739f..b3ac07c1 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);
-- 
GitLab