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 8793cf790b4bb32856f1eb386ce7ddc4f30a8a85..9059f6116039669f2b464f7418a3cfd886a8c6b4 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 @@ -107,6 +107,7 @@ public class Axis implements ChartPart { // System.out.println(min); // System.out.println(max); + // NaN indicates String axis data, so min and max play no role if (this.min == Double.NaN || min < this.min) { this.min = min; } @@ -343,27 +344,43 @@ public class Axis implements ChartPart { private AxisTickCalculator getAxisTickCalculator(double workingSpace) { - if (getDirection() == Direction.X && getChartInternal().getChartInternalType() == ChartInternalType.Category) { + // X-Axis + if (getDirection() == Direction.X) { - return new AxisTickCategoryChartCalculator(getDirection(), workingSpace, getMin(), getMax(), getChartInternal()); - } - else if (getChartInternal().getChartInternalType() == ChartInternalType.XY && getAxisType() == AxisType.Date) { + if (getChartInternal().getChartInternalType() == ChartInternalType.Category) { - return new AxisTickDateCalculator(getDirection(), workingSpace, getMin(), getMax(), getChartInternal().getStyleManager()); - } - else if (getDirection() == Direction.X && getChartInternal().getChartInternalType() == ChartInternalType.XY && getChartInternal().getStyleManager().isXAxisLogarithmic() - && getAxisType() != AxisType.Date) { + // No need to pass in min and max + // pass in axis type instead of ChartInternal + return new AxisTickCategoryChartCalculator(getDirection(), workingSpace, getChartInternal()); + } + else if (getChartInternal().getChartInternalType() == ChartInternalType.XY && getAxisType() == AxisType.Date) { - return new AxisTickLogarithmicCalculator(getDirection(), workingSpace, getMin(), getMax(), getChartInternal().getStyleManager()); - } - else if (getDirection() == Direction.Y && getChartInternal().getStyleManager().isYAxisLogarithmic() && getAxisType() != AxisType.Date) { + // TODO don't pass in style manager + return new AxisTickDateCalculator(getDirection(), workingSpace, getChartInternal().getxAxisMin(), getChartInternal().getxAxisMax(), getChartInternal().getStyleManager()); + } + else if (getChartInternal().getStyleManager().isXAxisLogarithmic()) { + + return new AxisTickLogarithmicCalculator(getDirection(), workingSpace, getChartInternal().getxAxisMin(), getChartInternal().getxAxisMax(), getChartInternal().getStyleManager()); + } + else { + return new AxisTickNumberCalculator(getDirection(), workingSpace, getChartInternal().getxAxisMin(), getChartInternal().getxAxisMax(), getChartInternal().getStyleManager()); - return new AxisTickLogarithmicCalculator(getDirection(), workingSpace, getMin(), getMax(), getChartInternal().getStyleManager()); + } } - else { // number - return new AxisTickNumberCalculator(getDirection(), workingSpace, getMin(), getMax(), getChartInternal().getStyleManager()); + // Y-Axis + else { + + if (getChartInternal().getStyleManager().isYAxisLogarithmic() && getAxisType() != AxisType.Date) { + + return new AxisTickLogarithmicCalculator(getDirection(), workingSpace, getChartInternal().getyAxisMin(), getChartInternal().getyAxisMax(), getChartInternal().getStyleManager()); + } + else { + return new AxisTickNumberCalculator(getDirection(), workingSpace, getChartInternal().getyAxisMin(), getChartInternal().getyAxisMax(), getChartInternal().getStyleManager()); + + } } + } @Override @@ -379,12 +396,12 @@ public class Axis implements ChartPart { return axisType; } - public double getMin() { + protected double getMin() { return min; } - public double getMax() { + protected double getMax() { return max; } diff --git a/xchart/src/main/java/org/knowm/xchart/internal/chartpart/AxisTickCalculator.java b/xchart/src/main/java/org/knowm/xchart/internal/chartpart/AxisTickCalculator.java index 9416ede52cc35fff71bd1e3053a929edc3cb13e9..5a41416987210bec93779bd6d1cff4ece74e8db0 100644 --- a/xchart/src/main/java/org/knowm/xchart/internal/chartpart/AxisTickCalculator.java +++ b/xchart/src/main/java/org/knowm/xchart/internal/chartpart/AxisTickCalculator.java @@ -25,8 +25,6 @@ import java.util.LinkedList; import java.util.List; import org.knowm.xchart.StyleManager; -import org.knowm.xchart.StyleManager.ChartType; -import org.knowm.xchart.internal.Utils; import org.knowm.xchart.internal.chartpart.Axis.Direction; /** @@ -44,9 +42,9 @@ public abstract class AxisTickCalculator { protected final double workingSpace; - protected double minValue; + protected final double minValue; - protected double maxValue; + protected final double maxValue; protected final StyleManager styleManager; @@ -61,40 +59,10 @@ public abstract class AxisTickCalculator { */ public AxisTickCalculator(Direction axisDirection, double workingSpace, double minValue, double maxValue, StyleManager styleManager) { - // override min/max value for bar charts' Y-Axis - double overrideMinValue = minValue; - double overrideMaxValue = maxValue; - if (styleManager.getChartType() == ChartType.Bar && axisDirection == Direction.Y) { // this is the Y-Axis for a bar chart - if (minValue > 0.0 && maxValue > 0.0) { - overrideMinValue = 0.0; - } - if (minValue < 0.0 && maxValue < 0.0) { - overrideMaxValue = 0.0; - } - } - - if (styleManager.getChartType() == ChartType.Bar && styleManager.isYAxisLogarithmic()) { - int logMin = (int) Math.floor(Math.log10(minValue)); - overrideMinValue = Utils.pow(10, logMin); - } - - // override min and maxValue if specified - if (axisDirection == Direction.X && styleManager.getXAxisMin() != null && styleManager.getChartType() != ChartType.Bar) { // bar chart cannot have a max or min - overrideMinValue = styleManager.getXAxisMin(); - } - if (axisDirection == Direction.Y && styleManager.getYAxisMin() != null) { - overrideMinValue = styleManager.getYAxisMin(); - } - if (axisDirection == Direction.X && styleManager.getXAxisMax() != null && styleManager.getChartType() != ChartType.Bar) { // bar chart cannot have a max or min - overrideMaxValue = styleManager.getXAxisMax(); - } - if (axisDirection == Direction.Y && styleManager.getYAxisMax() != null) { - overrideMaxValue = styleManager.getYAxisMax(); - } this.axisDirection = axisDirection; this.workingSpace = workingSpace; - this.minValue = overrideMinValue; - this.maxValue = overrideMaxValue; + this.minValue = minValue; + this.maxValue = maxValue; this.styleManager = styleManager; } 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 e9d869bac65aedc77d2010d7a7585c40585cebac..6620c7290045cc4a7fd13a1f7a887b035d99e96c 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,9 +42,9 @@ public class AxisTickCategoryChartCalculator extends AxisTickCalculator { * @param maxValue * @param styleManager */ - public AxisTickCategoryChartCalculator(Direction axisDirection, double workingSpace, double minValue, double maxValue, ChartInternal chart) { + public AxisTickCategoryChartCalculator(Direction axisDirection, double workingSpace, ChartInternal chart) { - super(axisDirection, workingSpace, minValue, maxValue, chart.getStyleManager()); + super(axisDirection, workingSpace, Double.NaN, Double.NaN, chart.getStyleManager()); calculate(chart); } diff --git a/xchart/src/main/java/org/knowm/xchart/internal/chartpart/AxisTickLogarithmicCalculator.java b/xchart/src/main/java/org/knowm/xchart/internal/chartpart/AxisTickLogarithmicCalculator.java index ce9bac51199c0a011423d0fb1dcecd366e733f8e..6ed465df226419aed0776c755a69946732aeeb93 100644 --- a/xchart/src/main/java/org/knowm/xchart/internal/chartpart/AxisTickLogarithmicCalculator.java +++ b/xchart/src/main/java/org/knowm/xchart/internal/chartpart/AxisTickLogarithmicCalculator.java @@ -74,18 +74,18 @@ public class AxisTickLogarithmicCalculator extends AxisTickCalculator { // System.out.println("logMin: " + logMin); // System.out.println("logMax: " + logMax); - if (axisDirection == Direction.Y && styleManager.getYAxisMin() != null) { - logMin = (int) (Math.log10(styleManager.getYAxisMin())); // no floor - } - if (axisDirection == Direction.Y && styleManager.getYAxisMax() != null) { - logMax = (int) (Math.log10(styleManager.getYAxisMax())); // no floor - } - if (axisDirection == Direction.X && styleManager.getXAxisMin() != null) { - logMin = (int) (Math.log10(styleManager.getXAxisMin())); // no floor - } - if (axisDirection == Direction.X && styleManager.getXAxisMax() != null) { - logMax = (int) (Math.log10(styleManager.getXAxisMax())); // no floor - } + // if (axisDirection == Direction.Y && styleManager.getYAxisMin() != null) { + // logMin = (int) (Math.log10(styleManager.getYAxisMin())); // no floor + // } + // if (axisDirection == Direction.Y && styleManager.getYAxisMax() != null) { + // logMax = (int) (Math.log10(styleManager.getYAxisMax())); // no floor + // } + // if (axisDirection == Direction.X && styleManager.getXAxisMin() != null) { + // logMin = (int) (Math.log10(styleManager.getXAxisMin())); // no floor + // } + // if (axisDirection == Direction.X && styleManager.getXAxisMax() != null) { + // logMax = (int) (Math.log10(styleManager.getXAxisMax())); // no floor + // } double firstPosition = Utils.pow(10, logMin); // System.out.println("firstPosition: " + firstPosition); 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 index b2c53e2959e014326b7a563db32048c8575ebf5b..6701d7ea8afb561f13dacea8a5b9f811bf0ce9a6 100644 --- a/xchart/src/main/java/org/knowm/xchart/internal/chartpart/ChartInternal.java +++ b/xchart/src/main/java/org/knowm/xchart/internal/chartpart/ChartInternal.java @@ -29,6 +29,7 @@ import java.util.Map; import org.knowm.xchart.Series; import org.knowm.xchart.StyleManager; +import org.knowm.xchart.StyleManager.ChartType; import org.knowm.xchart.internal.chartpart.Axis.AxisType; import org.knowm.xchart.internal.style.SeriesColorMarkerLineStyleCycler; @@ -52,6 +53,11 @@ public class ChartInternal { private final StyleManager styleManager; + private double xAxisMin; + private double xAxisMax; + private double yAxisMin; + private double yAxisMax; + // Chart Parts private Legend chartLegend; private AxisPair axisPair; @@ -294,18 +300,69 @@ public class ChartInternal { 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) { + xAxisMin = axisPair.getXAxis().getMin(); + xAxisMax = axisPair.getXAxis().getMax(); + yAxisMin = axisPair.getYAxis().getMin(); + yAxisMax = axisPair.getYAxis().getMax(); + + // override min/max value for bar charts' Y-Axis + double overrideXAxisMinValue = xAxisMin; + double overrideXAxisMaxValue = xAxisMax; + double overrideYAxisMinValue = yAxisMin; + double overrideYAxisMaxValue = yAxisMax; + if (styleManager.getChartType() == ChartType.Bar) { // this is the Y-Axis for a bar chart + if (yAxisMin > 0.0 && yAxisMax > 0.0) { + overrideYAxisMinValue = 0.0; + } + if (yAxisMin < 0.0 && yAxisMax < 0.0) { + overrideYAxisMaxValue = 0.0; + } + } + + // override min and maxValue if specified + if (styleManager.getXAxisMin() != null && styleManager.getChartType() != ChartType.Bar) { // bar chart cannot have a max or min TODO is this true? Do we want this? + overrideXAxisMinValue = styleManager.getXAxisMin(); + } + if (styleManager.getXAxisMax() != null && styleManager.getChartType() != ChartType.Bar) { // bar chart cannot have a max or min + overrideXAxisMaxValue = styleManager.getXAxisMax(); + } + if (styleManager.getYAxisMin() != null) { + overrideYAxisMinValue = styleManager.getYAxisMin(); + } + if (styleManager.getYAxisMax() != null) { + overrideYAxisMaxValue = styleManager.getYAxisMax(); + } + + this.xAxisMin = overrideXAxisMinValue; + this.xAxisMax = overrideXAxisMaxValue; + this.yAxisMin = overrideYAxisMinValue; + this.yAxisMax = overrideYAxisMaxValue; + + // logarithmic + + if (getStyleManager().isXAxisLogarithmic() && xAxisMin <= 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) { + if (getStyleManager().isYAxisLogarithmic() && yAxisMin <= 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!!!"); } + // if (styleManager.getChartType() == ChartType.Bar && styleManager.isYAxisLogarithmic()) { + // int logMin = (int) Math.floor(Math.log10(yAxisMin)); + // overrideYAxisMinValue = Utils.pow(10, logMin); + // } + // if (styleManager.isXAxisLogarithmic()) { + // xAxisMin = Math.log10(overrideXAxisMinValue); + // xAxisMax = Math.log10(overrideXAxisMaxValue); + // } + // if (styleManager.isYAxisLogarithmic()) { + // yAxisMin = Math.log10(overrideYAxisMinValue); + // yAxisMax = Math.log10(overrideYAxisMaxValue); + // } g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); // global rendering hint g.setColor(styleManager.getChartBackgroundColor()); @@ -392,4 +449,25 @@ public class ChartInternal { return styleManager; } + + public double getxAxisMin() { + + return xAxisMin; + } + + public double getxAxisMax() { + + return xAxisMax; + } + + public double getyAxisMin() { + + return yAxisMin; + } + + public double getyAxisMax() { + + return yAxisMax; + } + } 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 467d2c3f24541683595b18d5b577e1c9109a1eb2..de74676a44b0934355828dc1f256e8e8030b92c3 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 @@ -20,6 +20,8 @@ import java.awt.BasicStroke; import java.awt.Stroke; import java.awt.geom.Rectangle2D; +import org.knowm.xchart.StyleManager; + /** * @author timmolter */ @@ -28,16 +30,20 @@ public abstract class PlotContent implements ChartPart { /** parent */ protected Plot plot; + StyleManager styleManager; + protected final Stroke errorBarStroke = new BasicStroke(1.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL); /** * Constructor - * + * * @param plot */ protected PlotContent(Plot plot) { this.plot = plot; + + styleManager = getChartInternal().getStyleManager(); } @Override 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 5a87a81767f1008d2ecb774493bca869ce89964f..4cf7077598bb3a9b441965f0a07f660efa5810d3 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 @@ -27,7 +27,6 @@ import java.util.Iterator; import org.knowm.xchart.Series; import org.knowm.xchart.Series.SeriesType; -import org.knowm.xchart.StyleManager; import org.knowm.xchart.internal.Utils; /** @@ -48,13 +47,16 @@ public class PlotContentCategoricalChart extends PlotContent { @Override public void paint(Graphics2D g) { + // logarithmic + if (getChartInternal().getStyleManager().isYAxisLogarithmic()) { + throw new IllegalArgumentException("Category Charts cannot have logarithmic axes!!! (Not Yet Implemented)"); + } + Rectangle2D bounds = plot.getBounds(); // g.setStroke(new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL)); // g.setColor(Color.red); // g.draw(bounds); - StyleManager styleManager = 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, getChartInternal().getWidth(), getChartInternal().getHeight()); // g.setStroke(new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL)); @@ -73,6 +75,25 @@ public class PlotContentCategoricalChart extends PlotContent { int numCategories = getChartInternal().getSeriesMap().values().iterator().next().getXData().size(); double gridStep = xTickSpace / numCategories; + double yMin = getChartInternal().getyAxisMin(); + double yMax = getChartInternal().getyAxisMax(); + + // TODO only for bar charts necessary + // figure out the general form of the chart + int chartForm = 1; // 1=positive, -1=negative, 0=span + if (yMin > 0.0 && yMax > 0.0) { + chartForm = 1; // positive chart + } + else if (yMin < 0.0 && yMax < 0.0) { + chartForm = -1; // negative chart + } + else { + chartForm = 0;// span chart + } + // System.out.println(yMin); + // System.out.println(yMax); + // System.out.println("chartForm: " + chartForm); + // plot series int seriesCounter = 0; for (Series series : getChartInternal().getSeriesMap().values()) { @@ -81,93 +102,37 @@ public class PlotContentCategoricalChart extends PlotContent { double previousX = -Double.MAX_VALUE; double previousY = -Double.MAX_VALUE; - Collection<? extends Number> yData = series.getYData(); - double yMin = getChartInternal().getAxisPair().getYAxis().getMin(); - double yMax = getChartInternal().getAxisPair().getYAxis().getMax(); - - // if (styleManager.getChartType() == ChartType.Bar) { - // if min and max positive, set min to zero - if (yMin > 0.0 && yMax > 0.0) { - yMin = 0.0; - } - // if min and max negative, set max to zero - if (yMin < 0.0 && yMax < 0.0) { - yMax = 0.0; - } - // } - - // override min and maxValue if specified - if (getChartInternal().getStyleManager().getYAxisMin() != null) { - yMin = getChartInternal().getStyleManager().getYAxisMin(); - } - else if (getChartInternal().getStyleManager().isYAxisLogarithmic()) { - // int logMin = (int) Math.floor(Math.log10(getChartPainter().getAxisPair().getyAxis().getMin().doubleValue())); - 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 (getChartInternal().getStyleManager().getYAxisMax() != null) { - yMax = getChartInternal().getStyleManager().getYAxisMax(); - } - else if (getChartInternal().getStyleManager().isYAxisLogarithmic()) { - yMax = Math.log10(yMax); - } - - // figure out the general form of the chart - int chartForm = 1; // 1=positive, -1=negative, 0=span - if (yMin > 0.0 && yMax > 0.0) { - chartForm = 1; // positive chart - } - else if (yMin < 0.0 && yMax < 0.0) { - chartForm = -1; // negative chart - } - else { - chartForm = 0;// span chart - } - // System.out.println(yMin); - // System.out.println(yMax); - - // all the x-axis data are guaranteed to be the same so we just use the first one - Iterator<? extends Number> yItr = yData.iterator(); + Iterator<? extends Number> yItr = series.getYData().iterator(); Iterator<? extends Number> ebItr = null; Collection<? extends Number> errorBars = series.getErrorBars(); if (errorBars != null) { ebItr = errorBars.iterator(); } - int barCounter = 0; + int categoryCounter = 0; while (yItr.hasNext()) { - double y = ((Number) yItr.next()).doubleValue(); - // TODO test if this works, make an example chart - if (getChartInternal().getStyleManager().isYAxisLogarithmic()) { - y = Math.log10(y); - } + double y = yItr.next().doubleValue(); + // TODO only for bar charts necessary double yTop = 0.0; double yBottom = 0.0; - switch (chartForm) { case 1: // positive chart - // check for points off the chart draw area due to a custom yMin if (y < yMin) { - barCounter++; + categoryCounter++; continue; } - yTop = y; yBottom = yMin; break; case -1: // negative chart - // check for points off the chart draw area due to a custom yMin if (y > yMax) { - barCounter++; + categoryCounter++; continue; } - yTop = yMax; yBottom = y; break; @@ -186,6 +151,7 @@ public class PlotContentCategoricalChart extends PlotContent { } double yTransform = bounds.getHeight() - (yTopMargin + (yTop - yMin) / (yMax - yMin) * yTickSpace); + // double yTransform = bounds.getHeight() - (yTopMargin + (y - yMin) / (yMax - yMin) * yTickSpace); double yOffset = bounds.getY() + yTransform; @@ -198,13 +164,13 @@ public class PlotContentCategoricalChart extends PlotContent { double barWidthPercentage = getChartInternal().getStyleManager().getBarWidthPercentage(); barWidth = gridStep * barWidthPercentage; double barMargin = gridStep * (1 - barWidthPercentage) / 2; - xOffset = bounds.getX() + xLeftMargin + gridStep * barCounter++ + barMargin; + xOffset = bounds.getX() + xLeftMargin + gridStep * categoryCounter++ + barMargin; } else { 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; + xOffset = bounds.getX() + xLeftMargin + gridStep * categoryCounter++ + seriesCounter * barWidth + barMargin; } if (series.getSeriesType() == SeriesType.Bar) { // paint bar 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 468df77274d9fb57868eadb02c220ee9e6741b54..215dd209cefe27025a755c4a25416cf8351d2965 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 @@ -27,7 +27,6 @@ import java.util.Date; import java.util.Iterator; import org.knowm.xchart.Series; -import org.knowm.xchart.StyleManager; import org.knowm.xchart.internal.Utils; import org.knowm.xchart.internal.chartpart.Axis.AxisType; @@ -59,8 +58,6 @@ public class PlotContentNumericalChart extends PlotContent { return; } - StyleManager styleManager = 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 = g.getClipBounds(); @@ -84,41 +81,26 @@ public class PlotContentNumericalChart extends PlotContent { double yTickSpace = styleManager.getAxisTickSpacePercentage() * bounds.getHeight(); double yTopMargin = Utils.getTickStartOffset((int) bounds.getHeight(), yTickSpace); + double xMin = getChartInternal().getxAxisMin(); + double xMax = getChartInternal().getxAxisMax(); + double yMin = getChartInternal().getyAxisMin(); + double yMax = getChartInternal().getyAxisMax(); + + // logarithmic + if (getChartInternal().getStyleManager().isXAxisLogarithmic()) { + xMin = Math.log10(xMin); + xMax = Math.log10(xMax); + } + if (getChartInternal().getStyleManager().isYAxisLogarithmic()) { + yMin = Math.log10(yMin); + yMax = Math.log10(yMax); + } + for (Series series : getChartInternal().getSeriesMap().values()) { // data points Collection<?> xData = series.getXData(); - // System.out.println(xData); - double xMin = getChartInternal().getAxisPair().getXAxis().getMin(); - double xMax = getChartInternal().getAxisPair().getXAxis().getMax(); - Collection<? extends Number> yData = series.getYData(); - double yMin = getChartInternal().getAxisPair().getYAxis().getMin(); - double yMax = getChartInternal().getAxisPair().getYAxis().getMax(); - - // override min and maxValue if specified - if (getChartInternal().getStyleManager().getXAxisMin() != null) { - xMin = getChartInternal().getStyleManager().getXAxisMin(); - } - if (getChartInternal().getStyleManager().getYAxisMin() != null) { - yMin = getChartInternal().getStyleManager().getYAxisMin(); - } - if (getChartInternal().getStyleManager().getXAxisMax() != null) { - xMax = getChartInternal().getStyleManager().getXAxisMax(); - } - if (getChartInternal().getStyleManager().getYAxisMax() != null) { - yMax = getChartInternal().getStyleManager().getYAxisMax(); - } - - // logarithmic - if (getChartInternal().getStyleManager().isXAxisLogarithmic()) { - xMin = Math.log10(xMin); - xMax = Math.log10(xMax); - } - if (getChartInternal().getStyleManager().isYAxisLogarithmic()) { - yMin = Math.log10(yMin); - yMax = Math.log10(yMax); - } double previousX = -Double.MAX_VALUE; double previousY = -Double.MAX_VALUE; @@ -137,16 +119,15 @@ public class PlotContentNumericalChart extends PlotContent { double x = 0.0; if (getChartInternal().getAxisPair().getXAxis().getAxisType() == AxisType.Number) { x = ((Number) xItr.next()).doubleValue(); - // System.out.println(x); } else if (getChartInternal().getAxisPair().getXAxis().getAxisType() == AxisType.Date) { x = ((Date) xItr.next()).getTime(); - // System.out.println(x); } - + // System.out.println(x); if (getChartInternal().getStyleManager().isXAxisLogarithmic()) { x = Math.log10(x); } + // System.out.println(x); Number next = yItr.next(); if (next == null) { @@ -188,8 +169,11 @@ public class PlotContentNumericalChart extends PlotContent { double xOffset = bounds.getX() + xTransform; double yOffset = bounds.getY() + yTransform; - // System.out.println(yOffset); + // System.out.println(xTransform); + // System.out.println(xOffset); // System.out.println(yTransform); + // System.out.println(yOffset); + // System.out.println("---"); // paint line if (Series.SeriesType.Line.equals(series.getSeriesType()) || Series.SeriesType.Area.equals(series.getSeriesType())) { @@ -234,7 +218,7 @@ public class PlotContentNumericalChart extends PlotContent { series.getMarker().paint(g, xOffset, yOffset, getChartInternal().getStyleManager().getMarkerSize()); } - // paint errorbars + // paint error bars if (errorBars != null) { double eb = ebItr.next().doubleValue();