diff --git a/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/area/AreaChart01.java b/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/area/AreaChart01.java index 5ec467d90528cc1a6f08909eaea6b57d37379921..7e36c715eb816c871aa39e8819b93abf3c8f5eb4 100644 --- a/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/area/AreaChart01.java +++ b/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/area/AreaChart01.java @@ -17,9 +17,9 @@ package com.xeiam.xchart.demo.charts.area; import com.xeiam.xchart.Chart; import com.xeiam.xchart.ChartBuilder; -import com.xeiam.xchart.ChartBuilder.ChartType; import com.xeiam.xchart.SwingWrapper; import com.xeiam.xchart.demo.charts.line.ExampleChart; +import com.xeiam.xchart.style.StyleManager.ChartType; import com.xeiam.xchart.style.StyleManager.LegendPosition; /** @@ -40,7 +40,7 @@ public class AreaChart01 implements ExampleChart { public Chart getChart() { // Create Chart - Chart chart = new ChartBuilder().chartType(ChartType.Area).width(800).height(600).title("LineChart11").xAxisTitle("X").yAxisTitle("Y").build(); + Chart chart = new ChartBuilder().chartType(ChartType.Area).width(800).height(600).title("AreaChart01").xAxisTitle("X").yAxisTitle("Y").build(); chart.addSeries("a", new double[] { 0, 3, 5, 7, 9 }, new double[] { -3, 5, 9, 6, 5 }); chart.addSeries("b", new double[] { 0, 2, 4, 6, 9 }, new double[] { -1, 6, 4, 0, 4 }); chart.addSeries("c", new double[] { 0, 1, 3, 8, 9 }, new double[] { -2, -1, 1, 0, 1 }); diff --git a/xchart/src/main/java/com/xeiam/xchart/LineChart.java b/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/bar/BarChart01.java similarity index 53% rename from xchart/src/main/java/com/xeiam/xchart/LineChart.java rename to xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/bar/BarChart01.java index e79df9bf4fc730478cfdb042e42bb400d09d411a..1b23ded02cf16108eb8adba6614eafa37a0fe839 100644 --- a/xchart/src/main/java/com/xeiam/xchart/LineChart.java +++ b/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/bar/BarChart01.java @@ -19,34 +19,38 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package com.xeiam.xchart; +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.line.ExampleChart; +import com.xeiam.xchart.style.StyleManager.ChartType; +import com.xeiam.xchart.style.StyleManager.LegendPosition; /** - * A Scatter Chart is a contains series with no lines drawn between the points - * * @author timmolter */ -public class LineChart extends Chart { - - /** - * Constructor - * - * @param width - * @param height - */ - public LineChart(int width, int height) { +public class BarChart01 implements ExampleChart { - super(width, height); + public static void main(String[] args) { + ExampleChart exampleChart = new BarChart01(); + Chart chart = exampleChart.getChart(); + new SwingWrapper(chart).displayChart(); } - /** - * Constructor - * - * @param chartBuilder - */ - public LineChart(ChartBuilder chartBuilder) { + @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[] { 0, 1, 2, 3, 4 }, new double[] { -3, 5, 9, 6, 5 }); + + // Customize Chart + chart.getStyleManager().setChartTitleVisible(false); + chart.getStyleManager().setLegendPosition(LegendPosition.InsideNW); - super(chartBuilder); + 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 de30d5471385f4e1f6261ea1e370abd3fa19e859..2291ad4a0fba5332a487ef776dd9b8794591a678 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 @@ -19,7 +19,6 @@ import java.util.Arrays; import java.util.Collection; import com.xeiam.xchart.Chart; -import com.xeiam.xchart.LineChart; import com.xeiam.xchart.SwingWrapper; import com.xeiam.xchart.style.Series; import com.xeiam.xchart.style.SeriesMarker; @@ -79,7 +78,7 @@ public class LineChart01 implements ExampleChart { Collection<Number> yData = Arrays.asList(yDataArray); // Create Chart - Chart chart = new LineChart(800, 600); + Chart chart = new Chart(800, 600); // Customize Chart chart.setChartTitle("LineChart01"); diff --git a/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/line/LineChart02.java b/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/line/LineChart02.java index 72c3b9ce22916a2dfc662988832f594a8f7f1291..e1b558d8317589075dd0283424e1d7853b4b4932 100644 --- a/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/line/LineChart02.java +++ b/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/line/LineChart02.java @@ -19,7 +19,6 @@ import java.util.ArrayList; import java.util.List; import com.xeiam.xchart.Chart; -import com.xeiam.xchart.LineChart; import com.xeiam.xchart.SwingWrapper; import com.xeiam.xchart.style.Series; import com.xeiam.xchart.style.SeriesColor; @@ -57,7 +56,7 @@ public class LineChart02 implements ExampleChart { } // Create Chart - Chart chart = new LineChart(800, 600); + Chart chart = new Chart(800, 600); // Customize Chart chart.getStyleManager().setChartTitleVisible(false); diff --git a/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/line/LineChart03.java b/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/line/LineChart03.java index f7d1669b19ac1fa9ec64fa5665bd1bc9d50b233b..3404c6e8accdbabadb749288b47d99ae68bb2a9e 100644 --- a/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/line/LineChart03.java +++ b/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/line/LineChart03.java @@ -19,7 +19,6 @@ import java.util.ArrayList; import java.util.Collection; import com.xeiam.xchart.Chart; -import com.xeiam.xchart.LineChart; import com.xeiam.xchart.SwingWrapper; /** @@ -38,7 +37,7 @@ public class LineChart03 implements ExampleChart { public Chart getChart() { // Create Chart - Chart chart = new LineChart(800, 600); + Chart chart = new Chart(800, 600); for (int i = 1; i <= 14; i++) { diff --git a/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/line/LineChart04.java b/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/line/LineChart04.java index 018c6a8365fd119148f6da352bd74b2838e456d3..5e15c2e07a46d2075ce7b9c46648c98920acc60a 100644 --- a/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/line/LineChart04.java +++ b/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/line/LineChart04.java @@ -24,7 +24,6 @@ import java.util.Date; import java.util.TimeZone; import com.xeiam.xchart.Chart; -import com.xeiam.xchart.LineChart; import com.xeiam.xchart.SwingWrapper; import com.xeiam.xchart.style.Series; import com.xeiam.xchart.style.StyleManager.LegendPosition; @@ -50,7 +49,7 @@ public class LineChart04 implements ExampleChart { public Chart getChart() { // Create Chart - Chart chart = new LineChart(800, 600); + Chart chart = new Chart(800, 600); // generates linear data Collection<Date> xData = new ArrayList<Date>(); diff --git a/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/line/LineChart06.java b/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/line/LineChart06.java index fb586405706078a9a352dcdaddf3e5dfa193ae48..de073739fb25d4bbfcd663adfd2570c1be709ead 100644 --- a/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/line/LineChart06.java +++ b/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/line/LineChart06.java @@ -16,7 +16,6 @@ package com.xeiam.xchart.demo.charts.line; import com.xeiam.xchart.Chart; -import com.xeiam.xchart.LineChart; import com.xeiam.xchart.SwingWrapper; /** @@ -35,7 +34,7 @@ public class LineChart06 implements ExampleChart { public Chart getChart() { // Create Chart - Chart chart = new LineChart(800, 600); + Chart chart = new Chart(800, 600); // Customize Chart chart.setChartTitle("LineChart06"); diff --git a/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/line/LineChart07.java b/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/line/LineChart07.java index 4efa76fe5db4d0c58c5b72b3c11eb572152a2b53..1e54855ecf6e4aca3612be2e7fc87255d1d3aa82 100644 --- a/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/line/LineChart07.java +++ b/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/line/LineChart07.java @@ -19,7 +19,6 @@ import java.util.Arrays; import java.util.Collection; import com.xeiam.xchart.Chart; -import com.xeiam.xchart.LineChart; import com.xeiam.xchart.SwingWrapper; /** @@ -41,7 +40,7 @@ public class LineChart07 implements ExampleChart { Collection<Number> yData = Arrays.asList(new Number[] { 0.0, 1.0, 2.0, 0.0, 1.0, 2.0, 0.0, 1.0, 2.0, 0.0 }); // Create Chart - Chart chart = new LineChart(800, 600); + Chart chart = new Chart(800, 600); chart.setChartTitle("LineChart07"); chart.setXAxisTitle("X"); chart.setYAxisTitle("Y"); diff --git a/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/line/LineChart08.java b/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/line/LineChart08.java index 7c1ea138799e232158483f6a2f584057f31d7714..1d025112ec12e40ec59a7df5848e222cf3ed3d13 100644 --- a/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/line/LineChart08.java +++ b/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/line/LineChart08.java @@ -19,7 +19,6 @@ import java.util.ArrayList; import java.util.Collection; import com.xeiam.xchart.Chart; -import com.xeiam.xchart.LineChart; import com.xeiam.xchart.SwingWrapper; import com.xeiam.xchart.style.Series; import com.xeiam.xchart.style.SeriesColor; @@ -53,7 +52,7 @@ public class LineChart08 implements ExampleChart { } // Create Chart - Chart chart = new LineChart(800, 600); + Chart chart = new Chart(800, 600); // Customize Chart chart.getStyleManager().setChartTitleVisible(false); diff --git a/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/line/LineChart09.java b/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/line/LineChart09.java index fb44c79335da5b5425094a1015a4b13e77e97fb8..d6d73cd61e8a2b67eaf78c783b84446bc60af1b3 100644 --- a/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/line/LineChart09.java +++ b/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/line/LineChart09.java @@ -26,7 +26,6 @@ import java.util.Date; import java.util.Locale; import com.xeiam.xchart.Chart; -import com.xeiam.xchart.LineChart; import com.xeiam.xchart.SwingWrapper; import com.xeiam.xchart.style.ChartColor; import com.xeiam.xchart.style.Series; @@ -50,7 +49,7 @@ public class LineChart09 implements ExampleChart { public Chart getChart() { // Create Chart - Chart chart = new LineChart(800, 600); + Chart chart = new Chart(800, 600); // generates linear data Collection<Date> xData = new ArrayList<Date>(); diff --git a/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/line/LineChart10.java b/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/line/LineChart10.java index 6b628ee856507d0204ed4ea8918c0f445e714497..2b56b2d3bb005c7b08f007d548ba884e8b3ec169 100644 --- a/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/line/LineChart10.java +++ b/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/line/LineChart10.java @@ -16,7 +16,6 @@ package com.xeiam.xchart.demo.charts.line; import com.xeiam.xchart.Chart; -import com.xeiam.xchart.LineChart; import com.xeiam.xchart.SwingWrapper; import com.xeiam.xchart.style.Series; import com.xeiam.xchart.style.SeriesColor; @@ -39,7 +38,7 @@ public class LineChart10 implements ExampleChart { public Chart getChart() { // Create Chart - Chart chart = new LineChart(800, 600); + Chart chart = new Chart(800, 600); // Customize Chart chart.setChartTitle("LineChart10"); diff --git a/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/scatter/ScatterChart01.java b/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/scatter/ScatterChart01.java index b0d9053b6b4b6da1754ad7e15552653b8a22e0b1..9b8dadf18e13e1257bc45a7e7cfa288ca6fd31e6 100644 --- a/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/scatter/ScatterChart01.java +++ b/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/scatter/ScatterChart01.java @@ -20,9 +20,9 @@ import java.util.List; import java.util.Random; import com.xeiam.xchart.Chart; -import com.xeiam.xchart.ScatterChart; import com.xeiam.xchart.SwingWrapper; import com.xeiam.xchart.demo.charts.line.ExampleChart; +import com.xeiam.xchart.style.StyleManager.ChartType; /** * Gaussian Blob @@ -51,7 +51,8 @@ public class ScatterChart01 implements ExampleChart { } // Create Chart - Chart chart = new ScatterChart(800, 600); + Chart chart = new Chart(800, 600); + chart.getStyleManager().setChartType(ChartType.Scatter); // Customize Chart chart.getStyleManager().setChartTitleVisible(false); diff --git a/xchart/src/main/java/com/xeiam/xchart/Chart.java b/xchart/src/main/java/com/xeiam/xchart/Chart.java index 223ee965914d7b31c6f274cfa1ca6cf92f132f5d..2fb48add0cd16472fa27874e7de80b09c0aef933 100644 --- a/xchart/src/main/java/com/xeiam/xchart/Chart.java +++ b/xchart/src/main/java/com/xeiam/xchart/Chart.java @@ -35,7 +35,7 @@ import com.xeiam.xchart.style.theme.Theme; * * @author timmolter */ -public abstract class Chart { +public class Chart { private int width; private int height; @@ -74,6 +74,7 @@ public abstract class Chart { setXAxisTitle(chartBuilder.xAxisTitle); setYAxisTitle(chartBuilder.yAxisTitle); setTheme(chartBuilder.theme); + getStyleManager().setChartType(chartBuilder.chartType); } /** diff --git a/xchart/src/main/java/com/xeiam/xchart/ChartBuilder.java b/xchart/src/main/java/com/xeiam/xchart/ChartBuilder.java index ff7fefd74d05924b8f3f2a825c2aeebef047455c..f095bf0b15999d3f01cbbb35da7677921d6c6f17 100644 --- a/xchart/src/main/java/com/xeiam/xchart/ChartBuilder.java +++ b/xchart/src/main/java/com/xeiam/xchart/ChartBuilder.java @@ -21,6 +21,7 @@ */ package com.xeiam.xchart; +import com.xeiam.xchart.style.StyleManager.ChartType; import com.xeiam.xchart.style.theme.Theme; import com.xeiam.xchart.style.theme.XChartTheme; @@ -29,11 +30,6 @@ import com.xeiam.xchart.style.theme.XChartTheme; */ public class ChartBuilder { - public enum ChartType { - - Line, Scatter, Area - } - protected ChartType chartType = ChartType.Line; protected int width = 800; protected int height = 600; @@ -91,16 +87,7 @@ public class ChartBuilder { */ public Chart build() { - switch (chartType) { - case Line: - return new LineChart(this); - case Scatter: - return new ScatterChart(this); - case Area: - return new AreaChart(this); - default: - return new LineChart(this); - } + return new Chart(this); } diff --git a/xchart/src/main/java/com/xeiam/xchart/QuickChart.java b/xchart/src/main/java/com/xeiam/xchart/QuickChart.java index a242e338cba84d107c210cae97f2ba68c9d11cd6..2d4249b0b29576b3fbef74b03351ae40b56b0013 100644 --- a/xchart/src/main/java/com/xeiam/xchart/QuickChart.java +++ b/xchart/src/main/java/com/xeiam/xchart/QuickChart.java @@ -72,7 +72,7 @@ public final class QuickChart { public static Chart getChart(String chartTitle, String xTitle, String yTitle, String[] seriesNames, double[] xData, double[][] yData) { // Create Chart - Chart chart = new LineChart(WIDTH, HEIGHT); + Chart chart = new Chart(WIDTH, HEIGHT); // Customize Chart chart.setChartTitle(chartTitle); @@ -108,7 +108,7 @@ public final class QuickChart { public static Chart getChart(String chartTitle, String xTitle, String yTitle, String seriesName, Collection<Number> xData, Collection<Number> yData) { // Create Chart - Chart chart = new LineChart(WIDTH, HEIGHT); + Chart chart = new Chart(WIDTH, HEIGHT); // Customize Chart chart.setChartTitle(chartTitle); diff --git a/xchart/src/main/java/com/xeiam/xchart/ScatterChart.java b/xchart/src/main/java/com/xeiam/xchart/ScatterChart.java deleted file mode 100644 index fe1fe13b26ad97d413f0b579084abb184677fb3d..0000000000000000000000000000000000000000 --- a/xchart/src/main/java/com/xeiam/xchart/ScatterChart.java +++ /dev/null @@ -1,52 +0,0 @@ -/** - * 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; - -/** - * A Scatter Chart is a contains series with no lines drawn between the points - * - * @author timmolter - */ -public class ScatterChart extends Chart { - - /** - * Constructor - * - * @param width - * @param height - */ - public ScatterChart(int width, int height) { - - super(width, height); - - } - - /** - * Constructor - * - * @param chartBuilder - */ - public ScatterChart(ChartBuilder chartBuilder) { - - super(chartBuilder); - } -} diff --git a/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/Axis.java b/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/Axis.java index dde87027eefe0490fb5fd670d1d60d67f923b024..e5e1a3b88c861b30d09a8d9e1bfba81d534c0969 100644 --- a/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/Axis.java +++ b/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/Axis.java @@ -33,7 +33,7 @@ public class Axis implements ChartPart { public enum AxisType { - NUMBER, DATE; + Number, Date, Logarithmic; } /** parent */ @@ -66,7 +66,7 @@ public class Axis implements ChartPart { private Rectangle paintZone; /** An axis direction */ - protected enum Direction { + public enum Direction { /** the constant to represent X axis */ X, diff --git a/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/AxisPair.java b/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/AxisPair.java index 132373e8b2694e8852545d94d536b525e1b2eb05..d6cc1a8cec2dc8184a694b9cc6032189914dd5db 100644 --- a/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/AxisPair.java +++ b/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/AxisPair.java @@ -87,19 +87,19 @@ public class AxisPair implements ChartPart { Iterator<?> itr = xData.iterator(); Object dataPoint = itr.next(); if (dataPoint instanceof Number) { - xAxis.setAxisType(AxisType.NUMBER); + xAxis.setAxisType(AxisType.Number); } else if (dataPoint instanceof Date) { - xAxis.setAxisType(AxisType.DATE); + xAxis.setAxisType(AxisType.Date); } - yAxis.setAxisType(AxisType.NUMBER); + yAxis.setAxisType(AxisType.Number); series = new Series(seriesName, xData, xAxis.getAxisType(), yData, yAxis.getAxisType(), errorBars, seriesColorMarkerLineStyleCycler.getNextSeriesColorMarkerLineStyle()); } else { // generate xData Collection<Number> generatedXData = new ArrayList<Number>(); for (int i = 1; i < yData.size() + 1; i++) { generatedXData.add(i); } - xAxis.setAxisType(AxisType.NUMBER); - yAxis.setAxisType(AxisType.NUMBER); + xAxis.setAxisType(AxisType.Number); + yAxis.setAxisType(AxisType.Number); series = new Series(seriesName, generatedXData, xAxis.getAxisType(), yData, yAxis.getAxisType(), errorBars, seriesColorMarkerLineStyleCycler.getNextSeriesColorMarkerLineStyle()); } 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 bf0e2a8c1868f48747030695cd6bd9780fd40d13..1f1b99c8090f5923afd0304a077e868c53f27e89 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 @@ -17,25 +17,15 @@ package com.xeiam.xchart.internal.chartpart; import java.awt.Graphics2D; import java.awt.Rectangle; -import java.math.BigDecimal; -import java.util.LinkedList; import java.util.List; import com.xeiam.xchart.Chart; -import com.xeiam.xchart.internal.chartpart.Axis.AxisType; -import com.xeiam.xchart.internal.chartpart.Axis.Direction; /** * An axis tick */ public class AxisTick implements ChartPart { - /** the default tick mark step hint for x axis */ - private static final int DEFAULT_TICK_MARK_STEP_HINT_X = 74; - - /** the default tick mark step hint for y axis */ - private static final int DEFAULT_TICK_MARK_STEP_HINT_Y = 44; - /** parent */ private Axis axis; @@ -45,20 +35,14 @@ public class AxisTick implements ChartPart { /** the axistickmarks */ private AxisTickMarks axisTickMarks; - /** the List of tick label position in pixels */ - private List<Integer> tickLocations; - - /** the List of tick label values */ - private List<String> tickLabels; - - private int workingSpace; - /** the bounds */ private Rectangle bounds; /** the visibility state of axistick */ private boolean isVisible = true; // default to true + AxisTickComputer axisTickComputer; + /** * Constructor * @@ -84,6 +68,7 @@ public class AxisTick implements ChartPart { bounds = new Rectangle(); + int workingSpace = 0; if (axis.getDirection() == Axis.Direction.Y) { workingSpace = (int) axis.getPaintZone().getHeight(); // number of pixels the axis has to work with for drawing AxisTicks // System.out.println("workingspace= " + workingSpace); @@ -92,16 +77,10 @@ public class AxisTick implements ChartPart { // System.out.println("workingspace= " + workingSpace); } - determineAxisTick(); - - // for (Integer position : tickLocations) { - // System.out.println(position); - // } - // for (String label : tickLabels) { - // System.out.println(label); - // } + axisTickComputer = new AxisTickComputer(axis.getDirection(), workingSpace, axis.getMin(), axis.getMax(), getChart().getValueFormatter(), axis.getAxisType()); if (isVisible) { + axisTickLabels.paint(g); axisTickMarks.paint(g); @@ -121,136 +100,6 @@ public class AxisTick implements ChartPart { } - /** - * - */ - private void determineAxisTick() { - - tickLocations = new LinkedList<Integer>(); - tickLabels = new LinkedList<String>(); - - // System.out.println("workingSpace= " + workingSpace); - - int tickSpace = AxisPair.getTickSpace(workingSpace); - // System.out.println("tickSpace= " + tickSpace); - - int margin = AxisPair.getTickStartOffset(workingSpace, tickSpace); - - // a check if all axis data are the exact same values - if (axis.getMax() == axis.getMin()) { - tickLabels.add(format(axis.getMax())); - tickLocations.add((int) (margin + tickSpace / 2.0)); - } else { - - final BigDecimal min = new BigDecimal(axis.getMin().doubleValue()); - BigDecimal firstPosition; - BigDecimal gridStep = getGridStep(tickSpace); - - double xyz = min.remainder(gridStep).doubleValue(); - if (xyz <= 0.0) { - firstPosition = min.subtract(min.remainder(gridStep)); - } else { - firstPosition = min.subtract(min.remainder(gridStep)).add(gridStep); - } - - for (BigDecimal b = firstPosition; b.compareTo(axis.getMax()) <= 0; b = b.add(gridStep)) { - - // System.out.println("b= " + b); - tickLabels.add(format(b)); - int tickLabelPosition = (int) (margin + ((b.subtract(axis.getMin())).doubleValue() / (axis.getMax().subtract(axis.getMin())).doubleValue() * tickSpace)); - // System.out.println("tickLabelPosition= " + tickLabelPosition); - - tickLocations.add(tickLabelPosition); - } - } - } - - private BigDecimal getGridStep(int tickSpace) { - - double length = Math.abs(axis.getMax().subtract(axis.getMin()).doubleValue()); - // System.out.println(axis.getMax()); - // System.out.println(axis.min); - // System.out.println(length); - int tickMarkSpaceHint = (axis.getDirection() == Direction.X ? DEFAULT_TICK_MARK_STEP_HINT_X : DEFAULT_TICK_MARK_STEP_HINT_Y); - // for very short plots, squeeze some more ticks in than normal - if (axis.getDirection() == Direction.Y && tickSpace < 160) { - tickMarkSpaceHint = 25; - } - double gridStepHint = length / tickSpace * tickMarkSpaceHint; - - // gridStepHint --> mantissa * 10 ** exponent - // e.g. 724.1 --> 7.241 * 10 ** 2 - double mantissa = gridStepHint; - int exponent = 0; - if (mantissa == 0) { - exponent = 1; - } else if (mantissa < 1) { - while (mantissa < 1) { - mantissa *= 10.0; - exponent--; - } - } else { - while (mantissa >= 10) { - mantissa /= 10.0; - exponent++; - } - } - - // calculate the grid step with hint. - BigDecimal gridStep; - if (mantissa > 7.5) { - // gridStep = 10.0 * 10 ** exponent - gridStep = BigDecimal.TEN.multiply(pow(10, exponent)); - } else if (mantissa > 3.5) { - // gridStep = 5.0 * 10 ** exponent - gridStep = new BigDecimal(new Double(5).toString()).multiply(pow(10, exponent)); - } else if (mantissa > 1.5) { - // gridStep = 2.0 * 10 ** exponent - gridStep = new BigDecimal(new Double(2).toString()).multiply(pow(10, exponent)); - } else { - // gridStep = 1.0 * 10 ** exponent - gridStep = pow(10, exponent); - } - return gridStep; - } - - /** - * Calculates the value of the first argument raised to the power of the second argument. - * - * @param base the base - * @param exponent the exponent - * @return the value <tt>a<sup>b</sup></tt> in <tt>BigDecimal</tt> - */ - private BigDecimal pow(double base, int exponent) { - - BigDecimal value; - if (exponent > 0) { - value = new BigDecimal(new Double(base).toString()).pow(exponent); - } else { - value = BigDecimal.ONE.divide(new BigDecimal(new Double(base).toString()).pow(-exponent)); - } - return value; - } - - /** - * Format the number - * - * @param value The number to be formatted - * @return The formatted number in String form - */ - private String format(BigDecimal value) { - - if (axis.getAxisType() == AxisType.NUMBER) { - - return getChart().getValueFormatter().formatNumber(value); - - } else { - - return getChart().getValueFormatter().formatDateValue(value, axis.getMin(), axis.getMax()); - } - - } - @Override public Chart getChart() { @@ -259,23 +108,23 @@ public class AxisTick implements ChartPart { // Getters ///////////////////////////////////////////////// - public List<Integer> getTickLocations() { + public Axis getAxis() { - return tickLocations; + return axis; } - public List<String> getTickLabels() { + public AxisTickLabels getAxisTickLabels() { - return tickLabels; + return axisTickLabels; } - public Axis getAxis() { + public List<Integer> getTickLocations() { - return axis; + return axisTickComputer.getTickLocations(); } - public AxisTickLabels getAxisTickLabels() { + public List<String> getTickLabels() { - return axisTickLabels; + return axisTickComputer.getTickLabels(); } } diff --git a/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/AxisTickComputer.java b/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/AxisTickComputer.java new file mode 100644 index 0000000000000000000000000000000000000000..07e8a090ba99f15f48b9108100211bd4c8ef1934 --- /dev/null +++ b/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/AxisTickComputer.java @@ -0,0 +1,153 @@ +/** + * 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; + +import java.math.BigDecimal; +import java.util.LinkedList; +import java.util.List; + +import com.xeiam.xchart.internal.chartpart.Axis.AxisType; +import com.xeiam.xchart.internal.chartpart.Axis.Direction; +import com.xeiam.xchart.internal.chartpart.gridstep.DecimalGridStep; +import com.xeiam.xchart.style.ValueFormatter; + +/** + * This class encapsulates the logic to generate the axis tick mark and axis tick label data for rendering the axis ticks + * + * @author timmolter + */ +public class AxisTickComputer { + + /** the List of tick label position in pixels */ + private List<Integer> tickLocations = new LinkedList<Integer>();; + + /** the List of tick label values */ + private List<String> tickLabels = new LinkedList<String>(); + + private final Direction axisDirection; + + private final int workingSpace; + + private final BigDecimal minValue; + + private final BigDecimal maxValue; + + private final ValueFormatter valueFormatter; + + private final AxisType axisType; + + /** + * Constructor + * + * @param axisDirection + * @param workingSpace + * @param minValue + * @param maxValue + * @param valueFormatter + * @param axisType + */ + public AxisTickComputer(Direction axisDirection, int workingSpace, BigDecimal minValue, BigDecimal maxValue, ValueFormatter valueFormatter, AxisType axisType) { + + this.axisDirection = axisDirection; + this.workingSpace = workingSpace; + this.minValue = minValue; + this.maxValue = maxValue; + this.valueFormatter = valueFormatter; + this.axisType = axisType; + + computeAxisTick(); + } + + private void computeAxisTick() { + + System.out.println("workingSpace= " + workingSpace); + + // a check if all axis data are the exact same values + if (maxValue == minValue) { + tickLabels.add(format(maxValue)); + tickLocations.add((int) (workingSpace / 2.0)); + return; + } + + // tick space - a percentage of the working space available for ticks, i.e. 95% + int tickSpace = AxisPair.getTickSpace(workingSpace); // in plot space + System.out.println("tickSpace= " + tickSpace); + + // where the tick should begin in the working space in pixels + int margin = AxisPair.getTickStartOffset(workingSpace, tickSpace); // in plot space + + // the span of the data + double span = Math.abs(maxValue.subtract(minValue).doubleValue()); // in data space + + BigDecimal gridStep = null; + BigDecimal firstPosition = null; + if (axisType == AxisType.Number) { + + DecimalGridStep decimalGridStepHelper = new DecimalGridStep(); + gridStep = decimalGridStepHelper.getGridStepForDecimal(axisDirection, span, tickSpace); + firstPosition = decimalGridStepHelper.getFirstPosition(minValue, gridStep); + + } else if (axisType == AxisType.Date) { + + } else if (axisType == AxisType.Logarithmic) { + + } + + // generate all tickLabels and tickLocations from the first to last position + for (BigDecimal tickPosition = firstPosition; tickPosition.compareTo(maxValue) <= 0; tickPosition = tickPosition.add(gridStep)) { + + tickLabels.add(format(tickPosition)); + // here we convert tickPosition finally to plot space, i.e. pixels + int tickLabelPosition = (int) (margin + ((tickPosition.subtract(minValue)).doubleValue() / (maxValue.subtract(minValue)).doubleValue() * tickSpace)); + tickLocations.add(tickLabelPosition); + } + + } + + /** + * Format the number + * + * @param value The number to be formatted + * @return The formatted number in String form + */ + private String format(BigDecimal value) { + + if (axisType == AxisType.Number) { + + return valueFormatter.formatNumber(value); + } else { + + return valueFormatter.formatDateValue(value, minValue, maxValue); + } + } + + public List<Integer> getTickLocations() { + + return tickLocations; + } + + public List<String> getTickLabels() { + + return tickLabels; + } + +} diff --git a/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/AxisTickMarks.java b/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/AxisTickMarks.java index d86526cb4b1908de5903156ea3bfb0e252bf9c9c..09ce4d7270e62da8b34014f99c0cab0622cdee1d 100644 --- a/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/AxisTickMarks.java +++ b/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/AxisTickMarks.java @@ -87,6 +87,7 @@ public class AxisTickMarks implements ChartPart { } else { // X-Axis int xOffset = (int) (axisTick.getAxis().getPaintZone().getX()); + // int yOffset = (int) (axisTick.getAxisTickLabels().getBounds().getY() - getChart().getStyleManager().getAxisTickPadding()); int yOffset = (int) (axisTick.getAxisTickLabels().getBounds().getY() - getChart().getStyleManager().getAxisTickPadding()); // tick marks 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 c34cf3280ccc1fa11b1f088374d72c91ac9259ae..86f9aa01c99d5e77c59f38498dbcb66ae09574bb 100644 --- a/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/PlotContent.java +++ b/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/PlotContent.java @@ -25,11 +25,10 @@ import java.util.Date; import java.util.Iterator; import java.util.Map; -import com.xeiam.xchart.AreaChart; import com.xeiam.xchart.Chart; -import com.xeiam.xchart.ScatterChart; import com.xeiam.xchart.internal.chartpart.Axis.AxisType; import com.xeiam.xchart.style.Series; +import com.xeiam.xchart.style.StyleManager.ChartType; /** * @author timmolter @@ -60,9 +59,6 @@ public class PlotContent implements ChartPart { @Override public void paint(Graphics2D g) { - boolean isScatterChart = getChart() instanceof ScatterChart; - boolean isAreaChart = getChart() instanceof AreaChart; - Rectangle bounds = plot.getBounds(); Map<Integer, Series> seriesMap = getChart().getAxisPair().getSeriesMap(); @@ -99,10 +95,10 @@ public class PlotContent implements ChartPart { while (xItr.hasNext()) { BigDecimal x = null; - if (getChart().getAxisPair().getxAxis().getAxisType() == AxisType.NUMBER) { + if (getChart().getAxisPair().getxAxis().getAxisType() == AxisType.Number) { x = new BigDecimal(((Number) xItr.next()).doubleValue()); } - if (getChart().getAxisPair().getxAxis().getAxisType() == AxisType.DATE) { + if (getChart().getAxisPair().getxAxis().getAxisType() == AxisType.Date) { x = new BigDecimal(((Date) xItr.next()).getTime()); // System.out.println(x); } @@ -133,17 +129,16 @@ public class PlotContent implements ChartPart { // System.out.println(yTransform); // paint line - if (series.getStroke() != null && !isScatterChart) { + 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 (isAreaChart) { + 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); @@ -151,11 +146,21 @@ public class PlotContent implements ChartPart { } } + // 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) { + if (series.getMarker() != null && getChart().getStyleManager().getChartType() != ChartType.Bar) { g.setColor(series.getMarkerColor()); series.getMarker().paint(g, xOffset, yOffset); } diff --git a/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/gridstep/DecimalGridStep.java b/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/gridstep/DecimalGridStep.java new file mode 100644 index 0000000000000000000000000000000000000000..6748e34687284a1cf9fbbdc7f466bffc786cd62d --- /dev/null +++ b/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/gridstep/DecimalGridStep.java @@ -0,0 +1,121 @@ +/** + * 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.gridstep; + +import java.math.BigDecimal; + +import com.xeiam.xchart.internal.chartpart.Axis.Direction; + +/** + * @author timmolter + */ +public class DecimalGridStep { + + /** the default tick mark step hint for x axis */ + private static final int DEFAULT_TICK_MARK_STEP_HINT_X = 74; + + /** the default tick mark step hint for y axis */ + private static final int DEFAULT_TICK_MARK_STEP_HINT_Y = 44; + + /** + * Determine the grid step for the data set given the space in pixels allocated for the axis + * + * @param tickSpace in plot space + * @return + */ + public BigDecimal getGridStepForDecimal(Direction axisDirection, double span, int tickSpace) { + + int tickMarkSpaceHint = (axisDirection == Direction.X ? DEFAULT_TICK_MARK_STEP_HINT_X : DEFAULT_TICK_MARK_STEP_HINT_Y); + + // for very short plots, squeeze some more ticks in than normal + if (axisDirection == Direction.Y && tickSpace < 160) { + tickMarkSpaceHint = 25; + } + + double gridStepHint = span / tickSpace * tickMarkSpaceHint; + + // gridStepHint --> significand * 10 ** exponent + // e.g. 724.1 --> 7.241 * 10 ** 2 + double significand = gridStepHint; + int exponent = 0; + if (significand == 0) { + exponent = 1; + } else if (significand < 1) { + while (significand < 1) { + significand *= 10.0; + exponent--; + } + } else { + while (significand >= 10) { + significand /= 10.0; + exponent++; + } + } + + // calculate the grid step with hint. + BigDecimal gridStep; + if (significand > 7.5) { + // gridStep = 10.0 * 10 ** exponent + gridStep = BigDecimal.TEN.multiply(pow(10, exponent)); + } else if (significand > 3.5) { + // gridStep = 5.0 * 10 ** exponent + gridStep = new BigDecimal(new Double(5).toString()).multiply(pow(10, exponent)); + } else if (significand > 1.5) { + // gridStep = 2.0 * 10 ** exponent + gridStep = new BigDecimal(new Double(2).toString()).multiply(pow(10, exponent)); + } else { + // gridStep = 1.0 * 10 ** exponent + gridStep = pow(10, exponent); + } + return gridStep; + } + + /** + * Calculates the value of the first argument raised to the power of the second argument. + * + * @param base the base + * @param exponent the exponent + * @return the value <tt>a<sup>b</sup></tt> in <tt>BigDecimal</tt> + */ + private BigDecimal pow(double base, int exponent) { + + BigDecimal value; + if (exponent > 0) { + value = new BigDecimal(new Double(base).toString()).pow(exponent); + } else { + value = BigDecimal.ONE.divide(new BigDecimal(new Double(base).toString()).pow(-exponent)); + } + return value; + } + + public BigDecimal getFirstPosition(final BigDecimal min, BigDecimal gridStep) { + + BigDecimal firstPosition; + if (min.remainder(gridStep).doubleValue() <= 0.0) { + firstPosition = min.subtract(min.remainder(gridStep)); + } else { + firstPosition = min.subtract(min.remainder(gridStep)).add(gridStep); + } + return firstPosition; + } + +} diff --git a/xchart/src/main/java/com/xeiam/xchart/style/Series.java b/xchart/src/main/java/com/xeiam/xchart/style/Series.java index a8a86408da5c1f138bfb69047197cfd48ad8492d..e701cd7d8d087f8917d0ca6a465a74adaf9fc3ba 100644 --- a/xchart/src/main/java/com/xeiam/xchart/style/Series.java +++ b/xchart/src/main/java/com/xeiam/xchart/style/Series.java @@ -120,10 +120,10 @@ public class Series { BigDecimal bigDecimal = null; - if (axisType == AxisType.NUMBER) { + if (axisType == AxisType.Number) { bigDecimal = new BigDecimal(((Number) dataPoint).toString()); - } else if (axisType == AxisType.DATE) { + } else if (axisType == AxisType.Date) { Date date = (Date) dataPoint; bigDecimal = new BigDecimal(date.getTime()); } diff --git a/xchart/src/main/java/com/xeiam/xchart/style/StyleManager.java b/xchart/src/main/java/com/xeiam/xchart/style/StyleManager.java index 26c91023804e79889408b8c199e5116ca6e39626..ce15199f3cd94a4d6b2306c1bd0c56f259e0a093 100644 --- a/xchart/src/main/java/com/xeiam/xchart/style/StyleManager.java +++ b/xchart/src/main/java/com/xeiam/xchart/style/StyleManager.java @@ -33,7 +33,13 @@ import com.xeiam.xchart.style.theme.XChartTheme; */ public class StyleManager { + public enum ChartType { + + Line, Scatter, Area, Bar + } + public enum LegendPosition { + OutsideW, InsideNW, InsideNE, InsideSE, InsideSW } @@ -41,6 +47,7 @@ public class StyleManager { private Theme theme = new XChartTheme(); // Chart Style /////////////////////////////// + private ChartType chartType; private Color chartBackgroundColor; public Color chartFontColor; private int chartPadding; @@ -98,6 +105,7 @@ public class StyleManager { private void setAllStyles() { // Chart Style /////////////////////////////// + chartType = ChartType.Line; chartBackgroundColor = theme.getChartBackgroundColor(); chartFontColor = theme.getChartFontColor(); chartPadding = theme.getChartPadding(); @@ -158,6 +166,21 @@ public class StyleManager { // Chart Style /////////////////////////////// + /** + * sets the Chart Type + * + * @param chartType + */ + public void setChartType(ChartType chartType) { + + this.chartType = chartType; + } + + public ChartType getChartType() { + + return chartType; + } + /** * Set the chart background color - the part around the edge of the chart * diff --git a/xchart/src/test/java/com/xeiam/xchart/chart/Example1.java b/xchart/src/test/java/com/xeiam/xchart/chart/Example1.java index 1e8f7128d85d225d1523c0086027804ef3a6a302..5dcb57f5433e0c3eb5c4c74c620db3eadca56f6f 100644 --- a/xchart/src/test/java/com/xeiam/xchart/chart/Example1.java +++ b/xchart/src/test/java/com/xeiam/xchart/chart/Example1.java @@ -17,7 +17,6 @@ package com.xeiam.xchart.chart; import com.xeiam.xchart.BitmapEncoder; import com.xeiam.xchart.Chart; -import com.xeiam.xchart.LineChart; /** * Creates a simple Chart and saves it as a PNG and JPEG image file. @@ -31,7 +30,7 @@ public class Example1 { double[] yData = new double[] { 2.0, 1.0, 0.0 }; // Create Chart - Chart chart = new LineChart(500, 400); + Chart chart = new Chart(500, 400); chart.setChartTitle("Sample Chart"); chart.setXAxisTitle("X"); chart.setYAxisTitle("Y"); diff --git a/xchart/src/test/java/com/xeiam/xchart/chart/LineChart05.java b/xchart/src/test/java/com/xeiam/xchart/chart/LineChart05.java index 5981ceb13d9de17ef4331d4af2d5848e84c8af0c..a8ede1e9c59a1e36c1c1213d9d3dad4bb4f51f21 100644 --- a/xchart/src/test/java/com/xeiam/xchart/chart/LineChart05.java +++ b/xchart/src/test/java/com/xeiam/xchart/chart/LineChart05.java @@ -16,7 +16,6 @@ package com.xeiam.xchart.chart; import com.xeiam.xchart.Chart; -import com.xeiam.xchart.LineChart; import com.xeiam.xchart.SwingWrapper; /** @@ -29,7 +28,7 @@ public class LineChart05 { public static void main(String[] args) { // Create Chart - Chart chart = new LineChart(800, 600); + Chart chart = new Chart(800, 600); // Customize Chart chart.setChartTitle("LineChart05"); diff --git a/xchart/src/test/java/com/xeiam/xchart/chart/LineChart06.java b/xchart/src/test/java/com/xeiam/xchart/chart/LineChart06.java index 7d1deabdc2fd2340c5c2ea4a7431fb37cd190cbe..d673f1a17584cfc90acaaa6a64b246f81aea54de 100644 --- a/xchart/src/test/java/com/xeiam/xchart/chart/LineChart06.java +++ b/xchart/src/test/java/com/xeiam/xchart/chart/LineChart06.java @@ -16,7 +16,6 @@ package com.xeiam.xchart.chart; import com.xeiam.xchart.Chart; -import com.xeiam.xchart.LineChart; import com.xeiam.xchart.SwingWrapper; /** @@ -29,7 +28,7 @@ public class LineChart06 { public static void main(String[] args) { // Create Chart - Chart chart = new LineChart(800, 600); + Chart chart = new Chart(800, 600); // Customize Chart chart.setChartTitle("LineChart06"); diff --git a/xchart/src/test/java/com/xeiam/xchart/chart/NoBug.java b/xchart/src/test/java/com/xeiam/xchart/chart/NoBug.java index 0fae2dd04c9fb9cdc59ba44d8ee9ec6fd73508ac..e002be5836898d742d52f1993f0a786f6624d87d 100644 --- a/xchart/src/test/java/com/xeiam/xchart/chart/NoBug.java +++ b/xchart/src/test/java/com/xeiam/xchart/chart/NoBug.java @@ -25,7 +25,6 @@ import java.util.ArrayList; import java.util.List; import com.xeiam.xchart.Chart; -import com.xeiam.xchart.LineChart; import com.xeiam.xchart.SwingWrapper; import com.xeiam.xchart.style.Series; @@ -60,7 +59,7 @@ public class NoBug { public static void main(String[] args) { for (int i = 0; i < 4; i++) { - Chart chart = new LineChart(700, 500); + Chart chart = new Chart(700, 500); plot(chart, i); new SwingWrapper(chart).displayChart(); } diff --git a/xchart/src/main/java/com/xeiam/xchart/AreaChart.java b/xchart/src/test/java/com/xeiam/xchart/unit/DecimalGridStepTest.java similarity index 65% rename from xchart/src/main/java/com/xeiam/xchart/AreaChart.java rename to xchart/src/test/java/com/xeiam/xchart/unit/DecimalGridStepTest.java index 1e5d66097b58d553c7cfa5278d93257a6d6fd1f6..265fbf938c27778cf20a8a586dcc6e17e84c7538 100644 --- a/xchart/src/main/java/com/xeiam/xchart/AreaChart.java +++ b/xchart/src/test/java/com/xeiam/xchart/unit/DecimalGridStepTest.java @@ -19,32 +19,29 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package com.xeiam.xchart; +package com.xeiam.xchart.unit; + +import java.math.BigDecimal; + +import org.junit.Test; + +import com.xeiam.xchart.internal.chartpart.Axis.Direction; +import com.xeiam.xchart.internal.chartpart.gridstep.DecimalGridStep; /** * @author timmolter */ -public class AreaChart extends Chart { +public class DecimalGridStepTest { - /** - * Constructor - * - * @param width - * @param height - */ - public AreaChart(int width, int height) { + @Test + public void testDateOneMinuteTimespan() { - super(width, height); + DecimalGridStep decimalGridStep = new DecimalGridStep(); + BigDecimal gridStep = decimalGridStep.getGridStepForDecimal(Direction.X, 30, 600); + System.out.println("gridStep= " + gridStep); + BigDecimal first = decimalGridStep.getFirstPosition(new BigDecimal(-15), gridStep); + System.out.println("first= " + first); } - /** - * Constructor - * - * @param chartBuilder - */ - public AreaChart(ChartBuilder chartBuilder) { - - super(chartBuilder); - } } diff --git a/xchart/src/test/java/com/xeiam/xchart/unit/XAxisTest.java b/xchart/src/test/java/com/xeiam/xchart/unit/XAxisTest.java new file mode 100644 index 0000000000000000000000000000000000000000..4084df72324ee49d716fbb66bfe0619f7e3db01b --- /dev/null +++ b/xchart/src/test/java/com/xeiam/xchart/unit/XAxisTest.java @@ -0,0 +1,64 @@ +/** + * 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.unit; + +import java.math.BigDecimal; +import java.util.Arrays; +import java.util.List; + +import org.junit.Test; + +import com.xeiam.xchart.internal.chartpart.Axis.AxisType; +import com.xeiam.xchart.internal.chartpart.Axis.Direction; +import com.xeiam.xchart.internal.chartpart.AxisTickComputer; +import com.xeiam.xchart.style.ValueFormatter; + +/** + * @author timmolter + */ +public class XAxisTest { + + // @Test + public void testNumber() { + + AxisTickComputer axisTickComputer = new AxisTickComputer(Direction.X, 1000, new BigDecimal(0), new BigDecimal(10), new ValueFormatter(), AxisType.Number); + // Labels + List<String> tickLabels = axisTickComputer.getTickLabels(); + System.out.println(Arrays.toString(tickLabels.toArray())); + // Locations + List<Integer> tickLocations = axisTickComputer.getTickLocations(); + System.out.println(Arrays.toString(tickLocations.toArray())); + } + + @Test + public void testDateOneMinuteTimespan() { + + AxisTickComputer axisTickComputer = new AxisTickComputer(Direction.X, 1000, new BigDecimal(1361031254000L), new BigDecimal(1361031314000L), new ValueFormatter(), AxisType.Date); + // Labels + List<String> tickLabels = axisTickComputer.getTickLabels(); + System.out.println(Arrays.toString(tickLabels.toArray())); + // Locations + List<Integer> tickLocations = axisTickComputer.getTickLocations(); + System.out.println(Arrays.toString(tickLocations.toArray())); + } + +}