diff --git a/xchart/src/main/java/org/knowm/xchart/Chart.java b/xchart/src/main/java/org/knowm/xchart/Chart.java index b2e9deb470ef1fc8f79938c7a1424efe3308415a..0b5f054bff1275ccef211704407fb8bc729a80cf 100644 --- a/xchart/src/main/java/org/knowm/xchart/Chart.java +++ b/xchart/src/main/java/org/knowm/xchart/Chart.java @@ -22,7 +22,7 @@ import java.util.List; import java.util.Map; import org.knowm.xchart.StyleManager.ChartTheme; -import org.knowm.xchart.internal.chartpart.ChartPainter; +import org.knowm.xchart.internal.chartpart.ChartInternal; import org.knowm.xchart.internal.style.Theme; /** @@ -35,7 +35,7 @@ public class Chart { /** * Hides ugly details mostly related to painting the chart and managing the added series. Not to be exposed to outside. */ - private final ChartPainter chartPainter; + private final ChartInternal chartInternal; /** * Constructor @@ -45,7 +45,7 @@ public class Chart { */ public Chart(int width, int height) { - chartPainter = new ChartPainter(width, height); + chartInternal = new ChartInternal(width, height); } /** @@ -69,8 +69,8 @@ public class Chart { */ public Chart(int width, int height, Theme theme) { - chartPainter = new ChartPainter(width, height); - chartPainter.getStyleManager().setTheme(theme); + chartInternal = new ChartInternal(width, height); + chartInternal.getStyleManager().setTheme(theme); } /** @@ -94,7 +94,7 @@ public class Chart { */ public void paint(Graphics2D g, int width, int height) { - chartPainter.paint(g, width, height); + chartInternal.paint(g, width, height); } /** @@ -102,7 +102,7 @@ public class Chart { */ public void paint(Graphics2D g) { - chartPainter.paint(g); + chartInternal.paint(g); } /** @@ -116,7 +116,7 @@ public class Chart { */ public Series addSeries(String seriesName, List<?> xData, List<? extends Number> yData, List<? extends Number> errorBars) { - return chartPainter.getAxisPair().addSeries(seriesName, xData, yData, errorBars); + return chartInternal.addSeries(seriesName, xData, yData, errorBars); } /** @@ -231,7 +231,7 @@ public class Chart { */ public void setChartTitle(String title) { - chartPainter.getChartTitle().setText(title); + chartInternal.getChartTitle().setText(title); } /** @@ -241,7 +241,7 @@ public class Chart { */ public void setXAxisTitle(String title) { - chartPainter.getAxisPair().getXAxis().getAxisTitle().setText(title); + chartInternal.getAxisPair().getXAxis().getAxisTitle().setText(title); } /** @@ -251,7 +251,7 @@ public class Chart { */ public void setYAxisTitle(String title) { - chartPainter.getAxisPair().getYAxis().getAxisTitle().setText(title); + chartInternal.getAxisPair().getYAxis().getAxisTitle().setText(title); } /** @@ -261,22 +261,22 @@ public class Chart { */ public StyleManager getStyleManager() { - return chartPainter.getStyleManager(); + return chartInternal.getStyleManager(); } public int getWidth() { - return chartPainter.getWidth(); + return chartInternal.getWidth(); } public int getHeight() { - return chartPainter.getHeight(); + return chartInternal.getHeight(); } public Map<String, Series> getSeriesMap() { - return chartPainter.getAxisPair().getSeriesMap(); + return chartInternal.getSeriesMap(); } } diff --git a/xchart/src/main/java/org/knowm/xchart/internal/chartpart/Axis.java b/xchart/src/main/java/org/knowm/xchart/internal/chartpart/Axis.java index 6846d30aa5d6459fc08a26bf0cae6f72c3906bb2..315535a79c59d9f34cb9ca86f7a4991d3f6d49ae 100644 --- a/xchart/src/main/java/org/knowm/xchart/internal/chartpart/Axis.java +++ b/xchart/src/main/java/org/knowm/xchart/internal/chartpart/Axis.java @@ -149,8 +149,8 @@ public class Axis implements ChartPart { // | // | // ---- - double xOffset = getChartPainter().getStyleManager().getChartPadding(); - double yOffset = getChartPainter().getChartTitle().getSizeHint(); + double xOffset = getChartInternal().getStyleManager().getChartPadding(); + double yOffset = getChartInternal().getChartTitle().getSizeHint(); ///////////////////////// int i = 1; // just twice through is all it takes @@ -161,22 +161,22 @@ public class Axis implements ChartPart { double approximateXAxisWidth = - getChartPainter().getWidth() + getChartInternal().getWidth() - width // y-axis approx. width - - (getChartPainter().getStyleManager().getLegendPosition() == LegendPosition.OutsideE ? getChartPainter().getChartLegend().getLegendBoxWidth() : 0) + - (getChartInternal().getStyleManager().getLegendPosition() == LegendPosition.OutsideE ? getChartInternal().getChartLegend().getLegendBoxWidth() : 0) - - 2 * getChartPainter().getStyleManager().getChartPadding() + - 2 * getChartInternal().getStyleManager().getChartPadding() - - (getChartPainter().getStyleManager().isYAxisTicksVisible() ? (getChartPainter().getStyleManager().getPlotPadding()) : 0) + - (getChartInternal().getStyleManager().isYAxisTicksVisible() ? (getChartInternal().getStyleManager().getPlotPadding()) : 0) - - (getChartPainter().getStyleManager().getLegendPosition() == LegendPosition.OutsideE && getChartPainter().getStyleManager().isLegendVisible() ? getChartPainter().getStyleManager() + - (getChartInternal().getStyleManager().getLegendPosition() == LegendPosition.OutsideE && getChartInternal().getStyleManager().isLegendVisible() ? getChartInternal().getStyleManager() .getChartPadding() : 0) ; - height = getChartPainter().getHeight() - yOffset - axisPair.getXAxis().getXAxisHeightHint(approximateXAxisWidth) - getChartPainter().getStyleManager().getPlotPadding() - getChartPainter() + height = getChartInternal().getHeight() - yOffset - axisPair.getXAxis().getXAxisHeightHint(approximateXAxisWidth) - getChartInternal().getStyleManager().getPlotPadding() - getChartInternal() .getStyleManager().getChartPadding(); width = getYAxisWidthHint(height); @@ -199,7 +199,7 @@ public class Axis implements ChartPart { xOffset = paintZone.getX(); yOffset = paintZone.getY(); - width = (getChartPainter().getStyleManager().isYAxisTitleVisible() ? axisTitle.getBounds().getWidth() : 0) + axisTick.getBounds().getWidth(); + width = (getChartInternal().getStyleManager().isYAxisTitleVisible() ? axisTitle.getBounds().getWidth() : 0) + axisTick.getBounds().getWidth(); height = paintZone.getHeight(); bounds = new Rectangle2D.Double(xOffset, yOffset, width, height); @@ -212,23 +212,23 @@ public class Axis implements ChartPart { // calculate paint zone // |____________________| - double xOffset = axisPair.getYAxis().getBounds().getWidth() + (getChartPainter().getStyleManager().isYAxisTicksVisible() ? getChartPainter().getStyleManager().getPlotPadding() : 0) - + getChartPainter().getStyleManager().getChartPadding(); - double yOffset = axisPair.getYAxis().getBounds().getY() + axisPair.getYAxis().getBounds().getHeight() + getChartPainter().getStyleManager().getPlotPadding(); + double xOffset = axisPair.getYAxis().getBounds().getWidth() + (getChartInternal().getStyleManager().isYAxisTicksVisible() ? getChartInternal().getStyleManager().getPlotPadding() : 0) + + getChartInternal().getStyleManager().getChartPadding(); + double yOffset = axisPair.getYAxis().getBounds().getY() + axisPair.getYAxis().getBounds().getHeight() + getChartInternal().getStyleManager().getPlotPadding(); double width = - getChartPainter().getWidth() + getChartInternal().getWidth() - axisPair.getYAxis().getBounds().getWidth() // y-axis was already painted - - (getChartPainter().getStyleManager().getLegendPosition() == LegendPosition.OutsideE ? getChartPainter().getChartLegend().getLegendBoxWidth() : 0) + - (getChartInternal().getStyleManager().getLegendPosition() == LegendPosition.OutsideE ? getChartInternal().getChartLegend().getLegendBoxWidth() : 0) - - 2 * getChartPainter().getStyleManager().getChartPadding() + - 2 * getChartInternal().getStyleManager().getChartPadding() - - (getChartPainter().getStyleManager().isYAxisTicksVisible() ? (getChartPainter().getStyleManager().getPlotPadding()) : 0) + - (getChartInternal().getStyleManager().isYAxisTicksVisible() ? (getChartInternal().getStyleManager().getPlotPadding()) : 0) - - (getChartPainter().getStyleManager().getLegendPosition() == LegendPosition.OutsideE && getChartPainter().getStyleManager().isLegendVisible() ? getChartPainter().getStyleManager() + - (getChartInternal().getStyleManager().getLegendPosition() == LegendPosition.OutsideE && getChartInternal().getStyleManager().isLegendVisible() ? getChartInternal().getStyleManager() .getChartPadding() : 0) ; @@ -236,8 +236,8 @@ public class Axis implements ChartPart { // double height = this.getXAxisHeightHint(width); // System.out.println("height: " + height); // the Y-Axis was already draw at this point so we know how much vertical room is left for the X-Axis - double height = getChartPainter().getHeight() - axisPair.getYAxis().getBounds().getY() - axisPair.getYAxis().getBounds().getHeight() - getChartPainter().getStyleManager().getChartPadding() - - getChartPainter().getStyleManager().getPlotPadding(); + double height = getChartInternal().getHeight() - axisPair.getYAxis().getBounds().getY() - axisPair.getYAxis().getBounds().getHeight() - getChartInternal().getStyleManager().getChartPadding() + - getChartInternal().getStyleManager().getPlotPadding(); // System.out.println("height2: " + height2); Rectangle2D xAxisRectangle = new Rectangle2D.Double(xOffset, yOffset, width, height); @@ -269,15 +269,15 @@ public class Axis implements ChartPart { // Axis title double titleHeight = 0.0; - if (axisTitle.getText() != null && !axisTitle.getText().trim().equalsIgnoreCase("") && getChartPainter().getStyleManager().isXAxisTitleVisible()) { - TextLayout textLayout = new TextLayout(axisTitle.getText(), getChartPainter().getStyleManager().getAxisTitleFont(), new FontRenderContext(null, true, false)); + if (axisTitle.getText() != null && !axisTitle.getText().trim().equalsIgnoreCase("") && getChartInternal().getStyleManager().isXAxisTitleVisible()) { + TextLayout textLayout = new TextLayout(axisTitle.getText(), getChartInternal().getStyleManager().getAxisTitleFont(), new FontRenderContext(null, true, false)); Rectangle2D rectangle = textLayout.getBounds(); - titleHeight = rectangle.getHeight() + getChartPainter().getStyleManager().getAxisTitlePadding(); + titleHeight = rectangle.getHeight() + getChartInternal().getStyleManager().getAxisTitlePadding(); } // Axis tick labels double axisTickLabelsHeight = 0.0; - if (getChartPainter().getStyleManager().isXAxisTicksVisible()) { + if (getChartInternal().getStyleManager().isXAxisTicksVisible()) { // get some real tick labels // System.out.println("XAxisHeightHint"); @@ -294,13 +294,13 @@ public class Axis implements ChartPart { // System.out.println("sampleLabel: " + sampleLabel); // get the height of the label including rotation - TextLayout textLayout = new TextLayout(sampleLabel.length() == 0 ? " " : sampleLabel, getChartPainter().getStyleManager().getAxisTickLabelsFont(), new FontRenderContext(null, true, false)); - AffineTransform rot = getChartPainter().getStyleManager().getXAxisLabelRotation() == 0 ? null : AffineTransform.getRotateInstance(-1 * Math.toRadians(getChartPainter().getStyleManager() + TextLayout textLayout = new TextLayout(sampleLabel.length() == 0 ? " " : sampleLabel, getChartInternal().getStyleManager().getAxisTickLabelsFont(), new FontRenderContext(null, true, false)); + AffineTransform rot = getChartInternal().getStyleManager().getXAxisLabelRotation() == 0 ? null : AffineTransform.getRotateInstance(-1 * Math.toRadians(getChartInternal().getStyleManager() .getXAxisLabelRotation())); Shape shape = textLayout.getOutline(rot); Rectangle2D rectangle = shape.getBounds(); - axisTickLabelsHeight = rectangle.getHeight() + getChartPainter().getStyleManager().getAxisTickPadding() + getChartPainter().getStyleManager().getAxisTickMarkLength(); + axisTickLabelsHeight = rectangle.getHeight() + getChartInternal().getStyleManager().getAxisTickPadding() + getChartInternal().getStyleManager().getAxisTickMarkLength(); } return titleHeight + axisTickLabelsHeight; } @@ -309,15 +309,15 @@ public class Axis implements ChartPart { // Axis title double titleHeight = 0.0; - if (axisTitle.getText() != null && !axisTitle.getText().trim().equalsIgnoreCase("") && getChartPainter().getStyleManager().isYAxisTitleVisible()) { - TextLayout textLayout = new TextLayout(axisTitle.getText(), getChartPainter().getStyleManager().getAxisTitleFont(), new FontRenderContext(null, true, false)); + if (axisTitle.getText() != null && !axisTitle.getText().trim().equalsIgnoreCase("") && getChartInternal().getStyleManager().isYAxisTitleVisible()) { + TextLayout textLayout = new TextLayout(axisTitle.getText(), getChartInternal().getStyleManager().getAxisTitleFont(), new FontRenderContext(null, true, false)); Rectangle2D rectangle = textLayout.getBounds(); - titleHeight = rectangle.getHeight() + getChartPainter().getStyleManager().getAxisTitlePadding(); + titleHeight = rectangle.getHeight() + getChartInternal().getStyleManager().getAxisTitlePadding(); } // Axis tick labels double axisTickLabelsHeight = 0.0; - if (getChartPainter().getStyleManager().isYAxisTicksVisible()) { + if (getChartInternal().getStyleManager().isYAxisTicksVisible()) { // get some real tick labels // System.out.println("XAxisHeightHint"); @@ -332,10 +332,10 @@ public class Axis implements ChartPart { } // get the height of the label including rotation - TextLayout textLayout = new TextLayout(sampleLabel.length() == 0 ? " " : sampleLabel, getChartPainter().getStyleManager().getAxisTickLabelsFont(), new FontRenderContext(null, true, false)); + TextLayout textLayout = new TextLayout(sampleLabel.length() == 0 ? " " : sampleLabel, getChartInternal().getStyleManager().getAxisTickLabelsFont(), new FontRenderContext(null, true, false)); Rectangle2D rectangle = textLayout.getBounds(); - axisTickLabelsHeight = rectangle.getWidth() + getChartPainter().getStyleManager().getAxisTickPadding() + getChartPainter().getStyleManager().getAxisTickMarkLength(); + axisTickLabelsHeight = rectangle.getWidth() + getChartInternal().getStyleManager().getAxisTickPadding() + getChartInternal().getStyleManager().getAxisTickMarkLength(); } return titleHeight + axisTickLabelsHeight; } @@ -344,34 +344,34 @@ public class Axis implements ChartPart { if (getDirection() == Direction.X && getAxisType() == AxisType.String) { - return new AxisTickCategoryChartCalculator(getDirection(), workingSpace, getMin(), getMax(), getChartPainter()); + return new AxisTickCategoryChartCalculator(getDirection(), workingSpace, getMin(), getMax(), getChartInternal()); } - else if (getDirection() == Direction.X && getChartPainter().getStyleManager().isXAxisLogarithmic() && getAxisType() != AxisType.Date) { + else if (getDirection() == Direction.X && getChartInternal().getStyleManager().isXAxisLogarithmic() && getAxisType() != AxisType.Date) { - return new AxisTickLogarithmicCalculator(getDirection(), workingSpace, getMin(), getMax(), getChartPainter().getStyleManager()); + return new AxisTickLogarithmicCalculator(getDirection(), workingSpace, getMin(), getMax(), getChartInternal().getStyleManager()); } - else if (getDirection() == Direction.Y && getChartPainter().getStyleManager().isYAxisLogarithmic() && getAxisType() != AxisType.Date) { + else if (getDirection() == Direction.Y && getChartInternal().getStyleManager().isYAxisLogarithmic() && getAxisType() != AxisType.Date) { - return new AxisTickLogarithmicCalculator(getDirection(), workingSpace, getMin(), getMax(), getChartPainter().getStyleManager()); + return new AxisTickLogarithmicCalculator(getDirection(), workingSpace, getMin(), getMax(), getChartInternal().getStyleManager()); } else if (getAxisType() == AxisType.Date) { - return new AxisTickDateCalculator(getDirection(), workingSpace, getMin(), getMax(), getChartPainter().getStyleManager()); + return new AxisTickDateCalculator(getDirection(), workingSpace, getMin(), getMax(), getChartInternal().getStyleManager()); } else { // number - return new AxisTickNumberCalculator(getDirection(), workingSpace, getMin(), getMax(), getChartPainter().getStyleManager()); + return new AxisTickNumberCalculator(getDirection(), workingSpace, getMin(), getMax(), getChartInternal().getStyleManager()); } } @Override - public ChartPainter getChartPainter() { + public ChartInternal getChartInternal() { - return axisPair.getChartPainter(); + return axisPair.getChartInternal(); } // Getters ///////////////////////////////////////////////// diff --git a/xchart/src/main/java/org/knowm/xchart/internal/chartpart/AxisPair.java b/xchart/src/main/java/org/knowm/xchart/internal/chartpart/AxisPair.java index d6743ae75453aa87ad2c7fc2ba020cc1cece4cf3..f20e7c1c62448abe3cee17a09fad09902c81857b 100644 --- a/xchart/src/main/java/org/knowm/xchart/internal/chartpart/AxisPair.java +++ b/xchart/src/main/java/org/knowm/xchart/internal/chartpart/AxisPair.java @@ -18,16 +18,6 @@ package org.knowm.xchart.internal.chartpart; import java.awt.Graphics2D; import java.awt.Rectangle; -import java.util.ArrayList; -import java.util.Date; -import java.util.Iterator; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; - -import org.knowm.xchart.Series; -import org.knowm.xchart.internal.chartpart.Axis.AxisType; -import org.knowm.xchart.internal.style.SeriesColorMarkerLineStyleCycler; /** * @author timmolter @@ -35,129 +25,25 @@ import org.knowm.xchart.internal.style.SeriesColorMarkerLineStyleCycler; public class AxisPair implements ChartPart { /** parent */ - private final ChartPainter chartPainter; - - private Map<String, Series> seriesMap = new LinkedHashMap<String, Series>(); + private final ChartInternal chartInternal; private Axis xAxis; private Axis yAxis; - private SeriesColorMarkerLineStyleCycler seriesColorMarkerLineStyleCycler = new SeriesColorMarkerLineStyleCycler(); - /** * Constructor * - * @param the parent chartPainter + * @param the parent chartInternal */ - public AxisPair(ChartPainter chartPainter) { + public AxisPair(ChartInternal chartInternal) { - this.chartPainter = chartPainter; + this.chartInternal = chartInternal; // add axes xAxis = new Axis(this, Axis.Direction.X); yAxis = new Axis(this, Axis.Direction.Y); } - /** - * @param seriesName - * @param xData - * @param yData - * @param errorBars - * @return Series - */ - public Series addSeries(String seriesName, List<?> xData, List<? extends Number> yData, List<? extends Number> errorBars) { - - // Sanity checks - if (seriesName == null) { - throw new IllegalArgumentException("Series Name cannot be null!!!"); - } - if (yData == null) { - throw new IllegalArgumentException("Y-Axis data cannot be null!!!"); - } - if (yData.size() == 0) { - throw new IllegalArgumentException("Y-Axis data cannot be empty!!!"); - } - if (xData != null && xData.size() == 0) { - throw new IllegalArgumentException("X-Axis data cannot be empty!!!"); - } - // Sanity check - if (errorBars != null && errorBars.size() != yData.size()) { - throw new IllegalArgumentException("errorbars and Y-Axis sizes are not the same!!!"); - } - - Series series = null; - if (xData != null) { - - // Sanity check - if (xData.size() != yData.size()) { - throw new IllegalArgumentException("X and Y-Axis sizes are not the same!!!"); - } - // inspect the series to see what kind of data it contains (Number, Date or String) - Iterator<?> itr = xData.iterator(); - Object dataPoint = itr.next(); - if (dataPoint instanceof Number) { - xAxis.setAxisType(AxisType.Number); - } - else if (dataPoint instanceof Date) { - xAxis.setAxisType(AxisType.Date); - } - else if (dataPoint instanceof String) { - xAxis.setAxisType(AxisType.String); - } - else { - throw new IllegalArgumentException("Series data must be either Number, Date or String type!!!"); - } - yAxis.setAxisType(AxisType.Number); - series = new Series(seriesName, xData, xAxis.getAxisType(), yData, yAxis.getAxisType(), errorBars, seriesColorMarkerLineStyleCycler.getNextSeriesColorMarkerLineStyle()); - } - else { // generate xData - List<Double> generatedXData = new ArrayList<Double>(); - for (int i = 1; i < yData.size() + 1; i++) { - generatedXData.add((double) i); - } - xAxis.setAxisType(AxisType.Number); - yAxis.setAxisType(AxisType.Number); - series = new Series(seriesName, generatedXData, xAxis.getAxisType(), yData, yAxis.getAxisType(), errorBars, seriesColorMarkerLineStyleCycler.getNextSeriesColorMarkerLineStyle()); - } - - // set series type based on chart type, but only if it's not explicitly set on the series yet. - switch (chartPainter.getStyleManager().getChartType()) { - case Line: - if (series.getSeriesType() == null) { - series.setSeriesType(Series.SeriesType.Line); - } - break; - case Area: - if (series.getSeriesType() == null) { - series.setSeriesType(Series.SeriesType.Area); - } - break; - case Scatter: - if (series.getSeriesType() == null) { - series.setSeriesType(Series.SeriesType.Scatter); - } - break; - case Bar: - if (series.getSeriesType() == null) { - series.setSeriesType(Series.SeriesType.Bar); - } - break; - default: - if (series.getSeriesType() == null) { - series.setSeriesType(Series.SeriesType.Line); - } - break; - } - - if (seriesMap.keySet().contains(seriesName)) { - throw new IllegalArgumentException("Series name >" + seriesName + "< has already been used. Use unique names for each series!!!"); - } - - seriesMap.put(seriesName, series); - - return series; - } - @Override public void paint(Graphics2D g) { @@ -172,18 +58,13 @@ public class AxisPair implements ChartPart { } @Override - public ChartPainter getChartPainter() { + public ChartInternal getChartInternal() { - return chartPainter; + return chartInternal; } // Getters ///////////////////////////////////////////////// - public Map<String, Series> getSeriesMap() { - - return seriesMap; - } - public Axis getXAxis() { return xAxis; diff --git a/xchart/src/main/java/org/knowm/xchart/internal/chartpart/AxisTick.java b/xchart/src/main/java/org/knowm/xchart/internal/chartpart/AxisTick.java index b99262b074b7d09a23ff2fc12bd56421d38629ec..11fa08cbcebc3ff1f6601da33d46dd23807f68e3 100644 --- a/xchart/src/main/java/org/knowm/xchart/internal/chartpart/AxisTick.java +++ b/xchart/src/main/java/org/knowm/xchart/internal/chartpart/AxisTick.java @@ -72,7 +72,7 @@ public class AxisTick implements ChartPart { // System.out.println("AxisTick: " + axis.getDirection()); // System.out.println("workingSpace: " + workingSpace); - if (axis.getDirection() == Axis.Direction.Y && getChartPainter().getStyleManager().isYAxisTicksVisible()) { + if (axis.getDirection() == Axis.Direction.Y && getChartInternal().getStyleManager().isYAxisTicksVisible()) { axisTickLabels.paint(g); axisTickMarks.paint(g); @@ -83,7 +83,7 @@ public class AxisTick implements ChartPart { axisTickLabels.getBounds().getY(), - axisTickLabels.getBounds().getWidth() + getChartPainter().getStyleManager().getAxisTickPadding() + axisTickMarks.getBounds().getWidth(), + axisTickLabels.getBounds().getWidth() + getChartInternal().getStyleManager().getAxisTickPadding() + axisTickMarks.getBounds().getWidth(), axisTickMarks.getBounds().getHeight() @@ -93,13 +93,13 @@ public class AxisTick implements ChartPart { // g.draw(bounds); } - else if (axis.getDirection() == Axis.Direction.X && getChartPainter().getStyleManager().isXAxisTicksVisible()) { + else if (axis.getDirection() == Axis.Direction.X && getChartInternal().getStyleManager().isXAxisTicksVisible()) { axisTickLabels.paint(g); axisTickMarks.paint(g); bounds = new Rectangle2D.Double(axisTickMarks.getBounds().getX(), axisTickMarks.getBounds().getY(), axisTickLabels.getBounds().getWidth(), axisTickMarks.getBounds().getHeight() - + getChartPainter().getStyleManager().getAxisTickPadding() + axisTickLabels.getBounds().getHeight()); + + getChartInternal().getStyleManager().getAxisTickPadding() + axisTickLabels.getBounds().getHeight()); // g.setColor(Color.red); // g.draw(bounds); @@ -109,9 +109,9 @@ public class AxisTick implements ChartPart { } @Override - public ChartPainter getChartPainter() { + public ChartInternal getChartInternal() { - return axis.getChartPainter(); + return axis.getChartInternal(); } // Getters ///////////////////////////////////////////////// diff --git a/xchart/src/main/java/org/knowm/xchart/internal/chartpart/AxisTickCategoryChartCalculator.java b/xchart/src/main/java/org/knowm/xchart/internal/chartpart/AxisTickCategoryChartCalculator.java index 33d8d90a8a73316ddef6edd9d40246572f363ffe..5cec5523daf436316754eb934c61fa7265f6d8cd 100644 --- a/xchart/src/main/java/org/knowm/xchart/internal/chartpart/AxisTickCategoryChartCalculator.java +++ b/xchart/src/main/java/org/knowm/xchart/internal/chartpart/AxisTickCategoryChartCalculator.java @@ -42,7 +42,7 @@ public class AxisTickCategoryChartCalculator extends AxisTickCalculator { * @param maxValue * @param styleManager */ - public AxisTickCategoryChartCalculator(Direction axisDirection, double workingSpace, double minValue, double maxValue, ChartPainter chart) { + public AxisTickCategoryChartCalculator(Direction axisDirection, double workingSpace, double minValue, double maxValue, ChartInternal chart) { super(axisDirection, workingSpace, minValue, maxValue, chart.getStyleManager()); @@ -69,7 +69,7 @@ public class AxisTickCategoryChartCalculator extends AxisTickCalculator { calculate(chart); } - private void calculate(ChartPainter chartPainter) { + private void calculate(ChartInternal chartInternal) { // tick space - a percentage of the working space available for ticks int tickSpace = (int) (styleManager.getAxisTickSpacePercentage() * workingSpace); // in plot space @@ -77,12 +77,12 @@ public class AxisTickCategoryChartCalculator extends AxisTickCalculator { // where the tick should begin in the working space in pixels double margin = Utils.getTickStartOffset(workingSpace, tickSpace); - List<?> categories = (List<?>) chartPainter.getAxisPair().getSeriesMap().values().iterator().next().getXData(); + List<?> categories = (List<?>) chartInternal.getSeriesMap().values().iterator().next().getXData(); // verify all series have exactly the same xAxis - if (chartPainter.getAxisPair().getSeriesMap().size() > 1) { + if (chartInternal.getSeriesMap().size() > 1) { - for (Series series : chartPainter.getAxisPair().getSeriesMap().values()) { + for (Series series : chartInternal.getSeriesMap().values()) { if (!series.getXData().equals(categories)) { throw new IllegalArgumentException("X-Axis data must exactly match all other Series X-Axis data for Bar Charts!!"); } @@ -96,10 +96,10 @@ public class AxisTickCategoryChartCalculator extends AxisTickCalculator { // set up String formatters that may be encountered NumberFormatter numberFormatter = null; SimpleDateFormat simpleDateformat = null; - if (chartPainter.getAxisPair().getXAxis().getAxisType() == AxisType.Number) { + if (chartInternal.getAxisPair().getXAxis().getAxisType() == AxisType.Number) { numberFormatter = new NumberFormatter(styleManager); } - else if (chartPainter.getAxisPair().getXAxis().getAxisType() == AxisType.Date) { + else if (chartInternal.getAxisPair().getXAxis().getAxisType() == AxisType.Date) { if (styleManager.getDatePattern() == null) { throw new RuntimeException("You need to set the Date Formatting Pattern!!!"); } @@ -110,15 +110,15 @@ public class AxisTickCategoryChartCalculator extends AxisTickCalculator { int counter = 0; for (Object category : categories) { - if (chartPainter.getAxisPair().getXAxis().getAxisType() == AxisType.String) { + if (chartInternal.getAxisPair().getXAxis().getAxisType() == AxisType.String) { tickLabels.add(category.toString()); double tickLabelPosition = margin + firstPosition + gridStep * counter++; tickLocations.add(tickLabelPosition); } - else if (chartPainter.getAxisPair().getXAxis().getAxisType() == AxisType.Number) { + else if (chartInternal.getAxisPair().getXAxis().getAxisType() == AxisType.Number) { tickLabels.add(numberFormatter.formatNumber(new BigDecimal(category.toString()), minValue, maxValue, axisDirection)); } - else if (chartPainter.getAxisPair().getXAxis().getAxisType() == AxisType.Date) { + else if (chartInternal.getAxisPair().getXAxis().getAxisType() == AxisType.Date) { tickLabels.add(simpleDateformat.format((((Date) category).getTime()))); } diff --git a/xchart/src/main/java/org/knowm/xchart/internal/chartpart/AxisTickLabels.java b/xchart/src/main/java/org/knowm/xchart/internal/chartpart/AxisTickLabels.java index 90a8b3b0dce833e77d3f24c0399e73270b48902e..89fd605545fbcdfa45a5b859ed4ad34ed82d5fbe 100644 --- a/xchart/src/main/java/org/knowm/xchart/internal/chartpart/AxisTickLabels.java +++ b/xchart/src/main/java/org/knowm/xchart/internal/chartpart/AxisTickLabels.java @@ -55,11 +55,11 @@ public class AxisTickLabels implements ChartPart { @Override public void paint(Graphics2D g) { - g.setFont(getChartPainter().getStyleManager().getAxisTickLabelsFont()); + g.setFont(getChartInternal().getStyleManager().getAxisTickLabelsFont()); - g.setColor(getChartPainter().getStyleManager().getAxisTickLabelsColor()); + g.setColor(getChartInternal().getStyleManager().getAxisTickLabelsColor()); - if (axisTick.getAxis().getDirection() == Axis.Direction.Y && getChartPainter().getStyleManager().isYAxisTicksVisible()) { // Y-Axis + if (axisTick.getAxis().getDirection() == Axis.Direction.Y && getChartInternal().getStyleManager().isYAxisTicksVisible()) { // Y-Axis double xWidth = axisTick.getAxis().getAxisTitle().getBounds().getWidth(); double xOffset = axisTick.getAxis().getAxisTitle().getBounds().getX() + xWidth; @@ -77,7 +77,7 @@ public class AxisTickLabels implements ChartPart { if (tickLabel != null && flippedTickLocation > yOffset && flippedTickLocation < yOffset + height) { // some are null for logarithmic axes FontRenderContext frc = g.getFontRenderContext(); - TextLayout axisLabelTextLayout = new TextLayout(tickLabel, getChartPainter().getStyleManager().getAxisTickLabelsFont(), frc); + TextLayout axisLabelTextLayout = new TextLayout(tickLabel, getChartInternal().getStyleManager().getAxisTickLabelsFont(), frc); Rectangle2D tickLabelBounds = axisLabelTextLayout.getBounds(); double boundWidth = tickLabelBounds.getWidth(); if (boundWidth > maxTickLabelWidth) { @@ -99,7 +99,7 @@ public class AxisTickLabels implements ChartPart { AffineTransform at = new AffineTransform(); double boundWidth = tickLabelBounds.getWidth(); double xPos; - switch (getChartPainter().getStyleManager().getYAxisLabelAlignment()) { + switch (getChartInternal().getStyleManager().getYAxisLabelAlignment()) { case Right: xPos = xOffset + maxTickLabelWidth - boundWidth; break; @@ -124,7 +124,7 @@ public class AxisTickLabels implements ChartPart { } // X-Axis - else if (axisTick.getAxis().getDirection() == Axis.Direction.X && getChartPainter().getStyleManager().isXAxisTicksVisible()) { + else if (axisTick.getAxis().getDirection() == Axis.Direction.X && getChartInternal().getStyleManager().isXAxisTicksVisible()) { double xOffset = axisTick.getAxis().getPaintZone().getX(); double yOffset = axisTick.getAxis().getAxisTitle().getBounds().getY(); @@ -143,18 +143,18 @@ public class AxisTickLabels implements ChartPart { if (tickLabel != null && shiftedTickLocation > xOffset && shiftedTickLocation < xOffset + width) { // some are null for logarithmic axes FontRenderContext frc = g.getFontRenderContext(); - TextLayout textLayout = new TextLayout(tickLabel, getChartPainter().getStyleManager().getAxisTickLabelsFont(), frc); + TextLayout textLayout = new TextLayout(tickLabel, getChartInternal().getStyleManager().getAxisTickLabelsFont(), frc); // System.out.println(textLayout.getOutline(null).getBounds().toString()); // Shape shape = v.getOutline(); - AffineTransform rot = AffineTransform.getRotateInstance(-1 * Math.toRadians(getChartPainter().getStyleManager().getXAxisLabelRotation()), 0, 0); + AffineTransform rot = AffineTransform.getRotateInstance(-1 * Math.toRadians(getChartInternal().getStyleManager().getXAxisLabelRotation()), 0, 0); Shape shape = textLayout.getOutline(rot); Rectangle2D tickLabelBounds = shape.getBounds2D(); AffineTransform orig = g.getTransform(); AffineTransform at = new AffineTransform(); double xPos; - switch (getChartPainter().getStyleManager().getXAxisLabelAlignment()) { + switch (getChartInternal().getStyleManager().getXAxisLabelAlignment()) { case Left: xPos = shiftedTickLocation; break; @@ -166,7 +166,7 @@ public class AxisTickLabels implements ChartPart { xPos = shiftedTickLocation - tickLabelBounds.getWidth() / 2.0; } // System.out.println("tickLabelBounds: " + tickLabelBounds.toString()); - double shiftX = -1 * tickLabelBounds.getX() * Math.sin(Math.toRadians(getChartPainter().getStyleManager().getXAxisLabelRotation())); + double shiftX = -1 * tickLabelBounds.getX() * Math.sin(Math.toRadians(getChartInternal().getStyleManager().getXAxisLabelRotation())); double shiftY = -1 * (tickLabelBounds.getY() + tickLabelBounds.getHeight()); // System.out.println(shiftX); // System.out.println("shiftY: " + shiftY); @@ -200,8 +200,8 @@ public class AxisTickLabels implements ChartPart { } @Override - public ChartPainter getChartPainter() { + public ChartInternal getChartInternal() { - return axisTick.getChartPainter(); + return axisTick.getChartInternal(); } } diff --git a/xchart/src/main/java/org/knowm/xchart/internal/chartpart/AxisTickMarks.java b/xchart/src/main/java/org/knowm/xchart/internal/chartpart/AxisTickMarks.java index 53c0c03b9732a948789466227e88b92be7f4c52a..1c05c65bcf158b3760501abc8974966cd5de6f8a 100644 --- a/xchart/src/main/java/org/knowm/xchart/internal/chartpart/AxisTickMarks.java +++ b/xchart/src/main/java/org/knowm/xchart/internal/chartpart/AxisTickMarks.java @@ -51,21 +51,21 @@ public class AxisTickMarks implements ChartPart { @Override public void paint(Graphics2D g) { - g.setColor(getChartPainter().getStyleManager().getAxisTickMarksColor()); - g.setStroke(getChartPainter().getStyleManager().getAxisTickMarksStroke()); + g.setColor(getChartInternal().getStyleManager().getAxisTickMarksColor()); + g.setStroke(getChartInternal().getStyleManager().getAxisTickMarksStroke()); - if (axisTick.getAxis().getDirection() == Axis.Direction.Y && getChartPainter().getStyleManager().isYAxisTicksVisible()) { // Y-Axis + if (axisTick.getAxis().getDirection() == Axis.Direction.Y && getChartInternal().getStyleManager().isYAxisTicksVisible()) { // Y-Axis - double xOffset = axisTick.getAxisTickLabels().getBounds().getX() + axisTick.getAxisTickLabels().getBounds().getWidth() + getChartPainter().getStyleManager().getAxisTickPadding(); + double xOffset = axisTick.getAxisTickLabels().getBounds().getX() + axisTick.getAxisTickLabels().getBounds().getWidth() + getChartInternal().getStyleManager().getAxisTickPadding(); double yOffset = axisTick.getAxis().getPaintZone().getY(); // bounds - bounds = new Rectangle2D.Double(xOffset, yOffset, getChartPainter().getStyleManager().getAxisTickMarkLength(), axisTick.getAxis().getPaintZone().getHeight()); + bounds = new Rectangle2D.Double(xOffset, yOffset, getChartInternal().getStyleManager().getAxisTickMarkLength(), axisTick.getAxis().getPaintZone().getHeight()); // g.setColor(Color.yellow); // g.draw(bounds); // tick marks - if (getChartPainter().getStyleManager().isAxisTicksMarksVisible()) { + if (getChartInternal().getStyleManager().isAxisTicksMarksVisible()) { for (int i = 0; i < axisTick.getAxis().getAxisTickCalculator().getTickLabels().size(); i++) { @@ -73,16 +73,16 @@ public class AxisTickMarks implements ChartPart { double flippedTickLocation = yOffset + axisTick.getAxis().getPaintZone().getHeight() - tickLocation; if (flippedTickLocation > bounds.getY() && flippedTickLocation < bounds.getY() + bounds.getHeight()) { - Shape line = new Line2D.Double(xOffset, flippedTickLocation, xOffset + getChartPainter().getStyleManager().getAxisTickMarkLength(), flippedTickLocation); + Shape line = new Line2D.Double(xOffset, flippedTickLocation, xOffset + getChartInternal().getStyleManager().getAxisTickMarkLength(), flippedTickLocation); g.draw(line); } } } // Line - if (getChartPainter().getStyleManager().isAxisTicksLineVisible()) { + if (getChartInternal().getStyleManager().isAxisTicksLineVisible()) { - Shape line = new Line2D.Double(xOffset + getChartPainter().getStyleManager().getAxisTickMarkLength(), yOffset, xOffset + getChartPainter().getStyleManager().getAxisTickMarkLength(), yOffset + Shape line = new Line2D.Double(xOffset + getChartInternal().getStyleManager().getAxisTickMarkLength(), yOffset, xOffset + getChartInternal().getStyleManager().getAxisTickMarkLength(), yOffset + axisTick.getAxis().getPaintZone().getHeight()); g.draw(line); @@ -90,19 +90,19 @@ public class AxisTickMarks implements ChartPart { } // X-Axis - else if (axisTick.getAxis().getDirection() == Axis.Direction.X && getChartPainter().getStyleManager().isXAxisTicksVisible()) { + else if (axisTick.getAxis().getDirection() == Axis.Direction.X && getChartInternal().getStyleManager().isXAxisTicksVisible()) { double xOffset = axisTick.getAxis().getPaintZone().getX(); - double yOffset = axisTick.getAxisTickLabels().getBounds().getY() - getChartPainter().getStyleManager().getAxisTickPadding(); + double yOffset = axisTick.getAxisTickLabels().getBounds().getY() - getChartInternal().getStyleManager().getAxisTickPadding(); // bounds - bounds = new Rectangle2D.Double(xOffset, yOffset - getChartPainter().getStyleManager().getAxisTickMarkLength(), axisTick.getAxis().getPaintZone().getWidth(), getChartPainter().getStyleManager() + bounds = new Rectangle2D.Double(xOffset, yOffset - getChartInternal().getStyleManager().getAxisTickMarkLength(), axisTick.getAxis().getPaintZone().getWidth(), getChartInternal().getStyleManager() .getAxisTickMarkLength()); // g.setColor(Color.yellow); // g.draw(bounds); // tick marks - if (getChartPainter().getStyleManager().isAxisTicksMarksVisible()) { + if (getChartInternal().getStyleManager().isAxisTicksMarksVisible()) { for (int i = 0; i < axisTick.getAxis().getAxisTickCalculator().getTickLabels().size(); i++) { @@ -111,26 +111,26 @@ public class AxisTickMarks implements ChartPart { if (shiftedTickLocation > bounds.getX() && shiftedTickLocation < bounds.getX() + bounds.getWidth()) { - Shape line = new Line2D.Double(shiftedTickLocation, yOffset, xOffset + tickLocation, yOffset - getChartPainter().getStyleManager().getAxisTickMarkLength()); + Shape line = new Line2D.Double(shiftedTickLocation, yOffset, xOffset + tickLocation, yOffset - getChartInternal().getStyleManager().getAxisTickMarkLength()); g.draw(line); } } } // Line - if (getChartPainter().getStyleManager().isAxisTicksLineVisible()) { + if (getChartInternal().getStyleManager().isAxisTicksLineVisible()) { - g.setStroke(getChartPainter().getStyleManager().getAxisTickMarksStroke()); - g.drawLine((int) xOffset, (int) (yOffset - getChartPainter().getStyleManager().getAxisTickMarkLength()), (int) (xOffset + axisTick.getAxis().getPaintZone().getWidth()), (int) (yOffset - - getChartPainter().getStyleManager().getAxisTickMarkLength())); + g.setStroke(getChartInternal().getStyleManager().getAxisTickMarksStroke()); + g.drawLine((int) xOffset, (int) (yOffset - getChartInternal().getStyleManager().getAxisTickMarkLength()), (int) (xOffset + axisTick.getAxis().getPaintZone().getWidth()), (int) (yOffset + - getChartInternal().getStyleManager().getAxisTickMarkLength())); } } } @Override - public ChartPainter getChartPainter() { + public ChartInternal getChartInternal() { - return axisTick.getChartPainter(); + return axisTick.getChartInternal(); } } diff --git a/xchart/src/main/java/org/knowm/xchart/internal/chartpart/AxisTitle.java b/xchart/src/main/java/org/knowm/xchart/internal/chartpart/AxisTitle.java index de029e27d97c75b4ba8cffabbcebdc95f119443c..92dfb716ff4799572f438c405e02ffc8a242946c 100644 --- a/xchart/src/main/java/org/knowm/xchart/internal/chartpart/AxisTitle.java +++ b/xchart/src/main/java/org/knowm/xchart/internal/chartpart/AxisTitle.java @@ -58,15 +58,15 @@ public class AxisTitle implements ChartPart { bounds = new Rectangle2D.Double(); - g.setColor(getChartPainter().getStyleManager().getChartFontColor()); - g.setFont(getChartPainter().getStyleManager().getAxisTitleFont()); + g.setColor(getChartInternal().getStyleManager().getChartFontColor()); + g.setFont(getChartInternal().getStyleManager().getAxisTitleFont()); if (axis.getDirection() == Axis.Direction.Y) { - if (text != null && !text.trim().equalsIgnoreCase("") && getChartPainter().getStyleManager().isYAxisTitleVisible()) { + if (text != null && !text.trim().equalsIgnoreCase("") && getChartInternal().getStyleManager().isYAxisTitleVisible()) { FontRenderContext frc = g.getFontRenderContext(); - TextLayout nonRotatedTextLayout = new TextLayout(text, getChartPainter().getStyleManager().getAxisTitleFont(), frc); + TextLayout nonRotatedTextLayout = new TextLayout(text, getChartInternal().getStyleManager().getAxisTitleFont(), frc); Rectangle2D nonRotatedRectangle = nonRotatedTextLayout.getBounds(); // /////////////////////////////////////////////// @@ -89,7 +89,7 @@ public class AxisTitle implements ChartPart { // System.out.println(nonRotatedRectangle.getHeight()); // bounds - bounds = new Rectangle2D.Double(xOffset - nonRotatedRectangle.getHeight(), yOffset - nonRotatedRectangle.getWidth(), nonRotatedRectangle.getHeight() + getChartPainter().getStyleManager() + bounds = new Rectangle2D.Double(xOffset - nonRotatedRectangle.getHeight(), yOffset - nonRotatedRectangle.getWidth(), nonRotatedRectangle.getHeight() + getChartInternal().getStyleManager() .getAxisTitlePadding(), nonRotatedRectangle.getWidth()); // g.setColor(Color.blue); // g.draw(bounds); @@ -101,10 +101,10 @@ public class AxisTitle implements ChartPart { } else { - if (text != null && !text.trim().equalsIgnoreCase("") && getChartPainter().getStyleManager().isXAxisTitleVisible()) { + if (text != null && !text.trim().equalsIgnoreCase("") && getChartInternal().getStyleManager().isXAxisTitleVisible()) { FontRenderContext frc = g.getFontRenderContext(); - TextLayout textLayout = new TextLayout(text, getChartPainter().getStyleManager().getAxisTitleFont(), frc); + TextLayout textLayout = new TextLayout(text, getChartInternal().getStyleManager().getAxisTitleFont(), frc); Rectangle2D rectangle = textLayout.getBounds(); // System.out.println(rectangle); @@ -120,7 +120,7 @@ public class AxisTitle implements ChartPart { g.fill(shape); g.setTransform(orig); - bounds = new Rectangle2D.Double(xOffset, yOffset - getChartPainter().getStyleManager().getAxisTitlePadding(), rectangle.getWidth(), rectangle.getHeight() + getChartPainter().getStyleManager() + bounds = new Rectangle2D.Double(xOffset, yOffset - getChartInternal().getStyleManager().getAxisTitlePadding(), rectangle.getWidth(), rectangle.getHeight() + getChartInternal().getStyleManager() .getAxisTitlePadding()); // g.setColor(Color.blue); // g.draw(bounds); @@ -136,9 +136,9 @@ public class AxisTitle implements ChartPart { } @Override - public ChartPainter getChartPainter() { + public ChartInternal getChartInternal() { - return axis.getChartPainter(); + return axis.getChartInternal(); } // Getters ///////////////////////////////////////////////// diff --git a/xchart/src/main/java/org/knowm/xchart/internal/chartpart/ChartInternal.java b/xchart/src/main/java/org/knowm/xchart/internal/chartpart/ChartInternal.java new file mode 100644 index 0000000000000000000000000000000000000000..f84885658062a13ffe8bf9cd6749e7ac49a3b259 --- /dev/null +++ b/xchart/src/main/java/org/knowm/xchart/internal/chartpart/ChartInternal.java @@ -0,0 +1,299 @@ +/** + * Copyright 2015 Knowm Inc. (http://knowm.org) and contributors. + * Copyright 2011-2015 Xeiam LLC (http://xeiam.com) and contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.knowm.xchart.internal.chartpart; + +import java.awt.Graphics2D; +import java.awt.RenderingHints; +import java.awt.Shape; +import java.awt.geom.Rectangle2D; +import java.util.ArrayList; +import java.util.Date; +import java.util.Iterator; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; + +import org.knowm.xchart.Series; +import org.knowm.xchart.StyleManager; +import org.knowm.xchart.internal.chartpart.Axis.AxisType; +import org.knowm.xchart.internal.style.SeriesColorMarkerLineStyleCycler; + +/** + * @author timmolter + */ +public class ChartInternal { + + private int width; + private int height; + + private Map<String, Series> seriesMap = new LinkedHashMap<String, Series>(); + private SeriesColorMarkerLineStyleCycler seriesColorMarkerLineStyleCycler = new SeriesColorMarkerLineStyleCycler(); + + private final StyleManager styleManager; + + // Chart Parts + private Legend chartLegend; + private AxisPair axisPair; + private Plot plot; + private ChartTitle chartTitle; + + /** + * Constructor + * + * @param width + * @param height + */ + public ChartInternal(int width, int height) { + + this.width = width; + this.height = height; + + styleManager = new StyleManager(); + + chartLegend = new Legend(this); + axisPair = new AxisPair(this); + plot = new Plot(this); + chartTitle = new ChartTitle(this); + } + + /** + * @param seriesName + * @param xData + * @param yData + * @param errorBars + * @return Series + */ + public Series addSeries(String seriesName, List<?> xData, List<? extends Number> yData, List<? extends Number> errorBars) { + + // Sanity checks + if (seriesName == null) { + throw new IllegalArgumentException("Series Name cannot be null!!!"); + } + if (yData == null) { + throw new IllegalArgumentException("Y-Axis data cannot be null!!!"); + } + if (yData.size() == 0) { + throw new IllegalArgumentException("Y-Axis data cannot be empty!!!"); + } + if (xData != null && xData.size() == 0) { + throw new IllegalArgumentException("X-Axis data cannot be empty!!!"); + } + // Sanity check + if (errorBars != null && errorBars.size() != yData.size()) { + throw new IllegalArgumentException("errorbars and Y-Axis sizes are not the same!!!"); + } + + Series series = null; + if (xData != null) { + + // Sanity check + if (xData.size() != yData.size()) { + throw new IllegalArgumentException("X and Y-Axis sizes are not the same!!!"); + } + // inspect the series to see what kind of data it contains (Number, Date or String) + Iterator<?> itr = xData.iterator(); + Object dataPoint = itr.next(); + if (dataPoint instanceof Number) { + axisPair.getXAxis().setAxisType(AxisType.Number); + } + else if (dataPoint instanceof Date) { + axisPair.getXAxis().setAxisType(AxisType.Date); + } + else if (dataPoint instanceof String) { + axisPair.getXAxis().setAxisType(AxisType.String); + } + else { + throw new IllegalArgumentException("Series data must be either Number, Date or String type!!!"); + } + axisPair.getYAxis().setAxisType(AxisType.Number); + series = new Series(seriesName, xData, axisPair.getXAxis().getAxisType(), yData, axisPair.getYAxis().getAxisType(), errorBars, seriesColorMarkerLineStyleCycler + .getNextSeriesColorMarkerLineStyle()); + } + else { // generate xData + List<Double> generatedXData = new ArrayList<Double>(); + for (int i = 1; i < yData.size() + 1; i++) { + generatedXData.add((double) i); + } + axisPair.getXAxis().setAxisType(AxisType.Number); + axisPair.getYAxis().setAxisType(AxisType.Number); + series = new Series(seriesName, generatedXData, axisPair.getXAxis().getAxisType(), yData, axisPair.getYAxis().getAxisType(), errorBars, seriesColorMarkerLineStyleCycler + .getNextSeriesColorMarkerLineStyle()); + } + + // set series type based on chart type, but only if it's not explicitly set on the series yet. + switch (getStyleManager().getChartType()) { + case Line: + if (series.getSeriesType() == null) { + series.setSeriesType(Series.SeriesType.Line); + } + break; + case Area: + if (series.getSeriesType() == null) { + series.setSeriesType(Series.SeriesType.Area); + } + break; + case Scatter: + if (series.getSeriesType() == null) { + series.setSeriesType(Series.SeriesType.Scatter); + } + break; + case Bar: + if (series.getSeriesType() == null) { + series.setSeriesType(Series.SeriesType.Bar); + } + break; + default: + if (series.getSeriesType() == null) { + series.setSeriesType(Series.SeriesType.Line); + } + break; + } + + if (seriesMap.keySet().contains(seriesName)) { + throw new IllegalArgumentException("Series name >" + seriesName + "< has already been used. Use unique names for each series!!!"); + } + + seriesMap.put(seriesName, series); + + return series; + } + + /** + * @param g + * @param width + * @param height + */ + public void paint(Graphics2D g, int width, int height) { + + this.width = width; + this.height = height; + paint(g); + } + + /** + * @param g + */ + public void paint(Graphics2D g) { + + // calc axis min and max + axisPair.getXAxis().resetMinMax(); + axisPair.getYAxis().resetMinMax(); + + for (Series series : getSeriesMap().values()) { + // add min/max to axis + // System.out.println(series.getxMin()); + // System.out.println(series.getxMax()); + // System.out.println(series.getyMin()); + // System.out.println(series.getyMax()); + // System.out.println("****"); + axisPair.getXAxis().addMinMax(series.getXMin(), series.getXMax()); + axisPair.getYAxis().addMinMax(series.getYMin(), series.getYMax()); + } + + // Sanity checks + if (getSeriesMap().isEmpty()) { + throw new RuntimeException("No series defined for Chart!!!"); + } + if (getStyleManager().isXAxisLogarithmic() && axisPair.getXAxis().getMin() <= 0.0) { + throw new IllegalArgumentException("Series data (accounting for error bars too) cannot be less or equal to zero for a logarithmic X-Axis!!!"); + } + if (getStyleManager().isYAxisLogarithmic() && axisPair.getYAxis().getMin() <= 0.0) { + // System.out.println(axisPair.getyAxis().getMin()); + throw new IllegalArgumentException("Series data (accounting for error bars too) cannot be less or equal to zero for a logarithmic Y-Axis!!!"); + } + + g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); // global rendering hint + g.setColor(styleManager.getChartBackgroundColor()); + Shape rect = new Rectangle2D.Double(0, 0, width, height); + g.fill(rect); + + // now that we added all the series, we can calculate the legend size + chartLegend.determineLegendBoxSize(); + + axisPair.paint(g); + plot.paint(g); + chartTitle.paint(g); + chartLegend.paint(g); + + g.dispose(); + } + + /** + * for internal usage + * + * @return + */ + public ChartTitle getChartTitle() { + + return chartTitle; + } + + /** + * for internal usage + * + * @return + */ + public Legend getChartLegend() { + + return chartLegend; + } + + /** + * for internal usage + * + * @return + */ + public AxisPair getAxisPair() { + + return axisPair; + } + + /** + * for internal usage + * + * @return + */ + public Plot getPlot() { + + return plot; + } + + public int getWidth() { + + return width; + } + + public int getHeight() { + + return height; + } + + public Map<String, Series> getSeriesMap() { + + return seriesMap; + } + + /** + * Gets the Chart's style manager, which can be used to customize the Chart's appearance + * + * @return the style manager + */ + public StyleManager getStyleManager() { + + return styleManager; + } +} diff --git a/xchart/src/main/java/org/knowm/xchart/internal/chartpart/ChartPainter.java b/xchart/src/main/java/org/knowm/xchart/internal/chartpart/ChartPainter.java deleted file mode 100644 index 097202ac0b83bb4653a120522a277a05ca1e3c83..0000000000000000000000000000000000000000 --- a/xchart/src/main/java/org/knowm/xchart/internal/chartpart/ChartPainter.java +++ /dev/null @@ -1,181 +0,0 @@ -/** - * Copyright 2015 Knowm Inc. (http://knowm.org) and contributors. - * Copyright 2011-2015 Xeiam LLC (http://xeiam.com) and contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.knowm.xchart.internal.chartpart; - -import java.awt.Graphics2D; -import java.awt.RenderingHints; -import java.awt.Shape; -import java.awt.geom.Rectangle2D; - -import org.knowm.xchart.Series; -import org.knowm.xchart.StyleManager; - -/** - * @author timmolter - */ -public class ChartPainter { - - private int width; - private int height; - - private final StyleManager styleManager; - - // Chart Parts - private Legend chartLegend; - private AxisPair axisPair; - private Plot plot; - private ChartTitle chartTitle; - - /** - * Constructor - * - * @param width - * @param height - */ - public ChartPainter(int width, int height) { - - this.width = width; - this.height = height; - - styleManager = new StyleManager(); - - chartLegend = new Legend(this); - axisPair = new AxisPair(this); - plot = new Plot(this); - chartTitle = new ChartTitle(this); - } - - /** - * @param g - * @param width - * @param height - */ - public void paint(Graphics2D g, int width, int height) { - - this.width = width; - this.height = height; - paint(g); - } - - /** - * @param g - */ - public void paint(Graphics2D g) { - - // calc axis min and max - axisPair.getXAxis().resetMinMax(); - axisPair.getYAxis().resetMinMax(); - - for (Series series : getAxisPair().getSeriesMap().values()) { - // add min/max to axis - // System.out.println(series.getxMin()); - // System.out.println(series.getxMax()); - // System.out.println(series.getyMin()); - // System.out.println(series.getyMax()); - // System.out.println("****"); - axisPair.getXAxis().addMinMax(series.getXMin(), series.getXMax()); - axisPair.getYAxis().addMinMax(series.getYMin(), series.getYMax()); - } - - // Sanity checks - if (axisPair.getSeriesMap().isEmpty()) { - throw new RuntimeException("No series defined for Chart!!!"); - } - if (getStyleManager().isXAxisLogarithmic() && axisPair.getXAxis().getMin() <= 0.0) { - throw new IllegalArgumentException("Series data (accounting for error bars too) cannot be less or equal to zero for a logarithmic X-Axis!!!"); - } - if (getStyleManager().isYAxisLogarithmic() && axisPair.getYAxis().getMin() <= 0.0) { - // System.out.println(axisPair.getyAxis().getMin()); - throw new IllegalArgumentException("Series data (accounting for error bars too) cannot be less or equal to zero for a logarithmic Y-Axis!!!"); - } - - g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); // global rendering hint - g.setColor(styleManager.getChartBackgroundColor()); - Shape rect = new Rectangle2D.Double(0, 0, width, height); - g.fill(rect); - - // now that we added all the series, we can calculate the legend size - chartLegend.determineLegendBoxSize(); - - axisPair.paint(g); - plot.paint(g); - chartTitle.paint(g); - chartLegend.paint(g); - - g.dispose(); - } - - /** - * for internal usage - * - * @return - */ - public ChartTitle getChartTitle() { - - return chartTitle; - } - - /** - * for internal usage - * - * @return - */ - public Legend getChartLegend() { - - return chartLegend; - } - - /** - * for internal usage - * - * @return - */ - public AxisPair getAxisPair() { - - return axisPair; - } - - /** - * for internal usage - * - * @return - */ - public Plot getPlot() { - - return plot; - } - - public int getWidth() { - - return width; - } - - public int getHeight() { - - return height; - } - - /** - * Gets the Chart's style manager, which can be used to customize the Chart's appearance - * - * @return the style manager - */ - public StyleManager getStyleManager() { - - return styleManager; - } -} diff --git a/xchart/src/main/java/org/knowm/xchart/internal/chartpart/ChartPart.java b/xchart/src/main/java/org/knowm/xchart/internal/chartpart/ChartPart.java index b6e48fc5ff3c6671f5166a5f2fe17299e795fc43..6cba8ff526accffbc761be8ecfc538fdcfc1d2a5 100644 --- a/xchart/src/main/java/org/knowm/xchart/internal/chartpart/ChartPart.java +++ b/xchart/src/main/java/org/knowm/xchart/internal/chartpart/ChartPart.java @@ -30,6 +30,6 @@ public interface ChartPart { public void paint(final Graphics2D g); - public ChartPainter getChartPainter(); + public ChartInternal getChartInternal(); } diff --git a/xchart/src/main/java/org/knowm/xchart/internal/chartpart/ChartTitle.java b/xchart/src/main/java/org/knowm/xchart/internal/chartpart/ChartTitle.java index 2c861eac690cb958963c3febae4214aa1fe2916d..4bfe55aa91a66a525586034c2fce091f94ffdaf4 100644 --- a/xchart/src/main/java/org/knowm/xchart/internal/chartpart/ChartTitle.java +++ b/xchart/src/main/java/org/knowm/xchart/internal/chartpart/ChartTitle.java @@ -30,7 +30,7 @@ import java.awt.geom.Rectangle2D; public class ChartTitle implements ChartPart { /** parent */ - private final ChartPainter chartPainter; + private final ChartInternal chartInternal; /** the title text */ private String text = ""; // default to "" @@ -41,11 +41,11 @@ public class ChartTitle implements ChartPart { /** * Constructor * - * @param chartPainter + * @param chartInternal */ - public ChartTitle(ChartPainter chartPainter) { + public ChartTitle(ChartInternal chartInternal) { - this.chartPainter = chartPainter; + this.chartInternal = chartInternal; } /** @@ -56,10 +56,10 @@ public class ChartTitle implements ChartPart { public void setText(String text) { if (text.trim().equalsIgnoreCase("")) { - chartPainter.getStyleManager().setChartTitleVisible(false); + chartInternal.getStyleManager().setChartTitleVisible(false); } else { - chartPainter.getStyleManager().setChartTitleVisible(true); + chartInternal.getStyleManager().setChartTitleVisible(true); } this.text = text; } @@ -71,57 +71,57 @@ public class ChartTitle implements ChartPart { */ protected int getSizeHint() { - if (chartPainter.getStyleManager().isChartTitleVisible()) { + if (chartInternal.getStyleManager().isChartTitleVisible()) { - TextLayout textLayout = new TextLayout(text, chartPainter.getStyleManager().getChartTitleFont(), new FontRenderContext(null, true, false)); + TextLayout textLayout = new TextLayout(text, chartInternal.getStyleManager().getChartTitleFont(), new FontRenderContext(null, true, false)); Rectangle2D rectangle = textLayout.getBounds(); - int titleHeight = (int) ((chartPainter.getStyleManager().isChartTitleVisible() ? rectangle.getHeight() : 0)); - return chartPainter.getStyleManager().getChartPadding() + 2 * chartPainter.getStyleManager().getChartTitlePadding() + titleHeight; + int titleHeight = (int) ((chartInternal.getStyleManager().isChartTitleVisible() ? rectangle.getHeight() : 0)); + return chartInternal.getStyleManager().getChartPadding() + 2 * chartInternal.getStyleManager().getChartTitlePadding() + titleHeight; } else { // TODO make this zero - return chartPainter.getStyleManager().getChartPadding(); + return chartInternal.getStyleManager().getChartPadding(); } } @Override public void paint(Graphics2D g) { - g.setFont(chartPainter.getStyleManager().getChartTitleFont()); + g.setFont(chartInternal.getStyleManager().getChartTitleFont()); - if (chartPainter.getStyleManager().isChartTitleVisible()) { + if (chartInternal.getStyleManager().isChartTitleVisible()) { // create rectangle first for sizing FontRenderContext frc = g.getFontRenderContext(); - TextLayout textLayout = new TextLayout(text, chartPainter.getStyleManager().getChartTitleFont(), frc); + TextLayout textLayout = new TextLayout(text, chartInternal.getStyleManager().getChartTitleFont(), frc); Rectangle2D rectangle = textLayout.getBounds(); - double xOffset = (int) chartPainter.getPlot().getBounds().getX(); - double yOffset = chartPainter.getStyleManager().getChartPadding(); + double xOffset = (int) chartInternal.getPlot().getBounds().getX(); + double yOffset = chartInternal.getStyleManager().getChartPadding(); - if (chartPainter.getStyleManager().isChartTitleBoxVisible()) { + if (chartInternal.getStyleManager().isChartTitleBoxVisible()) { // paint the chart title box - double chartTitleBoxWidth = chartPainter.getPlot().getBounds().getWidth(); - double chartTitleBoxHeight = rectangle.getHeight() + 2 * chartPainter.getStyleManager().getChartTitlePadding(); + double chartTitleBoxWidth = chartInternal.getPlot().getBounds().getWidth(); + double chartTitleBoxHeight = rectangle.getHeight() + 2 * chartInternal.getStyleManager().getChartTitlePadding(); g.setStroke(new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL)); Shape rect = new Rectangle2D.Double(xOffset, yOffset, chartTitleBoxWidth, chartTitleBoxHeight); - g.setColor(chartPainter.getStyleManager().getChartTitleBoxBackgroundColor()); + g.setColor(chartInternal.getStyleManager().getChartTitleBoxBackgroundColor()); g.fill(rect); - g.setColor(chartPainter.getStyleManager().getChartTitleBoxBorderColor()); + g.setColor(chartInternal.getStyleManager().getChartTitleBoxBorderColor()); g.draw(rect); } // paint title - xOffset = chartPainter.getPlot().getBounds().getX() + (chartPainter.getPlot().getBounds().getWidth() - rectangle.getWidth()) / 2.0; - yOffset = chartPainter.getStyleManager().getChartPadding() - rectangle.getY() + chartPainter.getStyleManager().getChartTitlePadding(); + xOffset = chartInternal.getPlot().getBounds().getX() + (chartInternal.getPlot().getBounds().getWidth() - rectangle.getWidth()) / 2.0; + yOffset = chartInternal.getStyleManager().getChartPadding() - rectangle.getY() + chartInternal.getStyleManager().getChartTitlePadding(); bounds = new Rectangle2D.Double(xOffset, yOffset + rectangle.getY(), rectangle.getWidth(), rectangle.getHeight()); // g.setColor(Color.green); // g.draw(bounds); - g.setColor(chartPainter.getStyleManager().getChartFontColor()); + g.setColor(chartInternal.getStyleManager().getChartFontColor()); // textLayout.draw(g, xOffset, yOffset); Shape shape = textLayout.getOutline(null); @@ -142,8 +142,8 @@ public class ChartTitle implements ChartPart { } @Override - public ChartPainter getChartPainter() { + public ChartInternal getChartInternal() { - return chartPainter; + return chartInternal; } } \ No newline at end of file diff --git a/xchart/src/main/java/org/knowm/xchart/internal/chartpart/Legend.java b/xchart/src/main/java/org/knowm/xchart/internal/chartpart/Legend.java index 7827a3db1e308dcf2c299c3e06c10c1c884a631f..05b236f14998a43c34050d724eea047bb8baf3ff 100644 --- a/xchart/src/main/java/org/knowm/xchart/internal/chartpart/Legend.java +++ b/xchart/src/main/java/org/knowm/xchart/internal/chartpart/Legend.java @@ -44,7 +44,7 @@ public class Legend implements ChartPart { /** * parent */ - private final ChartPainter chartPainter; + private final ChartInternal chartInternal; /** * the bounds @@ -54,11 +54,11 @@ public class Legend implements ChartPart { /** * Constructor * - * @param chartPainter + * @param chartInternal */ - public Legend(ChartPainter chartPainter) { + public Legend(ChartInternal chartInternal) { - this.chartPainter = chartPainter; + this.chartInternal = chartInternal; } /** @@ -66,7 +66,7 @@ public class Legend implements ChartPart { */ public void determineLegendBoxSize() { - if (!chartPainter.getStyleManager().isLegendVisible()) { + if (!chartInternal.getStyleManager().isLegendVisible()) { return; } @@ -78,7 +78,7 @@ public class Legend implements ChartPart { // determine legend content height double legendContentHeight = 0; - for (Series series : chartPainter.getAxisPair().getSeriesMap().values()) { + for (Series series : chartInternal.getSeriesMap().values()) { Map<String, Rectangle2D> seriesBounds = getSeriesTextBounds(series); @@ -89,9 +89,9 @@ public class Legend implements ChartPart { } blockHeight -= MULTI_LINE_SPACE; - blockHeight = Math.max(blockHeight, series.getSeriesType() == Series.SeriesType.Bar ? BOX_SIZE : getChartPainter().getStyleManager().getMarkerSize()); + blockHeight = Math.max(blockHeight, series.getSeriesType() == Series.SeriesType.Bar ? BOX_SIZE : getChartInternal().getStyleManager().getMarkerSize()); - legendContentHeight += blockHeight + getChartPainter().getStyleManager().getLegendPadding(); + legendContentHeight += blockHeight + getChartInternal().getStyleManager().getLegendPadding(); if (series.getSeriesType() == Series.SeriesType.Bar) { containsBar = true; @@ -101,59 +101,59 @@ public class Legend implements ChartPart { // determine legend content width double legendContentWidth = 0; if (!containsBar) { - legendContentWidth = getChartPainter().getStyleManager().getLegendSeriesLineLength() + getChartPainter().getStyleManager().getLegendPadding() + legendTextContentMaxWidth; + legendContentWidth = getChartInternal().getStyleManager().getLegendSeriesLineLength() + getChartInternal().getStyleManager().getLegendPadding() + legendTextContentMaxWidth; } else { - legendContentWidth = BOX_SIZE + getChartPainter().getStyleManager().getLegendPadding() + legendTextContentMaxWidth; + legendContentWidth = BOX_SIZE + getChartInternal().getStyleManager().getLegendPadding() + legendTextContentMaxWidth; } // Legend Box - legendBoxWidth = legendContentWidth + 2 * getChartPainter().getStyleManager().getLegendPadding(); - legendBoxHeight = legendContentHeight + 1 * getChartPainter().getStyleManager().getLegendPadding(); + legendBoxWidth = legendContentWidth + 2 * getChartInternal().getStyleManager().getLegendPadding(); + legendBoxHeight = legendContentHeight + 1 * getChartInternal().getStyleManager().getLegendPadding(); } @Override public void paint(Graphics2D g) { - if (!getChartPainter().getStyleManager().isLegendVisible()) { + if (!getChartInternal().getStyleManager().isLegendVisible()) { return; } // if the area to draw a chart on is so small, don't even bother - if (chartPainter.getPlot().getBounds().getWidth() < 30) { + if (chartInternal.getPlot().getBounds().getWidth() < 30) { return; } bounds = new Rectangle2D.Double(); - // g.setFont(chartPainter.getStyleManager().getLegendFont()); + // g.setFont(chartInternal.getStyleManager().getLegendFont()); // legend draw position double xOffset = 0; double yOffset = 0; - switch (getChartPainter().getStyleManager().getLegendPosition()) { + switch (getChartInternal().getStyleManager().getLegendPosition()) { case OutsideE: - xOffset = chartPainter.getWidth() - legendBoxWidth - getChartPainter().getStyleManager().getChartPadding(); - yOffset = chartPainter.getPlot().getBounds().getY() + (chartPainter.getPlot().getBounds().getHeight() - legendBoxHeight) / 2.0; + xOffset = chartInternal.getWidth() - legendBoxWidth - getChartInternal().getStyleManager().getChartPadding(); + yOffset = chartInternal.getPlot().getBounds().getY() + (chartInternal.getPlot().getBounds().getHeight() - legendBoxHeight) / 2.0; break; case InsideNW: - xOffset = chartPainter.getPlot().getBounds().getX() + LEGEND_MARGIN; - yOffset = chartPainter.getPlot().getBounds().getY() + LEGEND_MARGIN; + xOffset = chartInternal.getPlot().getBounds().getX() + LEGEND_MARGIN; + yOffset = chartInternal.getPlot().getBounds().getY() + LEGEND_MARGIN; break; case InsideNE: - xOffset = chartPainter.getPlot().getBounds().getX() + chartPainter.getPlot().getBounds().getWidth() - legendBoxWidth - LEGEND_MARGIN; - yOffset = chartPainter.getPlot().getBounds().getY() + LEGEND_MARGIN; + xOffset = chartInternal.getPlot().getBounds().getX() + chartInternal.getPlot().getBounds().getWidth() - legendBoxWidth - LEGEND_MARGIN; + yOffset = chartInternal.getPlot().getBounds().getY() + LEGEND_MARGIN; break; case InsideSE: - xOffset = chartPainter.getPlot().getBounds().getX() + chartPainter.getPlot().getBounds().getWidth() - legendBoxWidth - LEGEND_MARGIN; - yOffset = chartPainter.getPlot().getBounds().getY() + chartPainter.getPlot().getBounds().getHeight() - legendBoxHeight - LEGEND_MARGIN; + xOffset = chartInternal.getPlot().getBounds().getX() + chartInternal.getPlot().getBounds().getWidth() - legendBoxWidth - LEGEND_MARGIN; + yOffset = chartInternal.getPlot().getBounds().getY() + chartInternal.getPlot().getBounds().getHeight() - legendBoxHeight - LEGEND_MARGIN; break; case InsideSW: - xOffset = chartPainter.getPlot().getBounds().getX() + LEGEND_MARGIN; - yOffset = chartPainter.getPlot().getBounds().getY() + chartPainter.getPlot().getBounds().getHeight() - legendBoxHeight - LEGEND_MARGIN; + xOffset = chartInternal.getPlot().getBounds().getX() + LEGEND_MARGIN; + yOffset = chartInternal.getPlot().getBounds().getY() + chartInternal.getPlot().getBounds().getHeight() - legendBoxHeight - LEGEND_MARGIN; break; case InsideN: - xOffset = chartPainter.getPlot().getBounds().getX() + (chartPainter.getPlot().getBounds().getWidth() - legendBoxWidth) / 2 + LEGEND_MARGIN; - yOffset = chartPainter.getPlot().getBounds().getY() + LEGEND_MARGIN; + xOffset = chartInternal.getPlot().getBounds().getX() + (chartInternal.getPlot().getBounds().getWidth() - legendBoxWidth) / 2 + LEGEND_MARGIN; + yOffset = chartInternal.getPlot().getBounds().getY() + LEGEND_MARGIN; break; default: @@ -163,16 +163,16 @@ public class Legend implements ChartPart { g.setStroke(new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 10.0f, new float[] { 3.0f, 0.0f }, 0.0f)); Shape rect = new Rectangle2D.Double(xOffset + 1, yOffset + 1, legendBoxWidth - 2, legendBoxHeight - 2); - g.setColor(getChartPainter().getStyleManager().getLegendBackgroundColor()); + g.setColor(getChartInternal().getStyleManager().getLegendBackgroundColor()); g.fill(rect); - g.setColor(getChartPainter().getStyleManager().getLegendBorderColor()); + g.setColor(getChartInternal().getStyleManager().getLegendBorderColor()); g.draw(rect); // Draw legend content inside legend box - double startx = xOffset + getChartPainter().getStyleManager().getLegendPadding(); - double starty = yOffset + getChartPainter().getStyleManager().getLegendPadding(); + double startx = xOffset + getChartInternal().getStyleManager().getLegendPadding(); + double starty = yOffset + getChartInternal().getStyleManager().getLegendPadding(); - for (Series series : chartPainter.getAxisPair().getSeriesMap().values()) { + for (Series series : chartInternal.getSeriesMap().values()) { Map<String, Rectangle2D> seriesTextBounds = getSeriesTextBounds(series); @@ -184,7 +184,7 @@ public class Legend implements ChartPart { } blockHeight -= MULTI_LINE_SPACE; - blockHeight = Math.max(blockHeight, series.getSeriesType() == Series.SeriesType.Bar ? BOX_SIZE : getChartPainter().getStyleManager().getMarkerSize()); + blockHeight = Math.max(blockHeight, series.getSeriesType() == Series.SeriesType.Bar ? BOX_SIZE : getChartInternal().getStyleManager().getMarkerSize()); if (series.getSeriesType() != Series.SeriesType.Bar) { @@ -192,7 +192,7 @@ public class Legend implements ChartPart { if (series.getSeriesType() != Series.SeriesType.Scatter && series.getStroke() != null) { g.setColor(series.getStrokeColor()); g.setStroke(series.getStroke()); - Shape line = new Line2D.Double(startx, starty + blockHeight / 2.0, startx + getChartPainter().getStyleManager().getLegendSeriesLineLength(), starty + blockHeight / 2.0); + Shape line = new Line2D.Double(startx, starty + blockHeight / 2.0, startx + getChartInternal().getStyleManager().getLegendSeriesLineLength(), starty + blockHeight / 2.0); g.draw(line); } @@ -205,7 +205,7 @@ public class Legend implements ChartPart { // paint marker if (series.getMarker() != null) { g.setColor(series.getMarkerColor()); - series.getMarker().paint(g, startx + getChartPainter().getStyleManager().getLegendSeriesLineLength() / 2.0, starty + blockHeight / 2.0, getChartPainter().getStyleManager().getMarkerSize()); + series.getMarker().paint(g, startx + getChartInternal().getStyleManager().getLegendSeriesLineLength() / 2.0, starty + blockHeight / 2.0, getChartInternal().getStyleManager().getMarkerSize()); } } @@ -225,20 +225,20 @@ public class Legend implements ChartPart { } // paint series text ///////////////////////////////////////////////////// - g.setColor(chartPainter.getStyleManager().getChartFontColor()); + g.setColor(chartInternal.getStyleManager().getChartFontColor()); double multiLineOffset = 0.0; if (series.getSeriesType() != Series.SeriesType.Bar) { - double x = startx + getChartPainter().getStyleManager().getLegendSeriesLineLength() + getChartPainter().getStyleManager().getLegendPadding(); + double x = startx + getChartInternal().getStyleManager().getLegendSeriesLineLength() + getChartInternal().getStyleManager().getLegendPadding(); for (Map.Entry<String, Rectangle2D> entry : seriesTextBounds.entrySet()) { double height = entry.getValue().getHeight(); - double centerOffsetY = (Math.max(getChartPainter().getStyleManager().getMarkerSize(), height) - height) / 2.0; + double centerOffsetY = (Math.max(getChartInternal().getStyleManager().getMarkerSize(), height) - height) / 2.0; FontRenderContext frc = g.getFontRenderContext(); - TextLayout tl = new TextLayout(entry.getKey(), getChartPainter().getStyleManager().getLegendFont(), frc); + TextLayout tl = new TextLayout(entry.getKey(), getChartInternal().getStyleManager().getLegendFont(), frc); Shape shape = tl.getOutline(null); AffineTransform orig = g.getTransform(); AffineTransform at = new AffineTransform(); @@ -255,18 +255,18 @@ public class Legend implements ChartPart { multiLineOffset += height + MULTI_LINE_SPACE; } - starty += blockHeight + getChartPainter().getStyleManager().getLegendPadding(); + starty += blockHeight + getChartInternal().getStyleManager().getLegendPadding(); } else { // bar type series - final double x = startx + BOX_SIZE + getChartPainter().getStyleManager().getLegendPadding(); + final double x = startx + BOX_SIZE + getChartInternal().getStyleManager().getLegendPadding(); for (Map.Entry<String, Rectangle2D> entry : seriesTextBounds.entrySet()) { double height = entry.getValue().getHeight(); double centerOffsetY = (Math.max(BOX_SIZE, height) - height) / 2.0; FontRenderContext frc = g.getFontRenderContext(); - TextLayout tl = new TextLayout(entry.getKey(), getChartPainter().getStyleManager().getLegendFont(), frc); + TextLayout tl = new TextLayout(entry.getKey(), getChartInternal().getStyleManager().getLegendFont(), frc); Shape shape = tl.getOutline(null); AffineTransform orig = g.getTransform(); AffineTransform at = new AffineTransform(); @@ -282,7 +282,7 @@ public class Legend implements ChartPart { multiLineOffset += height + MULTI_LINE_SPACE; } - starty += blockHeight + getChartPainter().getStyleManager().getLegendPadding(); + starty += blockHeight + getChartInternal().getStyleManager().getLegendPadding(); } } @@ -303,7 +303,7 @@ public class Legend implements ChartPart { String lines[] = series.getName().split("\\n"); Map<String, Rectangle2D> seriesTextBounds = new LinkedHashMap<String, Rectangle2D>(lines.length); for (String line : lines) { - TextLayout tl = new TextLayout(line, getChartPainter().getStyleManager().getLegendFont(), new FontRenderContext(null, true, false)); + TextLayout tl = new TextLayout(line, getChartInternal().getStyleManager().getLegendFont(), new FontRenderContext(null, true, false)); Shape shape = tl.getOutline(null); Rectangle2D bounds = shape.getBounds2D(); // System.out.println(tl.getAscent()); @@ -333,9 +333,9 @@ public class Legend implements ChartPart { } @Override - public ChartPainter getChartPainter() { + public ChartInternal getChartInternal() { - return chartPainter; + return chartInternal; } } diff --git a/xchart/src/main/java/org/knowm/xchart/internal/chartpart/Plot.java b/xchart/src/main/java/org/knowm/xchart/internal/chartpart/Plot.java index 9da422c9ed9eed7d2792e9c5560979f63dd3bab4..2775a6a20b5a482b5828003c43f6653b02cc644e 100644 --- a/xchart/src/main/java/org/knowm/xchart/internal/chartpart/Plot.java +++ b/xchart/src/main/java/org/knowm/xchart/internal/chartpart/Plot.java @@ -27,7 +27,7 @@ import org.knowm.xchart.StyleManager.ChartType; public class Plot implements ChartPart { /** parent */ - private final ChartPainter chartPainter; + private final ChartInternal chartInternal; /** the bounds */ private Rectangle2D bounds; @@ -39,11 +39,11 @@ public class Plot implements ChartPart { /** * Constructor * - * @param chartPainter + * @param chartInternal */ - public Plot(ChartPainter chartPainter) { + public Plot(ChartInternal chartInternal) { - this.chartPainter = chartPainter; + this.chartInternal = chartInternal; this.plotSurface = new PlotSurface(this); } @@ -59,23 +59,23 @@ public class Plot implements ChartPart { bounds = new Rectangle2D.Double(); // calculate bounds - double xOffset = chartPainter.getAxisPair().getYAxis().getBounds().getX() + double xOffset = chartInternal.getAxisPair().getYAxis().getBounds().getX() - + chartPainter.getAxisPair().getYAxis().getBounds().getWidth() + + chartInternal.getAxisPair().getYAxis().getBounds().getWidth() - + (chartPainter.getStyleManager().isYAxisTicksVisible() ? (chartPainter.getStyleManager().getPlotPadding()) : 0) + + (chartInternal.getStyleManager().isYAxisTicksVisible() ? (chartInternal.getStyleManager().getPlotPadding()) : 0) ; - double yOffset = chartPainter.getAxisPair().getYAxis().getBounds().getY(); - double width = chartPainter.getAxisPair().getXAxis().getBounds().getWidth(); - double height = chartPainter.getAxisPair().getYAxis().getBounds().getHeight(); + double yOffset = chartInternal.getAxisPair().getYAxis().getBounds().getY(); + double width = chartInternal.getAxisPair().getXAxis().getBounds().getWidth(); + double height = chartInternal.getAxisPair().getYAxis().getBounds().getHeight(); bounds = new Rectangle2D.Double(xOffset, yOffset, width, height); // g.setColor(Color.green); // g.draw(bounds); plotSurface.paint(g); - if (getChartPainter().getStyleManager().getChartType() == ChartType.Bar) { + if (getChartInternal().getStyleManager().getChartType() == ChartType.Bar) { this.plotContent = new PlotContentCategoricalChart(this); } else { @@ -86,8 +86,8 @@ public class Plot implements ChartPart { } @Override - public ChartPainter getChartPainter() { + public ChartInternal getChartInternal() { - return chartPainter; + return chartInternal; } } diff --git a/xchart/src/main/java/org/knowm/xchart/internal/chartpart/PlotContent.java b/xchart/src/main/java/org/knowm/xchart/internal/chartpart/PlotContent.java index 0f07e6d28ead7f2b1555c95f9285b9a5c16e7b57..467d2c3f24541683595b18d5b577e1c9109a1eb2 100644 --- a/xchart/src/main/java/org/knowm/xchart/internal/chartpart/PlotContent.java +++ b/xchart/src/main/java/org/knowm/xchart/internal/chartpart/PlotContent.java @@ -47,9 +47,9 @@ public abstract class PlotContent implements ChartPart { } @Override - public ChartPainter getChartPainter() { + public ChartInternal getChartInternal() { - return plot.getChartPainter(); + return plot.getChartInternal(); } } diff --git a/xchart/src/main/java/org/knowm/xchart/internal/chartpart/PlotContentCategoricalChart.java b/xchart/src/main/java/org/knowm/xchart/internal/chartpart/PlotContentCategoricalChart.java index 0579267d647b37872be654ea9280474fd2d2ee47..3f1f88f2e13e8285bcf55bd44030ec2e4b998760 100644 --- a/xchart/src/main/java/org/knowm/xchart/internal/chartpart/PlotContentCategoricalChart.java +++ b/xchart/src/main/java/org/knowm/xchart/internal/chartpart/PlotContentCategoricalChart.java @@ -53,10 +53,10 @@ public class PlotContentCategoricalChart extends PlotContent { // g.setColor(Color.red); // g.draw(bounds); - StyleManager styleManager = plot.getChartPainter().getStyleManager(); + StyleManager styleManager = plot.getChartInternal().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()); + Rectangle rectangle = new Rectangle(0, 0, getChartInternal().getWidth(), getChartInternal().getHeight()); // g.setStroke(new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL)); // g.setColor(Color.green); // g.draw(rectangle); @@ -70,20 +70,20 @@ public class PlotContentCategoricalChart extends PlotContent { double yTickSpace = styleManager.getAxisTickSpacePercentage() * bounds.getHeight(); double yTopMargin = Utils.getTickStartOffset(bounds.getHeight(), yTickSpace); - int numBars = getChartPainter().getAxisPair().getSeriesMap().values().iterator().next().getXData().size(); + int numBars = getChartInternal().getSeriesMap().values().iterator().next().getXData().size(); double gridStep = xTickSpace / numBars; // plot series int seriesCounter = 0; - for (Series series : getChartPainter().getAxisPair().getSeriesMap().values()) { + for (Series series : getChartInternal().getSeriesMap().values()) { // for line series double previousX = -Double.MAX_VALUE; double previousY = -Double.MAX_VALUE; Collection<? extends Number> yData = series.getYData(); - double yMin = getChartPainter().getAxisPair().getYAxis().getMin(); - double yMax = getChartPainter().getAxisPair().getYAxis().getMax(); + double yMin = getChartInternal().getAxisPair().getYAxis().getMin(); + double yMax = getChartInternal().getAxisPair().getYAxis().getMax(); // if min and max positive, set min to zero if (yMin > 0.0 && yMax > 0.0) { @@ -95,20 +95,20 @@ public class PlotContentCategoricalChart extends PlotContent { } // override min and maxValue if specified - if (getChartPainter().getStyleManager().getYAxisMin() != null) { - yMin = getChartPainter().getStyleManager().getYAxisMin(); + if (getChartInternal().getStyleManager().getYAxisMin() != null) { + yMin = getChartInternal().getStyleManager().getYAxisMin(); } - else if (getChartPainter().getStyleManager().isYAxisLogarithmic()) { + else if (getChartInternal().getStyleManager().isYAxisLogarithmic()) { // int logMin = (int) Math.floor(Math.log10(getChartPainter().getAxisPair().getyAxis().getMin().doubleValue())); - double logMin = Math.floor(Math.log10(getChartPainter().getAxisPair().getYAxis().getMin())); + double logMin = Math.floor(Math.log10(getChartInternal().getAxisPair().getYAxis().getMin())); // System.out.println("logMin: " + logMin); // System.out.println("min : " + getChartPainter().getAxisPair().getyAxis().getMin().doubleValue()); yMin = logMin; } - if (getChartPainter().getStyleManager().getYAxisMax() != null) { - yMax = getChartPainter().getStyleManager().getYAxisMax(); + if (getChartInternal().getStyleManager().getYAxisMax() != null) { + yMax = getChartInternal().getStyleManager().getYAxisMax(); } - else if (getChartPainter().getStyleManager().isYAxisLogarithmic()) { + else if (getChartInternal().getStyleManager().isYAxisLogarithmic()) { yMax = Math.log10(yMax); } // figure out the general form of the chart @@ -138,7 +138,7 @@ public class PlotContentCategoricalChart extends PlotContent { double y = ((Number) yItr.next()).doubleValue(); // TODO test if this works, make an example chart - if (getChartPainter().getStyleManager().isYAxisLogarithmic()) { + if (getChartInternal().getStyleManager().isYAxisLogarithmic()) { y = Math.log10(y); } @@ -191,15 +191,15 @@ public class PlotContentCategoricalChart extends PlotContent { double xOffset; double barWidth; - if (getChartPainter().getStyleManager().isBarsOverlapped()) { - double barWidthPercentage = getChartPainter().getStyleManager().getBarWidthPercentage(); + if (getChartInternal().getStyleManager().isBarsOverlapped()) { + double barWidthPercentage = getChartInternal().getStyleManager().getBarWidthPercentage(); barWidth = gridStep * barWidthPercentage; double barMargin = gridStep * (1 - barWidthPercentage) / 2; xOffset = bounds.getX() + xLeftMargin + gridStep * barCounter++ + barMargin; } else { - double barWidthPercentage = getChartPainter().getStyleManager().getBarWidthPercentage(); - barWidth = gridStep / getChartPainter().getAxisPair().getSeriesMap().size() * barWidthPercentage; + double barWidthPercentage = getChartInternal().getStyleManager().getBarWidthPercentage(); + barWidth = gridStep / getChartInternal().getSeriesMap().size() * barWidthPercentage; double barMargin = gridStep * (1 - barWidthPercentage) / 2; xOffset = bounds.getX() + xLeftMargin + gridStep * barCounter++ + seriesCounter * barWidth + barMargin; } @@ -213,7 +213,7 @@ public class PlotContentCategoricalChart extends PlotContent { path.lineTo(xOffset, zeroOffset); path.closePath(); g.setStroke(series.getStroke()); - if (getChartPainter().getStyleManager().isBarFilled()) { + if (getChartInternal().getStyleManager().isBarFilled()) { g.fill(path); } else { @@ -238,7 +238,7 @@ public class PlotContentCategoricalChart extends PlotContent { // paint marker if (series.getMarker() != null) { g.setColor(series.getMarkerColor()); - series.getMarker().paint(g, previousX, previousY, getChartPainter().getStyleManager().getMarkerSize()); + series.getMarker().paint(g, previousX, previousY, getChartInternal().getStyleManager().getMarkerSize()); } } @@ -254,11 +254,11 @@ public class PlotContentCategoricalChart extends PlotContent { double eb = ebItr.next().doubleValue(); // set error bar style - if (getChartPainter().getStyleManager().isErrorBarsColorSeriesColor()) { + if (getChartInternal().getStyleManager().isErrorBarsColorSeriesColor()) { g.setColor(series.getStrokeColor()); } else { - g.setColor(getChartPainter().getStyleManager().getErrorBarsColor()); + g.setColor(getChartInternal().getStyleManager().getErrorBarsColor()); } g.setStroke(errorBarStroke); @@ -289,9 +289,9 @@ public class PlotContentCategoricalChart extends PlotContent { } @Override - public ChartPainter getChartPainter() { + public ChartInternal getChartInternal() { - return plot.getChartPainter(); + return plot.getChartInternal(); } } diff --git a/xchart/src/main/java/org/knowm/xchart/internal/chartpart/PlotContentNumericalChart.java b/xchart/src/main/java/org/knowm/xchart/internal/chartpart/PlotContentNumericalChart.java index e7573278a02385f1dfd44c423eb6d578f3f08e93..64013caca6b76eb464aa6a8cc3367fd99a244fae 100644 --- a/xchart/src/main/java/org/knowm/xchart/internal/chartpart/PlotContentNumericalChart.java +++ b/xchart/src/main/java/org/knowm/xchart/internal/chartpart/PlotContentNumericalChart.java @@ -59,7 +59,7 @@ public class PlotContentNumericalChart extends PlotContent { return; } - StyleManager styleManager = plot.getChartPainter().getStyleManager(); + StyleManager styleManager = plot.getChartInternal().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 @@ -68,7 +68,7 @@ public class PlotContentNumericalChart extends PlotContent { // g.setColor(Color.green); // g.draw(rectangle); - Rectangle rectangle = new Rectangle(0, 0, getChartPainter().getWidth(), getChartPainter().getHeight()); + Rectangle rectangle = new Rectangle(0, 0, getChartInternal().getWidth(), getChartInternal().getHeight()); // g.setStroke(new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL)); // g.setColor(Color.green); // g.draw(rectangle); @@ -84,38 +84,38 @@ public class PlotContentNumericalChart extends PlotContent { double yTickSpace = styleManager.getAxisTickSpacePercentage() * bounds.getHeight(); double yTopMargin = Utils.getTickStartOffset((int) bounds.getHeight(), yTickSpace); - for (Series series : getChartPainter().getAxisPair().getSeriesMap().values()) { + for (Series series : getChartInternal().getSeriesMap().values()) { // data points Collection<?> xData = series.getXData(); // System.out.println(xData); - double xMin = getChartPainter().getAxisPair().getXAxis().getMin(); - double xMax = getChartPainter().getAxisPair().getXAxis().getMax(); + double xMin = getChartInternal().getAxisPair().getXAxis().getMin(); + double xMax = getChartInternal().getAxisPair().getXAxis().getMax(); Collection<? extends Number> yData = series.getYData(); - double yMin = getChartPainter().getAxisPair().getYAxis().getMin(); - double yMax = getChartPainter().getAxisPair().getYAxis().getMax(); + double yMin = getChartInternal().getAxisPair().getYAxis().getMin(); + double yMax = getChartInternal().getAxisPair().getYAxis().getMax(); // override min and maxValue if specified - if (getChartPainter().getStyleManager().getXAxisMin() != null) { - xMin = getChartPainter().getStyleManager().getXAxisMin(); + if (getChartInternal().getStyleManager().getXAxisMin() != null) { + xMin = getChartInternal().getStyleManager().getXAxisMin(); } - if (getChartPainter().getStyleManager().getYAxisMin() != null) { - yMin = getChartPainter().getStyleManager().getYAxisMin(); + if (getChartInternal().getStyleManager().getYAxisMin() != null) { + yMin = getChartInternal().getStyleManager().getYAxisMin(); } - if (getChartPainter().getStyleManager().getXAxisMax() != null) { - xMax = getChartPainter().getStyleManager().getXAxisMax(); + if (getChartInternal().getStyleManager().getXAxisMax() != null) { + xMax = getChartInternal().getStyleManager().getXAxisMax(); } - if (getChartPainter().getStyleManager().getYAxisMax() != null) { - yMax = getChartPainter().getStyleManager().getYAxisMax(); + if (getChartInternal().getStyleManager().getYAxisMax() != null) { + yMax = getChartInternal().getStyleManager().getYAxisMax(); } // logarithmic - if (getChartPainter().getStyleManager().isXAxisLogarithmic()) { + if (getChartInternal().getStyleManager().isXAxisLogarithmic()) { xMin = Math.log10(xMin); xMax = Math.log10(xMax); } - if (getChartPainter().getStyleManager().isYAxisLogarithmic()) { + if (getChartInternal().getStyleManager().isYAxisLogarithmic()) { yMin = Math.log10(yMin); yMax = Math.log10(yMax); } @@ -135,16 +135,16 @@ public class PlotContentNumericalChart extends PlotContent { while (xItr.hasNext()) { double x = 0.0; - if (getChartPainter().getAxisPair().getXAxis().getAxisType() == AxisType.Number) { + if (getChartInternal().getAxisPair().getXAxis().getAxisType() == AxisType.Number) { x = ((Number) xItr.next()).doubleValue(); // System.out.println(x); } - else if (getChartPainter().getAxisPair().getXAxis().getAxisType() == AxisType.Date) { + else if (getChartInternal().getAxisPair().getXAxis().getAxisType() == AxisType.Date) { x = ((Date) xItr.next()).getTime(); // System.out.println(x); } - if (getChartPainter().getStyleManager().isXAxisLogarithmic()) { + if (getChartInternal().getStyleManager().isXAxisLogarithmic()) { x = Math.log10(x); } @@ -165,7 +165,7 @@ public class PlotContentNumericalChart extends PlotContent { double y = 0.0; // System.out.println(y); - if (getChartPainter().getStyleManager().isYAxisLogarithmic()) { + if (getChartInternal().getStyleManager().isYAxisLogarithmic()) { y = Math.log10(yOrig); } else { @@ -231,7 +231,7 @@ public class PlotContentNumericalChart extends PlotContent { // paint marker if (series.getMarker() != null) { g.setColor(series.getMarkerColor()); - series.getMarker().paint(g, xOffset, yOffset, getChartPainter().getStyleManager().getMarkerSize()); + series.getMarker().paint(g, xOffset, yOffset, getChartInternal().getStyleManager().getMarkerSize()); } // paint errorbars @@ -240,17 +240,17 @@ public class PlotContentNumericalChart extends PlotContent { double eb = ebItr.next().doubleValue(); // set error bar style - if (getChartPainter().getStyleManager().isErrorBarsColorSeriesColor()) { + if (getChartInternal().getStyleManager().isErrorBarsColorSeriesColor()) { g.setColor(series.getStrokeColor()); } else { - g.setColor(getChartPainter().getStyleManager().getErrorBarsColor()); + g.setColor(getChartInternal().getStyleManager().getErrorBarsColor()); } g.setStroke(errorBarStroke); // Top value double topValue = 0.0; - if (getChartPainter().getStyleManager().isYAxisLogarithmic()) { + if (getChartInternal().getStyleManager().isYAxisLogarithmic()) { topValue = yOrig + eb; topValue = Math.log10(topValue); } @@ -262,7 +262,7 @@ public class PlotContentNumericalChart extends PlotContent { // Bottom value double bottomValue = 0.0; - if (getChartPainter().getStyleManager().isYAxisLogarithmic()) { + if (getChartInternal().getStyleManager().isYAxisLogarithmic()) { bottomValue = yOrig - eb; // System.out.println(bottomValue); bottomValue = Math.log10(bottomValue); diff --git a/xchart/src/main/java/org/knowm/xchart/internal/chartpart/PlotSurface.java b/xchart/src/main/java/org/knowm/xchart/internal/chartpart/PlotSurface.java index 784d68009dbe613ab7dcd48bb69bb20cbb63fdab..bc6854a5bf59d1497d05d966d5fe37934d9f0c03 100644 --- a/xchart/src/main/java/org/knowm/xchart/internal/chartpart/PlotSurface.java +++ b/xchart/src/main/java/org/knowm/xchart/internal/chartpart/PlotSurface.java @@ -55,12 +55,12 @@ public class PlotSurface implements ChartPart { // paint plot background Shape rect = new Rectangle2D.Double(bounds.getX(), bounds.getY(), bounds.getWidth(), bounds.getHeight()); - g.setColor(getChartPainter().getStyleManager().getPlotBackgroundColor()); + g.setColor(getChartInternal().getStyleManager().getPlotBackgroundColor()); g.fill(rect); // paint plot border - if (getChartPainter().getStyleManager().isPlotBorderVisible()) { - g.setColor(getChartPainter().getStyleManager().getPlotBorderColor()); + if (getChartInternal().getStyleManager().isPlotBorderVisible()) { + g.setColor(getChartInternal().getStyleManager().getPlotBorderColor()); // g.setStroke(getChartPainter().getStyleManager().getAxisTickMarksStroke()); g.draw(rect); } @@ -68,8 +68,8 @@ public class PlotSurface implements ChartPart { // paint grid lines and/or inner plot ticks // horizontal - if (getChartPainter().getStyleManager().isPlotGridHorizontalLinesVisible() || getChartPainter().getStyleManager().isPlotTicksMarksVisible()) { - List<Double> yAxisTickLocations = getChartPainter().getAxisPair().getYAxis().getAxisTickCalculator().getTickLocations(); + if (getChartInternal().getStyleManager().isPlotGridHorizontalLinesVisible() || getChartInternal().getStyleManager().isPlotTicksMarksVisible()) { + List<Double> yAxisTickLocations = getChartInternal().getAxisPair().getYAxis().getAxisTickCalculator().getTickLocations(); for (int i = 0; i < yAxisTickLocations.size(); i++) { double yOffset = bounds.getY() + bounds.getHeight() - yAxisTickLocations.get(i); @@ -77,22 +77,22 @@ public class PlotSurface implements ChartPart { if (yOffset > bounds.getY() && yOffset < bounds.getY() + bounds.getHeight()) { // draw lines - if (getChartPainter().getStyleManager().isPlotGridHorizontalLinesVisible()) { + if (getChartInternal().getStyleManager().isPlotGridHorizontalLinesVisible()) { - g.setColor(getChartPainter().getStyleManager().getPlotGridLinesColor()); - g.setStroke(getChartPainter().getStyleManager().getPlotGridLinesStroke()); + g.setColor(getChartInternal().getStyleManager().getPlotGridLinesColor()); + g.setStroke(getChartInternal().getStyleManager().getPlotGridLinesStroke()); Shape line = new Line2D.Double(bounds.getX(), yOffset, bounds.getX() + bounds.getWidth(), yOffset); g.draw(line); } // tick marks - if (getChartPainter().getStyleManager().isPlotTicksMarksVisible()) { + if (getChartInternal().getStyleManager().isPlotTicksMarksVisible()) { - g.setColor(getChartPainter().getStyleManager().getAxisTickMarksColor()); - g.setStroke(getChartPainter().getStyleManager().getAxisTickMarksStroke()); - Shape line = new Line2D.Double(bounds.getX(), yOffset, bounds.getX() + getChartPainter().getStyleManager().getAxisTickMarkLength(), yOffset); + g.setColor(getChartInternal().getStyleManager().getAxisTickMarksColor()); + g.setStroke(getChartInternal().getStyleManager().getAxisTickMarksStroke()); + Shape line = new Line2D.Double(bounds.getX(), yOffset, bounds.getX() + getChartInternal().getStyleManager().getAxisTickMarkLength(), yOffset); g.draw(line); - line = new Line2D.Double(bounds.getX() + bounds.getWidth(), yOffset, bounds.getX() + bounds.getWidth() - getChartPainter().getStyleManager().getAxisTickMarkLength(), yOffset); + line = new Line2D.Double(bounds.getX() + bounds.getWidth(), yOffset, bounds.getX() + bounds.getWidth() - getChartInternal().getStyleManager().getAxisTickMarkLength(), yOffset); g.draw(line); } } @@ -100,9 +100,9 @@ public class PlotSurface implements ChartPart { } // vertical - if (getChartPainter().getStyleManager().isPlotGridVerticalLinesVisible() || getChartPainter().getStyleManager().isPlotTicksMarksVisible()) { + if (getChartInternal().getStyleManager().isPlotGridVerticalLinesVisible() || getChartInternal().getStyleManager().isPlotTicksMarksVisible()) { - List<Double> xAxisTickLocations = getChartPainter().getAxisPair().getXAxis().getAxisTickCalculator().getTickLocations(); + List<Double> xAxisTickLocations = getChartInternal().getAxisPair().getXAxis().getAxisTickCalculator().getTickLocations(); for (int i = 0; i < xAxisTickLocations.size(); i++) { double tickLocation = xAxisTickLocations.get(i); @@ -111,22 +111,22 @@ public class PlotSurface implements ChartPart { if (xOffset > bounds.getX() && xOffset < bounds.getX() + bounds.getWidth()) { // draw lines - if (getChartPainter().getStyleManager().isPlotGridVerticalLinesVisible()) { - g.setColor(getChartPainter().getStyleManager().getPlotGridLinesColor()); - g.setStroke(getChartPainter().getStyleManager().getPlotGridLinesStroke()); + if (getChartInternal().getStyleManager().isPlotGridVerticalLinesVisible()) { + g.setColor(getChartInternal().getStyleManager().getPlotGridLinesColor()); + g.setStroke(getChartInternal().getStyleManager().getPlotGridLinesStroke()); Shape line = new Line2D.Double(xOffset, bounds.getY(), xOffset, bounds.getY() + bounds.getHeight()); g.draw(line); } // tick marks - if (getChartPainter().getStyleManager().isPlotTicksMarksVisible()) { + if (getChartInternal().getStyleManager().isPlotTicksMarksVisible()) { - g.setColor(getChartPainter().getStyleManager().getAxisTickMarksColor()); - g.setStroke(getChartPainter().getStyleManager().getAxisTickMarksStroke()); + g.setColor(getChartInternal().getStyleManager().getAxisTickMarksColor()); + g.setStroke(getChartInternal().getStyleManager().getAxisTickMarksStroke()); - Shape line = new Line2D.Double(xOffset, bounds.getY(), xOffset, bounds.getY() + getChartPainter().getStyleManager().getAxisTickMarkLength()); + Shape line = new Line2D.Double(xOffset, bounds.getY(), xOffset, bounds.getY() + getChartInternal().getStyleManager().getAxisTickMarkLength()); g.draw(line); - line = new Line2D.Double(xOffset, bounds.getY() + bounds.getHeight(), xOffset, bounds.getY() + bounds.getHeight() - getChartPainter().getStyleManager().getAxisTickMarkLength()); + line = new Line2D.Double(xOffset, bounds.getY() + bounds.getHeight(), xOffset, bounds.getY() + bounds.getHeight() - getChartInternal().getStyleManager().getAxisTickMarkLength()); g.draw(line); } } @@ -135,9 +135,9 @@ public class PlotSurface implements ChartPart { } @Override - public ChartPainter getChartPainter() { + public ChartInternal getChartInternal() { - return plot.getChartPainter(); + return plot.getChartInternal(); } }