diff --git a/xchart/src/main/java/com/xeiam/xchart/Chart.java b/xchart/src/main/java/com/xeiam/xchart/Chart.java index eea0356453aa4b4f0d05cb725ef0442e90c88c75..b82140fa5aaad8e273c07d9299a4c5ed723eb444 100644 --- a/xchart/src/main/java/com/xeiam/xchart/Chart.java +++ b/xchart/src/main/java/com/xeiam/xchart/Chart.java @@ -44,10 +44,10 @@ public class Chart { private ValueFormatter valueFormatter = new ValueFormatter(); // Chart Parts - public ChartTitle chartTitle = new ChartTitle(this); - public Legend chartLegend = new Legend(this); - public AxisPair axisPair = new AxisPair(this); - protected Plot plot = new Plot(this); + private ChartTitle chartTitle = new ChartTitle(this); + private Legend chartLegend = new Legend(this); + private AxisPair axisPair = new AxisPair(this); + private Plot plot = new Plot(this); /** * Constructor @@ -284,4 +284,44 @@ public class Chart { return valueFormatter; } + /** + * for internal useage + * + * @return + */ + public ChartTitle getChartTitle() { + + return chartTitle; + } + + /** + * for internal useage + * + * @return + */ + public Legend getChartLegend() { + + return chartLegend; + } + + /** + * for internal useage + * + * @return + */ + public AxisPair getAxisPair() { + + return axisPair; + } + + /** + * for internal useage + * + * @return + */ + public Plot getPlot() { + + return plot; + } + } 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 e40618ea14f95bc4c1d2e58f1bceed67d2d96ac3..cd6e0d2067b486d7ec1a10b86c9869c21af71014 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 @@ -21,14 +21,14 @@ import java.awt.font.FontRenderContext; import java.awt.font.TextLayout; import java.math.BigDecimal; -import com.xeiam.xchart.internal.interfaces.IChartPart; +import com.xeiam.xchart.Chart; /** * Axis * * @author timmolter */ -public class Axis implements IChartPart { +public class Axis implements ChartPart { public enum AxisType { @@ -80,8 +80,8 @@ public class Axis implements IChartPart { this.axisPair = axisPair; this.direction = direction; - axisTitle = new AxisTitle(this, direction == Direction.X ? axisPair.chart.getStyleManager().isxAxisTitleVisible() : axisPair.chart.getStyleManager().isyAxisTitleVisible()); - axisTick = new AxisTick(this, direction == Direction.X ? axisPair.chart.getStyleManager().isxAxisTicksVisible() : axisPair.chart.getStyleManager().isyAxisTicksVisible()); + axisTitle = new AxisTitle(this, direction == Direction.X ? getChart().getStyleManager().isxAxisTitleVisible() : getChart().getStyleManager().isyAxisTitleVisible()); + axisTick = new AxisTick(this, direction == Direction.X ? getChart().getStyleManager().isxAxisTicksVisible() : getChart().getStyleManager().isyAxisTicksVisible()); } /** @@ -141,19 +141,19 @@ public class Axis implements IChartPart { // Axis title double titleHeight = 0.0; - if (axisPair.chart.getStyleManager().isxAxisTitleVisible()) { - TextLayout textLayout = new TextLayout(axisTitle.text, axisTick.axis.axisPair.chart.getStyleManager().getAxisTitleFont(), new FontRenderContext(null, true, false)); + if (getChart().getStyleManager().isxAxisTitleVisible()) { + TextLayout textLayout = new TextLayout(axisTitle.text, axisTick.axis.getChart().getStyleManager().getAxisTitleFont(), new FontRenderContext(null, true, false)); Rectangle rectangle = textLayout.getPixelBounds(null, 0, 0); - titleHeight = rectangle.getHeight() + axisTick.axis.axisPair.chart.getStyleManager().getAxisTitlePadding(); + titleHeight = rectangle.getHeight() + axisTick.axis.getChart().getStyleManager().getAxisTitlePadding(); } // Axis tick labels double axisTickLabelsHeight = 0.0; - if (axisPair.chart.getStyleManager().isxAxisTicksVisible()) { - TextLayout textLayout = new TextLayout("0", axisTick.axis.axisPair.chart.getStyleManager().getAxisTicksFont(), new FontRenderContext(null, true, false)); + if (getChart().getStyleManager().isxAxisTicksVisible()) { + TextLayout textLayout = new TextLayout("0", axisTick.axis.getChart().getStyleManager().getAxisTicksFont(), new FontRenderContext(null, true, false)); Rectangle rectangle = textLayout.getPixelBounds(null, 0, 0); - axisTickLabelsHeight = rectangle.getHeight() + axisPair.chart.getStyleManager().getAxisTickPadding() + axisPair.chart.getStyleManager().getAxisTickMarkLength() - + axisPair.chart.getStyleManager().getPlotPadding(); + axisTickLabelsHeight = rectangle.getHeight() + getChart().getStyleManager().getAxisTickPadding() + getChart().getStyleManager().getAxisTickMarkLength() + + getChart().getStyleManager().getPlotPadding(); } return (int) (titleHeight + axisTickLabelsHeight); } else { // Y-Axis @@ -177,10 +177,10 @@ public class Axis implements IChartPart { // | // | // ---- - int xOffset = axisPair.chart.getStyleManager().getChartPadding(); - int yOffset = (int) (axisPair.getChartTitleBounds().getY() + axisPair.getChartTitleBounds().getHeight() + axisPair.chart.getStyleManager().getChartPadding()); + int xOffset = getChart().getStyleManager().getChartPadding(); + int yOffset = (int) (axisPair.getChartTitleBounds().getY() + axisPair.getChartTitleBounds().getHeight() + getChart().getStyleManager().getChartPadding()); int width = 80; // arbitrary, final width depends on Axis tick labels - int height = axisPair.chart.height - yOffset - axisPair.xAxis.getSizeHint() - axisPair.chart.getStyleManager().getChartPadding(); + int height = getChart().height - yOffset - axisPair.xAxis.getSizeHint() - getChart().getStyleManager().getChartPadding(); Rectangle yAxisRectangle = new Rectangle(xOffset, yOffset, width, height); this.paintZone = yAxisRectangle; // g.setColor(Color.green); @@ -192,7 +192,7 @@ public class Axis implements IChartPart { xOffset = (int) paintZone.getX(); yOffset = (int) paintZone.getY(); - width = (int) (axisPair.chart.getStyleManager().isyAxisTitleVisible() ? axisTitle.getBounds().getWidth() : 0) + (int) axisTick.getBounds().getWidth(); + width = (int) (getChart().getStyleManager().isyAxisTitleVisible() ? axisTitle.getBounds().getWidth() : 0) + (int) axisTick.getBounds().getWidth(); height = (int) paintZone.getHeight(); bounds = new Rectangle(xOffset, yOffset, width, height); // g.setColor(Color.yellow); @@ -203,11 +203,11 @@ public class Axis implements IChartPart { // calculate paint zone // |____________________| - int xOffset = (int) (axisPair.yAxis.getBounds().getWidth() + (axisPair.chart.getStyleManager().isyAxisTicksVisible() ? axisPair.chart.getStyleManager().getPlotPadding() : 0) + axisPair.chart + int xOffset = (int) (axisPair.yAxis.getBounds().getWidth() + (getChart().getStyleManager().isyAxisTicksVisible() ? getChart().getStyleManager().getPlotPadding() : 0) + getChart() .getStyleManager().getChartPadding()); int yOffset = (int) (axisPair.yAxis.getBounds().getY() + axisPair.yAxis.getBounds().getHeight()); - int width = (int) (axisPair.chart.width - axisPair.yAxis.getBounds().getWidth() - axisPair.getChartLegendBounds().getWidth() - (axisPair.chart.getStyleManager().isLegendVisible() ? 3 : 2) - * axisPair.chart.getStyleManager().getChartPadding()); + int width = (int) (getChart().width - axisPair.yAxis.getBounds().getWidth() - axisPair.getChartLegendBounds().getWidth() - (getChart().getStyleManager().isLegendVisible() ? 3 : 2) + * getChart().getStyleManager().getChartPadding()); int height = this.getSizeHint(); Rectangle xAxisRectangle = new Rectangle(xOffset, yOffset, width, height); this.paintZone = xAxisRectangle; @@ -220,7 +220,7 @@ public class Axis implements IChartPart { xOffset = (int) paintZone.getX(); yOffset = (int) paintZone.getY(); width = (int) paintZone.getWidth(); - height = (int) ((axisPair.chart.getStyleManager().isxAxisTitleVisible() ? axisTitle.getBounds().getHeight() : 0) + (int) axisTick.getBounds().getHeight()); + height = (int) ((getChart().getStyleManager().isxAxisTitleVisible() ? axisTitle.getBounds().getHeight() : 0) + (int) axisTick.getBounds().getHeight()); bounds = new Rectangle(xOffset, yOffset, width, height); bounds = new Rectangle(xOffset, yOffset, width, height); // g.setColor(Color.yellow); @@ -228,4 +228,10 @@ public class Axis implements IChartPart { } } + + @Override + public Chart getChart() { + + return axisPair.getChart(); + } } diff --git a/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/AxisPair.java b/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/AxisPair.java index 07e229705d29689ad03a3e7febf8e65884fbd09d..af24bf51cd0cddc1f2ad057cd3683e3217510f9b 100644 --- a/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/AxisPair.java +++ b/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/AxisPair.java @@ -26,17 +26,16 @@ import java.util.Map; import com.xeiam.xchart.Chart; import com.xeiam.xchart.internal.chartpart.Axis.AxisType; -import com.xeiam.xchart.internal.interfaces.IChartPart; import com.xeiam.xchart.internal.misc.SeriesColorMarkerLineStyleCycler; import com.xeiam.xchart.style.Series; /** * @author timmolter */ -public class AxisPair implements IChartPart { +public class AxisPair implements ChartPart { /** parent */ - protected Chart chart; + private final Chart chart; public Map<Integer, Series> seriesMap = new LinkedHashMap<Integer, Series>(); @@ -121,14 +120,16 @@ public class AxisPair implements IChartPart { return series; } + // TODO remove protected Rectangle getChartTitleBounds() { - return chart.chartTitle.getBounds(); + return chart.getChartTitle().getBounds(); } + // TODO remove protected Rectangle getChartLegendBounds() { - return chart.chartLegend.getBounds(); + return chart.getChartLegend().getBounds(); } /** @@ -168,4 +169,10 @@ public class AxisPair implements IChartPart { return null; // should never be called } + @Override + public Chart getChart() { + + return chart; + } + } diff --git a/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/AxisTick.java b/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/AxisTick.java index 9ecf6fc4e7ba5db6bff907c2c753802e90202552..833fea0455a42d30e66b69fc283525583e0430cf 100644 --- a/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/AxisTick.java +++ b/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/AxisTick.java @@ -23,14 +23,14 @@ import java.util.List; import java.util.Locale; import java.util.TimeZone; +import com.xeiam.xchart.Chart; import com.xeiam.xchart.internal.chartpart.Axis.AxisType; import com.xeiam.xchart.internal.chartpart.Axis.Direction; -import com.xeiam.xchart.internal.interfaces.IChartPart; /** * An axis tick */ -public class AxisTick implements IChartPart { +public class AxisTick implements ChartPart { /** the default tick mark step hint for x axis */ private static final int DEFAULT_TICK_MARK_STEP_HINT_X = 74; @@ -119,13 +119,13 @@ public class AxisTick implements IChartPart { if (axis.direction == Axis.Direction.Y) { bounds = new Rectangle((int) axisTickLabels.getBounds().getX(), (int) (axisTickLabels.getBounds().getY()), (int) (axisTickLabels.getBounds().getWidth() - + axis.axisPair.chart.getStyleManager().getAxisTickPadding() + axisTickMarks.getBounds().getWidth()), (int) (axisTickMarks.getBounds().getHeight())); + + getChart().getStyleManager().getAxisTickPadding() + axisTickMarks.getBounds().getWidth()), (int) (axisTickMarks.getBounds().getHeight())); // g.setColor(Color.red); // g.draw(bounds); } else { bounds = new Rectangle((int) axisTickMarks.getBounds().getX(), (int) (axisTickMarks.getBounds().getY()), (int) axisTickLabels.getBounds().getWidth(), (int) (axisTickMarks.getBounds() .getHeight() - + axis.axisPair.chart.getStyleManager().getAxisTickPadding() + axisTickLabels.getBounds().getHeight())); + + getChart().getStyleManager().getAxisTickPadding() + axisTickLabels.getBounds().getHeight())); // g.setColor(Color.red); // g.draw(bounds); } @@ -254,13 +254,18 @@ public class AxisTick implements IChartPart { if (axis.axisType == AxisType.NUMBER) { - return axis.axisPair.chart.getValueFormatter().formatNumber(value); + return getChart().getValueFormatter().formatNumber(value); } else { - return axis.axisPair.chart.getValueFormatter().formatDateValue(value, axis.min, axis.max); + return getChart().getValueFormatter().formatDateValue(value, axis.min, axis.max); } } + @Override + public Chart getChart() { + + return axis.getChart(); + } } diff --git a/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/AxisTickLabels.java b/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/AxisTickLabels.java index 7cdf531225997e558894bed9705bc73d31d8676f..55b5bd6f8b7516c55a2e4b64b6373b67afda8f96 100644 --- a/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/AxisTickLabels.java +++ b/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/AxisTickLabels.java @@ -20,12 +20,12 @@ import java.awt.Rectangle; import java.awt.font.FontRenderContext; import java.awt.font.TextLayout; -import com.xeiam.xchart.internal.interfaces.IChartPart; +import com.xeiam.xchart.Chart; /** * Axis tick labels */ -public class AxisTickLabels implements IChartPart { +public class AxisTickLabels implements ChartPart { /** parent */ private final AxisTick axisTick; @@ -53,9 +53,9 @@ public class AxisTickLabels implements IChartPart { public void paint(Graphics2D g) { bounds = new Rectangle(); - g.setFont(axisTick.axis.axisPair.chart.getStyleManager().getAxisTicksFont()); + g.setFont(getChart().getStyleManager().getAxisTicksFont()); - g.setColor(axisTick.axis.axisPair.chart.getStyleManager().getChartFontColor()); + g.setColor(getChart().getStyleManager().getChartFontColor()); if (axisTick.axis.direction == Axis.Direction.Y) { // Y-Axis @@ -70,7 +70,7 @@ public class AxisTickLabels implements IChartPart { FontRenderContext frc = g.getFontRenderContext(); // TextLayout layout = new TextLayout(tickLabel, font, new FontRenderContext(null, true, false)); - TextLayout layout = new TextLayout(tickLabel, axisTick.axis.axisPair.chart.getStyleManager().getAxisTicksFont(), frc); + TextLayout layout = new TextLayout(tickLabel, getChart().getStyleManager().getAxisTicksFont(), frc); Rectangle tickLabelBounds = layout.getPixelBounds(null, 0, 0); layout.draw(g, xOffset, (int) (yOffset + axisTick.axis.getPaintZone().getHeight() - tickLocation + tickLabelBounds.getHeight() / 2.0)); @@ -95,7 +95,7 @@ public class AxisTickLabels implements IChartPart { int tickLocation = axisTick.tickLocations.get(i); FontRenderContext frc = g.getFontRenderContext(); - TextLayout layout = new TextLayout(tickLabel, axisTick.axis.axisPair.chart.getStyleManager().getAxisTicksFont(), frc); + TextLayout layout = new TextLayout(tickLabel, getChart().getStyleManager().getAxisTicksFont(), frc); Rectangle tickLabelBounds = layout.getPixelBounds(null, 0, 0); layout.draw(g, (int) (xOffset + tickLocation - tickLabelBounds.getWidth() / 2.0), yOffset); @@ -112,4 +112,10 @@ public class AxisTickLabels implements IChartPart { } } + + @Override + public Chart getChart() { + + return axisTick.getChart(); + } } diff --git a/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/AxisTickMarks.java b/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/AxisTickMarks.java index 4eb497e3c3c9d8e954fc8b2d1624cd45cf9d7c2e..f3640b68cbe958c1a29adb952c757b6b72d80f48 100644 --- a/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/AxisTickMarks.java +++ b/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/AxisTickMarks.java @@ -20,12 +20,12 @@ import java.awt.Graphics2D; import java.awt.Rectangle; import java.awt.Stroke; -import com.xeiam.xchart.internal.interfaces.IChartPart; +import com.xeiam.xchart.Chart; /** * Axis tick marks. */ -public class AxisTickMarks implements IChartPart { +public class AxisTickMarks implements ChartPart { /** parent */ private AxisTick axisTick; @@ -57,11 +57,11 @@ public class AxisTickMarks implements IChartPart { bounds = new Rectangle(); - g.setColor(axisTick.axis.axisPair.chart.getStyleManager().getChartBordersColor()); + g.setColor(getChart().getStyleManager().getChartBordersColor()); if (axisTick.axis.direction == Axis.Direction.Y) { // Y-Axis - int xOffset = (int) (axisTick.axisTickLabels.getBounds().getX() + axisTick.axisTickLabels.getBounds().getWidth() + axisTick.axis.axisPair.chart.getStyleManager().getAxisTickPadding()); + int xOffset = (int) (axisTick.axisTickLabels.getBounds().getX() + axisTick.axisTickLabels.getBounds().getWidth() + getChart().getStyleManager().getAxisTickPadding()); int yOffset = (int) (axisTick.axis.getPaintZone().getY()); // tick marks @@ -69,53 +69,59 @@ public class AxisTickMarks implements IChartPart { int tickLocation = axisTick.tickLocations.get(i); - g.setColor(axisTick.axis.axisPair.chart.getStyleManager().getChartBordersColor()); + g.setColor(getChart().getStyleManager().getChartBordersColor()); g.setStroke(stroke); - g.drawLine(xOffset, yOffset + (int) (axisTick.axis.getPaintZone().getHeight() - tickLocation), xOffset + axisTick.axis.axisPair.chart.getStyleManager().getAxisTickMarkLength(), yOffset + g.drawLine(xOffset, yOffset + (int) (axisTick.axis.getPaintZone().getHeight() - tickLocation), xOffset + getChart().getStyleManager().getAxisTickMarkLength(), yOffset + (int) (axisTick.axis.getPaintZone().getHeight() - tickLocation)); } // Line - if (axisTick.axis.axisPair.chart.getStyleManager().isAxisTicksLineVisible()) { - g.drawLine(xOffset + axisTick.axis.axisPair.chart.getStyleManager().getAxisTickMarkLength(), yOffset, xOffset + axisTick.axis.axisPair.chart.getStyleManager().getAxisTickMarkLength(), yOffset + if (getChart().getStyleManager().isAxisTicksLineVisible()) { + g.drawLine(xOffset + getChart().getStyleManager().getAxisTickMarkLength(), yOffset, xOffset + getChart().getStyleManager().getAxisTickMarkLength(), yOffset + (int) axisTick.axis.getPaintZone().getHeight()); } // bounds - bounds = new Rectangle(xOffset, yOffset, axisTick.axis.axisPair.chart.getStyleManager().getAxisTickMarkLength(), (int) axisTick.axis.getPaintZone().getHeight()); + bounds = new Rectangle(xOffset, yOffset, getChart().getStyleManager().getAxisTickMarkLength(), (int) axisTick.axis.getPaintZone().getHeight()); // g.setColor(Color.yellow); // g.draw(bounds); } else { // X-Axis int xOffset = (int) (axisTick.axis.getPaintZone().getX()); - int yOffset = (int) (axisTick.axisTickLabels.getBounds().getY() - axisTick.axis.axisPair.chart.getStyleManager().getAxisTickPadding()); + int yOffset = (int) (axisTick.axisTickLabels.getBounds().getY() - getChart().getStyleManager().getAxisTickPadding()); // tick marks for (int i = 0; i < axisTick.tickLabels.size(); i++) { int tickLocation = axisTick.tickLocations.get(i); - g.setColor(axisTick.axis.axisPair.chart.getStyleManager().getChartBordersColor()); + g.setColor(getChart().getStyleManager().getChartBordersColor()); g.setStroke(stroke); - g.drawLine(xOffset + tickLocation, yOffset, xOffset + tickLocation, yOffset - axisTick.axis.axisPair.chart.getStyleManager().getAxisTickMarkLength()); + g.drawLine(xOffset + tickLocation, yOffset, xOffset + tickLocation, yOffset - getChart().getStyleManager().getAxisTickMarkLength()); } // Line - if (axisTick.axis.axisPair.chart.getStyleManager().isAxisTicksLineVisible()) { + if (getChart().getStyleManager().isAxisTicksLineVisible()) { - g.drawLine(xOffset, yOffset - axisTick.axis.axisPair.chart.getStyleManager().getAxisTickMarkLength(), xOffset + (int) axisTick.axis.getPaintZone().getWidth(), yOffset - - axisTick.axis.axisPair.chart.getStyleManager().getAxisTickMarkLength()); + g.drawLine(xOffset, yOffset - getChart().getStyleManager().getAxisTickMarkLength(), xOffset + (int) axisTick.axis.getPaintZone().getWidth(), yOffset + - getChart().getStyleManager().getAxisTickMarkLength()); } // bounds - bounds = new Rectangle(xOffset, yOffset - axisTick.axis.axisPair.chart.getStyleManager().getAxisTickMarkLength(), (int) axisTick.axis.getPaintZone().getWidth(), axisTick.axis.axisPair.chart - .getStyleManager().getAxisTickMarkLength()); + bounds = new Rectangle(xOffset, yOffset - getChart().getStyleManager().getAxisTickMarkLength(), (int) axisTick.axis.getPaintZone().getWidth(), getChart().getStyleManager() + .getAxisTickMarkLength()); // g.setColor(Color.yellow); // g.draw(bounds); } } + + @Override + public Chart getChart() { + + return axisTick.getChart(); + } } diff --git a/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/AxisTitle.java b/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/AxisTitle.java index 95d4dc693404a7b09e4e3d0db3ab81f05fe02d06..32d6b6816eed2641599506d04ab33e22922f889b 100644 --- a/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/AxisTitle.java +++ b/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/AxisTitle.java @@ -21,12 +21,12 @@ import java.awt.font.FontRenderContext; import java.awt.font.TextLayout; import java.awt.geom.AffineTransform; -import com.xeiam.xchart.internal.interfaces.IChartPart; +import com.xeiam.xchart.Chart; /** * AxisTitle */ -public class AxisTitle implements IChartPart { +public class AxisTitle implements ChartPart { /** parent */ private final Axis axis; @@ -58,14 +58,14 @@ public class AxisTitle implements IChartPart { bounds = new Rectangle(); - g.setColor(axis.axisPair.chart.getStyleManager().getChartFontColor()); - g.setFont(axis.axisPair.chart.getStyleManager().getAxisTitleFont()); + g.setColor(getChart().getStyleManager().getChartFontColor()); + g.setFont(getChart().getStyleManager().getAxisTitleFont()); if (axis.direction == Axis.Direction.Y) { - if (axis.axisPair.chart.getStyleManager().isyAxisTitleVisible()) { + if (getChart().getStyleManager().isyAxisTitleVisible()) { FontRenderContext frc = g.getFontRenderContext(); - TextLayout nonRotatedTextLayout = new TextLayout(text, axis.axisPair.chart.getStyleManager().getAxisTitleFont(), frc); + TextLayout nonRotatedTextLayout = new TextLayout(text, getChart().getStyleManager().getAxisTitleFont(), frc); Rectangle nonRotatedRectangle = nonRotatedTextLayout.getPixelBounds(null, 0, 0); // System.out.println(nonRotatedRectangle); @@ -94,7 +94,7 @@ public class AxisTitle implements IChartPart { // bounds bounds = new Rectangle((int) (xOffset - nonRotatedRectangle.getHeight()), (int) (yOffset - nonRotatedRectangle.getWidth()), (int) nonRotatedRectangle.getHeight() - + axis.axisPair.chart.getStyleManager().getAxisTitlePadding(), (int) nonRotatedRectangle.getWidth()); + + getChart().getStyleManager().getAxisTitlePadding(), (int) nonRotatedRectangle.getWidth()); // g.setColor(Color.blue); // g.draw(bounds); } else { @@ -103,10 +103,10 @@ public class AxisTitle implements IChartPart { } else { - if (axis.axisPair.chart.getStyleManager().isxAxisTitleVisible()) { + if (getChart().getStyleManager().isxAxisTitleVisible()) { FontRenderContext frc = g.getFontRenderContext(); - TextLayout textLayout = new TextLayout(text, axis.axisPair.chart.getStyleManager().getAxisTitleFont(), frc); + TextLayout textLayout = new TextLayout(text, getChart().getStyleManager().getAxisTitleFont(), frc); Rectangle rectangle = textLayout.getPixelBounds(null, 0, 0); // System.out.println(rectangle); @@ -115,8 +115,8 @@ public class AxisTitle implements IChartPart { textLayout.draw(g, xOffset, (float) (yOffset - rectangle.getY())); - bounds = new Rectangle(xOffset, yOffset - axis.axisPair.chart.getStyleManager().getAxisTitlePadding(), (int) rectangle.getWidth(), (int) rectangle.getHeight() - + axis.axisPair.chart.getStyleManager().getAxisTitlePadding()); + bounds = new Rectangle(xOffset, yOffset - getChart().getStyleManager().getAxisTitlePadding(), (int) rectangle.getWidth(), (int) rectangle.getHeight() + + getChart().getStyleManager().getAxisTitlePadding()); // g.setColor(Color.blue); // g.draw(bounds); @@ -128,4 +128,10 @@ public class AxisTitle implements IChartPart { } } } + + @Override + public Chart getChart() { + + return axis.getChart(); + } } diff --git a/xchart/src/main/java/com/xeiam/xchart/internal/interfaces/IChartPart.java b/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/ChartPart.java similarity index 86% rename from xchart/src/main/java/com/xeiam/xchart/internal/interfaces/IChartPart.java rename to xchart/src/main/java/com/xeiam/xchart/internal/chartpart/ChartPart.java index e88165d5a5c0523951a0c47c07ff19279d7fb817..971bb47f408577016720f65b579678dd9f3587c5 100644 --- a/xchart/src/main/java/com/xeiam/xchart/internal/interfaces/IChartPart.java +++ b/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/ChartPart.java @@ -13,20 +13,24 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.xeiam.xchart.internal.interfaces; +package com.xeiam.xchart.internal.chartpart; import java.awt.Graphics2D; import java.awt.Rectangle; +import com.xeiam.xchart.Chart; + /** * All components of a chart that need to be painted should implement this interface * * @author timmolter */ -public interface IChartPart { +public interface ChartPart { public Rectangle getBounds(); public void paint(final Graphics2D g); + public Chart getChart(); + } 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 3a15ac5a3e8a641a765381ad48daf63d6051dc94..edb759dbcaa62d42fdddad3c31594c0821628ff7 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 @@ -21,22 +21,21 @@ import java.awt.font.FontRenderContext; import java.awt.font.TextLayout; import com.xeiam.xchart.Chart; -import com.xeiam.xchart.internal.interfaces.IChartPart; /** * Chart Title */ -public class ChartTitle implements IChartPart { +public class ChartTitle implements ChartPart { /** parent */ private final Chart chart; - /** the title text */ - protected String text = ""; // default to "" - /** the bounds */ private Rectangle bounds; + /** the title text */ + protected String text = ""; // default to "" + /** * Constructor * @@ -92,4 +91,10 @@ public class ChartTitle implements IChartPart { return bounds; } + + @Override + public Chart getChart() { + + return chart; + } } \ No newline at end of file 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 3c1a8793c7645d3cdd459f8ac801d9294727c88e..f1ce8b7a6d48e8c855aa066f09428e38506001ad 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 @@ -22,14 +22,13 @@ import java.awt.font.TextLayout; import java.util.Map; import com.xeiam.xchart.Chart; -import com.xeiam.xchart.internal.interfaces.IChartPart; import com.xeiam.xchart.internal.markers.Marker; import com.xeiam.xchart.style.Series; /** * @author timmolter */ -public class Legend implements IChartPart { +public class Legend implements ChartPart { /** parent */ private final Chart chart; @@ -55,7 +54,7 @@ public class Legend implements IChartPart { if (chart.getStyleManager().isLegendVisible()) { - Map<Integer, Series> seriesMap = chart.axisPair.seriesMap; + Map<Integer, Series> seriesMap = chart.getAxisPair().seriesMap; // determine legend text content max width int legendTextContentMaxWidth = 0; @@ -86,7 +85,7 @@ public class Legend implements IChartPart { 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.chartTitle.getBounds().getY() + chart.chartTitle.getBounds().getHeight()); + int yOffset = (int) ((chart.height - legendBoxHeight) / 2.0 + chart.getChartTitle().getBounds().getY() + chart.getChartTitle().getBounds().getHeight()); g.setColor(chart.getStyleManager().getChartBordersColor()); g.drawRect(xOffset, yOffset, legendBoxWidth, legendBoxHeight); @@ -131,4 +130,10 @@ public class Legend implements IChartPart { return bounds; } + @Override + public Chart getChart() { + + return chart; + } + } 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 e9f4260448de7d15248a9267934c3c4dd014b4d6..5044d06e57ca0476d50822cb09d2c830b841be3e 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 @@ -19,23 +19,27 @@ import java.awt.Graphics2D; import java.awt.Rectangle; import com.xeiam.xchart.Chart; -import com.xeiam.xchart.internal.interfaces.IChartPart; /** * @author timmolter */ -public class Plot implements IChartPart { +public class Plot implements ChartPart { /** parent */ - protected Chart chart; - - public PlotSurface plotSurface; - - protected PlotContent plotContent; + private final Chart chart; /** the bounds */ private Rectangle bounds; + protected PlotSurface plotSurface; + + protected PlotContent plotContent; + + /** + * Constructor + * + * @param chart + */ public Plot(Chart chart) { this.chart = chart; @@ -55,11 +59,11 @@ public class Plot implements IChartPart { bounds = new Rectangle(); // calculate bounds - int xOffset = (int) (chart.axisPair.yAxis.getBounds().getX() + chart.axisPair.yAxis.getBounds().getWidth() + (chart.getStyleManager().isyAxisTicksVisible() ? (chart.getStyleManager() + int xOffset = (int) (chart.getAxisPair().yAxis.getBounds().getX() + chart.getAxisPair().yAxis.getBounds().getWidth() + (chart.getStyleManager().isyAxisTicksVisible() ? (chart.getStyleManager() .getPlotPadding() + 1) : 0)); - int yOffset = (int) (chart.axisPair.yAxis.getBounds().getY()); - int width = (int) chart.axisPair.xAxis.getBounds().getWidth(); - int height = (int) chart.axisPair.yAxis.getBounds().getHeight(); + int yOffset = (int) (chart.getAxisPair().yAxis.getBounds().getY()); + int width = (int) chart.getAxisPair().xAxis.getBounds().getWidth(); + int height = (int) chart.getAxisPair().yAxis.getBounds().getHeight(); bounds = new Rectangle(xOffset, yOffset, width, height); // g.setColor(Color.green); // g.draw(bounds); @@ -69,4 +73,9 @@ public class Plot implements IChartPart { } + @Override + public Chart getChart() { + + return chart; + } } diff --git a/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/PlotContent.java b/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/PlotContent.java index 0d21bb9c32549810f4bf7314c49fabb28278cf0c..4ee8353872b5e3ba9d241bbb65ee6537207e4d13 100644 --- a/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/PlotContent.java +++ b/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/PlotContent.java @@ -25,14 +25,14 @@ import java.util.Date; import java.util.Iterator; import java.util.Map; +import com.xeiam.xchart.Chart; import com.xeiam.xchart.internal.chartpart.Axis.AxisType; -import com.xeiam.xchart.internal.interfaces.IChartPart; import com.xeiam.xchart.style.Series; /** * @author timmolter */ -public class PlotContent implements IChartPart { +public class PlotContent implements ChartPart { /** parent */ private Plot plot; @@ -60,7 +60,7 @@ public class PlotContent implements IChartPart { Rectangle bounds = plot.getBounds(); - Map<Integer, Series> seriesMap = plot.chart.axisPair.seriesMap; + Map<Integer, Series> seriesMap = getChart().getAxisPair().seriesMap; for (Integer seriesId : seriesMap.keySet()) { Series series = seriesMap.get(seriesId); @@ -75,11 +75,11 @@ public class PlotContent implements IChartPart { // data points Collection<?> xData = series.xData; - BigDecimal xMin = plot.chart.axisPair.xAxis.min; - BigDecimal xMax = plot.chart.axisPair.xAxis.max; + BigDecimal xMin = getChart().getAxisPair().xAxis.min; + BigDecimal xMax = getChart().getAxisPair().xAxis.max; Collection<Number> yData = series.yData; - BigDecimal yMin = plot.chart.axisPair.yAxis.min; - BigDecimal yMax = plot.chart.axisPair.yAxis.max; + BigDecimal yMin = getChart().getAxisPair().yAxis.min; + BigDecimal yMax = getChart().getAxisPair().yAxis.max; Collection<Number> errorBars = series.errorBars; int previousX = Integer.MIN_VALUE; @@ -94,10 +94,10 @@ public class PlotContent implements IChartPart { while (xItr.hasNext()) { BigDecimal x = null; - if (plot.chart.axisPair.xAxis.axisType == AxisType.NUMBER) { + if (getChart().getAxisPair().xAxis.axisType == AxisType.NUMBER) { x = new BigDecimal(((Number) xItr.next()).doubleValue()); } - if (plot.chart.axisPair.xAxis.axisType == AxisType.DATE) { + if (getChart().getAxisPair().xAxis.axisType == AxisType.DATE) { x = new BigDecimal(((Date) xItr.next()).getTime()); // System.out.println(x); } @@ -148,7 +148,7 @@ public class PlotContent implements IChartPart { // paint errorbar if (errorBars != null) { - g.setColor(plot.chart.getStyleManager().getErrorBarsColor()); + g.setColor(getChart().getStyleManager().getErrorBarsColor()); g.setStroke(errorBarStroke); int bottom = (int) (-1 * bounds.getHeight() * eb / (yMax.subtract(yMin).doubleValue())); int top = (int) (bounds.getHeight() * eb / (yMax.subtract(yMin).doubleValue())); @@ -162,4 +162,10 @@ public class PlotContent implements IChartPart { } + @Override + public Chart getChart() { + + return plot.getChart(); + } + } diff --git a/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/PlotSurface.java b/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/PlotSurface.java index d0ab69f610a9856f3851bbc10e41b44cba107f0f..873748e4d5c843ca9a35e8b20e9fbaab4150d0e5 100644 --- a/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/PlotSurface.java +++ b/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/PlotSurface.java @@ -20,12 +20,12 @@ import java.awt.Graphics2D; import java.awt.Rectangle; import java.util.List; -import com.xeiam.xchart.internal.interfaces.IChartPart; +import com.xeiam.xchart.Chart; /** * @author timmolter */ -public class PlotSurface implements IChartPart { +public class PlotSurface implements ChartPart { /** parent */ private Plot plot; @@ -56,22 +56,22 @@ public class PlotSurface implements IChartPart { // paint plot background Rectangle backgroundRectangle = new Rectangle((int) bounds.getX() - 1, (int) bounds.getY(), (int) (bounds.getWidth()), (int) bounds.getHeight()); - g.setColor(plot.chart.getStyleManager().getPlotBackgroundColor()); + g.setColor(getChart().getStyleManager().getPlotBackgroundColor()); g.fill(backgroundRectangle); Rectangle borderRectangle = new Rectangle((int) bounds.getX() - 1, (int) bounds.getY(), (int) (bounds.getWidth()), (int) bounds.getHeight()); - g.setColor(plot.chart.getStyleManager().getChartBordersColor()); + g.setColor(getChart().getStyleManager().getChartBordersColor()); g.draw(borderRectangle); // paint grid lines - if (plot.chart.getStyleManager().isPlotGridLinesVisible()) { + if (getChart().getStyleManager().isPlotGridLinesVisible()) { // horizontal - List<Integer> yAxisTickLocations = plot.chart.axisPair.yAxis.axisTick.tickLocations; + List<Integer> yAxisTickLocations = getChart().getAxisPair().yAxis.axisTick.tickLocations; for (int i = 0; i < yAxisTickLocations.size(); i++) { int tickLocation = yAxisTickLocations.get(i); - g.setColor(plot.chart.getStyleManager().getPlotGridLinesColor()); + g.setColor(getChart().getStyleManager().getPlotGridLinesColor()); g.setStroke(stroke); // System.out.println("bounds.getY()= " + bounds.getY()); g.drawLine((int) bounds.getX(), (int) (bounds.getY() + bounds.getHeight() - tickLocation), (int) (bounds.getX() + bounds.getWidth() - 2), @@ -79,12 +79,12 @@ public class PlotSurface implements IChartPart { } // vertical - List<Integer> xAxisTickLocations = plot.chart.axisPair.xAxis.axisTick.tickLocations; + List<Integer> xAxisTickLocations = getChart().getAxisPair().xAxis.axisTick.tickLocations; for (int i = 0; i < xAxisTickLocations.size(); i++) { int tickLocation = xAxisTickLocations.get(i); - g.setColor(plot.chart.getStyleManager().getPlotGridLinesColor()); + g.setColor(getChart().getStyleManager().getPlotGridLinesColor()); g.setStroke(stroke); g.drawLine((int) (bounds.getX() + tickLocation - 1), (int) (bounds.getY() + 1), (int) (bounds.getX() + tickLocation - 1), (int) (bounds.getY() + bounds.getHeight() - 1)); @@ -92,4 +92,10 @@ public class PlotSurface implements IChartPart { } } + @Override + public Chart getChart() { + + return plot.getChart(); + } + }