diff --git a/xchart-demo/src/main/java/com/xeiam/xchart/demo/XChartDemo.java b/xchart-demo/src/main/java/com/xeiam/xchart/demo/XChartDemo.java index 728f46b6d8a01aec7faac4e66caa136feab15c08..1b47528a87c740044551f017417cf399c7104961 100644 --- a/xchart-demo/src/main/java/com/xeiam/xchart/demo/XChartDemo.java +++ b/xchart-demo/src/main/java/com/xeiam/xchart/demo/XChartDemo.java @@ -30,6 +30,10 @@ import javax.swing.tree.TreeSelectionModel; import com.xeiam.xchart.XChartPanel; import com.xeiam.xchart.demo.charts.area.AreaChart01; +import com.xeiam.xchart.demo.charts.bar.BarChart01; +import com.xeiam.xchart.demo.charts.bar.BarChart02; +import com.xeiam.xchart.demo.charts.bar.BarChart03; +import com.xeiam.xchart.demo.charts.bar.BarChart04; import com.xeiam.xchart.demo.charts.date.DateChart01; import com.xeiam.xchart.demo.charts.date.DateChart02; import com.xeiam.xchart.demo.charts.date.DateChart03; @@ -164,6 +168,22 @@ public class XChartDemo extends JPanel implements TreeSelectionListener { chart = new DefaultMutableTreeNode(new ChartInfo("ScatterChart04 - Error Bars", new ScatterChart04().getChart())); category.add(chart); + // Bar category + category = new DefaultMutableTreeNode("Bar Charts"); + top.add(category); + + chart = new DefaultMutableTreeNode(new ChartInfo("BarChart01 - Basic Bar Chart", new BarChart01().getChart())); + category.add(chart); + + chart = new DefaultMutableTreeNode(new ChartInfo("BarChart02 - Basic Bar Chart", new BarChart02().getChart())); + category.add(chart); + + chart = new DefaultMutableTreeNode(new ChartInfo("BarChart03 - Basic Bar Chart", new BarChart03().getChart())); + category.add(chart); + + chart = new DefaultMutableTreeNode(new ChartInfo("BarChart04 - Basic Bar Chart", new BarChart04().getChart())); + category.add(chart); + // Area category category = new DefaultMutableTreeNode("Area Charts"); top.add(category); diff --git a/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/bar/BarChart01.java b/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/bar/BarChart01.java index 24b32ea72ceeb27296fdabf91235352c37ce1cce..5712fc89d3f7184728746e5f24cbf9b7959b84e1 100644 --- a/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/bar/BarChart01.java +++ b/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/bar/BarChart01.java @@ -29,7 +29,14 @@ import com.xeiam.xchart.style.StyleManager.ChartType; import com.xeiam.xchart.style.StyleManager.LegendPosition; /** - * @author timmolter + * Basic Bar Chart + * <p> + * Demonstrates the following: + * <ul> + * <li>Number categories + * <li>All positive values + * <li>Single series + * <li>Place legend at Inside-NW position */ public class BarChart01 implements ExampleChart { @@ -45,7 +52,7 @@ public class BarChart01 implements ExampleChart { // Create Chart Chart chart = new ChartBuilder().chartType(ChartType.Bar).width(800).height(600).title("BarChart01").xAxisTitle("X").yAxisTitle("Y").build(); - chart.addSeries("a", new double[] { 0, 1, 2, 3, 4 }, new double[] { -3, 5, 9, 6, 5 }); + chart.addSeries("a", new double[] { 0, 1, 2, 3, 4 }, new double[] { 4, 5, 9, 6, 5 }); // Customize Chart chart.getStyleManager().setChartTitleVisible(false); diff --git a/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/bar/BarChart02.java b/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/bar/BarChart02.java new file mode 100644 index 0000000000000000000000000000000000000000..19f4dbd23d3e527cc5def7264e517c89b8f9396c --- /dev/null +++ b/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/bar/BarChart02.java @@ -0,0 +1,60 @@ +/** + * Copyright (C) 2013 Xeiam LLC http://xeiam.com + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies + * of the Software, and to permit persons to whom the Software is furnished to do + * so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package com.xeiam.xchart.demo.charts.bar; + +import com.xeiam.xchart.Chart; +import com.xeiam.xchart.ChartBuilder; +import com.xeiam.xchart.SwingWrapper; +import com.xeiam.xchart.demo.charts.ExampleChart; +import com.xeiam.xchart.style.StyleManager.ChartType; + +/** + * Basic Bar Chart + * <p> + * Demonstrates the following: + * <ul> + * <li>Number categories + * <li>All negative values + * <li>Single series + */ +public class BarChart02 implements ExampleChart { + + public static void main(String[] args) { + + ExampleChart exampleChart = new BarChart02(); + Chart chart = exampleChart.getChart(); + new SwingWrapper(chart).displayChart(); + } + + @Override + public Chart getChart() { + + // Create Chart + Chart chart = new ChartBuilder().chartType(ChartType.Bar).width(800).height(600).title("BarChart01").xAxisTitle("X").yAxisTitle("Y").build(); + chart.addSeries("a", new double[] { 10, 20, 30, 40 }, new double[] { -40, -30, -20, -60 }); + + // Customize Chart + chart.getStyleManager().setChartTitleVisible(false); + + return chart; + } +} diff --git a/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/bar/BarChart03.java b/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/bar/BarChart03.java new file mode 100644 index 0000000000000000000000000000000000000000..2a3ccdb4f63846e8afd293c01e7a3b8d76b28bdb --- /dev/null +++ b/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/bar/BarChart03.java @@ -0,0 +1,60 @@ +/** + * Copyright (C) 2013 Xeiam LLC http://xeiam.com + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies + * of the Software, and to permit persons to whom the Software is furnished to do + * so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package com.xeiam.xchart.demo.charts.bar; + +import com.xeiam.xchart.Chart; +import com.xeiam.xchart.ChartBuilder; +import com.xeiam.xchart.SwingWrapper; +import com.xeiam.xchart.demo.charts.ExampleChart; +import com.xeiam.xchart.style.StyleManager.ChartType; + +/** + * Basic Bar Chart + * <p> + * Demonstrates the following: + * <ul> + * <li>Number categories + * <li>Positive and negative values + * <li>Single series + */ +public class BarChart03 implements ExampleChart { + + public static void main(String[] args) { + + ExampleChart exampleChart = new BarChart03(); + Chart chart = exampleChart.getChart(); + new SwingWrapper(chart).displayChart(); + } + + @Override + public Chart getChart() { + + // Create Chart + Chart chart = new ChartBuilder().chartType(ChartType.Bar).width(800).height(600).title("BarChart01").xAxisTitle("X").yAxisTitle("Y").build(); + chart.addSeries("a", new double[] { 10, 20, 30, 40 }, new double[] { 40, -30, -20, -60 }); + + // Customize Chart + chart.getStyleManager().setChartTitleVisible(false); + + return chart; + } +} diff --git a/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/bar/BarChart04.java b/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/bar/BarChart04.java new file mode 100644 index 0000000000000000000000000000000000000000..19de76825f3f88427c3eaad2a8ee9d9850bc3639 --- /dev/null +++ b/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/bar/BarChart04.java @@ -0,0 +1,61 @@ +/** + * Copyright (C) 2013 Xeiam LLC http://xeiam.com + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies + * of the Software, and to permit persons to whom the Software is furnished to do + * so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package com.xeiam.xchart.demo.charts.bar; + +import com.xeiam.xchart.Chart; +import com.xeiam.xchart.ChartBuilder; +import com.xeiam.xchart.SwingWrapper; +import com.xeiam.xchart.demo.charts.ExampleChart; +import com.xeiam.xchart.style.StyleManager.ChartType; + +/** + * Basic Bar Chart + * <p> + * Demonstrates the following: + * <ul> + * <li>Number categories + * <li>Positive and negative values + * <li>Multiple series + */ +public class BarChart04 implements ExampleChart { + + public static void main(String[] args) { + + ExampleChart exampleChart = new BarChart04(); + Chart chart = exampleChart.getChart(); + new SwingWrapper(chart).displayChart(); + } + + @Override + public Chart getChart() { + + // Create Chart + Chart chart = new ChartBuilder().chartType(ChartType.Bar).width(800).height(600).title("BarChart01").xAxisTitle("X").yAxisTitle("Y").build(); + chart.addSeries("a", new double[] { 10, 20, 30, 40 }, new double[] { 40, 30, 20, 60 }); + chart.addSeries("b", new double[] { 10, 20, 30, 40 }, new double[] { 50, 10, 20, 40 }); + + // Customize Chart + chart.getStyleManager().setChartTitleVisible(false); + + return chart; + } +} diff --git a/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/line/LineChart01.java b/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/line/LineChart01.java index 8ecbbf73b9d99934e30c0fd388c0ec8e271c7126..1acc6a6b6833258e9a0ef766e6254afeae2ed545 100644 --- a/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/line/LineChart01.java +++ b/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/line/LineChart01.java @@ -28,7 +28,7 @@ import com.xeiam.xchart.style.StyleManager.LegendPosition; /** * Logarithmic Y-Axis * <p> - * * Demonstrates the following: + * Demonstrates the following: * <ul> * <li>Logarithmic Y-Axis * <li>Building a Chart with ChartBuilder diff --git a/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/AxisTick.java b/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/AxisTick.java index dde167ff84ed1d7e3fdf0aa8ecefe43c02b3b772..385db6db7ce7a667a15263bbc2bdc8d81813d59e 100644 --- a/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/AxisTick.java +++ b/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/AxisTick.java @@ -22,9 +22,11 @@ import java.util.List; import com.xeiam.xchart.Chart; import com.xeiam.xchart.internal.chartpart.Axis.AxisType; import com.xeiam.xchart.internal.chartpart.axistickcalculator.AxisTickCalculator; +import com.xeiam.xchart.internal.chartpart.axistickcalculator.BarChartAxisTickCalculator; import com.xeiam.xchart.internal.chartpart.axistickcalculator.DateAxisTickCalculator; import com.xeiam.xchart.internal.chartpart.axistickcalculator.LogarithmicAxisTickCalculator; import com.xeiam.xchart.internal.chartpart.axistickcalculator.NumberAxisTickCalculator; +import com.xeiam.xchart.style.StyleManager.ChartType; /** * An axis tick @@ -82,7 +84,11 @@ public class AxisTick implements ChartPart { // System.out.println("workingspace= " + workingSpace); } - if (axis.getDirection() == Axis.Direction.X && getChart().getStyleManager().isXAxisLogarithmic() && axis.getAxisType() != AxisType.Date) { + if (axis.getDirection() == Axis.Direction.X && getChart().getStyleManager().getChartType() == ChartType.Bar) { + + gridStep = new BarChartAxisTickCalculator(axis.getDirection(), workingSpace, axis.getMin(), axis.getMax(), getChart()); + + } else if (axis.getDirection() == Axis.Direction.X && getChart().getStyleManager().isXAxisLogarithmic() && axis.getAxisType() != AxisType.Date) { gridStep = new LogarithmicAxisTickCalculator(axis.getDirection(), workingSpace, axis.getMin(), axis.getMax(), getChart().getStyleManager()); diff --git a/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/Legend.java b/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/Legend.java index 68fa18a995dbabcb27dd21ecfe0b8f287ee8162c..0e73d203d9308f2ea4843d55fd5db966f55f540b 100644 --- a/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/Legend.java +++ b/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/Legend.java @@ -15,6 +15,7 @@ */ package com.xeiam.xchart.internal.chartpart; +import java.awt.BasicStroke; import java.awt.Graphics2D; import java.awt.Rectangle; import java.awt.font.FontRenderContext; @@ -94,7 +95,7 @@ public class Legend implements ChartPart { } else { legendContentWidth = BOX_SIZE + chart.getStyleManager().getLegendPadding() + legendTextContentMaxWidth; } - // Draw Legend Box + // Legend Box int legendBoxWidth = legendContentWidth + 2 * chart.getStyleManager().getLegendPadding(); int legendBoxHeight = legendContentHeight + 2 * chart.getStyleManager().getLegendPadding(); return new int[] { legendBoxWidth, legendBoxHeight, maxContentHeight }; @@ -145,7 +146,7 @@ public class Legend implements ChartPart { default: break; } - + g.setStroke(new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL)); g.setColor(chart.getStyleManager().getLegendBorderColor()); g.drawRect(xOffset, yOffset, legendBoxWidth, legendBoxHeight); g.setColor(chart.getStyleManager().getLegendBackgroundColor()); @@ -170,12 +171,12 @@ public class Legend implements ChartPart { series.getMarker().paint(g, (int) (startx + (Marker.SIZE * 1.5)), starty + (int) (maxContentHeight / 2.0)); } } else { - // paint box + // paint little box if (series.getStroke() != null) { g.setColor(series.getStrokeColor()); g.fillPolygon(new int[] { startx, startx + BOX_SIZE, startx + BOX_SIZE, startx }, new int[] { starty, starty, starty + BOX_SIZE, starty + BOX_SIZE }, 4); - g.setStroke(series.getStroke()); - g.drawPolygon(new int[] { startx, startx + BOX_SIZE, startx + BOX_SIZE, startx }, new int[] { starty, starty, starty + BOX_SIZE, starty + BOX_SIZE }, 4); + // g.setStroke(series.getStroke()); + // g.drawPolygon(new int[] { startx, startx + BOX_SIZE, startx + BOX_SIZE, startx }, new int[] { starty, starty, starty + BOX_SIZE, starty + BOX_SIZE }, 4); } } diff --git a/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/Plot.java b/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/Plot.java index 924ad7126351591acb11c2ec76dfa7409b36b3dd..30fb3d86839fe806f56fa845b9acc8637f39f110 100644 --- a/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/Plot.java +++ b/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/Plot.java @@ -19,6 +19,7 @@ import java.awt.Graphics2D; import java.awt.Rectangle; import com.xeiam.xchart.Chart; +import com.xeiam.xchart.style.StyleManager.ChartType; /** * @author timmolter @@ -44,7 +45,7 @@ public class Plot implements ChartPart { this.chart = chart; this.plotSurface = new PlotSurface(this); - this.plotContent = new PlotContent(this); + } @Override @@ -69,6 +70,11 @@ public class Plot implements ChartPart { // g.draw(bounds); plotSurface.paint(g); + if (getChart().getStyleManager().getChartType() == ChartType.Bar) { + this.plotContent = new PlotContentBarChart(this); + } else { + this.plotContent = new PlotContentLineChart(this); + } plotContent.paint(g); } diff --git a/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/PlotContent.java b/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/PlotContent.java index 9d4799bd9690e027553d16bae834c834928dab09..286a7557d8c68b83b839329ff2108b0e57fbed19 100644 --- a/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/PlotContent.java +++ b/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/PlotContent.java @@ -16,29 +16,20 @@ package com.xeiam.xchart.internal.chartpart; import java.awt.BasicStroke; -import java.awt.Graphics2D; import java.awt.Rectangle; import java.awt.Stroke; -import java.math.BigDecimal; -import java.util.Collection; -import java.util.Date; -import java.util.Iterator; -import java.util.Map; import com.xeiam.xchart.Chart; -import com.xeiam.xchart.Series; -import com.xeiam.xchart.internal.chartpart.Axis.AxisType; -import com.xeiam.xchart.style.StyleManager.ChartType; /** * @author timmolter */ -public class PlotContent implements ChartPart { +public abstract class PlotContent implements ChartPart { /** parent */ - private Plot plot; + protected Plot plot; - private final Stroke errorBarStroke = new BasicStroke(1.5f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL); + protected final Stroke errorBarStroke = new BasicStroke(1.5f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL); /** * Constructor @@ -56,148 +47,6 @@ public class PlotContent implements ChartPart { return plot.getBounds(); } - @Override - public void paint(Graphics2D g) { - - Rectangle bounds = plot.getBounds(); - - Map<Integer, Series> seriesMap = getChart().getAxisPair().getSeriesMap(); - for (Integer seriesId : seriesMap.keySet()) { - - Series series = seriesMap.get(seriesId); - - // X-Axis - int xTickSpace = AxisPair.getTickSpace((int) bounds.getWidth()); - int xLeftMargin = AxisPair.getTickStartOffset((int) bounds.getWidth(), xTickSpace); - - // Y-Axis - int yTickSpace = AxisPair.getTickSpace((int) bounds.getHeight()); - int yTopMargin = AxisPair.getTickStartOffset((int) bounds.getHeight(), yTickSpace); - - // data points - Collection<?> xData = series.getxData(); - BigDecimal xMin = getChart().getAxisPair().getxAxis().getMin(); - BigDecimal xMax = getChart().getAxisPair().getxAxis().getMax(); - if (getChart().getStyleManager().isXAxisLogarithmic()) { - xMin = new BigDecimal(Math.log10(xMin.doubleValue())); - xMax = new BigDecimal(Math.log10(xMax.doubleValue())); - } - Collection<Number> yData = series.getyData(); - BigDecimal yMin = getChart().getAxisPair().getyAxis().getMin(); - BigDecimal yMax = getChart().getAxisPair().getyAxis().getMax(); - if (getChart().getStyleManager().isYAxisLogarithmic()) { - yMin = new BigDecimal(Math.log10(yMin.doubleValue())); - yMax = new BigDecimal(Math.log10(yMax.doubleValue())); - } - Collection<Number> errorBars = series.getErrorBars(); - - int previousX = Integer.MIN_VALUE; - int previousY = Integer.MIN_VALUE; - - Iterator<?> xItr = xData.iterator(); - Iterator<Number> yItr = yData.iterator(); - Iterator<Number> ebItr = null; - if (errorBars != null) { - ebItr = errorBars.iterator(); - } - while (xItr.hasNext()) { - - BigDecimal x = null; - if (getChart().getAxisPair().getxAxis().getAxisType() == AxisType.Number) { - x = new BigDecimal(((Number) xItr.next()).doubleValue()); - } - if (getChart().getAxisPair().getxAxis().getAxisType() == AxisType.Date) { - x = new BigDecimal(((Date) xItr.next()).getTime()); - // System.out.println(x); - } - - if (getChart().getStyleManager().isXAxisLogarithmic()) { - x = new BigDecimal(Math.log10(x.doubleValue())); - } - - BigDecimal y = new BigDecimal(yItr.next().doubleValue()); - - if (getChart().getStyleManager().isYAxisLogarithmic()) { - y = new BigDecimal(Math.log10(y.doubleValue())); - } - - // System.out.println(y); - double eb = 0.0; - if (errorBars != null) { - eb = ebItr.next().doubleValue(); - } - - int xTransform = (int) (xLeftMargin + (x.subtract(xMin).doubleValue() / xMax.subtract(xMin).doubleValue() * xTickSpace)); - int yBottomOfArea = (int) (bounds.getHeight() - (yTopMargin + y.subtract(yMin).doubleValue() / yMax.subtract(yMin).doubleValue() * yTickSpace)); - - // a check if all x data are the exact same values - if (Math.abs(xMax.subtract(xMin).doubleValue()) / 5 == 0.0) { - xTransform = (int) (bounds.getWidth() / 2.0); - } - - // a check if all y data are the exact same values - if (Math.abs(yMax.subtract(yMin).doubleValue()) / 5 == 0.0) { - yBottomOfArea = (int) (bounds.getHeight() / 2.0); - } - - int xOffset = (int) (bounds.getX() + xTransform - 1); - int yOffset = (int) (bounds.getY() + yBottomOfArea); - // System.out.println(yOffset); - // System.out.println(yTransform); - - // paint line - if (series.getStroke() != null && getChart().getStyleManager().getChartType() != ChartType.Scatter && getChart().getStyleManager().getChartType() != ChartType.Bar) { - if (previousX != Integer.MIN_VALUE && previousY != Integer.MIN_VALUE) { - g.setColor(series.getStrokeColor()); - g.setStroke(series.getStroke()); - g.drawLine(previousX, previousY, xOffset, yOffset); - } - } - - // paint area - if (getChart().getStyleManager().getChartType() == ChartType.Area) { - if (previousX != Integer.MIN_VALUE && previousY != Integer.MIN_VALUE) { - g.setColor(series.getStrokeColor()); - yBottomOfArea = (int) (bounds.getY() + bounds.getHeight() - yTopMargin + 1); - g.fillPolygon(new int[] { previousX, xOffset, xOffset, previousX }, new int[] { previousY, yOffset, yBottomOfArea, yBottomOfArea }, 4); - } - } - - // paint bar - int halfWidth = 24; - if (getChart().getStyleManager().getChartType() == ChartType.Bar) { - g.setColor(series.getStrokeColor()); - yBottomOfArea = (int) (bounds.getY() + bounds.getHeight() - yTopMargin + 1); - g.fillPolygon(new int[] { xOffset - halfWidth, xOffset + halfWidth, xOffset + halfWidth, xOffset - halfWidth }, new int[] { yOffset, yOffset, yBottomOfArea, yBottomOfArea }, 4); - g.setStroke(series.getStroke()); - g.drawPolygon(new int[] { xOffset - halfWidth, xOffset + halfWidth, xOffset + halfWidth, xOffset - halfWidth }, new int[] { yOffset, yOffset, yBottomOfArea, yBottomOfArea }, 4); - } - - previousX = xOffset; - previousY = yOffset; - - // paint marker - if (series.getMarker() != null && getChart().getStyleManager().getChartType() != ChartType.Bar) { - g.setColor(series.getMarkerColor()); - series.getMarker().paint(g, xOffset, yOffset); - } - - // paint errorbar - if (errorBars != null) { - g.setColor(getChart().getStyleManager().getErrorBarsColor()); - g.setStroke(errorBarStroke); - int bottom = (int) (-1 * bounds.getHeight() * eb / (yMax.subtract(yMin).doubleValue())); - int top = (int) (bounds.getHeight() * eb / (yMax.subtract(yMin).doubleValue())); - g.drawLine(xOffset, yOffset + bottom, xOffset, yOffset + top); - g.drawLine(xOffset - 3, yOffset + bottom, xOffset + 3, yOffset + bottom); - g.drawLine(xOffset - 3, yOffset + top, xOffset + 3, yOffset + top); - } - } - - } - - } - @Override public Chart getChart() { diff --git a/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/PlotContentBarChart.java b/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/PlotContentBarChart.java new file mode 100644 index 0000000000000000000000000000000000000000..eae07dceabfba7e36765716d277a58aa6db142b4 --- /dev/null +++ b/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/PlotContentBarChart.java @@ -0,0 +1,141 @@ +/** + * Copyright 2011-2013 Xeiam LLC. + * + * 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 com.xeiam.xchart.internal.chartpart; + +import java.awt.Graphics2D; +import java.awt.Rectangle; +import java.math.BigDecimal; +import java.util.Collection; +import java.util.Date; +import java.util.Iterator; +import java.util.Map; +import java.util.Set; +import java.util.TreeSet; + +import com.xeiam.xchart.Chart; +import com.xeiam.xchart.Series; +import com.xeiam.xchart.internal.chartpart.Axis.AxisType; + +/** + * @author timmolter + */ +public class PlotContentBarChart extends PlotContent { + + /** + * Constructor + * + * @param plot + */ + protected PlotContentBarChart(Plot plot) { + + super(plot); + } + + @Override + public void paint(Graphics2D g) { + + Rectangle bounds = plot.getBounds(); + + // X-Axis + int xTickSpace = AxisPair.getTickSpace((int) bounds.getWidth()); + int xLeftMargin = AxisPair.getTickStartOffset((int) bounds.getWidth(), xTickSpace); + + // Y-Axis + int yTickSpace = AxisPair.getTickSpace((int) bounds.getHeight()); + int yTopMargin = AxisPair.getTickStartOffset((int) bounds.getHeight(), yTickSpace); + + // get all categories + Set<BigDecimal> categories = new TreeSet<BigDecimal>(); + Map<Integer, Series> seriesMap = getChart().getAxisPair().getSeriesMap(); + for (Integer seriesId : seriesMap.keySet()) { + + Series series = seriesMap.get(seriesId); + Iterator<?> xItr = series.getxData().iterator(); + while (xItr.hasNext()) { + BigDecimal x = null; + if (getChart().getAxisPair().getxAxis().getAxisType() == AxisType.Number) { + x = new BigDecimal(((Number) xItr.next()).doubleValue()); + } + if (getChart().getAxisPair().getxAxis().getAxisType() == AxisType.Date) { + x = new BigDecimal(((Date) xItr.next()).getTime()); + } + categories.add(x); + } + } + int numBars = categories.size(); + int gridStep = (int) (xTickSpace / (double) numBars); + int firstPosition = (int) (gridStep / 2.0); + + // plot series + int seriesCounter = 0; + for (Integer seriesId : seriesMap.keySet()) { + + Series series = seriesMap.get(seriesId); + + // data points + Collection<?> xData = series.getxData(); + + Collection<Number> yData = series.getyData(); + BigDecimal yMin = getChart().getAxisPair().getyAxis().getMin(); + BigDecimal yMax = getChart().getAxisPair().getyAxis().getMax(); + if (yMin.compareTo(BigDecimal.ZERO) > 0 && yMax.compareTo(BigDecimal.ZERO) > 0) { + yMin = BigDecimal.ZERO; + } else if (yMin.compareTo(BigDecimal.ZERO) < 0 && yMax.compareTo(BigDecimal.ZERO) < 0) { + yMax = BigDecimal.ZERO; + } + + Iterator<?> xItr = xData.iterator(); + Iterator<Number> yItr = yData.iterator(); + + int barCounter = 0; + while (xItr.hasNext()) { + BigDecimal x = null; + if (getChart().getAxisPair().getxAxis().getAxisType() == AxisType.Number) { + x = new BigDecimal(((Number) xItr.next()).doubleValue()); + } + if (getChart().getAxisPair().getxAxis().getAxisType() == AxisType.Date) { + x = new BigDecimal(((Date) xItr.next()).getTime()); + } + + if (categories.contains(x)) { + + BigDecimal y = new BigDecimal(yItr.next().doubleValue()); + int yTransform = (int) (bounds.getHeight() - (yTopMargin + y.subtract(yMin).doubleValue() / yMax.subtract(yMin).doubleValue() * yTickSpace)); + int yOffset = (int) (bounds.getY() + yTransform); + + int zeroTransform = (int) (bounds.getHeight() - (yTopMargin + (BigDecimal.ZERO.subtract(yMin).doubleValue()) / (yMax.subtract(yMin).doubleValue()) * yTickSpace)); + int zeroOffset = (int) (bounds.getY() + zeroTransform); + + // paint bar + int barWidth = (int) (gridStep / seriesMap.size() / 1.1); + int barMargin = (int) (gridStep * .05); + int xOffset = (int) (bounds.getX() + xLeftMargin + gridStep * barCounter++ + seriesCounter * barWidth + barMargin); + g.setColor(series.getStrokeColor()); + g.fillPolygon(new int[] { xOffset, xOffset + barWidth, xOffset + barWidth, xOffset }, new int[] { yOffset, yOffset, zeroOffset, zeroOffset }, 4); + } + } + seriesCounter++; + } + + } + + @Override + public Chart getChart() { + + return plot.getChart(); + } + +} diff --git a/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/PlotContentLineChart.java b/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/PlotContentLineChart.java new file mode 100644 index 0000000000000000000000000000000000000000..a7494d39838c4e4ea3870112b09bb12d8d1a4472 --- /dev/null +++ b/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/PlotContentLineChart.java @@ -0,0 +1,175 @@ +/** + * Copyright 2011-2013 Xeiam LLC. + * + * 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 com.xeiam.xchart.internal.chartpart; + +import java.awt.Graphics2D; +import java.awt.Rectangle; +import java.math.BigDecimal; +import java.util.Collection; +import java.util.Date; +import java.util.Iterator; +import java.util.Map; + +import com.xeiam.xchart.Series; +import com.xeiam.xchart.internal.chartpart.Axis.AxisType; +import com.xeiam.xchart.style.StyleManager.ChartType; + +/** + * @author timmolter + */ +public class PlotContentLineChart extends PlotContent { + + /** + * Constructor + * + * @param plot + */ + protected PlotContentLineChart(Plot plot) { + + super(plot); + } + + @Override + public void paint(Graphics2D g) { + + Rectangle bounds = plot.getBounds(); + + // X-Axis + int xTickSpace = AxisPair.getTickSpace((int) bounds.getWidth()); + int xLeftMargin = AxisPair.getTickStartOffset((int) bounds.getWidth(), xTickSpace); + + // Y-Axis + int yTickSpace = AxisPair.getTickSpace((int) bounds.getHeight()); + int yTopMargin = AxisPair.getTickStartOffset((int) bounds.getHeight(), yTickSpace); + + Map<Integer, Series> seriesMap = getChart().getAxisPair().getSeriesMap(); + for (Integer seriesId : seriesMap.keySet()) { + + Series series = seriesMap.get(seriesId); + + // data points + Collection<?> xData = series.getxData(); + BigDecimal xMin = getChart().getAxisPair().getxAxis().getMin(); + BigDecimal xMax = getChart().getAxisPair().getxAxis().getMax(); + if (getChart().getStyleManager().isXAxisLogarithmic()) { + xMin = new BigDecimal(Math.log10(xMin.doubleValue())); + xMax = new BigDecimal(Math.log10(xMax.doubleValue())); + } + Collection<Number> yData = series.getyData(); + BigDecimal yMin = getChart().getAxisPair().getyAxis().getMin(); + BigDecimal yMax = getChart().getAxisPair().getyAxis().getMax(); + if (getChart().getStyleManager().isYAxisLogarithmic()) { + yMin = new BigDecimal(Math.log10(yMin.doubleValue())); + yMax = new BigDecimal(Math.log10(yMax.doubleValue())); + } + Collection<Number> errorBars = series.getErrorBars(); + + int previousX = Integer.MIN_VALUE; + int previousY = Integer.MIN_VALUE; + + Iterator<?> xItr = xData.iterator(); + Iterator<Number> yItr = yData.iterator(); + Iterator<Number> ebItr = null; + if (errorBars != null) { + ebItr = errorBars.iterator(); + } + while (xItr.hasNext()) { + + BigDecimal x = null; + if (getChart().getAxisPair().getxAxis().getAxisType() == AxisType.Number) { + x = new BigDecimal(((Number) xItr.next()).doubleValue()); + } + if (getChart().getAxisPair().getxAxis().getAxisType() == AxisType.Date) { + x = new BigDecimal(((Date) xItr.next()).getTime()); + // System.out.println(x); + } + + if (getChart().getStyleManager().isXAxisLogarithmic()) { + x = new BigDecimal(Math.log10(x.doubleValue())); + } + + BigDecimal y = new BigDecimal(yItr.next().doubleValue()); + + if (getChart().getStyleManager().isYAxisLogarithmic()) { + y = new BigDecimal(Math.log10(y.doubleValue())); + } + + // System.out.println(y); + double eb = 0.0; + if (errorBars != null) { + eb = ebItr.next().doubleValue(); + } + + int xTransform = (int) (xLeftMargin + (x.subtract(xMin).doubleValue() / xMax.subtract(xMin).doubleValue() * xTickSpace)); + int yTransform = (int) (bounds.getHeight() - (yTopMargin + y.subtract(yMin).doubleValue() / yMax.subtract(yMin).doubleValue() * yTickSpace)); + + // a check if all x data are the exact same values + if (Math.abs(xMax.subtract(xMin).doubleValue()) / 5 == 0.0) { + xTransform = (int) (bounds.getWidth() / 2.0); + } + + // a check if all y data are the exact same values + if (Math.abs(yMax.subtract(yMin).doubleValue()) / 5 == 0.0) { + yTransform = (int) (bounds.getHeight() / 2.0); + } + + int xOffset = (int) (bounds.getX() + xTransform - 1); + int yOffset = (int) (bounds.getY() + yTransform); + // System.out.println(yOffset); + // System.out.println(yTransform); + + // paint line + if (series.getStroke() != null && getChart().getStyleManager().getChartType() != ChartType.Scatter) { + if (previousX != Integer.MIN_VALUE && previousY != Integer.MIN_VALUE) { + g.setColor(series.getStrokeColor()); + g.setStroke(series.getStroke()); + g.drawLine(previousX, previousY, xOffset, yOffset); + } + } + + // paint area + if (getChart().getStyleManager().getChartType() == ChartType.Area) { + if (previousX != Integer.MIN_VALUE && previousY != Integer.MIN_VALUE) { + g.setColor(series.getStrokeColor()); + int yBottomOfArea = (int) (bounds.getY() + bounds.getHeight() - yTopMargin + 1); + g.fillPolygon(new int[] { previousX, xOffset, xOffset, previousX }, new int[] { previousY, yOffset, yBottomOfArea, yBottomOfArea }, 4); + } + } + + previousX = xOffset; + previousY = yOffset; + + // paint marker + g.setColor(series.getMarkerColor()); + series.getMarker().paint(g, xOffset, yOffset); + + // paint errorbar + if (errorBars != null) { + g.setColor(getChart().getStyleManager().getErrorBarsColor()); + g.setStroke(errorBarStroke); + int bottom = (int) (-1 * bounds.getHeight() * eb / (yMax.subtract(yMin).doubleValue())); + int top = (int) (bounds.getHeight() * eb / (yMax.subtract(yMin).doubleValue())); + g.drawLine(xOffset, yOffset + bottom, xOffset, yOffset + top); + g.drawLine(xOffset - 3, yOffset + bottom, xOffset + 3, yOffset + bottom); + g.drawLine(xOffset - 3, yOffset + top, xOffset + 3, yOffset + top); + } + } + + } + + } + +} diff --git a/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/axistickcalculator/AxisTickCalculator.java b/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/axistickcalculator/AxisTickCalculator.java index 2dc8b452fc757c3c9bdffd86b40cb3a66d601226..2aa22592974626aadb5aca4a47b8802ff2879fa3 100644 --- a/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/axistickcalculator/AxisTickCalculator.java +++ b/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/axistickcalculator/AxisTickCalculator.java @@ -29,6 +29,7 @@ import java.util.List; import com.xeiam.xchart.internal.chartpart.Axis.Direction; import com.xeiam.xchart.style.StyleManager; +import com.xeiam.xchart.style.StyleManager.ChartType; /** * @author timmolter @@ -68,10 +69,22 @@ public abstract class AxisTickCalculator { */ public AxisTickCalculator(Direction axisDirection, int workingSpace, BigDecimal minValue, BigDecimal maxValue, StyleManager styleManager) { + // override min/max value for bar charts' Y-Axis + BigDecimal overrideMinValue = minValue; + BigDecimal overrideMaxValue = maxValue; + if (styleManager.getChartType() == ChartType.Bar) { // this is the Y-Axis for a bar chart + if (minValue.compareTo(BigDecimal.ZERO) > 0 && maxValue.compareTo(BigDecimal.ZERO) > 0) { + overrideMinValue = BigDecimal.ZERO; + } + if (minValue.compareTo(BigDecimal.ZERO) < 0 && maxValue.compareTo(BigDecimal.ZERO) < 0) { + overrideMaxValue = BigDecimal.ZERO; + } + } + this.axisDirection = axisDirection; this.workingSpace = workingSpace; - this.minValue = minValue; - this.maxValue = maxValue; + this.minValue = overrideMinValue; + this.maxValue = overrideMaxValue; this.styleManager = styleManager; } @@ -112,13 +125,13 @@ public abstract class AxisTickCalculator { } - BigDecimal getFirstPosition(final BigDecimal min, BigDecimal gridStep) { + BigDecimal getFirstPosition(BigDecimal gridStep) { BigDecimal firstPosition; - if (min.remainder(gridStep).doubleValue() <= 0.0) { - firstPosition = min.subtract(min.remainder(gridStep)); + if (minValue.remainder(gridStep).doubleValue() <= 0.0) { + firstPosition = minValue.subtract(minValue.remainder(gridStep)); } else { - firstPosition = min.subtract(min.remainder(gridStep)).add(gridStep); + firstPosition = minValue.subtract(minValue.remainder(gridStep)).add(gridStep); } return firstPosition; } diff --git a/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/axistickcalculator/BarChartAxisTickCalculator.java b/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/axistickcalculator/BarChartAxisTickCalculator.java new file mode 100644 index 0000000000000000000000000000000000000000..92eea63ced35a556c6929f952d446a0a1898b9b1 --- /dev/null +++ b/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/axistickcalculator/BarChartAxisTickCalculator.java @@ -0,0 +1,101 @@ +/** + * Copyright (C) 2013 Xeiam LLC http://xeiam.com + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies + * of the Software, and to permit persons to whom the Software is furnished to do + * so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package com.xeiam.xchart.internal.chartpart.axistickcalculator; + +import java.math.BigDecimal; +import java.util.Date; +import java.util.Iterator; +import java.util.Map; +import java.util.Set; +import java.util.TreeSet; + +import com.xeiam.xchart.Chart; +import com.xeiam.xchart.Series; +import com.xeiam.xchart.internal.chartpart.Axis.AxisType; +import com.xeiam.xchart.internal.chartpart.Axis.Direction; +import com.xeiam.xchart.internal.chartpart.AxisPair; + +/** + * This class encapsulates the logic to generate the axis tick mark and axis tick label data for rendering the axis ticks for decimal axes + * + * @author timmolter + */ +public class BarChartAxisTickCalculator extends AxisTickCalculator { + + /** + * Constructor + * + * @param axisDirection + * @param workingSpace + * @param minValue + * @param maxValue + * @param styleManager + */ + public BarChartAxisTickCalculator(Direction axisDirection, int workingSpace, BigDecimal minValue, BigDecimal maxValue, Chart chart) { + + super(axisDirection, workingSpace, minValue, maxValue, chart.getStyleManager()); + calculate(chart); + } + + private void calculate(Chart chart) { + + // tick space - a percentage of the working space available for ticks, i.e. 95% + int tickSpace = AxisPair.getTickSpace(workingSpace); // in plot space + + // where the tick should begin in the working space in pixels + int margin = AxisPair.getTickStartOffset(workingSpace, tickSpace); // in plot space BigDecimal gridStep = getGridStepForDecimal(tickSpace); + + // get all categories + Set<BigDecimal> categories = new TreeSet<BigDecimal>(); + Map<Integer, Series> seriesMap = chart.getAxisPair().getSeriesMap(); + for (Integer seriesId : seriesMap.keySet()) { + + Series series = seriesMap.get(seriesId); + Iterator<?> xItr = series.getxData().iterator(); + while (xItr.hasNext()) { + BigDecimal x = null; + if (chart.getAxisPair().getxAxis().getAxisType() == AxisType.Number) { + x = new BigDecimal(((Number) xItr.next()).doubleValue()); + } + if (chart.getAxisPair().getxAxis().getAxisType() == AxisType.Date) { + x = new BigDecimal(((Date) xItr.next()).getTime()); + // System.out.println(x); + } + categories.add(x); + } + } + + int numCategories = categories.size(); + + int gridStep = (int) (tickSpace / (double) numCategories); + int firstPosition = (int) (gridStep / 2.0); + + // generate all tickLabels and tickLocations from the first to last position + int counter = 0; + for (BigDecimal category : categories) { + tickLabels.add(formatNumber(category)); + int tickLabelPosition = margin + firstPosition + gridStep * counter++; + tickLocations.add(tickLabelPosition); + } + } + +} diff --git a/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/axistickcalculator/DateAxisTickCalculator.java b/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/axistickcalculator/DateAxisTickCalculator.java index 0397b8119747cc10d273b59fd4c06042074ee1a2..21e2ee12b05544b9b65e5ee05c07e640f275bcc8 100644 --- a/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/axistickcalculator/DateAxisTickCalculator.java +++ b/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/axistickcalculator/DateAxisTickCalculator.java @@ -90,7 +90,7 @@ public class DateAxisTickCalculator extends AxisTickCalculator { int margin = AxisPair.getTickStartOffset(workingSpace, tickSpace); // in plot space BigDecimal gridStep = getGridStepForDecimal(tickSpace); BigDecimal gridStep = getGridStep(tickSpace); - BigDecimal firstPosition = getFirstPosition(minValue, gridStep); + BigDecimal firstPosition = getFirstPosition(gridStep); // generate all tickLabels and tickLocations from the first to last position for (BigDecimal tickPosition = firstPosition; tickPosition.compareTo(maxValue) <= 0; tickPosition = tickPosition.add(gridStep)) { diff --git a/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/axistickcalculator/LogarithmicAxisTickCalculator.java b/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/axistickcalculator/LogarithmicAxisTickCalculator.java index 92aafe7e9c2f9d4cdb816b62f5abe0be329221fa..0265869ed2ae14e7c1d970f594ea2bbea33c2380 100644 --- a/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/axistickcalculator/LogarithmicAxisTickCalculator.java +++ b/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/axistickcalculator/LogarithmicAxisTickCalculator.java @@ -70,7 +70,7 @@ public class LogarithmicAxisTickCalculator extends AxisTickCalculator { final BigDecimal min = new BigDecimal(minValue.doubleValue()); BigDecimal tickStep = pow(10, logMin - 1); - BigDecimal firstPosition = getFirstPosition(minValue, tickStep); + BigDecimal firstPosition = getFirstPosition(tickStep); for (int i = logMin; i <= logMax; i++) { // for each decade diff --git a/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/axistickcalculator/NumberAxisTickCalculator.java b/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/axistickcalculator/NumberAxisTickCalculator.java index 55540bc0805276968048e0e754067c904b240718..f9db45bc21f07e113d32f98857a77ee24e2dc966 100644 --- a/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/axistickcalculator/NumberAxisTickCalculator.java +++ b/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/axistickcalculator/NumberAxisTickCalculator.java @@ -65,7 +65,7 @@ public class NumberAxisTickCalculator extends AxisTickCalculator { int margin = AxisPair.getTickStartOffset(workingSpace, tickSpace); // in plot space BigDecimal gridStep = getGridStepForDecimal(tickSpace); BigDecimal gridStep = getGridStep(tickSpace); - BigDecimal firstPosition = getFirstPosition(minValue, gridStep); + BigDecimal firstPosition = getFirstPosition(gridStep); // generate all tickLabels and tickLocations from the first to last position for (BigDecimal tickPosition = firstPosition; tickPosition.compareTo(maxValue) <= 0; tickPosition = tickPosition.add(gridStep)) { diff --git a/xchart/src/main/java/com/xeiam/xchart/style/SeriesLineStyle.java b/xchart/src/main/java/com/xeiam/xchart/style/SeriesLineStyle.java index fef49a8eb4637590a3d725b7e472bceeec29bebc..fbd7c6bdacdd0df47510e417ad3ebd2a68235ecc 100644 --- a/xchart/src/main/java/com/xeiam/xchart/style/SeriesLineStyle.java +++ b/xchart/src/main/java/com/xeiam/xchart/style/SeriesLineStyle.java @@ -28,16 +28,16 @@ public enum SeriesLineStyle { NONE(-1, null), /** SOLID */ - SOLID(0, new BasicStroke(1.8f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL)), + SOLID(0, new BasicStroke(2.0f, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_MITER)), /** DASH_DOT */ - DASH_DOT(1, new BasicStroke(1.8f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 10.0f, new float[] { 3.0f, 1.0f }, 0.0f)), + DASH_DOT(1, new BasicStroke(2.0f, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_MITER, 10.0f, new float[] { 3.0f, 1.0f }, 0.0f)), /** DASH_DASH */ - DASH_DASH(2, new BasicStroke(1.8f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 10.0f, new float[] { 3.0f, 3.0f }, 0.0f)), + DASH_DASH(2, new BasicStroke(2.0f, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_MITER, 10.0f, new float[] { 3.0f, 3.0f }, 0.0f)), /** DOT_DOT */ - DOT_DOT(3, new BasicStroke(1.8f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 10.0f, new float[] { 1.0f, 1.0f }, 0.0f)); + DOT_DOT(3, new BasicStroke(2.0f, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_MITER, 10.0f, new float[] { 1.0f, 1.0f }, 0.0f)); /** The index */ private int index;