Skip to content
Snippets Groups Projects
Commit de86d5c8 authored by Tim Molter's avatar Tim Molter
Browse files

moved min and max to ChartInternal for better shared usage

parent d54e6f94
No related branches found
No related tags found
No related merge requests found
Showing with 194 additions and 175 deletions
...@@ -107,6 +107,7 @@ public class Axis implements ChartPart { ...@@ -107,6 +107,7 @@ public class Axis implements ChartPart {
// System.out.println(min); // System.out.println(min);
// System.out.println(max); // System.out.println(max);
// NaN indicates String axis data, so min and max play no role
if (this.min == Double.NaN || min < this.min) { if (this.min == Double.NaN || min < this.min) {
this.min = min; this.min = min;
} }
...@@ -343,29 +344,45 @@ public class Axis implements ChartPart { ...@@ -343,29 +344,45 @@ public class Axis implements ChartPart {
private AxisTickCalculator getAxisTickCalculator(double workingSpace) { 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()); if (getChartInternal().getChartInternalType() == ChartInternalType.Category) {
// 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) { else if (getChartInternal().getChartInternalType() == ChartInternalType.XY && getAxisType() == AxisType.Date) {
return new AxisTickDateCalculator(getDirection(), workingSpace, getMin(), getMax(), getChartInternal().getStyleManager()); // 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 if (getDirection() == Direction.X && getChartInternal().getChartInternalType() == ChartInternalType.XY && getChartInternal().getStyleManager().isXAxisLogarithmic() else {
&& getAxisType() != AxisType.Date) { return new AxisTickNumberCalculator(getDirection(), workingSpace, getChartInternal().getxAxisMin(), getChartInternal().getxAxisMax(), getChartInternal().getStyleManager());
return new AxisTickLogarithmicCalculator(getDirection(), workingSpace, getMin(), getMax(), getChartInternal().getStyleManager());
} }
else if (getDirection() == Direction.Y && getChartInternal().getStyleManager().isYAxisLogarithmic() && getAxisType() != AxisType.Date) { }
return new AxisTickLogarithmicCalculator(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 { // number else {
return new AxisTickNumberCalculator(getDirection(), workingSpace, getChartInternal().getyAxisMin(), getChartInternal().getyAxisMax(), getChartInternal().getStyleManager());
return new AxisTickNumberCalculator(getDirection(), workingSpace, getMin(), getMax(), getChartInternal().getStyleManager());
} }
} }
}
@Override @Override
public ChartInternal getChartInternal() { public ChartInternal getChartInternal() {
...@@ -379,12 +396,12 @@ public class Axis implements ChartPart { ...@@ -379,12 +396,12 @@ public class Axis implements ChartPart {
return axisType; return axisType;
} }
public double getMin() { protected double getMin() {
return min; return min;
} }
public double getMax() { protected double getMax() {
return max; return max;
} }
......
...@@ -25,8 +25,6 @@ import java.util.LinkedList; ...@@ -25,8 +25,6 @@ import java.util.LinkedList;
import java.util.List; import java.util.List;
import org.knowm.xchart.StyleManager; 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; import org.knowm.xchart.internal.chartpart.Axis.Direction;
/** /**
...@@ -44,9 +42,9 @@ public abstract class AxisTickCalculator { ...@@ -44,9 +42,9 @@ public abstract class AxisTickCalculator {
protected final double workingSpace; protected final double workingSpace;
protected double minValue; protected final double minValue;
protected double maxValue; protected final double maxValue;
protected final StyleManager styleManager; protected final StyleManager styleManager;
...@@ -61,40 +59,10 @@ public abstract class AxisTickCalculator { ...@@ -61,40 +59,10 @@ public abstract class AxisTickCalculator {
*/ */
public AxisTickCalculator(Direction axisDirection, double workingSpace, double minValue, double maxValue, StyleManager styleManager) { 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.axisDirection = axisDirection;
this.workingSpace = workingSpace; this.workingSpace = workingSpace;
this.minValue = overrideMinValue; this.minValue = minValue;
this.maxValue = overrideMaxValue; this.maxValue = maxValue;
this.styleManager = styleManager; this.styleManager = styleManager;
} }
......
...@@ -42,9 +42,9 @@ public class AxisTickCategoryChartCalculator extends AxisTickCalculator { ...@@ -42,9 +42,9 @@ public class AxisTickCategoryChartCalculator extends AxisTickCalculator {
* @param maxValue * @param maxValue
* @param styleManager * @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); calculate(chart);
} }
......
...@@ -74,18 +74,18 @@ public class AxisTickLogarithmicCalculator extends AxisTickCalculator { ...@@ -74,18 +74,18 @@ public class AxisTickLogarithmicCalculator extends AxisTickCalculator {
// System.out.println("logMin: " + logMin); // System.out.println("logMin: " + logMin);
// System.out.println("logMax: " + logMax); // System.out.println("logMax: " + logMax);
if (axisDirection == Direction.Y && styleManager.getYAxisMin() != null) { // if (axisDirection == Direction.Y && styleManager.getYAxisMin() != null) {
logMin = (int) (Math.log10(styleManager.getYAxisMin())); // no floor // logMin = (int) (Math.log10(styleManager.getYAxisMin())); // no floor
} // }
if (axisDirection == Direction.Y && styleManager.getYAxisMax() != null) { // if (axisDirection == Direction.Y && styleManager.getYAxisMax() != null) {
logMax = (int) (Math.log10(styleManager.getYAxisMax())); // no floor // logMax = (int) (Math.log10(styleManager.getYAxisMax())); // no floor
} // }
if (axisDirection == Direction.X && styleManager.getXAxisMin() != null) { // if (axisDirection == Direction.X && styleManager.getXAxisMin() != null) {
logMin = (int) (Math.log10(styleManager.getXAxisMin())); // no floor // logMin = (int) (Math.log10(styleManager.getXAxisMin())); // no floor
} // }
if (axisDirection == Direction.X && styleManager.getXAxisMax() != null) { // if (axisDirection == Direction.X && styleManager.getXAxisMax() != null) {
logMax = (int) (Math.log10(styleManager.getXAxisMax())); // no floor // logMax = (int) (Math.log10(styleManager.getXAxisMax())); // no floor
} // }
double firstPosition = Utils.pow(10, logMin); double firstPosition = Utils.pow(10, logMin);
// System.out.println("firstPosition: " + firstPosition); // System.out.println("firstPosition: " + firstPosition);
......
...@@ -29,6 +29,7 @@ import java.util.Map; ...@@ -29,6 +29,7 @@ import java.util.Map;
import org.knowm.xchart.Series; import org.knowm.xchart.Series;
import org.knowm.xchart.StyleManager; import org.knowm.xchart.StyleManager;
import org.knowm.xchart.StyleManager.ChartType;
import org.knowm.xchart.internal.chartpart.Axis.AxisType; import org.knowm.xchart.internal.chartpart.Axis.AxisType;
import org.knowm.xchart.internal.style.SeriesColorMarkerLineStyleCycler; import org.knowm.xchart.internal.style.SeriesColorMarkerLineStyleCycler;
...@@ -52,6 +53,11 @@ public class ChartInternal { ...@@ -52,6 +53,11 @@ public class ChartInternal {
private final StyleManager styleManager; private final StyleManager styleManager;
private double xAxisMin;
private double xAxisMax;
private double yAxisMin;
private double yAxisMax;
// Chart Parts // Chart Parts
private Legend chartLegend; private Legend chartLegend;
private AxisPair axisPair; private AxisPair axisPair;
...@@ -294,18 +300,69 @@ public class ChartInternal { ...@@ -294,18 +300,69 @@ public class ChartInternal {
axisPair.getXAxis().addMinMax(series.getXMin(), series.getXMax()); axisPair.getXAxis().addMinMax(series.getXMin(), series.getXMax());
axisPair.getYAxis().addMinMax(series.getYMin(), series.getYMax()); axisPair.getYAxis().addMinMax(series.getYMin(), series.getYMax());
} }
// Sanity checks // Sanity checks
if (getSeriesMap().isEmpty()) { if (getSeriesMap().isEmpty()) {
throw new RuntimeException("No series defined for Chart!!!"); 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!!!"); 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()); // 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!!!"); 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.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); // global rendering hint
g.setColor(styleManager.getChartBackgroundColor()); g.setColor(styleManager.getChartBackgroundColor());
...@@ -392,4 +449,25 @@ public class ChartInternal { ...@@ -392,4 +449,25 @@ public class ChartInternal {
return styleManager; return styleManager;
} }
public double getxAxisMin() {
return xAxisMin;
}
public double getxAxisMax() {
return xAxisMax;
}
public double getyAxisMin() {
return yAxisMin;
}
public double getyAxisMax() {
return yAxisMax;
}
} }
...@@ -20,6 +20,8 @@ import java.awt.BasicStroke; ...@@ -20,6 +20,8 @@ import java.awt.BasicStroke;
import java.awt.Stroke; import java.awt.Stroke;
import java.awt.geom.Rectangle2D; import java.awt.geom.Rectangle2D;
import org.knowm.xchart.StyleManager;
/** /**
* @author timmolter * @author timmolter
*/ */
...@@ -28,6 +30,8 @@ public abstract class PlotContent implements ChartPart { ...@@ -28,6 +30,8 @@ public abstract class PlotContent implements ChartPart {
/** parent */ /** parent */
protected Plot plot; protected Plot plot;
StyleManager styleManager;
protected final Stroke errorBarStroke = new BasicStroke(1.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL); protected final Stroke errorBarStroke = new BasicStroke(1.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL);
/** /**
...@@ -38,6 +42,8 @@ public abstract class PlotContent implements ChartPart { ...@@ -38,6 +42,8 @@ public abstract class PlotContent implements ChartPart {
protected PlotContent(Plot plot) { protected PlotContent(Plot plot) {
this.plot = plot; this.plot = plot;
styleManager = getChartInternal().getStyleManager();
} }
@Override @Override
......
...@@ -27,7 +27,6 @@ import java.util.Iterator; ...@@ -27,7 +27,6 @@ import java.util.Iterator;
import org.knowm.xchart.Series; import org.knowm.xchart.Series;
import org.knowm.xchart.Series.SeriesType; import org.knowm.xchart.Series.SeriesType;
import org.knowm.xchart.StyleManager;
import org.knowm.xchart.internal.Utils; import org.knowm.xchart.internal.Utils;
/** /**
...@@ -48,13 +47,16 @@ public class PlotContentCategoricalChart extends PlotContent { ...@@ -48,13 +47,16 @@ public class PlotContentCategoricalChart extends PlotContent {
@Override @Override
public void paint(Graphics2D g) { 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(); Rectangle2D bounds = plot.getBounds();
// g.setStroke(new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL)); // g.setStroke(new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL));
// g.setColor(Color.red); // g.setColor(Color.red);
// g.draw(bounds); // 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 // 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()); Rectangle rectangle = new Rectangle(0, 0, getChartInternal().getWidth(), getChartInternal().getHeight());
// g.setStroke(new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL)); // g.setStroke(new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL));
...@@ -73,47 +75,10 @@ public class PlotContentCategoricalChart extends PlotContent { ...@@ -73,47 +75,10 @@ public class PlotContentCategoricalChart extends PlotContent {
int numCategories = getChartInternal().getSeriesMap().values().iterator().next().getXData().size(); int numCategories = getChartInternal().getSeriesMap().values().iterator().next().getXData().size();
double gridStep = xTickSpace / numCategories; double gridStep = xTickSpace / numCategories;
// plot series double yMin = getChartInternal().getyAxisMin();
int seriesCounter = 0; double yMax = getChartInternal().getyAxisMax();
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 = 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);
}
// TODO only for bar charts necessary
// figure out the general form of the chart // figure out the general form of the chart
int chartForm = 1; // 1=positive, -1=negative, 0=span int chartForm = 1; // 1=positive, -1=negative, 0=span
if (yMin > 0.0 && yMax > 0.0) { if (yMin > 0.0 && yMax > 0.0) {
...@@ -127,47 +92,47 @@ public class PlotContentCategoricalChart extends PlotContent { ...@@ -127,47 +92,47 @@ public class PlotContentCategoricalChart extends PlotContent {
} }
// System.out.println(yMin); // System.out.println(yMin);
// System.out.println(yMax); // System.out.println(yMax);
// System.out.println("chartForm: " + chartForm);
// plot series
int seriesCounter = 0;
for (Series series : getChartInternal().getSeriesMap().values()) {
// for line series
double previousX = -Double.MAX_VALUE;
double previousY = -Double.MAX_VALUE;
// all the x-axis data are guaranteed to be the same so we just use the first one Iterator<? extends Number> yItr = series.getYData().iterator();
Iterator<? extends Number> yItr = yData.iterator();
Iterator<? extends Number> ebItr = null; Iterator<? extends Number> ebItr = null;
Collection<? extends Number> errorBars = series.getErrorBars(); Collection<? extends Number> errorBars = series.getErrorBars();
if (errorBars != null) { if (errorBars != null) {
ebItr = errorBars.iterator(); ebItr = errorBars.iterator();
} }
int barCounter = 0; int categoryCounter = 0;
while (yItr.hasNext()) { while (yItr.hasNext()) {
double y = ((Number) yItr.next()).doubleValue(); double y = yItr.next().doubleValue();
// TODO test if this works, make an example chart
if (getChartInternal().getStyleManager().isYAxisLogarithmic()) {
y = Math.log10(y);
}
// TODO only for bar charts necessary
double yTop = 0.0; double yTop = 0.0;
double yBottom = 0.0; double yBottom = 0.0;
switch (chartForm) { switch (chartForm) {
case 1: // positive chart case 1: // positive chart
// check for points off the chart draw area due to a custom yMin // check for points off the chart draw area due to a custom yMin
if (y < yMin) { if (y < yMin) {
barCounter++; categoryCounter++;
continue; continue;
} }
yTop = y; yTop = y;
yBottom = yMin; yBottom = yMin;
break; break;
case -1: // negative chart case -1: // negative chart
// check for points off the chart draw area due to a custom yMin // check for points off the chart draw area due to a custom yMin
if (y > yMax) { if (y > yMax) {
barCounter++; categoryCounter++;
continue; continue;
} }
yTop = yMax; yTop = yMax;
yBottom = y; yBottom = y;
break; break;
...@@ -186,6 +151,7 @@ public class PlotContentCategoricalChart extends PlotContent { ...@@ -186,6 +151,7 @@ public class PlotContentCategoricalChart extends PlotContent {
} }
double yTransform = bounds.getHeight() - (yTopMargin + (yTop - yMin) / (yMax - yMin) * yTickSpace); 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; double yOffset = bounds.getY() + yTransform;
...@@ -198,13 +164,13 @@ public class PlotContentCategoricalChart extends PlotContent { ...@@ -198,13 +164,13 @@ public class PlotContentCategoricalChart extends PlotContent {
double barWidthPercentage = getChartInternal().getStyleManager().getBarWidthPercentage(); double barWidthPercentage = getChartInternal().getStyleManager().getBarWidthPercentage();
barWidth = gridStep * barWidthPercentage; barWidth = gridStep * barWidthPercentage;
double barMargin = gridStep * (1 - barWidthPercentage) / 2; double barMargin = gridStep * (1 - barWidthPercentage) / 2;
xOffset = bounds.getX() + xLeftMargin + gridStep * barCounter++ + barMargin; xOffset = bounds.getX() + xLeftMargin + gridStep * categoryCounter++ + barMargin;
} }
else { else {
double barWidthPercentage = getChartInternal().getStyleManager().getBarWidthPercentage(); double barWidthPercentage = getChartInternal().getStyleManager().getBarWidthPercentage();
barWidth = gridStep / getChartInternal().getSeriesMap().size() * barWidthPercentage; barWidth = gridStep / getChartInternal().getSeriesMap().size() * barWidthPercentage;
double barMargin = gridStep * (1 - barWidthPercentage) / 2; 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) { if (series.getSeriesType() == SeriesType.Bar) {
// paint bar // paint bar
......
...@@ -27,7 +27,6 @@ import java.util.Date; ...@@ -27,7 +27,6 @@ import java.util.Date;
import java.util.Iterator; import java.util.Iterator;
import org.knowm.xchart.Series; import org.knowm.xchart.Series;
import org.knowm.xchart.StyleManager;
import org.knowm.xchart.internal.Utils; import org.knowm.xchart.internal.Utils;
import org.knowm.xchart.internal.chartpart.Axis.AxisType; import org.knowm.xchart.internal.chartpart.Axis.AxisType;
...@@ -59,8 +58,6 @@ public class PlotContentNumericalChart extends PlotContent { ...@@ -59,8 +58,6 @@ public class PlotContentNumericalChart extends PlotContent {
return; 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 // 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(); // Rectangle rectangle = g.getClipBounds();
...@@ -84,31 +81,10 @@ public class PlotContentNumericalChart extends PlotContent { ...@@ -84,31 +81,10 @@ public class PlotContentNumericalChart extends PlotContent {
double yTickSpace = styleManager.getAxisTickSpacePercentage() * bounds.getHeight(); double yTickSpace = styleManager.getAxisTickSpacePercentage() * bounds.getHeight();
double yTopMargin = Utils.getTickStartOffset((int) bounds.getHeight(), yTickSpace); double yTopMargin = Utils.getTickStartOffset((int) bounds.getHeight(), yTickSpace);
for (Series series : getChartInternal().getSeriesMap().values()) { double xMin = getChartInternal().getxAxisMin();
double xMax = getChartInternal().getxAxisMax();
// data points double yMin = getChartInternal().getyAxisMin();
Collection<?> xData = series.getXData(); double yMax = getChartInternal().getyAxisMax();
// 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 // logarithmic
if (getChartInternal().getStyleManager().isXAxisLogarithmic()) { if (getChartInternal().getStyleManager().isXAxisLogarithmic()) {
...@@ -120,6 +96,12 @@ public class PlotContentNumericalChart extends PlotContent { ...@@ -120,6 +96,12 @@ public class PlotContentNumericalChart extends PlotContent {
yMax = Math.log10(yMax); yMax = Math.log10(yMax);
} }
for (Series series : getChartInternal().getSeriesMap().values()) {
// data points
Collection<?> xData = series.getXData();
Collection<? extends Number> yData = series.getYData();
double previousX = -Double.MAX_VALUE; double previousX = -Double.MAX_VALUE;
double previousY = -Double.MAX_VALUE; double previousY = -Double.MAX_VALUE;
...@@ -137,16 +119,15 @@ public class PlotContentNumericalChart extends PlotContent { ...@@ -137,16 +119,15 @@ public class PlotContentNumericalChart extends PlotContent {
double x = 0.0; double x = 0.0;
if (getChartInternal().getAxisPair().getXAxis().getAxisType() == AxisType.Number) { if (getChartInternal().getAxisPair().getXAxis().getAxisType() == AxisType.Number) {
x = ((Number) xItr.next()).doubleValue(); x = ((Number) xItr.next()).doubleValue();
// System.out.println(x);
} }
else if (getChartInternal().getAxisPair().getXAxis().getAxisType() == AxisType.Date) { else if (getChartInternal().getAxisPair().getXAxis().getAxisType() == AxisType.Date) {
x = ((Date) xItr.next()).getTime(); x = ((Date) xItr.next()).getTime();
// System.out.println(x);
} }
// System.out.println(x);
if (getChartInternal().getStyleManager().isXAxisLogarithmic()) { if (getChartInternal().getStyleManager().isXAxisLogarithmic()) {
x = Math.log10(x); x = Math.log10(x);
} }
// System.out.println(x);
Number next = yItr.next(); Number next = yItr.next();
if (next == null) { if (next == null) {
...@@ -188,8 +169,11 @@ public class PlotContentNumericalChart extends PlotContent { ...@@ -188,8 +169,11 @@ public class PlotContentNumericalChart extends PlotContent {
double xOffset = bounds.getX() + xTransform; double xOffset = bounds.getX() + xTransform;
double yOffset = bounds.getY() + yTransform; double yOffset = bounds.getY() + yTransform;
// System.out.println(yOffset); // System.out.println(xTransform);
// System.out.println(xOffset);
// System.out.println(yTransform); // System.out.println(yTransform);
// System.out.println(yOffset);
// System.out.println("---");
// paint line // paint line
if (Series.SeriesType.Line.equals(series.getSeriesType()) || Series.SeriesType.Area.equals(series.getSeriesType())) { if (Series.SeriesType.Line.equals(series.getSeriesType()) || Series.SeriesType.Area.equals(series.getSeriesType())) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment