diff --git a/NOTICE b/NOTICE index 8e6d9eb138b1843666791e8b4cb08e0d168c3c20..fa6f43d10569453e0d0036cda9534e0032fbc6fd 100644 --- a/NOTICE +++ b/NOTICE @@ -1,4 +1,4 @@ -Copyright 2015 Knowm Inc. (http://knowm.org) and contributors. +Copyright 2015-2016 Knowm Inc. (http://knowm.org) and contributors. Copyright 2011-2015 Xeiam LLC (http://xeiam.com) and contributors. Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/README.md b/README.md index 87ba9b686967184ed630fde74a89db3832794a0c..b91481086ffe1d229a3a63d997896dd15b91bc64 100644 --- a/README.md +++ b/README.md @@ -109,7 +109,7 @@ For snapshots, add the following to your pom.xml file: <dependency> <groupId>org.knowm.xchart</groupId> <artifactId>xchart</artifactId> - <version>2.7.0-SNAPSHOT</version> + <version>3.0.0-SNAPSHOT</version> </dependency> ``` diff --git a/pom.xml b/pom.xml index ccb912a0c64f35d695e6c8e33242eef6e48073fe..df474e78019ebca2292bcc66ec3a4673202ffbe5 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ <modelVersion>4.0.0</modelVersion> <groupId>org.knowm.xchart</groupId> <artifactId>xchart-parent</artifactId> - <version>2.7.0-SNAPSHOT</version> + <version>3.0.0-SNAPSHOT</version> <packaging>pom</packaging> <name>XChart Parent</name> <description>XChart is a light weight Java library for plotting data.</description> diff --git a/xchart-demo/pom.xml b/xchart-demo/pom.xml index 01d843b22330634dc7d6897796a246527118cd0a..9ec5d1f9dc73d3f5456fe085502b72f1a3920f4f 100644 --- a/xchart-demo/pom.xml +++ b/xchart-demo/pom.xml @@ -5,7 +5,7 @@ <parent> <groupId>org.knowm.xchart</groupId> <artifactId>xchart-parent</artifactId> - <version>2.6.2-SNAPSHOT</version> + <version>3.0.0-SNAPSHOT</version> </parent> <artifactId>xchart-demo</artifactId> @@ -17,7 +17,7 @@ <dependency> <groupId>org.knowm.xchart</groupId> <artifactId>xchart</artifactId> - <version>2.6.2-SNAPSHOT</version> + <version>3.0.0-SNAPSHOT</version> </dependency> </dependencies> diff --git a/xchart-demo/src/main/java/org/knowm/xchart/demo/ChartInfo.java b/xchart-demo/src/main/java/org/knowm/xchart/demo/ChartInfo.java index 836fe370e32c516b56866e0ecd6cb0b5a6b0ce96..5543ee420817f6e545eaa819eddf45f801470f11 100644 --- a/xchart-demo/src/main/java/org/knowm/xchart/demo/ChartInfo.java +++ b/xchart-demo/src/main/java/org/knowm/xchart/demo/ChartInfo.java @@ -1,5 +1,5 @@ /** - * Copyright 2015 Knowm Inc. (http://knowm.org) and contributors. + * Copyright 2015-2016 Knowm Inc. (http://knowm.org) and contributors. * Copyright 2011-2015 Xeiam LLC (http://xeiam.com) and contributors. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -16,7 +16,7 @@ */ package org.knowm.xchart.demo; -import org.knowm.xchart.Chart; +import org.knowm.xchart.internal.chartpart.Chart; /** * @author timmolter diff --git a/xchart-demo/src/main/java/org/knowm/xchart/demo/XChartDemo.java b/xchart-demo/src/main/java/org/knowm/xchart/demo/XChartDemo.java index 37ac297c328454b040458b3a26a2192483cea641..6c16a872d84efc5ae6ce12b7f49ea4dcdf555f06 100644 --- a/xchart-demo/src/main/java/org/knowm/xchart/demo/XChartDemo.java +++ b/xchart-demo/src/main/java/org/knowm/xchart/demo/XChartDemo.java @@ -1,5 +1,5 @@ /** - * Copyright 2015 Knowm Inc. (http://knowm.org) and contributors. + * Copyright 2015-2016 Knowm Inc. (http://knowm.org) and contributors. * Copyright 2011-2015 Xeiam LLC (http://xeiam.com) and contributors. * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/ExampleChart.java b/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/ExampleChart.java index b9424927943b2ee5e3e590a23679b29669650d6e..19631a3c6d0a81e9320b4d866b13b5dc46f2d6d2 100644 --- a/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/ExampleChart.java +++ b/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/ExampleChart.java @@ -1,5 +1,5 @@ /** - * Copyright 2015 Knowm Inc. (http://knowm.org) and contributors. + * Copyright 2015-2016 Knowm Inc. (http://knowm.org) and contributors. * Copyright 2011-2015 Xeiam LLC (http://xeiam.com) and contributors. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -16,10 +16,10 @@ */ package org.knowm.xchart.demo.charts; -import org.knowm.xchart.Chart; +import org.knowm.xchart.internal.chartpart.Chart; -public interface ExampleChart { +public interface ExampleChart<C extends Chart> { - public Chart getChart(); + public C getChart(); } diff --git a/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/area/AreaChart01.java b/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/area/AreaChart01.java index 2a2d3b377511ab65c934d3ba5447ae77769e898a..29ecd0cb6bd13f94b403dd49e93f39e7425afcbd 100644 --- a/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/area/AreaChart01.java +++ b/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/area/AreaChart01.java @@ -1,5 +1,5 @@ /** - * Copyright 2015 Knowm Inc. (http://knowm.org) and contributors. + * Copyright 2015-2016 Knowm Inc. (http://knowm.org) and contributors. * Copyright 2011-2015 Xeiam LLC (http://xeiam.com) and contributors. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -16,12 +16,13 @@ */ package org.knowm.xchart.demo.charts.area; -import org.knowm.xchart.Chart; -import org.knowm.xchart.ChartBuilder; -import org.knowm.xchart.StyleManager.ChartType; -import org.knowm.xchart.StyleManager.LegendPosition; +import org.knowm.xchart.ChartBuilderXY; +import org.knowm.xchart.Chart_XY; +import org.knowm.xchart.Series_XY.ChartXYSeriesRenderStyle; import org.knowm.xchart.SwingWrapper; import org.knowm.xchart.demo.charts.ExampleChart; +import org.knowm.xchart.internal.chartpart.Chart; +import org.knowm.xchart.internal.style.StyleManager.LegendPosition; /** * Area Chart with 3 series @@ -29,7 +30,7 @@ import org.knowm.xchart.demo.charts.ExampleChart; * Demonstrates the following: * <ul> * <li>Area Chart - * <li>Place legend at Inside-NW position + * <li>Place legend at Inside-NE position * <li>ChartBuilder */ public class AreaChart01 implements ExampleChart { @@ -45,15 +46,15 @@ public class AreaChart01 implements ExampleChart { public Chart getChart() { // Create Chart - Chart chart = new ChartBuilder().chartType(ChartType.Area).width(800).height(600).title(getClass().getSimpleName()).xAxisTitle("X").yAxisTitle("Y").build(); + Chart_XY chart = new ChartBuilderXY().width(800).height(600).title(getClass().getSimpleName()).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 }); // Customize Chart - chart.getStyleManager().setLegendPosition(LegendPosition.InsideNW); + chart.getStyleManager().setLegendPosition(LegendPosition.InsideNE); chart.getStyleManager().setAxisTitlesVisible(false); - + chart.getStyleManager().setChartXYSeriesRenderStyle(ChartXYSeriesRenderStyle.Area); return chart; } diff --git a/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/area/AreaChart02.java b/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/area/AreaChart02.java index 69968e1a161420b0731cd8df8897a1d9570fa357..2a39a6fd4fbc2c7b68af17fc24bb71917cf87783 100644 --- a/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/area/AreaChart02.java +++ b/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/area/AreaChart02.java @@ -1,5 +1,5 @@ /** - * Copyright 2015 Knowm Inc. (http://knowm.org) and contributors. + * Copyright 2015-2016 Knowm Inc. (http://knowm.org) and contributors. * Copyright 2011-2015 Xeiam LLC (http://xeiam.com) and contributors. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -19,12 +19,13 @@ package org.knowm.xchart.demo.charts.area; import java.util.ArrayList; import java.util.List; -import org.knowm.xchart.Chart; -import org.knowm.xchart.ChartBuilder; -import org.knowm.xchart.StyleManager.ChartType; -import org.knowm.xchart.StyleManager.LegendPosition; +import org.knowm.xchart.ChartBuilderXY; +import org.knowm.xchart.Chart_XY; +import org.knowm.xchart.Series_XY.ChartXYSeriesRenderStyle; import org.knowm.xchart.SwingWrapper; import org.knowm.xchart.demo.charts.ExampleChart; +import org.knowm.xchart.internal.chartpart.Chart; +import org.knowm.xchart.internal.style.StyleManager.LegendPosition; /** * Null Y-Axis Data Points @@ -48,7 +49,7 @@ public class AreaChart02 implements ExampleChart { public Chart getChart() { // Create Chart - Chart chart = new ChartBuilder().chartType(ChartType.Area).width(800).height(600).title(getClass().getSimpleName()).xAxisTitle("X").yAxisTitle("Y").build(); + Chart_XY chart = new ChartBuilderXY().width(800).height(600).title(getClass().getSimpleName()).xAxisTitle("X").yAxisTitle("Y").build(); List<Integer> xData = new ArrayList<Integer>(); List<Integer> yData = new ArrayList<Integer>(); @@ -73,6 +74,7 @@ public class AreaChart02 implements ExampleChart { chart.addSeries("a", xData, yData); // Customize Chart + chart.getStyleManager().setChartXYSeriesRenderStyle(ChartXYSeriesRenderStyle.Area); chart.getStyleManager().setLegendPosition(LegendPosition.InsideNW); return chart; diff --git a/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/area/AreaLineChart03.java b/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/area/AreaLineChart03.java index a40b5deef4693d60048567c31b9d187d5bea1678..1a683a2a585668f0c0491cd04d49da18b72e81b5 100644 --- a/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/area/AreaLineChart03.java +++ b/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/area/AreaLineChart03.java @@ -1,5 +1,5 @@ /** - * Copyright 2015 Knowm Inc. (http://knowm.org) and contributors. + * Copyright 2015-2016 Knowm Inc. (http://knowm.org) and contributors. * Copyright 2011-2015 Xeiam LLC (http://xeiam.com) and contributors. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -16,14 +16,15 @@ */ package org.knowm.xchart.demo.charts.area; -import org.knowm.xchart.Chart; -import org.knowm.xchart.Series; +import org.knowm.xchart.Chart_XY; import org.knowm.xchart.SeriesMarker; -import org.knowm.xchart.StyleManager; -import org.knowm.xchart.StyleManager.ChartType; -import org.knowm.xchart.StyleManager.LegendPosition; +import org.knowm.xchart.Series_XY; +import org.knowm.xchart.Series_XY.ChartXYSeriesRenderStyle; import org.knowm.xchart.SwingWrapper; import org.knowm.xchart.demo.charts.ExampleChart; +import org.knowm.xchart.internal.chartpart.Chart; +import org.knowm.xchart.internal.style.StyleManager; +import org.knowm.xchart.internal.style.StyleManager.LegendPosition; /** * Combination Line & Area Chart @@ -47,14 +48,14 @@ public class AreaLineChart03 implements ExampleChart { public Chart getChart() { // Create Chart - Chart chart = new Chart(800, 600); + Chart_XY chart = new Chart_XY(800, 600); // Customize Chart - chart.setChartTitle(getClass().getSimpleName()); + chart.setTitle(getClass().getSimpleName()); chart.setXAxisTitle("Age"); chart.setYAxisTitle("Amount"); chart.getStyleManager().setLegendPosition(LegendPosition.InsideNW); - chart.getStyleManager().setChartType(ChartType.Line); + chart.getStyleManager().setChartXYSeriesRenderStyle(ChartXYSeriesRenderStyle.Line); // @formatter:off double[] xAges = new double[] { 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, @@ -77,17 +78,17 @@ public class AreaLineChart03 implements ExampleChart { 565197, 496959, 421280, 358113, 276518, 195571, 109514, 13876, 29, 0, 0, 0, 0 }; // @formatter:on - Series seriesLiability = chart.addSeries("Liability", xAges, yLiability); + Series_XY seriesLiability = chart.addSeries("Liability", xAges, yLiability); seriesLiability.setMarker(SeriesMarker.NONE); - seriesLiability.setSeriesType(Series.SeriesType.Area); + seriesLiability.setChartXYSeriesRenderStyle(Series_XY.ChartXYSeriesRenderStyle.Area); - Series seriesPercentile75th = chart.addSeries("75th Percentile", xAges, yPercentile75th); + Series_XY seriesPercentile75th = chart.addSeries("75th Percentile", xAges, yPercentile75th); seriesPercentile75th.setMarker(SeriesMarker.NONE); - Series seriesPercentile50th = chart.addSeries("50th Percentile", xAges, yPercentile50th); + Series_XY seriesPercentile50th = chart.addSeries("50th Percentile", xAges, yPercentile50th); seriesPercentile50th.setMarker(SeriesMarker.NONE); - Series seriesPercentile25th = chart.addSeries("25th Percentile", xAges, yPercentile25th); + Series_XY seriesPercentile25th = chart.addSeries("25th Percentile", xAges, yPercentile25th); seriesPercentile25th.setMarker(SeriesMarker.NONE); chart.getStyleManager().setYAxisLabelAlignment(StyleManager.TextAlignment.Right); diff --git a/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/bar/BarChart01.java b/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/bar/BarChart01.java index bedf64209ee39f025f828613907ce5c753520512..8e2aef59ec2ead6e1ecf66f7bef66c98520dc74f 100644 --- a/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/bar/BarChart01.java +++ b/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/bar/BarChart01.java @@ -1,5 +1,5 @@ /** - * Copyright 2015 Knowm Inc. (http://knowm.org) and contributors. + * Copyright 2015-2016 Knowm Inc. (http://knowm.org) and contributors. * Copyright 2011-2015 Xeiam LLC (http://xeiam.com) and contributors. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,19 +18,19 @@ package org.knowm.xchart.demo.charts.bar; import java.util.Arrays; -import org.knowm.xchart.Chart; -import org.knowm.xchart.ChartBuilder; -import org.knowm.xchart.StyleManager.ChartType; -import org.knowm.xchart.StyleManager.LegendPosition; +import org.knowm.xchart.ChartBuilder_Category; +import org.knowm.xchart.Chart_Category; import org.knowm.xchart.SwingWrapper; import org.knowm.xchart.demo.charts.ExampleChart; +import org.knowm.xchart.internal.chartpart.Chart; +import org.knowm.xchart.internal.style.StyleManager.LegendPosition; /** * Basic Bar Chart * <p> * Demonstrates the following: * <ul> - * <li>Number categories + * <li>Integer categories as List * <li>All positive values * <li>Single series * <li>Place legend at Inside-NW position @@ -48,8 +48,8 @@ public class BarChart01 implements ExampleChart { public Chart getChart() { // Create Chart - Chart chart = new ChartBuilder().chartType(ChartType.Bar).width(800).height(600).title("Score Histogram").xAxisTitle("Score").yAxisTitle("Number").build(); - chart.addCategorySeries("test 1", Arrays.asList(new Integer[] { 0, 1, 2, 3, 4 }), Arrays.asList(new Integer[] { 4, 5, 9, 6, 5 })); + Chart_Category chart = new ChartBuilder_Category().width(800).height(600).title("Score Histogram").xAxisTitle("Score").yAxisTitle("Number").build(); + chart.addSeries("test 1", Arrays.asList(new Integer[] { 0, 1, 2, 3, 4 }), Arrays.asList(new Integer[] { 4, 5, 9, 6, 5 })); // Customize Chart chart.getStyleManager().setLegendPosition(LegendPosition.InsideNW); diff --git a/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/bar/BarChart02.java b/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/bar/BarChart02.java index 780a81a9c4b6968fb2ed18936c7380b7fb4f1230..0693fb8586f6a69eea86c34162e53c013bd4d299 100644 --- a/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/bar/BarChart02.java +++ b/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/bar/BarChart02.java @@ -1,5 +1,5 @@ /** - * Copyright 2015 Knowm Inc. (http://knowm.org) and contributors. + * Copyright 2015-2016 Knowm Inc. (http://knowm.org) and contributors. * Copyright 2011-2015 Xeiam LLC (http://xeiam.com) and contributors. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -24,21 +24,21 @@ import java.util.Date; import java.util.List; import java.util.Random; -import org.knowm.xchart.Chart; -import org.knowm.xchart.ChartBuilder; -import org.knowm.xchart.Series; -import org.knowm.xchart.StyleManager.ChartTheme; -import org.knowm.xchart.StyleManager.ChartType; +import org.knowm.xchart.ChartBuilder_Category; +import org.knowm.xchart.Chart_Category; +import org.knowm.xchart.Series_Category; import org.knowm.xchart.SwingWrapper; import org.knowm.xchart.demo.charts.ExampleChart; +import org.knowm.xchart.internal.chartpart.Chart; import org.knowm.xchart.internal.style.MatlabTheme; +import org.knowm.xchart.internal.style.StyleManager.ChartTheme; /** * Date Categories * <p> * Demonstrates the following: * <ul> - * <li>Date categories + * <li>Date categories as List * <li>All negative values * <li>Single series * <li>No horizontal plot gridlines @@ -58,7 +58,7 @@ public class BarChart02 implements ExampleChart { public Chart getChart() { // Create Chart - Chart chart = new ChartBuilder().theme(ChartTheme.Matlab).chartType(ChartType.Bar).width(800).height(600).title("Units Sold Per Year").xAxisTitle("Year").yAxisTitle("Units Sold").build(); + Chart_Category chart = new ChartBuilder_Category().theme(ChartTheme.Matlab).width(800).height(600).title("Units Sold Per Year").xAxisTitle("Year").yAxisTitle("Units Sold").build(); List<Date> xData = new ArrayList<Date>(); List<Number> yData = new ArrayList<Number>(); @@ -75,7 +75,7 @@ public class BarChart02 implements ExampleChart { xData.add(date); yData.add(-1 * 0.00000001 * ((random.nextInt(i) + 1))); } - Series series = chart.addCategorySeries("Model 77", xData, yData); + Series_Category series = chart.addSeries("Model 77", xData, yData); series.setLineColor(MatlabTheme.RED); chart.getStyleManager().setPlotGridLinesVisible(false); chart.getStyleManager().setBarFilled(false); diff --git a/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/bar/BarChart03.java b/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/bar/BarChart03.java index fb57944c46007bdd55b0376423ee4a4990a11cb0..dfdbe78217d922908e8bd891b898795e16180599 100644 --- a/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/bar/BarChart03.java +++ b/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/bar/BarChart03.java @@ -1,5 +1,5 @@ /** - * Copyright 2015 Knowm Inc. (http://knowm.org) and contributors. + * Copyright 2015-2016 Knowm Inc. (http://knowm.org) and contributors. * Copyright 2011-2015 Xeiam LLC (http://xeiam.com) and contributors. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -16,20 +16,18 @@ */ package org.knowm.xchart.demo.charts.bar; -import java.util.Arrays; - -import org.knowm.xchart.Chart; -import org.knowm.xchart.ChartBuilder; -import org.knowm.xchart.StyleManager.ChartType; +import org.knowm.xchart.ChartBuilder_Category; +import org.knowm.xchart.Chart_Category; import org.knowm.xchart.SwingWrapper; import org.knowm.xchart.demo.charts.ExampleChart; +import org.knowm.xchart.internal.chartpart.Chart; /** * Positive and Negative * <p> * Demonstrates the following: * <ul> - * <li>Number categories + * <li>int categories as array * <li>Positive and negative values * <li>Single series */ @@ -46,8 +44,8 @@ public class BarChart03 implements ExampleChart { public Chart getChart() { // Create Chart - Chart chart = new ChartBuilder().chartType(ChartType.Bar).width(800).height(600).title("Score vs. Age").xAxisTitle("Age").yAxisTitle("Score").build(); - chart.addCategorySeries("males", Arrays.asList(new Integer[] { 10, 20, 30, 40 }), Arrays.asList(new Integer[] { 40, -30, -20, -60 })); + Chart_Category chart = new ChartBuilder_Category().width(800).height(600).title("Score vs. Age").xAxisTitle("Age").yAxisTitle("Score").build(); + chart.addSeries("males", new int[] { 10, 20, 30, 40 }, new int[] { 40, -30, -20, -60 }); return chart; } diff --git a/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/bar/BarChart04.java b/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/bar/BarChart04.java index ed79870882a3e5da2ef48b956fd9309737929ad9..c00b78ba57933642ec5a0278eb284bfd4953ab34 100644 --- a/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/bar/BarChart04.java +++ b/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/bar/BarChart04.java @@ -1,5 +1,5 @@ /** - * Copyright 2015 Knowm Inc. (http://knowm.org) and contributors. + * Copyright 2015-2016 Knowm Inc. (http://knowm.org) and contributors. * Copyright 2011-2015 Xeiam LLC (http://xeiam.com) and contributors. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,11 +18,11 @@ package org.knowm.xchart.demo.charts.bar; import java.util.Arrays; -import org.knowm.xchart.Chart; -import org.knowm.xchart.ChartBuilder; -import org.knowm.xchart.StyleManager.ChartType; +import org.knowm.xchart.ChartBuilder_Category; +import org.knowm.xchart.Chart_Category; import org.knowm.xchart.SwingWrapper; import org.knowm.xchart.demo.charts.ExampleChart; +import org.knowm.xchart.internal.chartpart.Chart; /** * Missing Point in Series @@ -48,9 +48,9 @@ public class BarChart04 implements ExampleChart { public Chart getChart() { // Create Chart - Chart chart = new ChartBuilder().chartType(ChartType.Bar).width(800).height(600).title("XFactor vs. Age").xAxisTitle("Age").yAxisTitle("XFactor").build(); - chart.addCategorySeries("female", Arrays.asList(new Integer[] { 10, 20, 30, 40, 50 }), Arrays.asList(new Integer[] { 50, 10, 20, 40, 35 })); - chart.addCategorySeries("male", Arrays.asList(new Integer[] { 10, 20, 30, 40, 50 }), Arrays.asList(new Integer[] { 40, 30, 20, null, 60 })); + Chart_Category chart = new ChartBuilder_Category().width(800).height(600).title("XFactor vs. Age").xAxisTitle("Age").yAxisTitle("XFactor").build(); + chart.addSeries("female", Arrays.asList(new Integer[] { 10, 20, 30, 40, 50 }), Arrays.asList(new Integer[] { 50, 10, 20, 40, 35 })); + chart.addSeries("male", Arrays.asList(new Integer[] { 10, 20, 30, 40, 50 }), Arrays.asList(new Integer[] { 40, 30, 20, null, 60 })); chart.getStyleManager().setYAxisMin(5); chart.getStyleManager().setYAxisMax(70); diff --git a/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/bar/BarChart05.java b/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/bar/BarChart05.java index 7250c4cfff407f4b1d6e0411fe7de8cf1fd67c59..bdfab910088782fdf8acb865278f58cae37484ec 100644 --- a/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/bar/BarChart05.java +++ b/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/bar/BarChart05.java @@ -1,5 +1,5 @@ /** - * Copyright 2015 Knowm Inc. (http://knowm.org) and contributors. + * Copyright 2015-2016 Knowm Inc. (http://knowm.org) and contributors. * Copyright 2011-2015 Xeiam LLC (http://xeiam.com) and contributors. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -19,12 +19,12 @@ package org.knowm.xchart.demo.charts.bar; import java.util.ArrayList; import java.util.Arrays; -import org.knowm.xchart.Chart; -import org.knowm.xchart.ChartBuilder; -import org.knowm.xchart.StyleManager.ChartTheme; -import org.knowm.xchart.StyleManager.ChartType; +import org.knowm.xchart.ChartBuilder_Category; +import org.knowm.xchart.Chart_Category; import org.knowm.xchart.SwingWrapper; import org.knowm.xchart.demo.charts.ExampleChart; +import org.knowm.xchart.internal.chartpart.Chart; +import org.knowm.xchart.internal.style.StyleManager.ChartTheme; /** * GGPlot2 Theme @@ -48,17 +48,17 @@ public class BarChart05 implements ExampleChart { public Chart getChart() { // Create Chart - Chart chart = new ChartBuilder().chartType(ChartType.Bar).width(800).height(600).title("Temperature vs. Color").xAxisTitle("Color").yAxisTitle("Temperature").theme(ChartTheme.GGPlot2).build(); - chart.addCategorySeries("fish", new ArrayList<String>(Arrays.asList(new String[] { "Blue", "Red", "Green", "Yellow", "Orange" })), new ArrayList<Number>(Arrays.asList(new Number[] { -40, 30, 20, - 60, 60 }))); - chart.addCategorySeries("worms", new ArrayList<String>(Arrays.asList(new String[] { "Blue", "Red", "Green", "Yellow", "Orange" })), new ArrayList<Number>(Arrays.asList(new Number[] { 50, 10, -20, - 40, 60 }))); - chart.addCategorySeries("birds", new ArrayList<String>(Arrays.asList(new String[] { "Blue", "Red", "Green", "Yellow", "Orange" })), new ArrayList<Number>(Arrays.asList(new Number[] { 13, 22, -23, - -34, 37 }))); - chart.addCategorySeries("ants", new ArrayList<String>(Arrays.asList(new String[] { "Blue", "Red", "Green", "Yellow", "Orange" })), new ArrayList<Number>(Arrays.asList(new Number[] { 50, 57, -14, - -20, 31 }))); - chart.addCategorySeries("slugs", new ArrayList<String>(Arrays.asList(new String[] { "Blue", "Red", "Green", "Yellow", "Orange" })), new ArrayList<Number>(Arrays.asList(new Number[] { -2, 29, 49, - -16, -43 }))); + Chart_Category chart = new ChartBuilder_Category().width(800).height(600).title("Temperature vs. Color").xAxisTitle("Color").yAxisTitle("Temperature").theme(ChartTheme.GGPlot2).build(); + chart.addSeries("fish", new ArrayList<String>(Arrays.asList(new String[] { "Blue", "Red", "Green", "Yellow", "Orange" })), new ArrayList<Number>(Arrays.asList(new Number[] { -40, 30, 20, 60, + 60 }))); + chart.addSeries("worms", new ArrayList<String>(Arrays.asList(new String[] { "Blue", "Red", "Green", "Yellow", "Orange" })), new ArrayList<Number>(Arrays.asList(new Number[] { 50, 10, -20, 40, + 60 }))); + chart.addSeries("birds", new ArrayList<String>(Arrays.asList(new String[] { "Blue", "Red", "Green", "Yellow", "Orange" })), new ArrayList<Number>(Arrays.asList(new Number[] { 13, 22, -23, -34, + 37 }))); + chart.addSeries("ants", new ArrayList<String>(Arrays.asList(new String[] { "Blue", "Red", "Green", "Yellow", "Orange" })), new ArrayList<Number>(Arrays.asList(new Number[] { 50, 57, -14, -20, + 31 }))); + chart.addSeries("slugs", new ArrayList<String>(Arrays.asList(new String[] { "Blue", "Red", "Green", "Yellow", "Orange" })), new ArrayList<Number>(Arrays.asList(new Number[] { -2, 29, 49, -16, + -43 }))); return chart; } diff --git a/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/bar/BarChart06.java b/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/bar/BarChart06.java index 64c088feae9d808d14700bd4f654ffd48f21b7ed..01fa815a32e1813330ea8a71e91aa2f74af5d51a 100644 --- a/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/bar/BarChart06.java +++ b/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/bar/BarChart06.java @@ -1,5 +1,5 @@ /** - * Copyright 2015 Knowm Inc. (http://knowm.org) and contributors. + * Copyright 2015-2016 Knowm Inc. (http://knowm.org) and contributors. * Copyright 2011-2015 Xeiam LLC (http://xeiam.com) and contributors. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -20,13 +20,13 @@ import java.util.ArrayList; import java.util.List; import java.util.Random; -import org.knowm.xchart.Chart; -import org.knowm.xchart.ChartBuilder; +import org.knowm.xchart.ChartBuilder_Category; +import org.knowm.xchart.Chart_Category; import org.knowm.xchart.Histogram; -import org.knowm.xchart.StyleManager.ChartType; -import org.knowm.xchart.StyleManager.LegendPosition; import org.knowm.xchart.SwingWrapper; import org.knowm.xchart.demo.charts.ExampleChart; +import org.knowm.xchart.internal.chartpart.Chart; +import org.knowm.xchart.internal.style.StyleManager.LegendPosition; /** * Histogram Overlapped @@ -49,12 +49,12 @@ public class BarChart06 implements ExampleChart { public Chart getChart() { // Create Chart - Chart chart = new ChartBuilder().chartType(ChartType.Bar).width(800).height(600).title("Score Histogram").xAxisTitle("Mean").yAxisTitle("Count").build(); + Chart_Category chart = new ChartBuilder_Category().width(800).height(600).title("Score Histogram").xAxisTitle("Mean").yAxisTitle("Count").build(); Histogram histogram1 = new Histogram(getGaussianData(10000), 30, -30, 30); Histogram histogram2 = new Histogram(getGaussianData(5000), 30, -30, 30); - chart.addCategorySeries("histogram 1", histogram1.getxAxisData(), histogram1.getyAxisData()); - chart.addCategorySeries("histogram 2", histogram2.getxAxisData(), histogram2.getyAxisData()); + chart.addSeries("histogram 1", histogram1.getxAxisData(), histogram1.getyAxisData()); + chart.addSeries("histogram 2", histogram2.getxAxisData(), histogram2.getyAxisData()); // Customize Chart chart.getStyleManager().setLegendPosition(LegendPosition.InsideNW); diff --git a/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/bar/BarChart07.java b/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/bar/BarChart07.java index 5711df06ea911780d589e059a0a27bed7cc404ce..3932d53ac4afd0714e1923f064e5fe48124b392f 100644 --- a/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/bar/BarChart07.java +++ b/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/bar/BarChart07.java @@ -1,5 +1,5 @@ /** - * Copyright 2015 Knowm Inc. (http://knowm.org) and contributors. + * Copyright 2015-2016 Knowm Inc. (http://knowm.org) and contributors. * Copyright 2011-2015 Xeiam LLC (http://xeiam.com) and contributors. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -20,13 +20,13 @@ import java.util.ArrayList; import java.util.List; import java.util.Random; -import org.knowm.xchart.Chart; -import org.knowm.xchart.ChartBuilder; +import org.knowm.xchart.ChartBuilder_Category; +import org.knowm.xchart.Chart_Category; import org.knowm.xchart.Histogram; -import org.knowm.xchart.StyleManager.ChartType; -import org.knowm.xchart.StyleManager.LegendPosition; import org.knowm.xchart.SwingWrapper; import org.knowm.xchart.demo.charts.ExampleChart; +import org.knowm.xchart.internal.chartpart.Chart; +import org.knowm.xchart.internal.style.StyleManager.LegendPosition; /** * Histogram Not Overlapped @@ -50,12 +50,12 @@ public class BarChart07 implements ExampleChart { public Chart getChart() { // Create Chart - Chart chart = new ChartBuilder().chartType(ChartType.Bar).width(800).height(600).title("Score Histogram").xAxisTitle("Mean").yAxisTitle("Count").build(); + Chart_Category chart = new ChartBuilder_Category().width(800).height(600).title("Score Histogram").xAxisTitle("Mean").yAxisTitle("Count").build(); Histogram histogram1 = new Histogram(getGaussianData(1000), 10, -30, 30); - chart.addCategorySeries("histogram 1", histogram1.getxAxisData(), histogram1.getyAxisData()); + chart.addSeries("histogram 1", histogram1.getxAxisData(), histogram1.getyAxisData()); Histogram histogram2 = new Histogram(getGaussianData(1000), 10, -30, 30); - chart.addCategorySeries("histogram 2", histogram2.getxAxisData(), histogram2.getyAxisData()); + chart.addSeries("histogram 2", histogram2.getxAxisData(), histogram2.getyAxisData()); // Customize Chart chart.getStyleManager().setLegendPosition(LegendPosition.InsideNW); diff --git a/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/bar/BarChart08.java b/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/bar/BarChart08.java index 17725bba4b03bf3f5a1734b31b1ad9976920e1ff..799cd18142d9eb5d62d1ded4aba36f213de1ba82 100644 --- a/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/bar/BarChart08.java +++ b/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/bar/BarChart08.java @@ -1,5 +1,5 @@ /** - * Copyright 2015 Knowm Inc. (http://knowm.org) and contributors. + * Copyright 2015-2016 Knowm Inc. (http://knowm.org) and contributors. * Copyright 2011-2015 Xeiam LLC (http://xeiam.com) and contributors. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -20,13 +20,13 @@ import java.util.ArrayList; import java.util.List; import java.util.Random; -import org.knowm.xchart.Chart; -import org.knowm.xchart.ChartBuilder; +import org.knowm.xchart.ChartBuilder_Category; +import org.knowm.xchart.Chart_Category; import org.knowm.xchart.Histogram; -import org.knowm.xchart.StyleManager.ChartType; -import org.knowm.xchart.StyleManager.LegendPosition; import org.knowm.xchart.SwingWrapper; import org.knowm.xchart.demo.charts.ExampleChart; +import org.knowm.xchart.internal.chartpart.Chart; +import org.knowm.xchart.internal.style.StyleManager.LegendPosition; /** * Histogram with Error Bars @@ -49,10 +49,10 @@ public class BarChart08 implements ExampleChart { public Chart getChart() { // Create Chart - Chart chart = new ChartBuilder().chartType(ChartType.Bar).width(800).height(600).title("Histogram").xAxisTitle("Mean").yAxisTitle("Count").build(); + Chart_Category chart = new ChartBuilder_Category().width(800).height(600).title("Histogram").xAxisTitle("Mean").yAxisTitle("Count").build(); Histogram histogram1 = new Histogram(getGaussianData(10000), 10, -10, 10); - chart.addCategorySeries("histogram", histogram1.getxAxisData(), histogram1.getyAxisData(), getFakeErrorData(histogram1.getxAxisData().size())); + chart.addSeries("histogram", histogram1.getxAxisData(), histogram1.getyAxisData(), getFakeErrorData(histogram1.getxAxisData().size())); // Customize Chart chart.getStyleManager().setLegendPosition(LegendPosition.InsideNW); diff --git a/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/bar/BarChart09.java b/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/bar/BarChart09.java index 0920bc39a60f7315e179a9487c85ce261a375c54..55acc4fa65381ee7008f8a58ca65e198a0357a34 100644 --- a/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/bar/BarChart09.java +++ b/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/bar/BarChart09.java @@ -1,5 +1,5 @@ /** - * Copyright 2015 Knowm Inc. (http://knowm.org) and contributors. + * Copyright 2015-2016 Knowm Inc. (http://knowm.org) and contributors. * Copyright 2011-2015 Xeiam LLC (http://xeiam.com) and contributors. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -19,15 +19,15 @@ package org.knowm.xchart.demo.charts.bar; import java.util.ArrayList; import java.util.Arrays; -import org.knowm.xchart.Chart; -import org.knowm.xchart.ChartBuilder; -import org.knowm.xchart.Series; -import org.knowm.xchart.Series.SeriesType; -import org.knowm.xchart.StyleManager.ChartTheme; -import org.knowm.xchart.StyleManager.ChartType; -import org.knowm.xchart.StyleManager.LegendPosition; +import org.knowm.xchart.ChartBuilder_Category; +import org.knowm.xchart.Chart_Category; +import org.knowm.xchart.Series_Category; +import org.knowm.xchart.Series_Category.ChartCategorySeriesRenderStyle; import org.knowm.xchart.SwingWrapper; import org.knowm.xchart.demo.charts.ExampleChart; +import org.knowm.xchart.internal.chartpart.Chart; +import org.knowm.xchart.internal.style.StyleManager.ChartTheme; +import org.knowm.xchart.internal.style.StyleManager.LegendPosition; /** * Category chart with Bar, Line and Scatter Series @@ -50,14 +50,14 @@ public class BarChart09 implements ExampleChart { public Chart getChart() { // Create Chart - Chart chart = new ChartBuilder().chartType(ChartType.Bar).width(800).height(600).title("Value vs. Letter").xAxisTitle("Letter").yAxisTitle("Value").theme(ChartTheme.GGPlot2).build(); - chart.addCategorySeries("China", new ArrayList<String>(Arrays.asList(new String[] { "A", "B", "C", "D", "E" })), new ArrayList<Number>(Arrays.asList(new Number[] { 11, 23, 20, 36, 5 }))); - Series series2 = chart.addCategorySeries("Korea", new ArrayList<String>(Arrays.asList(new String[] { "A", "B", "C", "D", "E" })), new ArrayList<Number>(Arrays.asList(new Number[] { 13, 25, 22, 38, - 7 })), new ArrayList<Number>(Arrays.asList(new Number[] { 1, 3, 2, 1, 2 }))); - series2.setSeriesType(SeriesType.Line); - Series series3 = chart.addCategorySeries("World Ave.", new ArrayList<String>(Arrays.asList(new String[] { "A", "B", "C", "D", "E" })), new ArrayList<Number>(Arrays.asList(new Number[] { 20, 22, + Chart_Category chart = new ChartBuilder_Category().width(800).height(600).title("Value vs. Letter").xAxisTitle("Letter").yAxisTitle("Value").theme(ChartTheme.GGPlot2).build(); + chart.addSeries("China", new ArrayList<String>(Arrays.asList(new String[] { "A", "B", "C", "D", "E" })), new ArrayList<Number>(Arrays.asList(new Number[] { 11, 23, 20, 36, 5 }))); + Series_Category series2 = chart.addSeries("Korea", new ArrayList<String>(Arrays.asList(new String[] { "A", "B", "C", "D", "E" })), new ArrayList<Number>(Arrays.asList(new Number[] { 13, 25, 22, + 38, 7 })), new ArrayList<Number>(Arrays.asList(new Number[] { 1, 3, 2, 1, 2 }))); + series2.setChartCategorySeriesRenderStyle(ChartCategorySeriesRenderStyle.Line); + Series_Category series3 = chart.addSeries("World Ave.", new ArrayList<String>(Arrays.asList(new String[] { "A", "B", "C", "D", "E" })), new ArrayList<Number>(Arrays.asList(new Number[] { 20, 22, 18, 36, 32 }))); - series3.setSeriesType(SeriesType.Scatter); + series3.setChartCategorySeriesRenderStyle(ChartCategorySeriesRenderStyle.Scatter); // Customize Chart chart.getStyleManager().setLegendPosition(LegendPosition.InsideNW); diff --git a/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/date/DateChart01.java b/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/date/DateChart01.java index 3b7d00ac548ee9ab80dcd0c01ce4fc200b2e4be4..c710df9f1509013de3e80d60fe97775a028fc751 100644 --- a/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/date/DateChart01.java +++ b/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/date/DateChart01.java @@ -1,5 +1,5 @@ /** - * Copyright 2015 Knowm Inc. (http://knowm.org) and contributors. + * Copyright 2015-2016 Knowm Inc. (http://knowm.org) and contributors. * Copyright 2011-2015 Xeiam LLC (http://xeiam.com) and contributors. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -24,12 +24,13 @@ import java.util.Date; import java.util.List; import java.util.Random; -import org.knowm.xchart.Chart; -import org.knowm.xchart.ChartBuilder; -import org.knowm.xchart.Series; +import org.knowm.xchart.ChartBuilderXY; +import org.knowm.xchart.Chart_XY; import org.knowm.xchart.SeriesMarker; +import org.knowm.xchart.Series_XY; import org.knowm.xchart.SwingWrapper; import org.knowm.xchart.demo.charts.ExampleChart; +import org.knowm.xchart.internal.chartpart.Chart; /** * Millisecond Scale @@ -52,7 +53,7 @@ public class DateChart01 implements ExampleChart { public Chart getChart() { // Create Chart - Chart chart = new ChartBuilder().width(800).height(600).title("Millisecond Scale").build(); + Chart_XY chart = new ChartBuilderXY().width(800).height(600).title("Millisecond Scale").build(); chart.getStyleManager().setLegendVisible(false); Random random = new Random(); @@ -76,7 +77,7 @@ public class DateChart01 implements ExampleChart { yData.add(Math.random() * i); } - Series series = chart.addSeries("blah", xData, yData); + Series_XY series = chart.addSeries("blah", xData, yData); series.setMarker(SeriesMarker.NONE); return chart; diff --git a/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/date/DateChart02.java b/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/date/DateChart02.java index 311db555ead52ca89aef0fa1615d3fa446bf73cc..9a917e7fd90ce02be47b66edc17c79dc9c91efb9 100644 --- a/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/date/DateChart02.java +++ b/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/date/DateChart02.java @@ -1,5 +1,5 @@ /** - * Copyright 2015 Knowm Inc. (http://knowm.org) and contributors. + * Copyright 2015-2016 Knowm Inc. (http://knowm.org) and contributors. * Copyright 2011-2015 Xeiam LLC (http://xeiam.com) and contributors. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -24,10 +24,11 @@ import java.util.Date; import java.util.List; import java.util.Random; -import org.knowm.xchart.Chart; -import org.knowm.xchart.ChartBuilder; +import org.knowm.xchart.ChartBuilderXY; +import org.knowm.xchart.Chart_XY; import org.knowm.xchart.SwingWrapper; import org.knowm.xchart.demo.charts.ExampleChart; +import org.knowm.xchart.internal.chartpart.Chart; /** * Second Scale @@ -45,7 +46,7 @@ public class DateChart02 implements ExampleChart { public Chart getChart() { // Create Chart - Chart chart = new ChartBuilder().width(800).height(600).title("Second Scale").build(); + Chart_XY chart = new ChartBuilderXY().width(800).height(600).title("Second Scale").build(); chart.getStyleManager().setLegendVisible(false); // generate data diff --git a/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/date/DateChart03.java b/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/date/DateChart03.java index d8e14b084715475153f63ad076f80180c430c914..5e9519b882389f77bfc55abab6035a6c9956113e 100644 --- a/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/date/DateChart03.java +++ b/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/date/DateChart03.java @@ -1,5 +1,5 @@ /** - * Copyright 2015 Knowm Inc. (http://knowm.org) and contributors. + * Copyright 2015-2016 Knowm Inc. (http://knowm.org) and contributors. * Copyright 2011-2015 Xeiam LLC (http://xeiam.com) and contributors. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -24,10 +24,11 @@ import java.util.Date; import java.util.List; import java.util.Random; -import org.knowm.xchart.Chart; -import org.knowm.xchart.ChartBuilder; +import org.knowm.xchart.ChartBuilderXY; +import org.knowm.xchart.Chart_XY; import org.knowm.xchart.SwingWrapper; import org.knowm.xchart.demo.charts.ExampleChart; +import org.knowm.xchart.internal.chartpart.Chart; /** * Minute Scale @@ -45,7 +46,7 @@ public class DateChart03 implements ExampleChart { public Chart getChart() { // Create Chart - Chart chart = new ChartBuilder().width(800).height(600).title("Minute Scale").build(); + Chart_XY chart = new ChartBuilderXY().width(800).height(600).title("Minute Scale").build(); chart.getStyleManager().setLegendVisible(false); // generate data diff --git a/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/date/DateChart04.java b/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/date/DateChart04.java index 54afe53fa35c332188ec471b676a430319d22ad3..ad26c13de77170a53bfddfe318d73ece4dfbd383 100644 --- a/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/date/DateChart04.java +++ b/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/date/DateChart04.java @@ -1,5 +1,5 @@ /** - * Copyright 2015 Knowm Inc. (http://knowm.org) and contributors. + * Copyright 2015-2016 Knowm Inc. (http://knowm.org) and contributors. * Copyright 2011-2015 Xeiam LLC (http://xeiam.com) and contributors. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -24,10 +24,11 @@ import java.util.Date; import java.util.List; import java.util.Random; -import org.knowm.xchart.Chart; -import org.knowm.xchart.ChartBuilder; +import org.knowm.xchart.ChartBuilderXY; +import org.knowm.xchart.Chart_XY; import org.knowm.xchart.SwingWrapper; import org.knowm.xchart.demo.charts.ExampleChart; +import org.knowm.xchart.internal.chartpart.Chart; /** * Hour Scale @@ -45,7 +46,7 @@ public class DateChart04 implements ExampleChart { public Chart getChart() { // Create Chart - Chart chart = new ChartBuilder().width(800).height(600).title("Hour Scale").build(); + Chart_XY chart = new ChartBuilderXY().width(800).height(600).title("Hour Scale").build(); chart.getStyleManager().setLegendVisible(false); // generate data diff --git a/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/date/DateChart05.java b/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/date/DateChart05.java index f195812ce6adef4b85e7ea5fd8bebfa9c6d7b039..34b7b78afb454d2255277d8b401310326353a628 100644 --- a/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/date/DateChart05.java +++ b/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/date/DateChart05.java @@ -1,5 +1,5 @@ /** - * Copyright 2015 Knowm Inc. (http://knowm.org) and contributors. + * Copyright 2015-2016 Knowm Inc. (http://knowm.org) and contributors. * Copyright 2011-2015 Xeiam LLC (http://xeiam.com) and contributors. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -24,10 +24,11 @@ import java.util.Date; import java.util.List; import java.util.Random; -import org.knowm.xchart.Chart; -import org.knowm.xchart.ChartBuilder; +import org.knowm.xchart.ChartBuilderXY; +import org.knowm.xchart.Chart_XY; import org.knowm.xchart.SwingWrapper; import org.knowm.xchart.demo.charts.ExampleChart; +import org.knowm.xchart.internal.chartpart.Chart; /** * Day Scale @@ -45,7 +46,7 @@ public class DateChart05 implements ExampleChart { public Chart getChart() { // Create Chart - Chart chart = new ChartBuilder().width(800).height(600).title("Day Scale").build(); + Chart_XY chart = new ChartBuilderXY().width(800).height(600).title("Day Scale").build(); chart.getStyleManager().setLegendVisible(false); // generate data diff --git a/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/date/DateChart06.java b/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/date/DateChart06.java index de3afa5485c58a080a7db026905095015c99cbc3..0c97fe00b283386ebf4647b8cea02ff38cb39b7f 100644 --- a/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/date/DateChart06.java +++ b/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/date/DateChart06.java @@ -1,5 +1,5 @@ /** - * Copyright 2015 Knowm Inc. (http://knowm.org) and contributors. + * Copyright 2015-2016 Knowm Inc. (http://knowm.org) and contributors. * Copyright 2011-2015 Xeiam LLC (http://xeiam.com) and contributors. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -24,10 +24,11 @@ import java.util.Date; import java.util.List; import java.util.Random; -import org.knowm.xchart.Chart; -import org.knowm.xchart.ChartBuilder; +import org.knowm.xchart.ChartBuilderXY; +import org.knowm.xchart.Chart_XY; import org.knowm.xchart.SwingWrapper; import org.knowm.xchart.demo.charts.ExampleChart; +import org.knowm.xchart.internal.chartpart.Chart; /** * Month scale @@ -45,7 +46,7 @@ public class DateChart06 implements ExampleChart { public Chart getChart() { // Create Chart - Chart chart = new ChartBuilder().width(800).height(600).title("Month Scale").build(); + Chart_XY chart = new ChartBuilderXY().width(800).height(600).title("Month Scale").build(); chart.getStyleManager().setLegendVisible(false); // generate data diff --git a/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/date/DateChart07.java b/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/date/DateChart07.java index f7693202f2ee19953dac7f109a37c87533064378..f357f4f1d2c67e1b6ef30894c0b301768efd8bef 100644 --- a/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/date/DateChart07.java +++ b/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/date/DateChart07.java @@ -1,5 +1,5 @@ /** - * Copyright 2015 Knowm Inc. (http://knowm.org) and contributors. + * Copyright 2015-2016 Knowm Inc. (http://knowm.org) and contributors. * Copyright 2011-2015 Xeiam LLC (http://xeiam.com) and contributors. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -24,10 +24,11 @@ import java.util.Date; import java.util.List; import java.util.Random; -import org.knowm.xchart.Chart; -import org.knowm.xchart.ChartBuilder; +import org.knowm.xchart.ChartBuilderXY; +import org.knowm.xchart.Chart_XY; import org.knowm.xchart.SwingWrapper; import org.knowm.xchart.demo.charts.ExampleChart; +import org.knowm.xchart.internal.chartpart.Chart; /** * Year scale @@ -45,7 +46,7 @@ public class DateChart07 implements ExampleChart { public Chart getChart() { // Create Chart - Chart chart = new ChartBuilder().width(800).height(600).title("Year Scale").build(); + Chart_XY chart = new ChartBuilderXY().width(800).height(600).title("Year Scale").build(); chart.getStyleManager().setLegendVisible(false); // generate data diff --git a/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/date/DateChart08.java b/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/date/DateChart08.java index bbd60e18d1bbc3e5a6e45ff5b3235372f985c6c4..f8def44c033be1dc08e8a15120df482e46163542 100644 --- a/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/date/DateChart08.java +++ b/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/date/DateChart08.java @@ -1,5 +1,5 @@ /** - * Copyright 2015 Knowm Inc. (http://knowm.org) and contributors. + * Copyright 2015-2016 Knowm Inc. (http://knowm.org) and contributors. * Copyright 2011-2015 Xeiam LLC (http://xeiam.com) and contributors. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -24,10 +24,11 @@ import java.util.Date; import java.util.List; import java.util.Random; -import org.knowm.xchart.Chart; -import org.knowm.xchart.ChartBuilder; +import org.knowm.xchart.ChartBuilderXY; +import org.knowm.xchart.Chart_XY; import org.knowm.xchart.SwingWrapper; import org.knowm.xchart.demo.charts.ExampleChart; +import org.knowm.xchart.internal.chartpart.Chart; /** * Year scale @@ -50,7 +51,7 @@ public class DateChart08 implements ExampleChart { public Chart getChart() { // Create Chart - Chart chart = new ChartBuilder().width(800).height(600).title("Rotated Tick Labels").build(); + Chart_XY chart = new ChartBuilderXY().width(800).height(600).title("Rotated Tick Labels").build(); chart.getStyleManager().setLegendVisible(false); chart.getStyleManager().setXAxisLabelRotation(60); chart.getStyleManager().setDatePattern("yyyy-MM-dd"); diff --git a/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/line/LineChart01.java b/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/line/LineChart01.java index e8846a4acdad2417c526f4d3af341dffa8aad061..cd2e519ace7e87a5bd6e90c978b03e89ad095926 100644 --- a/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/line/LineChart01.java +++ b/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/line/LineChart01.java @@ -1,5 +1,5 @@ /** - * Copyright 2015 Knowm Inc. (http://knowm.org) and contributors. + * Copyright 2015-2016 Knowm Inc. (http://knowm.org) and contributors. * Copyright 2011-2015 Xeiam LLC (http://xeiam.com) and contributors. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -19,11 +19,12 @@ package org.knowm.xchart.demo.charts.line; import java.util.ArrayList; import java.util.List; -import org.knowm.xchart.Chart; -import org.knowm.xchart.ChartBuilder; -import org.knowm.xchart.StyleManager.LegendPosition; +import org.knowm.xchart.ChartBuilderXY; +import org.knowm.xchart.Chart_XY; import org.knowm.xchart.SwingWrapper; import org.knowm.xchart.demo.charts.ExampleChart; +import org.knowm.xchart.internal.chartpart.Chart; +import org.knowm.xchart.internal.style.StyleManager.LegendPosition; /** * Logarithmic Y-Axis @@ -55,10 +56,10 @@ public class LineChart01 implements ExampleChart { } // Create Chart - Chart chart = new ChartBuilder().width(800).height(600).build(); + Chart_XY chart = new ChartBuilderXY().width(800).height(600).title("Powers of Ten").xAxisTitle("Power").yAxisTitle("Value").build(); // Customize Chart - chart.getStyleManager().setChartTitleVisible(false); + chart.getStyleManager().setChartTitleVisible(true); chart.getStyleManager().setLegendPosition(LegendPosition.InsideNW); chart.getStyleManager().setYAxisLogarithmic(true); // chart.getStyleManager().setXAxisLabelAlignment(TextAlignment.Right); diff --git a/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/line/LineChart02.java b/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/line/LineChart02.java index e4333adacdebb3aba4fc78c541250a26cefbc5c5..435e344c67b441f598ce946908073f55265f70ee 100644 --- a/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/line/LineChart02.java +++ b/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/line/LineChart02.java @@ -1,5 +1,5 @@ /** - * Copyright 2015 Knowm Inc. (http://knowm.org) and contributors. + * Copyright 2015-2016 Knowm Inc. (http://knowm.org) and contributors. * Copyright 2011-2015 Xeiam LLC (http://xeiam.com) and contributors. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -19,13 +19,14 @@ package org.knowm.xchart.demo.charts.line; import java.util.ArrayList; import java.util.List; -import org.knowm.xchart.Chart; -import org.knowm.xchart.Series; +import org.knowm.xchart.Chart_XY; import org.knowm.xchart.SeriesLineStyle; import org.knowm.xchart.SeriesMarker; +import org.knowm.xchart.Series_XY; import org.knowm.xchart.SwingWrapper; import org.knowm.xchart.demo.charts.ExampleChart; -import org.knowm.xchart.internal.style.XChartTheme; +import org.knowm.xchart.internal.chartpart.Chart; +import org.knowm.xchart.internal.style.colors.XChartSeriesColors; /** * Sine wave with customized series style @@ -57,17 +58,17 @@ public class LineChart02 implements ExampleChart { } // Create Chart - Chart chart = new Chart(800, 600); + Chart_XY chart = new Chart_XY(800, 600); // Customize Chart chart.getStyleManager().setChartTitleVisible(false); chart.getStyleManager().setLegendVisible(false); // Series 1 - Series series1 = chart.addSeries("y=sin(x)", xData, yData); - series1.setLineColor(XChartTheme.PURPLE); + Series_XY series1 = chart.addSeries("y=sin(x)", xData, yData); + series1.setLineColor(XChartSeriesColors.PURPLE); series1.setLineStyle(SeriesLineStyle.DASH_DASH); - series1.setMarkerColor(XChartTheme.GREEN); + series1.setMarkerColor(XChartSeriesColors.GREEN); series1.setMarker(SeriesMarker.SQUARE); return chart; diff --git a/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/line/LineChart03.java b/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/line/LineChart03.java index 6a919496d08953361ac741e24f6e9614935eb011..edd28b755430f36b97c0237ba7c99185f46042ca 100644 --- a/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/line/LineChart03.java +++ b/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/line/LineChart03.java @@ -1,5 +1,5 @@ /** - * Copyright 2015 Knowm Inc. (http://knowm.org) and contributors. + * Copyright 2015-2016 Knowm Inc. (http://knowm.org) and contributors. * Copyright 2011-2015 Xeiam LLC (http://xeiam.com) and contributors. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -26,15 +26,16 @@ import java.util.Date; import java.util.List; import java.util.Locale; -import org.knowm.xchart.Chart; import org.knowm.xchart.ChartColor; -import org.knowm.xchart.Series; +import org.knowm.xchart.Chart_XY; import org.knowm.xchart.SeriesLineStyle; import org.knowm.xchart.SeriesMarker; -import org.knowm.xchart.StyleManager.LegendPosition; +import org.knowm.xchart.Series_XY; import org.knowm.xchart.SwingWrapper; import org.knowm.xchart.demo.charts.ExampleChart; -import org.knowm.xchart.internal.style.XChartTheme; +import org.knowm.xchart.internal.chartpart.Chart; +import org.knowm.xchart.internal.style.StyleManager.LegendPosition; +import org.knowm.xchart.internal.style.colors.XChartSeriesColors; /** * Extensive Chart Customization @@ -52,7 +53,7 @@ public class LineChart03 implements ExampleChart { public Chart getChart() { // Create Chart - Chart chart = new Chart(800, 600); + Chart_XY chart = new Chart_XY(800, 600); // generates linear data List<Date> xData = new ArrayList<Date>(); @@ -72,7 +73,7 @@ public class LineChart03 implements ExampleChart { } // Customize Chart - chart.setChartTitle("LineChart03"); + chart.setTitle("LineChart03"); chart.setXAxisTitle("X"); chart.setYAxisTitle("Y"); chart.getStyleManager().setPlotBackgroundColor(ChartColor.getAWTColor(ChartColor.GREY)); @@ -101,8 +102,8 @@ public class LineChart03 implements ExampleChart { chart.getStyleManager().setDecimalPattern("#0.000"); chart.getStyleManager().setLocale(Locale.GERMAN); - Series series = chart.addSeries("Fake Data", xData, yData); - series.setLineColor(XChartTheme.BLUE); + Series_XY series = chart.addSeries("Fake Data", xData, yData); + series.setLineColor(XChartSeriesColors.BLUE); series.setMarkerColor(Color.ORANGE); series.setMarker(SeriesMarker.CIRCLE); series.setLineStyle(SeriesLineStyle.SOLID); diff --git a/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/line/LineChart04.java b/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/line/LineChart04.java index 4925c568a8b76093800d7ee3a3b0d87ba9d1673e..0712ee83c695de8e5557e9ec0adf984b6a7cb332 100644 --- a/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/line/LineChart04.java +++ b/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/line/LineChart04.java @@ -1,5 +1,5 @@ /** - * Copyright 2015 Knowm Inc. (http://knowm.org) and contributors. + * Copyright 2015-2016 Knowm Inc. (http://knowm.org) and contributors. * Copyright 2011-2015 Xeiam LLC (http://xeiam.com) and contributors. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -16,13 +16,14 @@ */ package org.knowm.xchart.demo.charts.line; -import org.knowm.xchart.Chart; -import org.knowm.xchart.Series; +import org.knowm.xchart.Chart_XY; import org.knowm.xchart.SeriesLineStyle; import org.knowm.xchart.SeriesMarker; +import org.knowm.xchart.Series_XY; import org.knowm.xchart.SwingWrapper; import org.knowm.xchart.demo.charts.ExampleChart; -import org.knowm.xchart.internal.style.XChartTheme; +import org.knowm.xchart.internal.chartpart.Chart; +import org.knowm.xchart.internal.style.colors.XChartSeriesColors; /** * Hundreds of Series on One Plot @@ -40,20 +41,20 @@ public class LineChart04 implements ExampleChart { public Chart getChart() { // Create Chart - Chart chart = new Chart(800, 600); + Chart_XY chart = new Chart_XY(800, 600); // Customize Chart - chart.setChartTitle("LineChart04"); + chart.setTitle("LineChart04"); chart.setXAxisTitle("X"); chart.setYAxisTitle("Y"); chart.getStyleManager().setLegendVisible(false); for (int i = 0; i < 200; i++) { - Series series = chart.addSeries("A" + i, new double[] { Math.random() / 1000, Math.random() / 1000 }, new double[] { Math.random() / -1000, Math.random() / -1000 }); - series.setLineColor(XChartTheme.BLUE); + Series_XY series = chart.addSeries("A" + i, new double[] { Math.random() / 1000, Math.random() / 1000 }, new double[] { Math.random() / -1000, Math.random() / -1000 }); + series.setLineColor(XChartSeriesColors.BLUE); series.setLineStyle(SeriesLineStyle.SOLID); series.setMarker(SeriesMarker.CIRCLE); - series.setMarkerColor(XChartTheme.BLUE); + series.setMarkerColor(XChartSeriesColors.BLUE); } diff --git a/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/line/LineChart05.java b/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/line/LineChart05.java index 49ecf60221897f8efa0c7d91c9e34d613b5931c9..dab6163b3e7346b630b145c1c42391c5e1a051ff 100644 --- a/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/line/LineChart05.java +++ b/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/line/LineChart05.java @@ -1,5 +1,5 @@ /** - * Copyright 2015 Knowm Inc. (http://knowm.org) and contributors. + * Copyright 2015-2016 Knowm Inc. (http://knowm.org) and contributors. * Copyright 2011-2015 Xeiam LLC (http://xeiam.com) and contributors. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,13 +18,14 @@ package org.knowm.xchart.demo.charts.line; import java.awt.Color; -import org.knowm.xchart.Chart; -import org.knowm.xchart.Series; +import org.knowm.xchart.Chart_XY; import org.knowm.xchart.SeriesLineStyle; import org.knowm.xchart.SeriesMarker; -import org.knowm.xchart.StyleManager.LegendPosition; +import org.knowm.xchart.Series_XY; import org.knowm.xchart.SwingWrapper; import org.knowm.xchart.demo.charts.ExampleChart; +import org.knowm.xchart.internal.chartpart.Chart; +import org.knowm.xchart.internal.style.StyleManager.LegendPosition; /** * Scatter and Line @@ -49,10 +50,10 @@ public class LineChart05 implements ExampleChart { public Chart getChart() { // Create Chart - Chart chart = new Chart(800, 600); + Chart_XY chart = new Chart_XY(800, 600); // Customize Chart - chart.setChartTitle("LineChart05"); + chart.setTitle("LineChart05"); chart.setXAxisTitle("X"); chart.setYAxisTitle("Y"); chart.getStyleManager().setLegendPosition(LegendPosition.InsideSW); @@ -61,12 +62,12 @@ public class LineChart05 implements ExampleChart { double[] yData = new double[] { 106, 44, 26, 10, 7.5, 3.4, .88 }; double[] yData2 = new double[] { 102, 49, 23.6, 11.3, 5.4, 2.6, 1.25 }; - Series series = chart.addSeries("A", xData, yData); + Series_XY series = chart.addSeries("A", xData, yData); series.setLineStyle(SeriesLineStyle.NONE); series.setMarker(SeriesMarker.DIAMOND); series.setMarkerColor(Color.BLACK); - Series series2 = chart.addSeries("B", xData, yData2); + Series_XY series2 = chart.addSeries("B", xData, yData2); series2.setMarker(SeriesMarker.NONE); series2.setLineStyle(SeriesLineStyle.DASH_DASH); series2.setLineColor(Color.BLACK); diff --git a/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/line/LineChart06.java b/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/line/LineChart06.java index 522c6bf3e3518a68f646fd4217ccf862d077c102..72f8db5c2024299e0f57b3424f093b6b278c3c5f 100644 --- a/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/line/LineChart06.java +++ b/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/line/LineChart06.java @@ -1,5 +1,5 @@ /** - * Copyright 2015 Knowm Inc. (http://knowm.org) and contributors. + * Copyright 2015-2016 Knowm Inc. (http://knowm.org) and contributors. * Copyright 2011-2015 Xeiam LLC (http://xeiam.com) and contributors. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,12 +18,13 @@ package org.knowm.xchart.demo.charts.line; import java.awt.Color; -import org.knowm.xchart.Chart; -import org.knowm.xchart.Series; +import org.knowm.xchart.Chart_XY; import org.knowm.xchart.SeriesLineStyle; import org.knowm.xchart.SeriesMarker; +import org.knowm.xchart.Series_XY; import org.knowm.xchart.SwingWrapper; import org.knowm.xchart.demo.charts.ExampleChart; +import org.knowm.xchart.internal.chartpart.Chart; /** * Logarithmic Y-Axis with Error Bars @@ -53,7 +54,7 @@ public class LineChart06 implements ExampleChart { int[] errdata = new int[] { 50, 20, 10, 52, 9, 2, 1 }; - Chart chart = new Chart(800, 600); + Chart_XY chart = new Chart_XY(800, 600); chart.getStyleManager().setYAxisLogarithmic(true); @@ -63,13 +64,13 @@ public class LineChart06 implements ExampleChart { chart.getStyleManager().setErrorBarsColor(Color.black); - Series series1 = chart.addSeries("Error bar\ntest data", xData, yData1, errdata); + Series_XY series1 = chart.addSeries("Error bar\ntest data", xData, yData1, errdata); series1.setLineStyle(SeriesLineStyle.SOLID); series1.setMarker(SeriesMarker.DIAMOND); - series1.setMarkerColor(Color.MAGENTA); + series1.setMarkerColor(Color.GREEN); return chart; } diff --git a/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/line/LineChart07.java b/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/line/LineChart07.java index 4cfb46349386edc4ef8e0db8d36f6a5d8bdfaf33..edd78b03de51b38c1895b6a6d2caafec66e6aba8 100644 --- a/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/line/LineChart07.java +++ b/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/line/LineChart07.java @@ -1,5 +1,5 @@ /** - * Copyright 2015 Knowm Inc. (http://knowm.org) and contributors. + * Copyright 2015-2016 Knowm Inc. (http://knowm.org) and contributors. * Copyright 2011-2015 Xeiam LLC (http://xeiam.com) and contributors. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -19,15 +19,15 @@ package org.knowm.xchart.demo.charts.line; import java.util.Arrays; import java.util.List; -import org.knowm.xchart.Chart; -import org.knowm.xchart.Series; -import org.knowm.xchart.Series.SeriesType; +import org.knowm.xchart.Chart_Category; import org.knowm.xchart.SeriesMarker; -import org.knowm.xchart.StyleManager.ChartTheme; -import org.knowm.xchart.StyleManager.ChartType; -import org.knowm.xchart.StyleManager.LegendPosition; +import org.knowm.xchart.Series_Category; +import org.knowm.xchart.Series_Category.ChartCategorySeriesRenderStyle; import org.knowm.xchart.SwingWrapper; import org.knowm.xchart.demo.charts.ExampleChart; +import org.knowm.xchart.internal.chartpart.Chart; +import org.knowm.xchart.internal.style.StyleManager.ChartTheme; +import org.knowm.xchart.internal.style.StyleManager.LegendPosition; /** * Line chart with multiple Category Series @@ -50,11 +50,11 @@ public class LineChart07 implements ExampleChart { public Chart getChart() { // Create Chart - Chart chart = new Chart(1024, 768, ChartTheme.GGPlot2); - chart.getStyleManager().setChartType(ChartType.Line); + Chart_Category chart = new Chart_Category(1024, 768, ChartTheme.GGPlot2); + chart.getStyleManager().setChartCategorySeriesRenderStyle(ChartCategorySeriesRenderStyle.Line); // Customize Chart - chart.setChartTitle("ThreadPoolBenchmark"); + chart.setTitle("ThreadPoolBenchmark"); chart.setXAxisTitle("Threads"); chart.setYAxisTitle("Executions"); chart.getStyleManager().setXAxisLabelRotation(270); @@ -95,9 +95,9 @@ public class LineChart07 implements ExampleChart { // Add data series to chart for (int i = 0; i < seriesNames.length; i++) { - Series series = chart.addCategorySeries(seriesNames[i], xAxisKeys, Arrays.asList(dataPerSeries[i])); + Series_Category series = chart.addSeries(seriesNames[i], xAxisKeys, Arrays.asList(dataPerSeries[i])); series.setMarker(SeriesMarker.NONE); - series.setSeriesType(SeriesType.Line); + // series.setChartCategorySeriesRenderStyle(ChartCategorySeriesRenderStyle.Line); } chart.getStyleManager().setYAxisLogarithmic(true); diff --git a/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/pie/PieChart01.java b/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/pie/PieChart01.java index a30d580ae9c6b3e86a7cc220ca34459686e887e5..37779bfbd9ea59b606b25772f22db5d314e87f9a 100644 --- a/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/pie/PieChart01.java +++ b/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/pie/PieChart01.java @@ -1,5 +1,5 @@ /** - * Copyright 2015 Knowm Inc. (http://knowm.org) and contributors. + * Copyright 2015-2016 Knowm Inc. (http://knowm.org) and contributors. * Copyright 2011-2015 Xeiam LLC (http://xeiam.com) and contributors. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -16,9 +16,8 @@ */ package org.knowm.xchart.demo.charts.pie; -import org.knowm.xchart.Chart; -import org.knowm.xchart.ChartBuilder; -import org.knowm.xchart.StyleManager.ChartType; +import org.knowm.xchart.ChartBuilderPie; +import org.knowm.xchart.Chart_Pie; import org.knowm.xchart.SwingWrapper; import org.knowm.xchart.demo.charts.ExampleChart; @@ -30,25 +29,25 @@ import org.knowm.xchart.demo.charts.ExampleChart; * <li>Pie Chart * <li>ChartBuilder */ -public class PieChart01 implements ExampleChart { +public class PieChart01 implements ExampleChart<Chart_Pie> { public static void main(String[] args) { - ExampleChart exampleChart = new PieChart01(); - Chart chart = exampleChart.getChart(); + ExampleChart<Chart_Pie> exampleChart = new PieChart01(); + Chart_Pie chart = exampleChart.getChart(); new SwingWrapper(chart).displayChart(); } @Override - public Chart getChart() { + public Chart_Pie getChart() { // Create Chart // TODO remove chartType(ChartType.Pie) - Chart chart = new ChartBuilder().chartType(ChartType.Pie).width(800).height(600).title(getClass().getSimpleName()).xAxisTitle("X").yAxisTitle("Y").build(); - chart.addPieSeries("Pennies", 387); - chart.addPieSeries("Nickels", 234); - chart.addPieSeries("Dimes", 190); - chart.addPieSeries("Quarters", 270); + Chart_Pie chart = new ChartBuilderPie().width(800).height(600).title(getClass().getSimpleName()).build(); + chart.addSeries("Pennies", 387); + chart.addSeries("Nickels", 234); + chart.addSeries("Dimes", 190); + chart.addSeries("Quarters", 270); return chart; } diff --git a/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/realtime/RealtimeChart01.java b/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/realtime/RealtimeChart01.java index b9b39f3ed6e9a7013c92572cdf5a250f58c7d0a1..d41aca2edc38f6c5c0ff32ec93fd8c07107da569 100644 --- a/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/realtime/RealtimeChart01.java +++ b/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/realtime/RealtimeChart01.java @@ -1,5 +1,5 @@ /** - * Copyright 2015 Knowm Inc. (http://knowm.org) and contributors. + * Copyright 2015-2016 Knowm Inc. (http://knowm.org) and contributors. * Copyright 2011-2015 Xeiam LLC (http://xeiam.com) and contributors. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -23,9 +23,10 @@ import java.util.concurrent.CopyOnWriteArrayList; import javax.swing.JFrame; -import org.knowm.xchart.Chart; +import org.knowm.xchart.Chart_XY; import org.knowm.xchart.XChartPanel; import org.knowm.xchart.demo.charts.ExampleChart; +import org.knowm.xchart.internal.chartpart.Chart; /** * Realtime @@ -92,8 +93,8 @@ public class RealtimeChart01 implements ExampleChart { yData = getRandomData(5); // Create Chart - Chart chart = new Chart(500, 400); - chart.setChartTitle("Sample Real-time Chart"); + Chart_XY chart = new Chart_XY(500, 400); + chart.setTitle("Sample Real-time Chart"); chart.setXAxisTitle("X"); chart.setYAxisTitle("Y"); chart.addSeries(SERIES_NAME, null, yData); diff --git a/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/realtime/RealtimeChart02.java b/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/realtime/RealtimeChart02.java index c8fa94900407a64fc72ee38dd05b529188a38a18..81cfc9c946c0bad54500b7e4f7fdfceded359dcc 100644 --- a/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/realtime/RealtimeChart02.java +++ b/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/realtime/RealtimeChart02.java @@ -1,5 +1,5 @@ /** - * Copyright 2015 Knowm Inc. (http://knowm.org) and contributors. + * Copyright 2015-2016 Knowm Inc. (http://knowm.org) and contributors. * Copyright 2011-2015 Xeiam LLC (http://xeiam.com) and contributors. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -23,9 +23,10 @@ import java.util.concurrent.CopyOnWriteArrayList; import javax.swing.JFrame; -import org.knowm.xchart.Chart; +import org.knowm.xchart.Chart_XY; import org.knowm.xchart.XChartPanel; import org.knowm.xchart.demo.charts.ExampleChart; +import org.knowm.xchart.internal.chartpart.Chart; /** * Realtime @@ -95,8 +96,8 @@ public class RealtimeChart02 implements ExampleChart { yData = getRandomData(5); // Create Chart - Chart chart = new Chart(500, 400); - chart.setChartTitle("Sample Real-time Chart"); + Chart_XY chart = new Chart_XY(500, 400); + chart.setTitle("Sample Real-time Chart"); chart.setXAxisTitle("X"); chart.setYAxisTitle("Y"); chart.addSeries(SERIES_NAME, xData, yData); diff --git a/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/realtime/RealtimeChart03.java b/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/realtime/RealtimeChart03.java index c71b9492dbb166f5568fdeeee4fafba47ef810fb..9a208c81bf45722e55fa4c719bedb70ebc919ba0 100644 --- a/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/realtime/RealtimeChart03.java +++ b/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/realtime/RealtimeChart03.java @@ -1,5 +1,5 @@ /** - * Copyright 2015 Knowm Inc. (http://knowm.org) and contributors. + * Copyright 2015-2016 Knowm Inc. (http://knowm.org) and contributors. * Copyright 2011-2015 Xeiam LLC (http://xeiam.com) and contributors. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -24,9 +24,10 @@ import java.util.concurrent.CopyOnWriteArrayList; import javax.swing.JFrame; -import org.knowm.xchart.Chart; +import org.knowm.xchart.Chart_XY; import org.knowm.xchart.XChartPanel; import org.knowm.xchart.demo.charts.ExampleChart; +import org.knowm.xchart.internal.chartpart.Chart; /** * Realtime @@ -111,8 +112,8 @@ public class RealtimeChart03 implements ExampleChart { } // Create Chart - Chart chart = new Chart(500, 400); - chart.setChartTitle("Sample Real-time Chart"); + Chart_XY chart = new Chart_XY(500, 400); + chart.setTitle("Sample Real-time Chart"); chart.setXAxisTitle("X"); chart.setYAxisTitle("Y"); chart.addSeries(SERIES_NAME, xData, yData, errorBars); diff --git a/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/scatter/ScatterChart01.java b/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/scatter/ScatterChart01.java index d154885c7ea2f982cd1103724fd0163e3a9f0f80..1546be81534d17aedbf346847e49ccc53073f693 100644 --- a/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/scatter/ScatterChart01.java +++ b/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/scatter/ScatterChart01.java @@ -1,5 +1,5 @@ /** - * Copyright 2015 Knowm Inc. (http://knowm.org) and contributors. + * Copyright 2015-2016 Knowm Inc. (http://knowm.org) and contributors. * Copyright 2011-2015 Xeiam LLC (http://xeiam.com) and contributors. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -20,11 +20,12 @@ import java.util.LinkedList; import java.util.List; import java.util.Random; -import org.knowm.xchart.Chart; -import org.knowm.xchart.StyleManager.ChartType; -import org.knowm.xchart.StyleManager.LegendPosition; +import org.knowm.xchart.Chart_XY; +import org.knowm.xchart.Series_XY.ChartXYSeriesRenderStyle; import org.knowm.xchart.SwingWrapper; import org.knowm.xchart.demo.charts.ExampleChart; +import org.knowm.xchart.internal.chartpart.Chart; +import org.knowm.xchart.internal.style.StyleManager.LegendPosition; /** * Gaussian Blob @@ -58,8 +59,8 @@ public class ScatterChart01 implements ExampleChart { } // Create Chart - Chart chart = new Chart(800, 600); - chart.getStyleManager().setChartType(ChartType.Scatter); + Chart_XY chart = new Chart_XY(800, 600); + chart.getStyleManager().setChartXYSeriesRenderStyle(ChartXYSeriesRenderStyle.Scatter); // Customize Chart chart.getStyleManager().setChartTitleVisible(false); diff --git a/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/scatter/ScatterChart02.java b/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/scatter/ScatterChart02.java index 2883b9456d28af9298b0ed5593c97c20cca41928..bdbb9304af7695af98f53d910914a3de06159c2d 100644 --- a/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/scatter/ScatterChart02.java +++ b/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/scatter/ScatterChart02.java @@ -1,5 +1,5 @@ /** - * Copyright 2015 Knowm Inc. (http://knowm.org) and contributors. + * Copyright 2015-2016 Knowm Inc. (http://knowm.org) and contributors. * Copyright 2011-2015 Xeiam LLC (http://xeiam.com) and contributors. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -20,11 +20,12 @@ import java.util.ArrayList; import java.util.List; import java.util.Random; -import org.knowm.xchart.Chart; -import org.knowm.xchart.StyleManager.ChartType; -import org.knowm.xchart.StyleManager.LegendPosition; +import org.knowm.xchart.Chart_XY; +import org.knowm.xchart.Series_XY.ChartXYSeriesRenderStyle; import org.knowm.xchart.SwingWrapper; import org.knowm.xchart.demo.charts.ExampleChart; +import org.knowm.xchart.internal.chartpart.Chart; +import org.knowm.xchart.internal.style.StyleManager.LegendPosition; /** * Logarithmic Data @@ -35,7 +36,7 @@ import org.knowm.xchart.demo.charts.ExampleChart; * <li>Logarithmic X-Axis * <li>Place legend at Inside-NW position * <li>Formatting of number with large magnitude but small differences - * + * * @author timmolter */ public class ScatterChart02 implements ExampleChart { @@ -61,9 +62,9 @@ public class ScatterChart02 implements ExampleChart { } // Create Chart - Chart chart = new Chart(800, 600); - chart.setChartTitle("Logarithmic Data"); - chart.getStyleManager().setChartType(ChartType.Scatter); + Chart_XY chart = new Chart_XY(800, 600); + chart.setTitle("Logarithmic Data"); + chart.getStyleManager().setChartXYSeriesRenderStyle(ChartXYSeriesRenderStyle.Scatter); chart.getStyleManager().setXAxisLogarithmic(true); // Customize Chart diff --git a/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/scatter/ScatterChart03.java b/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/scatter/ScatterChart03.java index c9a11fcd20dbc65772da5551434a75c3f54145e0..8533ebffed29cbb3a903deeb06f8d876d7d09102 100644 --- a/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/scatter/ScatterChart03.java +++ b/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/scatter/ScatterChart03.java @@ -1,5 +1,5 @@ /** - * Copyright 2015 Knowm Inc. (http://knowm.org) and contributors. + * Copyright 2015-2016 Knowm Inc. (http://knowm.org) and contributors. * Copyright 2011-2015 Xeiam LLC (http://xeiam.com) and contributors. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -16,9 +16,10 @@ */ package org.knowm.xchart.demo.charts.scatter; -import org.knowm.xchart.Chart; +import org.knowm.xchart.Chart_XY; import org.knowm.xchart.SwingWrapper; import org.knowm.xchart.demo.charts.ExampleChart; +import org.knowm.xchart.internal.chartpart.Chart; /** * Single point @@ -40,10 +41,10 @@ public class ScatterChart03 implements ExampleChart { public Chart getChart() { // Create Chart - Chart chart = new Chart(800, 600); + Chart_XY chart = new Chart_XY(800, 600); // Customize Chart - chart.setChartTitle("Single Point"); + chart.setTitle("Single Point"); chart.setXAxisTitle("X"); chart.setYAxisTitle("Y"); diff --git a/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/scatter/ScatterChart04.java b/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/scatter/ScatterChart04.java index 3a14b6fdd0bc059af30558da8a88091854254222..be387c486e52b5db795fb20d3b2e0696c6492bc6 100644 --- a/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/scatter/ScatterChart04.java +++ b/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/scatter/ScatterChart04.java @@ -1,5 +1,5 @@ /** - * Copyright 2015 Knowm Inc. (http://knowm.org) and contributors. + * Copyright 2015-2016 Knowm Inc. (http://knowm.org) and contributors. * Copyright 2011-2015 Xeiam LLC (http://xeiam.com) and contributors. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -20,13 +20,13 @@ import java.awt.Color; import java.util.ArrayList; import java.util.List; -import org.knowm.xchart.Chart; -import org.knowm.xchart.ChartBuilder; -import org.knowm.xchart.Series; +import org.knowm.xchart.ChartBuilderXY; +import org.knowm.xchart.Chart_XY; import org.knowm.xchart.SeriesMarker; -import org.knowm.xchart.StyleManager.ChartType; +import org.knowm.xchart.Series_XY; import org.knowm.xchart.SwingWrapper; import org.knowm.xchart.demo.charts.ExampleChart; +import org.knowm.xchart.internal.chartpart.Chart; /** * Error Bars @@ -63,7 +63,7 @@ public class ScatterChart04 implements ExampleChart { } // Create Chart - Chart chart = new ChartBuilder().width(800).height(600).title("ScatterChart04").xAxisTitle("X").yAxisTitle("Y").chartType(ChartType.Scatter).build(); + Chart_XY chart = new ChartBuilderXY().width(800).height(600).title("ScatterChart04").xAxisTitle("X").yAxisTitle("Y").build(); // Customize Chart chart.getStyleManager().setChartTitleVisible(false); @@ -72,7 +72,7 @@ public class ScatterChart04 implements ExampleChart { chart.getStyleManager().setXAxisDecimalPattern("0.0000000"); // Series - Series series = chart.addSeries("10^(-x)", xData, yData, errorBars); + Series_XY series = chart.addSeries("10^(-x)", xData, yData, errorBars); series.setMarkerColor(Color.RED); series.setMarker(SeriesMarker.SQUARE); diff --git a/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/theme/ThemeChart01.java b/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/theme/ThemeChart01.java index 5c147d15e942ea9eb5e76b9757e9b949563d3e80..35e6d989eccbe1d168b19cfe20cbf4f217a54a83 100644 --- a/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/theme/ThemeChart01.java +++ b/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/theme/ThemeChart01.java @@ -1,5 +1,5 @@ /** - * Copyright 2015 Knowm Inc. (http://knowm.org) and contributors. + * Copyright 2015-2016 Knowm Inc. (http://knowm.org) and contributors. * Copyright 2011-2015 Xeiam LLC (http://xeiam.com) and contributors. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -19,9 +19,10 @@ package org.knowm.xchart.demo.charts.theme; import java.util.ArrayList; import java.util.List; -import org.knowm.xchart.Chart; +import org.knowm.xchart.Chart_XY; import org.knowm.xchart.SwingWrapper; import org.knowm.xchart.demo.charts.ExampleChart; +import org.knowm.xchart.internal.chartpart.Chart; /** * Default XChart Theme @@ -43,7 +44,7 @@ public class ThemeChart01 implements ExampleChart { public Chart getChart() { // Create Chart - Chart chart = new Chart(800, 600); + Chart_XY chart = new Chart_XY(800, 600); for (int i = 1; i <= 14; i++) { @@ -57,7 +58,7 @@ public class ThemeChart01 implements ExampleChart { } // Customize Chart - chart.setChartTitle("XChart Theme"); + chart.setTitle("XChart Theme"); chart.setXAxisTitle("X"); chart.setYAxisTitle("Y"); diff --git a/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/theme/ThemeChart02.java b/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/theme/ThemeChart02.java index 78c0cb6a7dc4bcdf15481c4c6b7efe65de237f6b..200fb5cb7a9d1f632374aabed0cf48071f164a1b 100644 --- a/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/theme/ThemeChart02.java +++ b/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/theme/ThemeChart02.java @@ -1,5 +1,5 @@ /** - * Copyright 2015 Knowm Inc. (http://knowm.org) and contributors. + * Copyright 2015-2016 Knowm Inc. (http://knowm.org) and contributors. * Copyright 2011-2015 Xeiam LLC (http://xeiam.com) and contributors. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -16,11 +16,12 @@ */ package org.knowm.xchart.demo.charts.theme; -import org.knowm.xchart.Chart; -import org.knowm.xchart.ChartBuilder; -import org.knowm.xchart.StyleManager.ChartTheme; +import org.knowm.xchart.ChartBuilderXY; +import org.knowm.xchart.Chart_XY; import org.knowm.xchart.SwingWrapper; import org.knowm.xchart.demo.charts.ExampleChart; +import org.knowm.xchart.internal.chartpart.Chart; +import org.knowm.xchart.internal.style.StyleManager.ChartTheme; /** * GGPlot2 Theme @@ -44,7 +45,7 @@ public class ThemeChart02 implements ExampleChart { public Chart getChart() { // Create Chart - Chart chart = new ChartBuilder().width(800).height(600).theme(ChartTheme.GGPlot2).title("GGPlot2 Theme").xAxisTitle("X").yAxisTitle("Y").build(); + Chart_XY chart = new ChartBuilderXY().width(800).height(600).theme(ChartTheme.GGPlot2).title("GGPlot2 Theme").xAxisTitle("X").yAxisTitle("Y").build(); chart.addSeries("vertical", new double[] { 1, 1 }, new double[] { -10, 10 }); chart.addSeries("horizontal", new double[] { -10, 10 }, new double[] { 0, 0 }); diff --git a/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/theme/ThemeChart03.java b/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/theme/ThemeChart03.java index cfb4a6a667564bd956602c41ebee2e80a3a57ae5..76e0e9f8ba3eb705481b5d645d0201885d21cc9d 100644 --- a/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/theme/ThemeChart03.java +++ b/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/theme/ThemeChart03.java @@ -1,5 +1,5 @@ /** - * Copyright 2015 Knowm Inc. (http://knowm.org) and contributors. + * Copyright 2015-2016 Knowm Inc. (http://knowm.org) and contributors. * Copyright 2011-2015 Xeiam LLC (http://xeiam.com) and contributors. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -23,11 +23,12 @@ import java.util.ArrayList; import java.util.Date; import java.util.List; -import org.knowm.xchart.Chart; -import org.knowm.xchart.ChartBuilder; -import org.knowm.xchart.StyleManager.ChartTheme; +import org.knowm.xchart.ChartBuilderXY; +import org.knowm.xchart.Chart_XY; import org.knowm.xchart.SwingWrapper; import org.knowm.xchart.demo.charts.ExampleChart; +import org.knowm.xchart.internal.chartpart.Chart; +import org.knowm.xchart.internal.style.StyleManager.ChartTheme; /** * Matlab Theme @@ -51,7 +52,7 @@ public class ThemeChart03 implements ExampleChart { public Chart getChart() { // Create Chart - Chart chart = new ChartBuilder().width(800).height(600).theme(ChartTheme.Matlab).title("Matlab Theme").xAxisTitle("X").yAxisTitle("Y").build(); + Chart_XY chart = new ChartBuilderXY().width(800).height(600).theme(ChartTheme.Matlab).title("Matlab Theme").xAxisTitle("X").yAxisTitle("Y").build(); chart.getStyleManager().setPlotGridLinesVisible(false); chart.getStyleManager().setXAxisTickMarkSpacingHint(100); // generate data diff --git a/xchart-demo/src/main/java/org/knowm/xchart/standalone/CSVChartColumns.java b/xchart-demo/src/main/java/org/knowm/xchart/standalone/CSVChartColumns.java index 83ffb2be0a5608df7da2f68b8c633ddd0f1f1a16..6b53ea24a11833d83c7c3cfe1ad801a94b425805 100644 --- a/xchart-demo/src/main/java/org/knowm/xchart/standalone/CSVChartColumns.java +++ b/xchart-demo/src/main/java/org/knowm/xchart/standalone/CSVChartColumns.java @@ -1,5 +1,5 @@ /** - * Copyright 2015 Knowm Inc. (http://knowm.org) and contributors. + * Copyright 2015-2016 Knowm Inc. (http://knowm.org) and contributors. * Copyright 2011-2015 Xeiam LLC (http://xeiam.com) and contributors. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -19,7 +19,7 @@ package org.knowm.xchart.standalone; import org.knowm.xchart.CSVExporter; import org.knowm.xchart.CSVImporter; import org.knowm.xchart.CSVImporter.DataOrientation; -import org.knowm.xchart.Chart; +import org.knowm.xchart.Chart_XY; import org.knowm.xchart.SwingWrapper; /** @@ -30,7 +30,7 @@ public class CSVChartColumns { public static void main(String[] args) throws Exception { // import chart from a folder containing CSV files - Chart chart = CSVImporter.getChartFromCSVDir("./CSV/CSVChartColumns/", DataOrientation.Columns, 600, 600); + Chart_XY chart = CSVImporter.getChartFromCSVDir("./CSV/CSVChartColumns/", DataOrientation.Columns, 600, 600); CSVExporter.writeCSVColumns(chart.getSeriesMap().get("series1"), "./CSV/CSVChartColumnsExport/"); diff --git a/xchart-demo/src/main/java/org/knowm/xchart/standalone/CSVChartRows.java b/xchart-demo/src/main/java/org/knowm/xchart/standalone/CSVChartRows.java index 97018f8f88901bb7a52b9fdc995ad9501b0ed522..e9a5d65c1669c1d6ee83a53175ebb2a574ac8e70 100644 --- a/xchart-demo/src/main/java/org/knowm/xchart/standalone/CSVChartRows.java +++ b/xchart-demo/src/main/java/org/knowm/xchart/standalone/CSVChartRows.java @@ -1,5 +1,5 @@ /** - * Copyright 2015 Knowm Inc. (http://knowm.org) and contributors. + * Copyright 2015-2016 Knowm Inc. (http://knowm.org) and contributors. * Copyright 2011-2015 Xeiam LLC (http://xeiam.com) and contributors. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -19,7 +19,7 @@ package org.knowm.xchart.standalone; import org.knowm.xchart.CSVExporter; import org.knowm.xchart.CSVImporter; import org.knowm.xchart.CSVImporter.DataOrientation; -import org.knowm.xchart.Chart; +import org.knowm.xchart.Chart_XY; import org.knowm.xchart.SwingWrapper; /** @@ -30,7 +30,7 @@ public class CSVChartRows { public static void main(String[] args) throws Exception { // import chart from a folder containing CSV files - Chart chart = CSVImporter.getChartFromCSVDir("./CSV/CSVChartRows/", DataOrientation.Rows, 600, 400); + Chart_XY chart = CSVImporter.getChartFromCSVDir("./CSV/CSVChartRows/", DataOrientation.Rows, 600, 400); CSVExporter.writeCSVRows(chart.getSeriesMap().get("series1"), "./CSV/CSVChartRowsExport/"); diff --git a/xchart-demo/src/main/java/org/knowm/xchart/standalone/DateChart.java b/xchart-demo/src/main/java/org/knowm/xchart/standalone/DateChart.java deleted file mode 100644 index 74773f6d834860a7a71ced92c51324fe499b3bd6..0000000000000000000000000000000000000000 --- a/xchart-demo/src/main/java/org/knowm/xchart/standalone/DateChart.java +++ /dev/null @@ -1,76 +0,0 @@ -/** - * Copyright 2015 Knowm Inc. (http://knowm.org) and contributors. - * Copyright 2011-2015 Xeiam LLC (http://xeiam.com) and contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.knowm.xchart.standalone; - -import java.text.DateFormat; -import java.text.ParseException; -import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.Date; -import java.util.List; -import java.util.Random; - -import org.knowm.xchart.Chart; -import org.knowm.xchart.ChartBuilder; -import org.knowm.xchart.SwingWrapper; -import org.knowm.xchart.demo.charts.ExampleChart; - -/** - * @author timmolter - */ -public class DateChart implements ExampleChart { - - public static void main(String[] args) { - - ExampleChart exampleChart = new DateChart(); - Chart chart = exampleChart.getChart(); - new SwingWrapper(chart).displayChart(); - } - - @Override - public Chart getChart() { - - // Create Chart - Chart chart = new ChartBuilder().width(800).height(600).title("Day Scale").build(); - chart.getStyleManager().setLegendVisible(false); - - // generate data - List<Date> xData = new ArrayList<Date>(); - List<Double> yData = new ArrayList<Double>(); - - Random random = new Random(); - - DateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); - Date date = null; - for (int i = 1; i <= 5; i++) { - try { - date = sdf.parse("2014-02-" + i); - } catch (ParseException e) { - e.printStackTrace(); - } - System.out.println(date); - xData.add(date); - System.out.println(date.getTime()); - yData.add(Math.random() * i); - } - - chart.addSeries("blah", xData, yData); - - return chart; - - } -} diff --git a/xchart-demo/src/main/java/org/knowm/xchart/standalone/ErrorBarLogTest.java b/xchart-demo/src/main/java/org/knowm/xchart/standalone/ErrorBarLogTest.java index 845fa559b04b696acaf1eb58a45f1d3a71d7f24d..b692b80b0ce505c2f08a3811a464e4e527658777 100644 --- a/xchart-demo/src/main/java/org/knowm/xchart/standalone/ErrorBarLogTest.java +++ b/xchart-demo/src/main/java/org/knowm/xchart/standalone/ErrorBarLogTest.java @@ -1,5 +1,5 @@ /** - * Copyright 2015 Knowm Inc. (http://knowm.org) and contributors. + * Copyright 2015-2016 Knowm Inc. (http://knowm.org) and contributors. * Copyright 2011-2015 Xeiam LLC (http://xeiam.com) and contributors. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,12 +18,12 @@ package org.knowm.xchart.standalone; import java.awt.Color; -import org.knowm.xchart.Chart; -import org.knowm.xchart.Series; +import org.knowm.xchart.Chart_XY; import org.knowm.xchart.SeriesLineStyle; import org.knowm.xchart.SeriesMarker; +import org.knowm.xchart.Series_XY; import org.knowm.xchart.SwingWrapper; -import org.knowm.xchart.internal.style.XChartTheme; +import org.knowm.xchart.internal.style.colors.XChartSeriesColors; /** * @author timmolter @@ -44,7 +44,7 @@ public class ErrorBarLogTest { // double[] errdata = new double[] { 1, .699, .301, 2, 1, .699, 0.301 }; double[] errdata = new double[] { 50, 20, 10, 52, 9, 2, 1 }; - Chart mychart = new Chart(1200, 800); + Chart_XY mychart = new Chart_XY(1200, 800); mychart.getStyleManager().setYAxisLogarithmic(true); // set log or linear Y axis @@ -54,11 +54,11 @@ public class ErrorBarLogTest { mychart.getStyleManager().setErrorBarsColor(Color.black); - Series series1 = mychart.addSeries("Error bar test data", xData, yData1, errdata); + Series_XY series1 = mychart.addSeries("Error bar test data", xData, yData1, errdata); - Series series2 = mychart.addSeries("Y+error", xData, yData2); + Series_XY series2 = mychart.addSeries("Y+error", xData, yData2); - Series series3 = mychart.addSeries("Y-error", xData, yData3); + Series_XY series3 = mychart.addSeries("Y-error", xData, yData3); series1.setLineStyle(SeriesLineStyle.SOLID); @@ -70,13 +70,13 @@ public class ErrorBarLogTest { series2.setMarker(SeriesMarker.NONE); - series2.setLineColor(XChartTheme.RED); + series2.setLineColor(XChartSeriesColors.RED); series3.setLineStyle(SeriesLineStyle.DASH_DASH); series3.setMarker(SeriesMarker.NONE); - series3.setLineColor(XChartTheme.RED); + series3.setLineColor(XChartSeriesColors.RED); new SwingWrapper(mychart).displayChart(); diff --git a/xchart-demo/src/main/java/org/knowm/xchart/standalone/ErrorBarTest.java b/xchart-demo/src/main/java/org/knowm/xchart/standalone/ErrorBarTest.java index 9b8ff7400aacf1840f9232a97ec81cc2afcdd7cc..fc79eea9b58b2426dd05bfd20b54c3bb1e2c84c9 100644 --- a/xchart-demo/src/main/java/org/knowm/xchart/standalone/ErrorBarTest.java +++ b/xchart-demo/src/main/java/org/knowm/xchart/standalone/ErrorBarTest.java @@ -1,5 +1,5 @@ /** - * Copyright 2015 Knowm Inc. (http://knowm.org) and contributors. + * Copyright 2015-2016 Knowm Inc. (http://knowm.org) and contributors. * Copyright 2011-2015 Xeiam LLC (http://xeiam.com) and contributors. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,12 +18,12 @@ package org.knowm.xchart.standalone; import java.awt.Color; -import org.knowm.xchart.Chart; -import org.knowm.xchart.Series; +import org.knowm.xchart.Chart_XY; import org.knowm.xchart.SeriesLineStyle; import org.knowm.xchart.SeriesMarker; +import org.knowm.xchart.Series_XY; import org.knowm.xchart.SwingWrapper; -import org.knowm.xchart.internal.style.XChartTheme; +import org.knowm.xchart.internal.style.colors.XChartSeriesColors; /** * @author timmolter @@ -39,22 +39,22 @@ public class ErrorBarTest { double[] yData2 = new double[] { 50, 80, 90, 0, 10, 30, 40 }; double[] yData3 = new double[] { 150, 120, 110, 100, 90, 70, 60 }; - Chart mychart = new Chart(900, 700); + Chart_XY mychart = new Chart_XY(900, 700); mychart.getStyleManager().setYAxisMin(0); mychart.getStyleManager().setYAxisMax(150); mychart.getStyleManager().setErrorBarsColor(Color.black); - Series series1 = mychart.addSeries("Error bar test data", xData, yData1, errdata); - Series series2 = mychart.addSeries("Y+error", xData, yData2); - Series series3 = mychart.addSeries("Y-error", xData, yData3); + Series_XY series1 = mychart.addSeries("Error bar test data", xData, yData1, errdata); + Series_XY series2 = mychart.addSeries("Y+error", xData, yData2); + Series_XY series3 = mychart.addSeries("Y-error", xData, yData3); series1.setLineStyle(SeriesLineStyle.SOLID); series1.setMarker(SeriesMarker.DIAMOND); series1.setMarkerColor(Color.MAGENTA); series2.setLineStyle(SeriesLineStyle.DASH_DASH); series2.setMarker(SeriesMarker.NONE); - series2.setLineColor(XChartTheme.RED); + series2.setLineColor(XChartSeriesColors.RED); series3.setLineStyle(SeriesLineStyle.DASH_DASH); series3.setMarker(SeriesMarker.NONE); - series3.setLineColor(XChartTheme.RED); + series3.setLineColor(XChartSeriesColors.RED); new SwingWrapper(mychart).displayChart(); } diff --git a/xchart-demo/src/main/java/org/knowm/xchart/standalone/Example0.java b/xchart-demo/src/main/java/org/knowm/xchart/standalone/Example0.java index a19c84e8df259491043568afd0f2304b2e081f73..ec61fb3d3478c293e0b1c352033e603d05c498c9 100644 --- a/xchart-demo/src/main/java/org/knowm/xchart/standalone/Example0.java +++ b/xchart-demo/src/main/java/org/knowm/xchart/standalone/Example0.java @@ -1,5 +1,5 @@ /** - * Copyright 2015 Knowm Inc. (http://knowm.org) and contributors. + * Copyright 2015-2016 Knowm Inc. (http://knowm.org) and contributors. * Copyright 2011-2015 Xeiam LLC (http://xeiam.com) and contributors. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -16,9 +16,9 @@ */ package org.knowm.xchart.standalone; -import org.knowm.xchart.Chart; import org.knowm.xchart.QuickChart; import org.knowm.xchart.SwingWrapper; +import org.knowm.xchart.internal.chartpart.Chart; /** * Creates a simple Chart using QuickChart diff --git a/xchart-demo/src/main/java/org/knowm/xchart/standalone/Example0WithoutHorizontalLines.java b/xchart-demo/src/main/java/org/knowm/xchart/standalone/Example0WithoutHorizontalLines.java index 286df0778c99204c36d5d95ab1667bf5ed85aa8c..aa303a6f4191166e6e5abe9e56dab20c0e38a9cb 100644 --- a/xchart-demo/src/main/java/org/knowm/xchart/standalone/Example0WithoutHorizontalLines.java +++ b/xchart-demo/src/main/java/org/knowm/xchart/standalone/Example0WithoutHorizontalLines.java @@ -1,5 +1,5 @@ /** - * Copyright 2015 Knowm Inc. (http://knowm.org) and contributors. + * Copyright 2015-2016 Knowm Inc. (http://knowm.org) and contributors. * Copyright 2011-2015 Xeiam LLC (http://xeiam.com) and contributors. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -19,53 +19,50 @@ package org.knowm.xchart.standalone; import java.util.ArrayList; import java.util.List; -import org.knowm.xchart.BitmapEncoder; -import org.knowm.xchart.BitmapEncoder.BitmapFormat; -import org.knowm.xchart.Chart; -import org.knowm.xchart.ChartBuilder; -import org.knowm.xchart.Series; +import org.knowm.xchart.ChartBuilderXY; +import org.knowm.xchart.Chart_XY; import org.knowm.xchart.SeriesMarker; +import org.knowm.xchart.Series_XY; import org.knowm.xchart.SwingWrapper; -import org.knowm.xchart.VectorGraphicsEncoder; -import org.knowm.xchart.VectorGraphicsEncoder.VectorGraphicsFormat; +import org.knowm.xchart.internal.chartpart.Chart; /** * Creates a simple Chart and saves it as a PNG and JPEG image file. */ public class Example0WithoutHorizontalLines { - public static void main(String[] args) { + public static void main(String[] args) { - int numCharts = 4; + int numCharts = 4; - List<Chart> charts = new ArrayList<Chart>(); + List<Chart> charts = new ArrayList<Chart>(); - for (int i = 0; i < numCharts; i++) { - Chart chart = new ChartBuilder().xAxisTitle("X").yAxisTitle("Y").width(600).height(400).build(); - chart.getStyleManager().setYAxisMin(-10); - chart.getStyleManager().setYAxisMax(10); - chart.getStyleManager().setPlotGridHorizontalLinesVisible(false); - Series series = chart.addSeries("" + i, null, getRandomWalk(200)); - series.setMarker(SeriesMarker.NONE); - charts.add(chart); - } - new SwingWrapper(charts).displayChartMatrix(); - } + for (int i = 0; i < numCharts; i++) { + Chart_XY chart = new ChartBuilderXY().xAxisTitle("X").yAxisTitle("Y").width(600).height(400).build(); + chart.getStyleManager().setYAxisMin(-10); + chart.getStyleManager().setYAxisMax(10); + chart.getStyleManager().setPlotGridHorizontalLinesVisible(false); + Series_XY series = chart.addSeries("" + i, null, getRandomWalk(200)); + series.setMarker(SeriesMarker.NONE); + charts.add(chart); + } + new SwingWrapper(charts).displayChartMatrix(); + } - /** - * Generates a set of random walk data - * - * @param numPoints - * @return - */ - private static double[] getRandomWalk(int numPoints) { + /** + * Generates a set of random walk data + * + * @param numPoints + * @return + */ + private static double[] getRandomWalk(int numPoints) { - double[] y = new double[numPoints]; - y[0] = 0; - for (int i = 1; i < y.length; i++) { - y[i] = y[i - 1] + Math.random() - .5; - } - return y; - } + double[] y = new double[numPoints]; + y[0] = 0; + for (int i = 1; i < y.length; i++) { + y[i] = y[i - 1] + Math.random() - .5; + } + return y; + } } diff --git a/xchart-demo/src/main/java/org/knowm/xchart/standalone/Example0WithoutVerticalAndHorizontalLines.java b/xchart-demo/src/main/java/org/knowm/xchart/standalone/Example0WithoutVerticalAndHorizontalLines.java index 9463c65da6623c08f78c771c513fdfd3e5075f54..afc8d0b406d2e8eaec0edca1d69633d4d3ae0fb6 100644 --- a/xchart-demo/src/main/java/org/knowm/xchart/standalone/Example0WithoutVerticalAndHorizontalLines.java +++ b/xchart-demo/src/main/java/org/knowm/xchart/standalone/Example0WithoutVerticalAndHorizontalLines.java @@ -1,5 +1,5 @@ /** - * Copyright 2015 Knowm Inc. (http://knowm.org) and contributors. + * Copyright 2015-2016 Knowm Inc. (http://knowm.org) and contributors. * Copyright 2011-2015 Xeiam LLC (http://xeiam.com) and contributors. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -19,15 +19,16 @@ package org.knowm.xchart.standalone; import java.util.ArrayList; import java.util.List; -import org.knowm.xchart.Chart; -import org.knowm.xchart.ChartBuilder; -import org.knowm.xchart.Series; +import org.knowm.xchart.ChartBuilderXY; +import org.knowm.xchart.Chart_XY; import org.knowm.xchart.SeriesMarker; +import org.knowm.xchart.Series_XY; import org.knowm.xchart.SwingWrapper; +import org.knowm.xchart.internal.chartpart.Chart; /** * Create a Chart matrix - * + * * @author timmolter */ public class Example0WithoutVerticalAndHorizontalLines { @@ -39,12 +40,12 @@ public class Example0WithoutVerticalAndHorizontalLines { List<Chart> charts = new ArrayList<Chart>(); for (int i = 0; i < numCharts; i++) { - Chart chart = new ChartBuilder().xAxisTitle("X").yAxisTitle("Y").width(600).height(400).build(); + Chart_XY chart = new ChartBuilderXY().xAxisTitle("X").yAxisTitle("Y").width(600).height(400).build(); chart.getStyleManager().setYAxisMin(-10); chart.getStyleManager().setYAxisMax(10); chart.getStyleManager().setPlotGridVerticalLinesVisible(false); chart.getStyleManager().setPlotGridHorizontalLinesVisible(false); - Series series = chart.addSeries("" + i, null, getRandomWalk(200)); + Series_XY series = chart.addSeries("" + i, null, getRandomWalk(200)); series.setMarker(SeriesMarker.NONE); charts.add(chart); } @@ -53,7 +54,7 @@ public class Example0WithoutVerticalAndHorizontalLines { /** * Generates a set of random walk data - * + * * @param numPoints * @return */ diff --git a/xchart-demo/src/main/java/org/knowm/xchart/standalone/Example0WithoutVerticalLines.java b/xchart-demo/src/main/java/org/knowm/xchart/standalone/Example0WithoutVerticalLines.java index 4602df17ca10c9e4e1be665f7a18862e068b335c..6708ce6afccad7e383174dcccb2c19c98e95d94d 100644 --- a/xchart-demo/src/main/java/org/knowm/xchart/standalone/Example0WithoutVerticalLines.java +++ b/xchart-demo/src/main/java/org/knowm/xchart/standalone/Example0WithoutVerticalLines.java @@ -1,5 +1,5 @@ /** - * Copyright 2015 Knowm Inc. (http://knowm.org) and contributors. + * Copyright 2015-2016 Knowm Inc. (http://knowm.org) and contributors. * Copyright 2011-2015 Xeiam LLC (http://xeiam.com) and contributors. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -19,49 +19,50 @@ package org.knowm.xchart.standalone; import java.util.ArrayList; import java.util.List; -import org.knowm.xchart.Chart; -import org.knowm.xchart.ChartBuilder; -import org.knowm.xchart.Series; +import org.knowm.xchart.ChartBuilderXY; +import org.knowm.xchart.Chart_XY; import org.knowm.xchart.SeriesMarker; +import org.knowm.xchart.Series_XY; import org.knowm.xchart.SwingWrapper; +import org.knowm.xchart.internal.chartpart.Chart; /** * Creates a simple Chart using QuickChart */ public class Example0WithoutVerticalLines { - public static void main(String[] args) { + public static void main(String[] args) { - int numCharts = 4; + int numCharts = 4; - List<Chart> charts = new ArrayList<Chart>(); + List<Chart> charts = new ArrayList<Chart>(); - for (int i = 0; i < numCharts; i++) { - Chart chart = new ChartBuilder().xAxisTitle("X").yAxisTitle("Y").width(600).height(400).build(); - chart.getStyleManager().setYAxisMin(-10); - chart.getStyleManager().setYAxisMax(10); - chart.getStyleManager().setPlotGridVerticalLinesVisible(false); - Series series = chart.addSeries("" + i, null, getRandomWalk(200)); - series.setMarker(SeriesMarker.NONE); - charts.add(chart); - } - new SwingWrapper(charts).displayChartMatrix(); - } + for (int i = 0; i < numCharts; i++) { + Chart_XY chart = new ChartBuilderXY().xAxisTitle("X").yAxisTitle("Y").width(600).height(400).build(); + chart.getStyleManager().setYAxisMin(-10); + chart.getStyleManager().setYAxisMax(10); + chart.getStyleManager().setPlotGridVerticalLinesVisible(false); + Series_XY series = chart.addSeries("" + i, null, getRandomWalk(200)); + series.setMarker(SeriesMarker.NONE); + charts.add(chart); + } + new SwingWrapper(charts).displayChartMatrix(); + } - /** - * Generates a set of random walk data - * - * @param numPoints - * @return - */ - private static double[] getRandomWalk(int numPoints) { + /** + * Generates a set of random walk data + * + * @param numPoints + * @return + */ + private static double[] getRandomWalk(int numPoints) { - double[] y = new double[numPoints]; - y[0] = 0; - for (int i = 1; i < y.length; i++) { - y[i] = y[i - 1] + Math.random() - .5; - } - return y; - } + double[] y = new double[numPoints]; + y[0] = 0; + for (int i = 1; i < y.length; i++) { + y[i] = y[i - 1] + Math.random() - .5; + } + return y; + } } diff --git a/xchart-demo/src/main/java/org/knowm/xchart/standalone/Example1.java b/xchart-demo/src/main/java/org/knowm/xchart/standalone/Example1.java index d8c394dc0375e8ce1e5cad37a4b91618f587f154..651a0fd4063cff71855c73e902465c0a968299e9 100644 --- a/xchart-demo/src/main/java/org/knowm/xchart/standalone/Example1.java +++ b/xchart-demo/src/main/java/org/knowm/xchart/standalone/Example1.java @@ -1,5 +1,5 @@ /** - * Copyright 2015 Knowm Inc. (http://knowm.org) and contributors. + * Copyright 2015-2016 Knowm Inc. (http://knowm.org) and contributors. * Copyright 2011-2015 Xeiam LLC (http://xeiam.com) and contributors. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,9 +18,9 @@ package org.knowm.xchart.standalone; import org.knowm.xchart.BitmapEncoder; import org.knowm.xchart.BitmapEncoder.BitmapFormat; -import org.knowm.xchart.Chart; -import org.knowm.xchart.Series; +import org.knowm.xchart.Chart_XY; import org.knowm.xchart.SeriesMarker; +import org.knowm.xchart.Series_XY; import org.knowm.xchart.VectorGraphicsEncoder; import org.knowm.xchart.VectorGraphicsEncoder.VectorGraphicsFormat; @@ -34,11 +34,11 @@ public class Example1 { double[] yData = new double[] { 2.0, 1.0, 0.0 }; // Create Chart - Chart chart = new Chart(500, 400); - chart.setChartTitle("Sample Chart"); + Chart_XY chart = new Chart_XY(500, 400); + chart.setTitle("Sample Chart"); chart.setXAxisTitle("X"); - chart.setYAxisTitle("Y"); - Series series = chart.addSeries("y(x)", null, yData); + chart.setXAxisTitle("Y"); + Series_XY series = chart.addSeries("y(x)", null, yData); series.setMarker(SeriesMarker.CIRCLE); BitmapEncoder.saveBitmap(chart, "./Sample_Chart", BitmapFormat.PNG); diff --git a/xchart-demo/src/main/java/org/knowm/xchart/standalone/Example2.java b/xchart-demo/src/main/java/org/knowm/xchart/standalone/Example2.java index 906d3d6ef0f09824cb2cd403d7bd979e9dc066dd..960e51894be78954b44cb3e4e947434cf75e90f2 100644 --- a/xchart-demo/src/main/java/org/knowm/xchart/standalone/Example2.java +++ b/xchart-demo/src/main/java/org/knowm/xchart/standalone/Example2.java @@ -1,5 +1,5 @@ /** - * Copyright 2015 Knowm Inc. (http://knowm.org) and contributors. + * Copyright 2015-2016 Knowm Inc. (http://knowm.org) and contributors. * Copyright 2011-2015 Xeiam LLC (http://xeiam.com) and contributors. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -19,15 +19,16 @@ package org.knowm.xchart.standalone; import java.util.ArrayList; import java.util.List; -import org.knowm.xchart.Chart; -import org.knowm.xchart.ChartBuilder; -import org.knowm.xchart.Series; +import org.knowm.xchart.ChartBuilderXY; +import org.knowm.xchart.Chart_XY; import org.knowm.xchart.SeriesMarker; +import org.knowm.xchart.Series_XY; import org.knowm.xchart.SwingWrapper; +import org.knowm.xchart.internal.chartpart.Chart; /** * Create a Chart matrix - * + * * @author timmolter */ public class Example2 { @@ -39,10 +40,10 @@ public class Example2 { List<Chart> charts = new ArrayList<Chart>(); for (int i = 0; i < numCharts; i++) { - Chart chart = new ChartBuilder().xAxisTitle("X").yAxisTitle("Y").width(600).height(400).build(); + Chart_XY chart = new ChartBuilderXY().xAxisTitle("X").yAxisTitle("Y").width(600).height(400).build(); chart.getStyleManager().setYAxisMin(-10); chart.getStyleManager().setYAxisMax(10); - Series series = chart.addSeries("" + i, null, getRandomWalk(200)); + Series_XY series = chart.addSeries("" + i, null, getRandomWalk(200)); series.setMarker(SeriesMarker.NONE); charts.add(chart); } @@ -51,7 +52,7 @@ public class Example2 { /** * Generates a set of random walk data - * + * * @param numPoints * @return */ diff --git a/xchart-demo/src/main/java/org/knowm/xchart/standalone/SwingDemo.java b/xchart-demo/src/main/java/org/knowm/xchart/standalone/SwingDemo.java index 2f4dce8a416c7cd65efb29c6b365f8f9bc2be0ce..ed824123bfa7367353136902cbc315fa07efcf85 100644 --- a/xchart-demo/src/main/java/org/knowm/xchart/standalone/SwingDemo.java +++ b/xchart-demo/src/main/java/org/knowm/xchart/standalone/SwingDemo.java @@ -1,5 +1,5 @@ /** - * Copyright 2015 Knowm Inc. (http://knowm.org) and contributors. + * Copyright 2015-2016 Knowm Inc. (http://knowm.org) and contributors. * Copyright 2011-2015 Xeiam LLC (http://xeiam.com) and contributors. * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/xchart-demo/src/main/java/org/knowm/xchart/standalone/TestForIssue111.java b/xchart-demo/src/main/java/org/knowm/xchart/standalone/TestForIssue111.java index 8cc3f82bfda81923f7ce32c17fd9f5f725623977..3bdb025bed7167e7d95ffe090fca205749fc6612 100644 --- a/xchart-demo/src/main/java/org/knowm/xchart/standalone/TestForIssue111.java +++ b/xchart-demo/src/main/java/org/knowm/xchart/standalone/TestForIssue111.java @@ -1,5 +1,5 @@ /** - * Copyright 2015 Knowm Inc. (http://knowm.org) and contributors. + * Copyright 2015-2016 Knowm Inc. (http://knowm.org) and contributors. * Copyright 2011-2015 Xeiam LLC (http://xeiam.com) and contributors. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -16,9 +16,8 @@ */ package org.knowm.xchart.standalone; -import org.knowm.xchart.Chart; -import org.knowm.xchart.ChartBuilder; -import org.knowm.xchart.StyleManager.ChartType; +import org.knowm.xchart.ChartBuilder_Category; +import org.knowm.xchart.Chart_Category; import org.knowm.xchart.SwingWrapper; /** @@ -33,7 +32,7 @@ public class TestForIssue111 { // int[] x = new int[] { 0, 1, 2, 3, 4, 5, 6, 7 }; // int[] y = new int[] { 1, 0, 1, 0, 1, 0, 0, 0 }; - Chart chart = new ChartBuilder().chartType(ChartType.Bar).width(640).height(480).build(); + Chart_Category chart = new ChartBuilder_Category().width(640).height(480).build(); chart.addSeries("test", x, y); chart.getStyleManager().setLegendVisible(false); new SwingWrapper(chart).displayChart(); diff --git a/xchart-demo/src/main/java/org/knowm/xchart/standalone/TestForIssue83.java b/xchart-demo/src/main/java/org/knowm/xchart/standalone/TestForIssue83.java index 309986e844acc066226b6c2ec047b6f91a9edc1c..f2797e91875eddeda366b91438630f5a8f8aac3f 100644 --- a/xchart-demo/src/main/java/org/knowm/xchart/standalone/TestForIssue83.java +++ b/xchart-demo/src/main/java/org/knowm/xchart/standalone/TestForIssue83.java @@ -1,5 +1,5 @@ /** - * Copyright 2015 Knowm Inc. (http://knowm.org) and contributors. + * Copyright 2015-2016 Knowm Inc. (http://knowm.org) and contributors. * Copyright 2011-2015 Xeiam LLC (http://xeiam.com) and contributors. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,11 +18,11 @@ package org.knowm.xchart.standalone; import java.io.IOException; -import org.knowm.xchart.Chart; +import org.knowm.xchart.Chart_XY; import org.knowm.xchart.SeriesLineStyle; -import org.knowm.xchart.StyleManager; -import org.knowm.xchart.StyleManager.LegendPosition; import org.knowm.xchart.SwingWrapper; +import org.knowm.xchart.internal.style.StyleManager; +import org.knowm.xchart.internal.style.StyleManager.LegendPosition; /** * @author timmolter @@ -31,7 +31,7 @@ public class TestForIssue83 { public static void main(String[] args) throws IOException { - final Chart chart = new Chart(500, 580); + final Chart_XY chart = new Chart_XY(500, 580); final StyleManager styleManager = chart.getStyleManager(); styleManager.setLegendPosition(LegendPosition.InsideNW); styleManager.setLegendVisible(false); diff --git a/xchart-demo/src/main/java/org/knowm/xchart/standalone/TestForIssue98.java b/xchart-demo/src/main/java/org/knowm/xchart/standalone/TestForIssue98.java index d7744df7d08cd72025dc526c91b8a8e46b9ac53d..7468f91d14c0e830393f77bb70eed7261025043f 100644 --- a/xchart-demo/src/main/java/org/knowm/xchart/standalone/TestForIssue98.java +++ b/xchart-demo/src/main/java/org/knowm/xchart/standalone/TestForIssue98.java @@ -1,5 +1,5 @@ /** - * Copyright 2015 Knowm Inc. (http://knowm.org) and contributors. + * Copyright 2015-2016 Knowm Inc. (http://knowm.org) and contributors. * Copyright 2011-2015 Xeiam LLC (http://xeiam.com) and contributors. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -20,10 +20,10 @@ import java.io.IOException; import java.util.ArrayList; import java.util.Date; -import org.knowm.xchart.Chart; -import org.knowm.xchart.StyleManager; -import org.knowm.xchart.StyleManager.LegendPosition; +import org.knowm.xchart.Chart_XY; +import org.knowm.xchart.StyleManagerXY; import org.knowm.xchart.SwingWrapper; +import org.knowm.xchart.internal.style.StyleManager.LegendPosition; /** * @author timmolter @@ -32,8 +32,8 @@ public class TestForIssue98 { public static void main(String[] args) throws IOException { - final Chart chart = new Chart(1920, 1080); - StyleManager manager = chart.getStyleManager(); + final Chart_XY chart = new Chart_XY(1920, 1080); + StyleManagerXY manager = chart.getStyleManager(); manager.setLegendPosition(LegendPosition.InsideNW); manager.setYAxisLogarithmic(true); diff --git a/xchart/pom.xml b/xchart/pom.xml index cbfa725badc4f4323869adc0c3fcf5234a8e610b..171631c156b82cb68b15790f058d683c4d46a0aa 100644 --- a/xchart/pom.xml +++ b/xchart/pom.xml @@ -5,7 +5,7 @@ <parent> <groupId>org.knowm.xchart</groupId> <artifactId>xchart-parent</artifactId> - <version>2.6.2-SNAPSHOT</version> + <version>3.0.0-SNAPSHOT</version> </parent> <artifactId>xchart</artifactId> diff --git a/xchart/src/main/java/org/knowm/xchart/BitmapEncoder.java b/xchart/src/main/java/org/knowm/xchart/BitmapEncoder.java index 631a58cf3070533d775f5f79aed7d75996824cd6..234b526b9dc8fc6c27b3f672a249cf47f00bc8c1 100644 --- a/xchart/src/main/java/org/knowm/xchart/BitmapEncoder.java +++ b/xchart/src/main/java/org/knowm/xchart/BitmapEncoder.java @@ -1,5 +1,5 @@ /** - * Copyright 2015 Knowm Inc. (http://knowm.org) and contributors. + * Copyright 2015-2016 Knowm Inc. (http://knowm.org) and contributors. * Copyright 2011-2015 Xeiam LLC (http://xeiam.com) and contributors. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -37,6 +37,8 @@ import javax.imageio.metadata.IIOMetadata; import javax.imageio.metadata.IIOMetadataNode; import javax.imageio.stream.FileImageOutputStream; +import org.knowm.xchart.internal.chartpart.Chart; + /** * A helper class with static methods for saving Charts as bitmaps * diff --git a/xchart/src/main/java/org/knowm/xchart/CSVExporter.java b/xchart/src/main/java/org/knowm/xchart/CSVExporter.java index d73d0b324ea0f19ec96e7e36ac81a049cb933b8e..f3b6ddae9fb32008c086bc54a6b0bfd0796427aa 100644 --- a/xchart/src/main/java/org/knowm/xchart/CSVExporter.java +++ b/xchart/src/main/java/org/knowm/xchart/CSVExporter.java @@ -1,5 +1,5 @@ /** - * Copyright 2015 Knowm Inc. (http://knowm.org) and contributors. + * Copyright 2015-2016 Knowm Inc. (http://knowm.org) and contributors. * Copyright 2011-2015 Xeiam LLC (http://xeiam.com) and contributors. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -28,18 +28,18 @@ import java.util.Iterator; /** * This class is used to export Chart data to a folder containing one or more CSV files. The parent folder's name is the title of the chart. Each * series becomes a CSV file in the folder. The series' name becomes the CSV files' name. - * + * * @author timmolter */ public class CSVExporter { /** * Write a Chart series as rows in a CSV file. - * + * * @param series * @param path2Dir - ex. "./path/to/directory/" *make sure you have the '/' on the end */ - public static void writeCSVRows(Series series, String path2Dir) { + public static void writeCSVRows(Series_AxesChart series, String path2Dir) { File newFile = new File(path2Dir + series.getName() + ".csv"); Writer out = null; @@ -71,11 +71,11 @@ public class CSVExporter { /** * Write a Chart series as columns in a CSV file. - * + * * @param series * @param path2Dir - ex. "./path/to/directory/" *make sure you have the '/' on the end */ - public static void writeCSVColumns(Series series, String path2Dir) { + public static void writeCSVColumns(Series_AxesChart series, String path2Dir) { File newFile = new File(path2Dir + series.getName() + ".csv"); Writer out = null; diff --git a/xchart/src/main/java/org/knowm/xchart/CSVImporter.java b/xchart/src/main/java/org/knowm/xchart/CSVImporter.java index 20aa7f51fd3a334d42d8a87ce4e13cd9224c81bf..77f7f2517b94221c0788f8cd15c6b309dfc8ab32 100644 --- a/xchart/src/main/java/org/knowm/xchart/CSVImporter.java +++ b/xchart/src/main/java/org/knowm/xchart/CSVImporter.java @@ -1,5 +1,5 @@ /** - * Copyright 2015 Knowm Inc. (http://knowm.org) and contributors. + * Copyright 2015-2016 Knowm Inc. (http://knowm.org) and contributors. * Copyright 2011-2015 Xeiam LLC (http://xeiam.com) and contributors. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -23,12 +23,12 @@ import java.io.IOException; import java.util.ArrayList; import java.util.List; -import org.knowm.xchart.StyleManager.ChartTheme; +import org.knowm.xchart.internal.style.StyleManager.ChartTheme; /** * This class is used to create a Chart object from a folder containing one or more CSV files. The parent folder's name becomes the title of the * chart. Each CSV file in the folder becomes a series on the chart. the CSV file's name becomes the series' name. - * + * * @author timmolter */ public class CSVImporter { @@ -46,15 +46,15 @@ public class CSVImporter { * @param chartTheme * @return */ - public static Chart getChartFromCSVDir(String path2Directory, DataOrientation dataOrientation, int width, int height, ChartTheme chartTheme) { + public static Chart_XY getChartFromCSVDir(String path2Directory, DataOrientation dataOrientation, int width, int height, ChartTheme chartTheme) { // 1. get the directory, name chart the dir name - Chart chart = null; + Chart_XY chart = null; if (chartTheme != null) { - chart = new Chart(width, height, chartTheme); + chart = new Chart_XY(width, height, chartTheme); } else { - chart = new Chart(width, height); + chart = new Chart_XY(width, height); } // 2. get all the csv files in the dir @@ -89,14 +89,14 @@ public class CSVImporter { * @param height * @return */ - public static Chart getChartFromCSVDir(String path2Directory, DataOrientation dataOrientation, int width, int height) { + public static Chart_XY getChartFromCSVDir(String path2Directory, DataOrientation dataOrientation, int width, int height) { return getChartFromCSVDir(path2Directory, dataOrientation, width, height, null); } /** * Get the series's data from a file - * + * * @param csvFile * @return */ @@ -189,7 +189,7 @@ public class CSVImporter { /** * This method returns the files found in the given directory matching the given regular expression. - * + * * @param dirName - ex. "./path/to/directory/" *make sure you have the '/' on the end * @param regex - ex. ".*.csv" * @return File[] - an array of files @@ -213,7 +213,7 @@ public class CSVImporter { /** * This method returns the Files found in the given directory - * + * * @param dirName - ex. "./path/to/directory/" *make sure you have the '/' on the end * @return File[] - an array of files */ diff --git a/xchart/src/main/java/org/knowm/xchart/Chart.java b/xchart/src/main/java/org/knowm/xchart/Chart.java deleted file mode 100644 index d8714285ca14ffb32f76540f4ffdc6115eabd8e2..0000000000000000000000000000000000000000 --- a/xchart/src/main/java/org/knowm/xchart/Chart.java +++ /dev/null @@ -1,321 +0,0 @@ -/** - * Copyright 2015 Knowm Inc. (http://knowm.org) and contributors. - * Copyright 2011-2015 Xeiam LLC (http://xeiam.com) and contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.knowm.xchart; - -import java.awt.Graphics2D; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; - -import org.knowm.xchart.StyleManager.ChartTheme; -import org.knowm.xchart.internal.chartpart.ChartInternal; -import org.knowm.xchart.internal.style.Theme; - -/** - * An XChart Chart - * - * @author timmolter - */ -public class Chart { - - /** - * Hides ugly details mostly related to painting the chart and managing the added series. Not to be exposed to outside. - */ - private final ChartInternal chartInternal; - - /** - * Constructor - * - * @param width - * @param height - */ - public Chart(int width, int height) { - - chartInternal = new ChartInternal(width, height); - } - - /** - * Constructor - * - * @param width - * @param height - * @param chartTheme - */ - public Chart(int width, int height, ChartTheme chartTheme) { - - this(width, height, chartTheme.newInstance(chartTheme)); - } - - /** - * Constructor - * - * @param width - * @param height - * @param theme instance of Theme class - */ - public Chart(int width, int height, Theme theme) { - - chartInternal = new ChartInternal(width, height); - chartInternal.getStyleManager().setTheme(theme); - } - - /** - * Constructor - * - * @param chartBuilder - */ - public Chart(ChartBuilder chartBuilder) { - - this(chartBuilder.width, chartBuilder.height, chartBuilder.chartTheme); - setChartTitle(chartBuilder.title); - setXAxisTitle(chartBuilder.xAxisTitle); - setYAxisTitle(chartBuilder.yAxisTitle); - getStyleManager().setChartType(chartBuilder.chartType); - } - - /** - * @param g - * @param width - * @param height - */ - public void paint(Graphics2D g, int width, int height) { - - chartInternal.paint(g, width, height); - } - - /** - * @param g - */ - public void paint(Graphics2D g) { - - chartInternal.paint(g); - } - - /** - * Add a series for a X-Y type chart using Lists with error bars - * - * @param seriesName - * @param xData the X-Axis data - * @param yData the Y-Axis data - * @param errorBars the error bar data - * @return A Series object that you can set properties on - */ - public Series addSeries(String seriesName, List<?> xData, List<? extends Number> yData, List<? extends Number> errorBars) { - - return chartInternal.addSeries(seriesName, xData, yData, errorBars); - } - - /** - * Add a series for a X-Y type chart using Lists - * - * @param seriesName - * @param xData the X-Axis data - * @param yData the Y-Axis data - * @return A Series object that you can set properties on - */ - public Series addSeries(String seriesName, List<?> xData, List<? extends Number> yData) { - - return addSeries(seriesName, xData, yData, null); - } - - /** - * Add a series for a Category type chart using Lists with error bars - * - * @param seriesName - * @param xData the X-Axis data - * @param yData the Y-Axis data - * @param errorBars the error bar data - * @return A Series object that you can set properties on - */ - public Series addCategorySeries(String seriesName, List<?> xData, List<? extends Number> yData, List<? extends Number> errorBars) { - - return chartInternal.addCategorySeries(seriesName, xData, yData, errorBars); - } - - /** - * Add a series for a Category type chart using Lists - * - * @param seriesName - * @param xData the X-Axis data - * @param yData the Y-Axis data - * @return A Series object that you can set properties on - */ - public Series addCategorySeries(String seriesName, List<?> xData, List<? extends Number> yData) { - - return addCategorySeries(seriesName, xData, yData, null); - } - - /** - * Add a series for a Pie type chart - * - * @param seriesName - * @param value - * @return - */ - public Series addPieSeries(String seriesName, Number value) { - - return chartInternal.addPieSeries(seriesName, value); - } - - /** - * Add a series for a X-Y type chart using using double arrays - * - * @param seriesName - * @param xData the X-Axis data - * @param xData the Y-Axis data - * @return A Series object that you can set properties on - */ - public Series addSeries(String seriesName, double[] xData, double[] yData) { - - return addSeries(seriesName, xData, yData, null); - } - - /** - * Add a series for a X-Y type chart using using double arrays with error bars - * - * @param seriesName - * @param xData the X-Axis data - * @param xData the Y-Axis data - * @param errorBars the error bar data - * @return A Series object that you can set properties on - */ - public Series addSeries(String seriesName, double[] xData, double[] yData, double[] errorBars) { - - List<Double> xDataNumber = null; - if (xData != null) { - xDataNumber = new ArrayList<Double>(); - for (double d : xData) { - xDataNumber.add(new Double(d)); - } - } - List<Double> yDataNumber = new ArrayList<Double>(); - for (double d : yData) { - yDataNumber.add(new Double(d)); - } - List<Double> errorBarDataNumber = null; - if (errorBars != null) { - errorBarDataNumber = new ArrayList<Double>(); - for (double d : errorBars) { - errorBarDataNumber.add(new Double(d)); - } - } - - return addSeries(seriesName, xDataNumber, yDataNumber, errorBarDataNumber); - } - - /** - * Add a series for a X-Y type chart using using int arrays - * - * @param seriesName - * @param xData the X-Axis data - * @param xData the Y-Axis data - * @return A Series object that you can set properties on - */ - public Series addSeries(String seriesName, int[] xData, int[] yData) { - - return addSeries(seriesName, xData, yData, null); - } - - /** - * Add a series for a X-Y type chart using using int arrays with error bars - * - * @param seriesName - * @param xData the X-Axis data - * @param xData the Y-Axis data - * @param errorBars the error bar data - * @return A Series object that you can set properties on - */ - public Series addSeries(String seriesName, int[] xData, int[] yData, int[] errorBars) { - - List<Double> xDataNumber = null; - if (xData != null) { - xDataNumber = new ArrayList<Double>(); - for (int d : xData) { - xDataNumber.add(new Double(d)); - } - } - List<Double> yDataNumber = new ArrayList<Double>(); - for (int d : yData) { - yDataNumber.add(new Double(d)); - } - List<Double> errorBarDataNumber = null; - if (errorBars != null) { - errorBarDataNumber = new ArrayList<Double>(); - for (int d : errorBars) { - errorBarDataNumber.add(new Double(d)); - } - } - - return addSeries(seriesName, xDataNumber, yDataNumber, errorBarDataNumber); - } - - /** - * Set the chart title - * - * @param title - */ - public void setChartTitle(String title) { - - chartInternal.getChartTitle().setText(title); - } - - /** - * Set the x-axis title - * - * @param title - */ - public void setXAxisTitle(String title) { - - chartInternal.getAxisPair().getXAxis().getAxisTitle().setText(title); - } - - /** - * Set the y-axis title - * - * @param title - */ - public void setYAxisTitle(String title) { - - chartInternal.getAxisPair().getYAxis().getAxisTitle().setText(title); - } - - /** - * Gets the Chart's style manager, which can be used to customize the Chart's appearance - * - * @return the style manager - */ - public StyleManager getStyleManager() { - - return chartInternal.getStyleManager(); - } - - public int getWidth() { - - return chartInternal.getWidth(); - } - - public int getHeight() { - - return chartInternal.getHeight(); - } - - public Map<String, Series> getSeriesMap() { - - return chartInternal.getSeriesMap(); - } - -} diff --git a/xchart/src/main/java/org/knowm/xchart/ChartBuilder.java b/xchart/src/main/java/org/knowm/xchart/ChartBuilder.java deleted file mode 100644 index 76d3548bdc22d42292d9390e5420440e39281fbc..0000000000000000000000000000000000000000 --- a/xchart/src/main/java/org/knowm/xchart/ChartBuilder.java +++ /dev/null @@ -1,90 +0,0 @@ -/** - * Copyright 2015 Knowm Inc. (http://knowm.org) and contributors. - * Copyright 2011-2015 Xeiam LLC (http://xeiam.com) and contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.knowm.xchart; - -import org.knowm.xchart.StyleManager.ChartTheme; -import org.knowm.xchart.StyleManager.ChartType; - -/** - * A "Builder" to make creating charts easier - * - * @author timmolter - */ -public class ChartBuilder { - - ChartType chartType = ChartType.Line; - int width = 800; - int height = 600; - String title = ""; - String xAxisTitle = ""; - String yAxisTitle = ""; - ChartTheme chartTheme = ChartTheme.XChart; - - public ChartBuilder chartType(ChartType chartType) { - - this.chartType = chartType; - return this; - } - - public ChartBuilder width(int width) { - - this.width = width; - return this; - } - - public ChartBuilder height(int height) { - - this.height = height; - return this; - } - - public ChartBuilder title(String title) { - - this.title = title; - return this; - } - - public ChartBuilder xAxisTitle(String xAxisTitle) { - - this.xAxisTitle = xAxisTitle; - return this; - } - - public ChartBuilder yAxisTitle(String yAxisTitle) { - - this.yAxisTitle = yAxisTitle; - return this; - } - - public ChartBuilder theme(ChartTheme chartTheme) { - - this.chartTheme = chartTheme; - return this; - } - - /** - * return fully built Chart - * - * @return a Chart - */ - public Chart build() { - - return new Chart(this); - - } - -} diff --git a/xchart/src/main/java/org/knowm/xchart/ChartBuilderPie.java b/xchart/src/main/java/org/knowm/xchart/ChartBuilderPie.java new file mode 100644 index 0000000000000000000000000000000000000000..c678df5920141bd87a0e85de5c1f10ebb17534a7 --- /dev/null +++ b/xchart/src/main/java/org/knowm/xchart/ChartBuilderPie.java @@ -0,0 +1,40 @@ +/** + * Copyright 2015-2016 Knowm Inc. (http://knowm.org) and contributors. + * Copyright 2011-2015 Xeiam LLC (http://xeiam.com) and contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.knowm.xchart; + +import org.knowm.xchart.internal.ChartBuilder; + +/** + * @author timmolter + */ +public class ChartBuilderPie extends ChartBuilder<ChartBuilderPie, Chart_Pie> { + + public ChartBuilderPie() { + + } + + /** + * return fully built ChartPie + * + * @return a ChartPie + */ + @Override + public Chart_Pie build() { + + return new Chart_Pie(this); + } +} diff --git a/xchart/src/main/java/org/knowm/xchart/ChartBuilderXY.java b/xchart/src/main/java/org/knowm/xchart/ChartBuilderXY.java new file mode 100644 index 0000000000000000000000000000000000000000..147be6cff9da0d58c3f054c59bb0a99ee49b0c7d --- /dev/null +++ b/xchart/src/main/java/org/knowm/xchart/ChartBuilderXY.java @@ -0,0 +1,55 @@ +/** + * Copyright 2015-2016 Knowm Inc. (http://knowm.org) and contributors. + * Copyright 2011-2015 Xeiam LLC (http://xeiam.com) and contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.knowm.xchart; + +import org.knowm.xchart.internal.ChartBuilder; + +/** + * @author timmolter + */ +public class ChartBuilderXY extends ChartBuilder<ChartBuilderXY, Chart_XY> { + + String xAxisTitle = ""; + String yAxisTitle = ""; + + public ChartBuilderXY() { + + } + + public ChartBuilderXY xAxisTitle(String xAxisTitle) { + + this.xAxisTitle = xAxisTitle; + return this; + } + + public ChartBuilderXY yAxisTitle(String yAxisTitle) { + + this.yAxisTitle = yAxisTitle; + return this; + } + + /** + * return fully built ChartXY + * + * @return a ChartXY + */ + @Override + public Chart_XY build() { + + return new Chart_XY(this); + } +} diff --git a/xchart/src/main/java/org/knowm/xchart/ChartBuilder_Category.java b/xchart/src/main/java/org/knowm/xchart/ChartBuilder_Category.java new file mode 100644 index 0000000000000000000000000000000000000000..0eefb429080c9fd72864ef2550d94a5bb10ca674 --- /dev/null +++ b/xchart/src/main/java/org/knowm/xchart/ChartBuilder_Category.java @@ -0,0 +1,55 @@ +/** + * Copyright 2015-2016 Knowm Inc. (http://knowm.org) and contributors. + * Copyright 2011-2015 Xeiam LLC (http://xeiam.com) and contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.knowm.xchart; + +import org.knowm.xchart.internal.ChartBuilder; + +/** + * @author timmolter + */ +public class ChartBuilder_Category extends ChartBuilder<ChartBuilder_Category, Chart_Category> { + + String xAxisTitle = ""; + String yAxisTitle = ""; + + public ChartBuilder_Category() { + + } + + public ChartBuilder_Category xAxisTitle(String xAxisTitle) { + + this.xAxisTitle = xAxisTitle; + return this; + } + + public ChartBuilder_Category yAxisTitle(String yAxisTitle) { + + this.yAxisTitle = yAxisTitle; + return this; + } + + /** + * return fully built Chart_Category + * + * @return a Chart_Category + */ + @Override + public Chart_Category build() { + + return new Chart_Category(this); + } +} diff --git a/xchart/src/main/java/org/knowm/xchart/ChartColor.java b/xchart/src/main/java/org/knowm/xchart/ChartColor.java index 1b4edc2b7c9cd22184bec3096af0691e58e5a775..0d9fe8caf48861621a7622ea1c96ce330890c206 100644 --- a/xchart/src/main/java/org/knowm/xchart/ChartColor.java +++ b/xchart/src/main/java/org/knowm/xchart/ChartColor.java @@ -1,5 +1,5 @@ /** - * Copyright 2015 Knowm Inc. (http://knowm.org) and contributors. + * Copyright 2015-2016 Knowm Inc. (http://knowm.org) and contributors. * Copyright 2011-2015 Xeiam LLC (http://xeiam.com) and contributors. * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/xchart/src/main/java/org/knowm/xchart/Chart_Category.java b/xchart/src/main/java/org/knowm/xchart/Chart_Category.java new file mode 100644 index 0000000000000000000000000000000000000000..c35580e73d9902daa5234952692f38d56e98b9b8 --- /dev/null +++ b/xchart/src/main/java/org/knowm/xchart/Chart_Category.java @@ -0,0 +1,259 @@ +/** + * Copyright 2015-2016 Knowm Inc. (http://knowm.org) and contributors. + * Copyright 2011-2015 Xeiam LLC (http://xeiam.com) and contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.knowm.xchart; + +import java.awt.Graphics2D; +import java.awt.RenderingHints; +import java.awt.Shape; +import java.awt.geom.Rectangle2D; +import java.util.List; + +import org.knowm.xchart.internal.chartpart.Axis.AxisDataType; +import org.knowm.xchart.internal.chartpart.AxisPair; +import org.knowm.xchart.internal.chartpart.Chart; +import org.knowm.xchart.internal.chartpart.LegendAxesChart; +import org.knowm.xchart.internal.chartpart.Plot_Category; +import org.knowm.xchart.internal.style.Theme; +import org.knowm.xchart.internal.style.StyleManager.ChartTheme; + +/** + * @author timmolter + */ +public class Chart_Category extends Chart<StyleManagerCategory, Series_Category> { + + /** + * Constructor - the default Chart Theme will be used (XChartTheme) + * + * @param width + * @param height + */ + public Chart_Category(int width, int height) { + + super(width, height, new StyleManagerCategory()); + axisPair = new AxisPair(this); + plot = new Plot_Category(this); + chartLegend = new LegendAxesChart(this); + } + + /** + * Constructor + * + * @param width + * @param height + * @param theme - pass in a instance of Theme class, probably a custom Theme. + */ + public Chart_Category(int width, int height, Theme theme) { + + this(width, height); + styleManager.setTheme(theme); + } + + /** + * Constructor + * + * @param width + * @param height + * @param chartTheme - pass in the desired ChartTheme enum + */ + public Chart_Category(int width, int height, ChartTheme chartTheme) { + + this(width, height, chartTheme.newInstance(chartTheme)); + } + + /** + * Constructor + * + * @param chartBuilder + */ + public Chart_Category(ChartBuilder_Category chartBuilder) { + + this(chartBuilder.width, chartBuilder.height, chartBuilder.chartTheme); + setTitle(chartBuilder.title); + setXAxisTitle(chartBuilder.xAxisTitle); + setYAxisTitle(chartBuilder.yAxisTitle); + } + + /** + * Add a series for a Category type chart using using double arrays + * + * @param seriesName + * @param xData the X-Axis data + * @param xData the Y-Axis data + * @return A Series object that you can set properties on + */ + public Series_Category addSeries(String seriesName, double[] xData, double[] yData) { + + return addSeries(seriesName, xData, yData, null); + } + + /** + * Add a series for a Category type chart using using double arrays with error bars + * + * @param seriesName + * @param xData the X-Axis data + * @param xData the Y-Axis data + * @param errorBars the error bar data + * @return A Series object that you can set properties on + */ + public Series_Category addSeries(String seriesName, double[] xData, double[] yData, double[] errorBars) { + + return addSeries(seriesName, getNumberListFromDoubleArray(xData), getNumberListFromDoubleArray(yData), getNumberListFromDoubleArray(errorBars)); + } + + /** + * Add a series for a X-Y type chart using using int arrays + * + * @param seriesName + * @param xData the X-Axis data + * @param xData the Y-Axis data + * @return A Series object that you can set properties on + */ + public Series_Category addSeries(String seriesName, int[] xData, int[] yData) { + + return addSeries(seriesName, xData, yData, null); + } + + /** + * Add a series for a X-Y type chart using using int arrays with error bars + * + * @param seriesName + * @param xData the X-Axis data + * @param xData the Y-Axis data + * @param errorBars the error bar data + * @return A Series object that you can set properties on + */ + public Series_Category addSeries(String seriesName, int[] xData, int[] yData, int[] errorBars) { + + return addSeries(seriesName, getNumberListFromIntArray(xData), getNumberListFromIntArray(yData), getNumberListFromIntArray(errorBars)); + } + + /** + * Add a series for a Category type chart using Lists + * + * @param seriesName + * @param xData the X-Axis data + * @param yData the Y-Axis data + * @return A Series object that you can set properties on + */ + public Series_Category addSeries(String seriesName, List<?> xData, List<? extends Number> yData) { + + return addSeries(seriesName, xData, yData, null); + } + + /** + * Add a series for a Category type chart using Lists with error bars + * + * @param seriesName + * @param xData the X-Axis data + * @param yData the Y-Axis data + * @param errorBars the error bar data + * @return A Series object that you can set properties on + */ + public Series_Category addSeries(String seriesName, List<?> xData, List<? extends Number> yData, List<? extends Number> errorBars) { + + // Sanity checks + sanityCheck(seriesName, xData, yData, errorBars); + + Series_Category series = null; + if (xData != null) { + + // Sanity check + if (xData.size() != yData.size()) { + throw new IllegalArgumentException("X and Y-Axis sizes are not the same!!!"); + } + + // inspect the series to see what kind of data it contains (Number, Date) + + series = new Series_Category(seriesName, xData, yData, errorBars, styleManager.getSeriesColorMarkerLineStyleCycler().getNextSeriesColorMarkerLineStyle()); + } + else { // generate xData + series = new Series_Category(seriesName, getGeneratedData(yData.size()), yData, errorBars, styleManager.getSeriesColorMarkerLineStyleCycler().getNextSeriesColorMarkerLineStyle()); + } + + seriesMap.put(seriesName, series); + + getXAxis().setAxisType(series.getxAxisType()); + getYAxis().setAxisType(AxisDataType.Number); + + return series; + } + + /////////////////////////////////////////////////// + // Internal Members and Methods /////////////////// + /////////////////////////////////////////////////// + + private void sanityCheck(String seriesName, List<?> xData, List<? extends Number> yData, List<? extends Number> errorBars) { + + if (seriesMap.keySet().contains(seriesName)) { + throw new IllegalArgumentException("Series name >" + seriesName + "< has already been used. Use unique names for each series!!!"); + } + if (yData == null) { + throw new IllegalArgumentException("Y-Axis data cannot be null!!!"); + } + if (yData.size() == 0) { + throw new IllegalArgumentException("Y-Axis data cannot be empty!!!"); + } + if (xData != null && xData.size() == 0) { + throw new IllegalArgumentException("X-Axis data cannot be empty!!!"); + } + if (errorBars != null && errorBars.size() != yData.size()) { + throw new IllegalArgumentException("Error bars and Y-Axis sizes are not the same!!!"); + } + } + + @Override + public void paint(Graphics2D g, int width, int height) { + + setWidth(width); + setHeight(height); + paint(g); + } + + @Override + public void paint(Graphics2D g) { + + // Sanity checks + if (getSeriesMap().isEmpty()) { + throw new RuntimeException("No series defined for Chart!!!"); + } + + // set the series render styles if they are not set. Legend and Plot need it. + for (Series_Category seriesCategory : getSeriesMap().values()) { + Series_Category.ChartCategorySeriesRenderStyle seriesType = seriesCategory.getChartCategorySeriesRenderStyle(); // would be directly set + if (seriesType == null) { // wasn't overridden, use default from Style Manager + seriesCategory.setChartCategorySeriesRenderStyle(getStyleManager().getChartCategorySeriesRenderStyle()); + } + } + + // override min/max value for bar charts' Y-Axis + // getyAxis().setMin(0); + + // paint chart main background + g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); // global rendering hint + g.setColor(styleManager.getChartBackgroundColor()); + Shape rect = new Rectangle2D.Double(0, 0, getWidth(), getHeight()); + g.fill(rect); + + axisPair.paint(g); + plot.paint(g); + chartTitle.paint(g); + chartLegend.paint(g); + + g.dispose(); + } + +} diff --git a/xchart/src/main/java/org/knowm/xchart/Chart_Pie.java b/xchart/src/main/java/org/knowm/xchart/Chart_Pie.java new file mode 100644 index 0000000000000000000000000000000000000000..1538d83237e88af9ca9739ec5623f49c6467fb7a --- /dev/null +++ b/xchart/src/main/java/org/knowm/xchart/Chart_Pie.java @@ -0,0 +1,140 @@ +/** + * Copyright 2015-2016 Knowm Inc. (http://knowm.org) and contributors. + * Copyright 2011-2015 Xeiam LLC (http://xeiam.com) and contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.knowm.xchart; + +import java.awt.Graphics2D; +import java.awt.RenderingHints; +import java.awt.Shape; +import java.awt.geom.Rectangle2D; + +import org.knowm.xchart.internal.Series; +import org.knowm.xchart.internal.chartpart.Chart; +import org.knowm.xchart.internal.chartpart.LegendPie; +import org.knowm.xchart.internal.chartpart.Plot_Pie; +import org.knowm.xchart.internal.style.Theme; +import org.knowm.xchart.internal.style.StyleManager.ChartTheme; + +/** + * @author timmolter + */ +public class Chart_Pie extends Chart<StyleManagerPie, Series_Pie> { + + /** + * Constructor - the default Chart Theme will be used (XChartTheme) + * + * @param width + * @param height + */ + public Chart_Pie(int width, int height) { + + super(width, height, new StyleManagerPie()); + plot = new Plot_Pie(this); + chartLegend = new LegendPie(this); + } + + /** + * Constructor + * + * @param width + * @param height + * @param theme - pass in a instance of Theme class, probably a custom Theme. + */ + public Chart_Pie(int width, int height, Theme theme) { + + this(width, height); + styleManager.setTheme(theme); + } + + /** + * Constructor + * + * @param width + * @param height + * @param chartTheme - pass in the desired ChartTheme enum + */ + public Chart_Pie(int width, int height, ChartTheme chartTheme) { + + this(width, height, chartTheme.newInstance(chartTheme)); + } + + /** + * Constructor + * + * @param chartBuilder + */ + public Chart_Pie(ChartBuilderPie chartBuilder) { + + this(chartBuilder.width, chartBuilder.height, chartBuilder.chartTheme); + setTitle(chartBuilder.title); + } + + /** + * Add a series for a Pie type chart + * + * @param seriesName + * @param value + * @return + */ + public Series addSeries(String seriesName, Number value) { + + Series_Pie series = new Series_Pie(seriesName, value, styleManager.getSeriesColorMarkerLineStyleCycler().getNextSeriesColorMarkerLineStyle()); + + if (seriesMap.keySet().contains(seriesName)) { + throw new IllegalArgumentException("Series name >" + seriesName + "< has already been used. Use unique names for each series!!!"); + } + seriesMap.put(seriesName, series); + + return series; + } + + @Override + public void paint(Graphics2D g, int width, int height) { + + setWidth(width); + setHeight(height); + paint(g); + } + + @Override + public void paint(Graphics2D g) { + + // Sanity checks + if (getSeriesMap().isEmpty()) { + throw new RuntimeException("No series defined for Chart!!!"); + } + + // set the series types if they are not set. Legend and Plot need it. + for (Series_Pie seriesPie : getSeriesMap().values()) { + Series_Pie.ChartPieSeriesRenderStyle seriesType = seriesPie.getChartPieSeriesRenderStyle(); // would be directly set + if (seriesType == null) { // wasn't overridden, use default from Style Manager + seriesPie.setChartPieSeriesRenderStyle(getStyleManager().getChartPieSeriesRenderStyle()); + } + } + + // paint chart main background + g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); // global rendering hint + g.setColor(styleManager.getChartBackgroundColor()); + Shape rect = new Rectangle2D.Double(0, 0, getWidth(), getHeight()); + g.fill(rect); + + plot.paint(g); + chartTitle.paint(g); + chartLegend.paint(g); + + g.dispose(); + } +} diff --git a/xchart/src/main/java/org/knowm/xchart/Chart_XY.java b/xchart/src/main/java/org/knowm/xchart/Chart_XY.java new file mode 100644 index 0000000000000000000000000000000000000000..4a0a053707a153040cca928a8b8f4674b33bbb78 --- /dev/null +++ b/xchart/src/main/java/org/knowm/xchart/Chart_XY.java @@ -0,0 +1,256 @@ +/** + * Copyright 2015-2016 Knowm Inc. (http://knowm.org) and contributors. + * Copyright 2011-2015 Xeiam LLC (http://xeiam.com) and contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.knowm.xchart; + +import java.awt.Graphics2D; +import java.awt.RenderingHints; +import java.awt.Shape; +import java.awt.geom.Rectangle2D; +import java.util.List; + +import org.knowm.xchart.internal.chartpart.Axis.AxisDataType; +import org.knowm.xchart.internal.chartpart.AxisPair; +import org.knowm.xchart.internal.chartpart.Chart; +import org.knowm.xchart.internal.chartpart.LegendAxesChart; +import org.knowm.xchart.internal.chartpart.Plot_XY; +import org.knowm.xchart.internal.style.Theme; +import org.knowm.xchart.internal.style.StyleManager.ChartTheme; + +/** + * @author timmolter + */ +public class Chart_XY extends Chart<StyleManagerXY, Series_XY> { + + /** + * Constructor - the default Chart Theme will be used (XChartTheme) + * + * @param width + * @param height + */ + public Chart_XY(int width, int height) { + + super(width, height, new StyleManagerXY()); + axisPair = new AxisPair(this); + plot = new Plot_XY(this); + chartLegend = new LegendAxesChart(this); + } + + /** + * Constructor + * + * @param width + * @param height + * @param theme - pass in a instance of Theme class, probably a custom Theme. + */ + public Chart_XY(int width, int height, Theme theme) { + + this(width, height); + styleManager.setTheme(theme); + } + + /** + * Constructor + * + * @param width + * @param height + * @param chartTheme - pass in the desired ChartTheme enum + */ + public Chart_XY(int width, int height, ChartTheme chartTheme) { + + this(width, height, chartTheme.newInstance(chartTheme)); + } + + /** + * Constructor + * + * @param chartBuilder + */ + public Chart_XY(ChartBuilderXY chartBuilder) { + + this(chartBuilder.width, chartBuilder.height, chartBuilder.chartTheme); + setTitle(chartBuilder.title); + setXAxisTitle(chartBuilder.xAxisTitle); + setYAxisTitle(chartBuilder.yAxisTitle); + } + + /** + * Add a series for a X-Y type chart using Lists + * + * @param seriesName + * @param xData the X-Axis data + * @param yData the Y-Axis data + * @return A Series object that you can set properties on + */ + public Series_XY addSeries(String seriesName, List<?> xData, List<? extends Number> yData) { + + return addSeries(seriesName, xData, yData, null); + } + + /** + * Add a series for a X-Y type chart using using double arrays + * + * @param seriesName + * @param xData the X-Axis data + * @param xData the Y-Axis data + * @return A Series object that you can set properties on + */ + public Series_XY addSeries(String seriesName, double[] xData, double[] yData) { + + return addSeries(seriesName, xData, yData, null); + } + + /** + * Add a series for a X-Y type chart using using double arrays with error bars + * + * @param seriesName + * @param xData the X-Axis data + * @param xData the Y-Axis data + * @param errorBars the error bar data + * @return A Series object that you can set properties on + */ + public Series_XY addSeries(String seriesName, double[] xData, double[] yData, double[] errorBars) { + + return addSeries(seriesName, getNumberListFromDoubleArray(xData), getNumberListFromDoubleArray(yData), getNumberListFromDoubleArray(errorBars)); + } + + /** + * Add a series for a X-Y type chart using using int arrays + * + * @param seriesName + * @param xData the X-Axis data + * @param xData the Y-Axis data + * @return A Series object that you can set properties on + */ + public Series_XY addSeries(String seriesName, int[] xData, int[] yData) { + + return addSeries(seriesName, xData, yData, null); + } + + /** + * Add a series for a X-Y type chart using using int arrays with error bars + * + * @param seriesName + * @param xData the X-Axis data + * @param xData the Y-Axis data + * @param errorBars the error bar data + * @return A Series object that you can set properties on + */ + public Series_XY addSeries(String seriesName, int[] xData, int[] yData, int[] errorBars) { + + return addSeries(seriesName, getNumberListFromIntArray(xData), getNumberListFromIntArray(yData), getNumberListFromIntArray(errorBars)); + } + + /** + * Add a series for a X-Y type chart using Lists with error bars + * + * @param seriesName + * @param xData the X-Axis data + * @param yData the Y-Axis data + * @param errorBars the error bar data + * @return A Series object that you can set properties on + */ + public Series_XY addSeries(String seriesName, List<?> xData, List<? extends Number> yData, List<? extends Number> errorBars) { + + // Sanity checks + sanityCheck(seriesName, xData, yData, errorBars); + + Series_XY series = null; + if (xData != null) { + + // Sanity check + if (xData.size() != yData.size()) { + throw new IllegalArgumentException("X and Y-Axis sizes are not the same!!!"); + } + + // inspect the series to see what kind of data it contains (Number, Date) + + series = new Series_XY(seriesName, xData, yData, errorBars, styleManager.getSeriesColorMarkerLineStyleCycler().getNextSeriesColorMarkerLineStyle()); + } + else { // generate xData + series = new Series_XY(seriesName, getGeneratedData(yData.size()), yData, errorBars, styleManager.getSeriesColorMarkerLineStyleCycler().getNextSeriesColorMarkerLineStyle()); + } + + seriesMap.put(seriesName, series); + + getXAxis().setAxisType(series.getxAxisType()); + getYAxis().setAxisType(AxisDataType.Number); + + return series; + } + + /////////////////////////////////////////////////// + // Internal Members and Methods /////////////////// + /////////////////////////////////////////////////// + + private void sanityCheck(String seriesName, List<?> xData, List<? extends Number> yData, List<? extends Number> errorBars) { + + if (seriesMap.keySet().contains(seriesName)) { + throw new IllegalArgumentException("Series name >" + seriesName + "< has already been used. Use unique names for each series!!!"); + } + if (yData == null) { + throw new IllegalArgumentException("Y-Axis data cannot be null!!!"); + } + if (yData.size() == 0) { + throw new IllegalArgumentException("Y-Axis data cannot be empty!!!"); + } + if (xData != null && xData.size() == 0) { + throw new IllegalArgumentException("X-Axis data cannot be empty!!!"); + } + if (errorBars != null && errorBars.size() != yData.size()) { + throw new IllegalArgumentException("Error bars and Y-Axis sizes are not the same!!!"); + } + } + + @Override + public void paint(Graphics2D g, int width, int height) { + + setWidth(width); + setHeight(height); + paint(g); + } + + @Override + public void paint(Graphics2D g) { + + // Sanity checks + if (getSeriesMap().isEmpty()) { + throw new RuntimeException("No series defined for Chart!!!"); + } + + // set the series render styles if they are not set. Legend and Plot need it. + for (Series_XY seriesXY : getSeriesMap().values()) { + Series_XY.ChartXYSeriesRenderStyle seriesType = seriesXY.getChartXYSeriesRenderStyle(); // would be directly set + if (seriesType == null) { // wasn't overridden, use default from Style Manager + seriesXY.setChartXYSeriesRenderStyle(getStyleManager().getChartXYSeriesRenderStyle()); + } + } + + // paint chart main background + g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); // global rendering hint + g.setColor(styleManager.getChartBackgroundColor()); + Shape rect = new Rectangle2D.Double(0, 0, getWidth(), getHeight()); + g.fill(rect); + + axisPair.paint(g); + plot.paint(g); + chartTitle.paint(g); + chartLegend.paint(g); + + g.dispose(); + } + +} diff --git a/xchart/src/main/java/org/knowm/xchart/Histogram.java b/xchart/src/main/java/org/knowm/xchart/Histogram.java index c22d2234a80a78468377ed5de6eb05059443c214..619889d08715cebc7049cf394b6bdfdc49cc70a2 100644 --- a/xchart/src/main/java/org/knowm/xchart/Histogram.java +++ b/xchart/src/main/java/org/knowm/xchart/Histogram.java @@ -1,5 +1,5 @@ /** - * Copyright 2015 Knowm Inc. (http://knowm.org) and contributors. + * Copyright 2015-2016 Knowm Inc. (http://knowm.org) and contributors. * Copyright 2011-2015 Xeiam LLC (http://xeiam.com) and contributors. * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/xchart/src/main/java/org/knowm/xchart/QuickChart.java b/xchart/src/main/java/org/knowm/xchart/QuickChart.java index bf795a2d5c8517e6f2441cff154ec84be09cd6f8..e338a9c24d51ccbb847bc3aa0d817c83b1971b13 100644 --- a/xchart/src/main/java/org/knowm/xchart/QuickChart.java +++ b/xchart/src/main/java/org/knowm/xchart/QuickChart.java @@ -1,5 +1,5 @@ /** - * Copyright 2015 Knowm Inc. (http://knowm.org) and contributors. + * Copyright 2015-2016 Knowm Inc. (http://knowm.org) and contributors. * Copyright 2011-2015 Xeiam LLC (http://xeiam.com) and contributors. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,6 +18,8 @@ package org.knowm.xchart; import java.util.List; +import org.knowm.xchart.internal.chartpart.Chart; + /** * A convenience class for making Charts with one line of code * @@ -71,16 +73,16 @@ 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 Chart(WIDTH, HEIGHT); + Chart_XY chart = new Chart_XY(WIDTH, HEIGHT); // Customize Chart - chart.setChartTitle(chartTitle); + chart.setTitle(chartTitle); chart.setXAxisTitle(xTitle); chart.setYAxisTitle(yTitle); // Series for (int i = 0; i < yData.length; i++) { - Series series; + Series_XY series; if (seriesNames != null) { series = chart.addSeries(seriesNames[i], xData, yData[i]); } @@ -108,14 +110,14 @@ public final class QuickChart { public static Chart getChart(String chartTitle, String xTitle, String yTitle, String seriesName, List<? extends Number> xData, List<? extends Number> yData) { // Create Chart - Chart chart = new Chart(WIDTH, HEIGHT); + Chart_XY chart = new Chart_XY(WIDTH, HEIGHT); // Customize Chart - chart.setChartTitle(chartTitle); + chart.setTitle(chartTitle); chart.setXAxisTitle(xTitle); chart.setYAxisTitle(yTitle); - Series series = chart.addSeries(seriesName, xData, yData); + Series_XY series = chart.addSeries(seriesName, xData, yData); series.setMarker(SeriesMarker.NONE); return chart; diff --git a/xchart/src/main/java/org/knowm/xchart/SeriesColor.java b/xchart/src/main/java/org/knowm/xchart/SeriesColor.java deleted file mode 100644 index 756d504f80a25decf6fe29db7ffd3283f430f419..0000000000000000000000000000000000000000 --- a/xchart/src/main/java/org/knowm/xchart/SeriesColor.java +++ /dev/null @@ -1,72 +0,0 @@ -/** - * Copyright 2015 Knowm Inc. (http://knowm.org) and contributors. - * Copyright 2011-2015 Xeiam LLC (http://xeiam.com) and contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.knowm.xchart; - -import java.awt.Color; - -/** - * Pre-defined Colors used for Series Lines and Markers - * - * @author timmolter - */ -public class SeriesColor { - - /** The AWT Color */ - private Color color; - - /** - * Constructor - * - * @param color - */ - public SeriesColor(Color color) { - - this.color = color; - } - - /** - * Constructor - * - * @param color - */ - public SeriesColor(int r, int g, int b, int a) { - - this.color = new Color(r, g, b, a); - } - - /** - * Gets the SeriesColor's AWT Color - * - * @return the AWT Color - */ - public Color getColor() { - - return color; - } - - // /** - // * get the AWT Color given a SeriesColor - // * - // * @param seriesColor - // * @return the AWT Color - // */ - // public Color getAWTColor(SeriesColor seriesColor) { - // - // return seriesColor.color; - // } - -} diff --git a/xchart/src/main/java/org/knowm/xchart/SeriesLineStyle.java b/xchart/src/main/java/org/knowm/xchart/SeriesLineStyle.java index e3130074e3e8ea15ec5cea59515ee2a4e6463e52..c5fa248b86171062e0bdd869045e403325804da7 100644 --- a/xchart/src/main/java/org/knowm/xchart/SeriesLineStyle.java +++ b/xchart/src/main/java/org/knowm/xchart/SeriesLineStyle.java @@ -1,5 +1,5 @@ /** - * Copyright 2015 Knowm Inc. (http://knowm.org) and contributors. + * Copyright 2015-2016 Knowm Inc. (http://knowm.org) and contributors. * Copyright 2011-2015 Xeiam LLC (http://xeiam.com) and contributors. * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/xchart/src/main/java/org/knowm/xchart/SeriesMarker.java b/xchart/src/main/java/org/knowm/xchart/SeriesMarker.java index 5bd00b225470435942cf39432436a4c3cc1e9d65..9be4d83e1eec8f1412978a40d8e749c420112185 100644 --- a/xchart/src/main/java/org/knowm/xchart/SeriesMarker.java +++ b/xchart/src/main/java/org/knowm/xchart/SeriesMarker.java @@ -1,5 +1,5 @@ /** - * Copyright 2015 Knowm Inc. (http://knowm.org) and contributors. + * Copyright 2015-2016 Knowm Inc. (http://knowm.org) and contributors. * Copyright 2011-2015 Xeiam LLC (http://xeiam.com) and contributors. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -16,12 +16,12 @@ */ package org.knowm.xchart; -import org.knowm.xchart.internal.markers.Circle; -import org.knowm.xchart.internal.markers.Diamond; -import org.knowm.xchart.internal.markers.Marker; -import org.knowm.xchart.internal.markers.Square; -import org.knowm.xchart.internal.markers.TriangleDown; -import org.knowm.xchart.internal.markers.TriangleUp; +import org.knowm.xchart.internal.style.markers.Circle; +import org.knowm.xchart.internal.style.markers.Diamond; +import org.knowm.xchart.internal.style.markers.Marker; +import org.knowm.xchart.internal.style.markers.Square; +import org.knowm.xchart.internal.style.markers.TriangleDown; +import org.knowm.xchart.internal.style.markers.TriangleUp; /** * Pre-defined Markers used for Series Lines diff --git a/xchart/src/main/java/org/knowm/xchart/Series.java b/xchart/src/main/java/org/knowm/xchart/Series_AxesChart.java similarity index 74% rename from xchart/src/main/java/org/knowm/xchart/Series.java rename to xchart/src/main/java/org/knowm/xchart/Series_AxesChart.java index 574c71cbcbd3540d2e3acb3d2e5816ac257656e7..c4418a977adbffe73352fc7be3dbafa8ad6d853e 100644 --- a/xchart/src/main/java/org/knowm/xchart/Series.java +++ b/xchart/src/main/java/org/knowm/xchart/Series_AxesChart.java @@ -1,5 +1,5 @@ /** - * Copyright 2015 Knowm Inc. (http://knowm.org) and contributors. + * Copyright 2015-2016 Knowm Inc. (http://knowm.org) and contributors. * Copyright 2011-2015 Xeiam LLC (http://xeiam.com) and contributors. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -23,30 +23,25 @@ import java.util.Date; import java.util.Iterator; import java.util.List; -import org.knowm.xchart.internal.chartpart.Axis.AxisType; -import org.knowm.xchart.internal.markers.Marker; +import org.knowm.xchart.internal.Series; +import org.knowm.xchart.internal.chartpart.Axis.AxisDataType; import org.knowm.xchart.internal.style.SeriesColorMarkerLineStyle; +import org.knowm.xchart.internal.style.markers.Marker; /** - * A Series containing X and Y data to be plotted on a Chart + * A Series containing X and Y data to be plotted on a Chart with X and Y Axes * * @author timmolter */ -public class Series { +public abstract class Series_AxesChart extends Series { - public enum SeriesType { - Line, Scatter, Area, Bar, Pie - } - - private SeriesType seriesType = null; + public abstract AxisDataType getAxesType(List<?> data); - private String name = ""; - - private List<?> xData; - private AxisType xAxisType; + private List<?> xData; // can be Number or Date or String + private AxisDataType xAxisType; private List<? extends Number> yData; - private AxisType yAxisType; + private AxisDataType yAxisType; private List<? extends Number> errorBars; @@ -68,9 +63,6 @@ public class Series { /** Line Color */ private Color strokeColor; - /** Fill Colour */ - private Color fillColor; - /** Marker Style */ private Marker marker; @@ -88,27 +80,60 @@ public class Series { * @param errorBars * @param seriesColorMarkerLineStyle */ - public Series(String name, List<?> xData, AxisType xAxisType, List<? extends Number> yData, AxisType yAxisType, List<? extends Number> errorBars, - SeriesColorMarkerLineStyle seriesColorMarkerLineStyle) { + public Series_AxesChart(String name, List<?> xData, List<? extends Number> yData, List<? extends Number> errorBars, SeriesColorMarkerLineStyle seriesColorMarkerLineStyle) { + + super(name, seriesColorMarkerLineStyle); - if (name == null || name.length() < 1) { - throw new IllegalArgumentException("Series name cannot be null or zero-length!!!"); - } - this.name = name; this.xData = xData; - this.xAxisType = xAxisType; + this.xAxisType = getAxesType(xData); this.yData = yData; - this.yAxisType = yAxisType; + this.yAxisType = AxisDataType.Number; this.errorBars = errorBars; - strokeColor = seriesColorMarkerLineStyle.getColor(); - fillColor = seriesColorMarkerLineStyle.getColor(); markerColor = seriesColorMarkerLineStyle.getColor(); marker = seriesColorMarkerLineStyle.getMarker(); stroke = seriesColorMarkerLineStyle.getStroke(); calculateMinMax(); + } + public void replaceData(List<?> newXData, List<? extends Number> newYData, List<? extends Number> newErrorBars) { + + // Sanity check + if (newErrorBars != null && newErrorBars.size() != newYData.size()) { + throw new IllegalArgumentException("error bars and Y-Axis sizes are not the same!!!"); + } + if (newXData.size() != newYData.size()) { + throw new IllegalArgumentException("X and Y-Axis sizes are not the same!!!"); + } + + xData = newXData; + yData = newYData; + errorBars = newErrorBars; + calculateMinMax(); + } + + private void calculateMinMax() { + + // xData + double[] xMinMax = findMinMax(xData, xAxisType); + xMin = xMinMax[0]; + xMax = xMinMax[1]; + // System.out.println(xMin); + // System.out.println(xMax); + + // yData + double[] yMinMax = null; + if (errorBars == null) { + yMinMax = findMinMax(yData, yAxisType); + } + else { + yMinMax = findMinMaxWithErrorBars(yData, errorBars); + } + yMin = yMinMax[0]; + yMax = yMinMax[1]; + // System.out.println(yMin); + // System.out.println(yMax); } /** @@ -117,7 +142,7 @@ public class Series { * @param data * @return */ - private double[] findMinMax(Collection<?> data, AxisType axisType) { + private double[] findMinMax(Collection<?> data, AxisDataType axisType) { double min = Double.MAX_VALUE; double max = -Double.MAX_VALUE; @@ -130,14 +155,14 @@ public class Series { double value = 0.0; - if (axisType == AxisType.Number) { + if (axisType == AxisDataType.Number) { value = ((Number) dataPoint).doubleValue(); } - else if (axisType == AxisType.Date) { + else if (axisType == AxisDataType.Date) { Date date = (Date) dataPoint; value = date.getTime(); } - else if (axisType == AxisType.String) { + else if (axisType == AxisDataType.String) { return new double[] { Double.NaN, Double.NaN }; } if (value < min) { @@ -199,17 +224,6 @@ public class Series { return this; } - /** - * Set the line color of the series - * - * @param seriesColor - */ - public Series setLineColor(SeriesColor seriesColor) { - - strokeColor = seriesColor.getColor(); - return this; - } - /** * Set the line color of the series * @@ -232,17 +246,6 @@ public class Series { return this; } - /** - * Sets the marker color for the series - * - * @param seriesColor - */ - public Series setMarkerColor(SeriesColor seriesColor) { - - this.markerColor = seriesColor.getColor(); - return this; - } - /** * Sets the marker color for the series * @@ -254,24 +257,24 @@ public class Series { return this; } - public SeriesType getSeriesType() { + public Collection<?> getXData() { - return seriesType; + return xData; } - public void setSeriesType(SeriesType seriesType) { + public AxisDataType getxAxisType() { - this.seriesType = seriesType; + return xAxisType; } - public Collection<?> getXData() { + public Collection<? extends Number> getYData() { - return xData; + return yData; } - public Collection<? extends Number> getYData() { + public AxisDataType getyAxisType() { - return yData; + return yAxisType; } public Collection<? extends Number> getErrorBars() { @@ -319,57 +322,4 @@ public class Series { return markerColor; } - public Color getFillColor() { - - return fillColor; - } - - public void setFillColor(Color fillColor) { - - this.fillColor = fillColor; - } - - public String getName() { - - return name; - } - - public void replaceData(List<?> newXData, List<? extends Number> newYData, List<? extends Number> newErrorBars) { - - // Sanity check - if (newErrorBars != null && newErrorBars.size() != newYData.size()) { - throw new IllegalArgumentException("errorbars and Y-Axis sizes are not the same!!!"); - } - if (newXData.size() != newYData.size()) { - throw new IllegalArgumentException("X and Y-Axis sizes are not the same!!!"); - } - - xData = newXData; - yData = newYData; - errorBars = newErrorBars; - calculateMinMax(); - } - - private void calculateMinMax() { - - // xData - double[] xMinMax = findMinMax(xData, xAxisType); - xMin = xMinMax[0]; - xMax = xMinMax[1]; - // System.out.println(xMin); - // System.out.println(xMax); - - // yData - double[] yMinMax = null; - if (errorBars == null) { - yMinMax = findMinMax(yData, yAxisType); - } - else { - yMinMax = findMinMaxWithErrorBars(yData, errorBars); - } - yMin = yMinMax[0]; - yMax = yMinMax[1]; - // System.out.println(yMin); - // System.out.println(yMax); - } -} +} \ No newline at end of file diff --git a/xchart/src/main/java/org/knowm/xchart/Series_Category.java b/xchart/src/main/java/org/knowm/xchart/Series_Category.java new file mode 100644 index 0000000000000000000000000000000000000000..aaefc7b7d5c1565ebdc5495690b62466f3bdeab3 --- /dev/null +++ b/xchart/src/main/java/org/knowm/xchart/Series_Category.java @@ -0,0 +1,106 @@ +/** + * Copyright 2015-2016 Knowm Inc. (http://knowm.org) and contributors. + * Copyright 2011-2015 Xeiam LLC (http://xeiam.com) and contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.knowm.xchart; + +import java.util.Date; +import java.util.Iterator; +import java.util.List; + +import org.knowm.xchart.internal.chartpart.Axis.AxisDataType; +import org.knowm.xchart.internal.chartpart.RenderableSeries; +import org.knowm.xchart.internal.chartpart.RenderableSeries.LegendRenderType; +import org.knowm.xchart.internal.style.SeriesColorMarkerLineStyle; + +/** + * A Series containing X and Y data to be plotted on a Chart + * + * @author timmolter + */ +public class Series_Category extends Series_AxesChart { + + public enum ChartCategorySeriesRenderStyle implements RenderableSeries { + + Line(LegendRenderType.Line), Area(LegendRenderType.Line), Scatter(LegendRenderType.Scatter), Bar(LegendRenderType.Box); + + private final LegendRenderType legendRenderType; + + private ChartCategorySeriesRenderStyle(LegendRenderType legendRenderType) { + this.legendRenderType = legendRenderType; + } + + @Override + public LegendRenderType getLegendRenderType() { + + return legendRenderType; + } + } + + private ChartCategorySeriesRenderStyle chartCategorySeriesRenderStyle = null; + + /** + * Constructor + * + * @param name + * @param xData + * @param yData + * @param errorBars + * @param seriesColorMarkerLineStyle + */ + public Series_Category(String name, List<?> xData, List<? extends Number> yData, List<? extends Number> errorBars, SeriesColorMarkerLineStyle seriesColorMarkerLineStyle) { + + super(name, xData, yData, errorBars, seriesColorMarkerLineStyle); + + } + + public ChartCategorySeriesRenderStyle getChartCategorySeriesRenderStyle() { + + return chartCategorySeriesRenderStyle; + } + + public void setChartCategorySeriesRenderStyle(ChartCategorySeriesRenderStyle chartXYSeriesRenderStyle) { + + this.chartCategorySeriesRenderStyle = chartXYSeriesRenderStyle; + } + + @Override + public LegendRenderType getLegendRenderType() { + + return chartCategorySeriesRenderStyle.getLegendRenderType(); + } + + @Override + public AxisDataType getAxesType(List<?> data) { + + AxisDataType axisType; + + Iterator<?> itr = data.iterator(); + Object dataPoint = itr.next(); + if (dataPoint instanceof Number) { + axisType = AxisDataType.Number; + } + else if (dataPoint instanceof Date) { + axisType = AxisDataType.Date; + } + else if (dataPoint instanceof String) { + axisType = AxisDataType.String; + } + else { + throw new IllegalArgumentException("Series data must be either Number, Date or String type!!!"); + } + return axisType; + } +} diff --git a/xchart/src/main/java/org/knowm/xchart/Series_Pie.java b/xchart/src/main/java/org/knowm/xchart/Series_Pie.java new file mode 100644 index 0000000000000000000000000000000000000000..129d491d5c6fdc091429d12903c445aae1240b1a --- /dev/null +++ b/xchart/src/main/java/org/knowm/xchart/Series_Pie.java @@ -0,0 +1,91 @@ +/** + * Copyright 2015-2016 Knowm Inc. (http://knowm.org) and contributors. + * Copyright 2011-2015 Xeiam LLC (http://xeiam.com) and contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.knowm.xchart; + +import org.knowm.xchart.internal.Series; +import org.knowm.xchart.internal.chartpart.RenderableSeries; +import org.knowm.xchart.internal.chartpart.RenderableSeries.LegendRenderType; +import org.knowm.xchart.internal.style.SeriesColorMarkerLineStyle; + +/** + * A Series containing Pie data to be plotted on a Chart + * + * @author timmolter + */ +public class Series_Pie extends Series { + + public enum ChartPieSeriesRenderStyle implements RenderableSeries { + + Pie(LegendRenderType.Box); + + private final LegendRenderType legendRenderType; + + private ChartPieSeriesRenderStyle(LegendRenderType legendRenderType) { + this.legendRenderType = legendRenderType; + } + + @Override + public LegendRenderType getLegendRenderType() { + + return legendRenderType; + } + } + + private ChartPieSeriesRenderStyle chartPieSeriesRenderStyle = null; + + private Number value; + + /** + * Constructor + * + * @param name + * @param value + * @param seriesColorMarkerLineStyle + */ + public Series_Pie(String name, Number value, SeriesColorMarkerLineStyle seriesColorMarkerLineStyle) { + + super(name, seriesColorMarkerLineStyle); + this.value = value; + } + + public ChartPieSeriesRenderStyle getChartPieSeriesRenderStyle() { + + return chartPieSeriesRenderStyle; + } + + public void setChartPieSeriesRenderStyle(ChartPieSeriesRenderStyle chartPieSeriesRenderStyle) { + + this.chartPieSeriesRenderStyle = chartPieSeriesRenderStyle; + } + + @Override + public LegendRenderType getLegendRenderType() { + + return chartPieSeriesRenderStyle.getLegendRenderType(); + } + + public Number getValue() { + + return value; + } + + public void setValue(Number value) { + + this.value = value; + } + +} diff --git a/xchart/src/main/java/org/knowm/xchart/Series_XY.java b/xchart/src/main/java/org/knowm/xchart/Series_XY.java new file mode 100644 index 0000000000000000000000000000000000000000..ab961a8c61f140fec9eb4c7f5dea8aef1fd52f9e --- /dev/null +++ b/xchart/src/main/java/org/knowm/xchart/Series_XY.java @@ -0,0 +1,102 @@ +/** + * Copyright 2015-2016 Knowm Inc. (http://knowm.org) and contributors. + * Copyright 2011-2015 Xeiam LLC (http://xeiam.com) and contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.knowm.xchart; + +import java.util.Date; +import java.util.Iterator; +import java.util.List; + +import org.knowm.xchart.internal.chartpart.Axis.AxisDataType; +import org.knowm.xchart.internal.chartpart.RenderableSeries; +import org.knowm.xchart.internal.chartpart.RenderableSeries.LegendRenderType; +import org.knowm.xchart.internal.style.SeriesColorMarkerLineStyle; + +/** + * A Series containing X and Y data to be plotted on a Chart + * + * @author timmolter + */ +public class Series_XY extends Series_AxesChart { + + public enum ChartXYSeriesRenderStyle implements RenderableSeries { + + Line(LegendRenderType.Line), Scatter(LegendRenderType.Scatter), Area(LegendRenderType.Line); + + private final LegendRenderType legendRenderType; + + private ChartXYSeriesRenderStyle(LegendRenderType legendRenderType) { + this.legendRenderType = legendRenderType; + } + + @Override + public LegendRenderType getLegendRenderType() { + + return legendRenderType; + } + } + + private ChartXYSeriesRenderStyle chartXYSeriesRenderStyle = null; + + /** + * Constructor + * + * @param name + * @param xData + * @param yData + * @param errorBars + * @param seriesColorMarkerLineStyle + */ + public Series_XY(String name, List<?> xData, List<? extends Number> yData, List<? extends Number> errorBars, SeriesColorMarkerLineStyle seriesColorMarkerLineStyle) { + + super(name, xData, yData, errorBars, seriesColorMarkerLineStyle); + } + + public ChartXYSeriesRenderStyle getChartXYSeriesRenderStyle() { + + return chartXYSeriesRenderStyle; + } + + public void setChartXYSeriesRenderStyle(ChartXYSeriesRenderStyle chartXYSeriesRenderStyle) { + + this.chartXYSeriesRenderStyle = chartXYSeriesRenderStyle; + } + + @Override + public LegendRenderType getLegendRenderType() { + + return chartXYSeriesRenderStyle.getLegendRenderType(); + } + + @Override + public AxisDataType getAxesType(List<?> data) { + + AxisDataType axisType; + + Iterator<?> itr = data.iterator(); + Object dataPoint = itr.next(); + if (dataPoint instanceof Number) { + axisType = AxisDataType.Number; + } + else if (dataPoint instanceof Date) { + axisType = AxisDataType.Date; + } + else { + throw new IllegalArgumentException("Series data must be either Number or Date type!!!"); + } + return axisType; + } +} \ No newline at end of file diff --git a/xchart/src/main/java/org/knowm/xchart/StyleManagerCategory.java b/xchart/src/main/java/org/knowm/xchart/StyleManagerCategory.java new file mode 100644 index 0000000000000000000000000000000000000000..5cfc95e908b72b729cc02c1e868a1b63ffefb9cf --- /dev/null +++ b/xchart/src/main/java/org/knowm/xchart/StyleManagerCategory.java @@ -0,0 +1,75 @@ +/** + * Copyright 2015-2016 Knowm Inc. (http://knowm.org) and contributors. + * Copyright 2011-2015 Xeiam LLC (http://xeiam.com) and contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.knowm.xchart; + +import org.knowm.xchart.Series_Category.ChartCategorySeriesRenderStyle; +import org.knowm.xchart.internal.style.StyleManagerAxesChart; +import org.knowm.xchart.internal.style.Theme; + +/** + * @author timmolter + */ +public class StyleManagerCategory extends StyleManagerAxesChart { + + private ChartCategorySeriesRenderStyle chartCategorySeriesRenderStyle; + + /** + * Constructor + */ + public StyleManagerCategory() { + + this.setAllStyles(); + super.setAllStyles(); + } + + @Override + protected void setAllStyles() { + + chartCategorySeriesRenderStyle = ChartCategorySeriesRenderStyle.Bar; // set default to bar + } + + public ChartCategorySeriesRenderStyle getChartCategorySeriesRenderStyle() { + + return chartCategorySeriesRenderStyle; + } + + /** + * Sets the default series render style for the chart (line, scatter, area, etc.) You can override the series render style individually on each Series object. + * + * @param chartXYSeriesRenderStyle + */ + public void setChartCategorySeriesRenderStyle(ChartCategorySeriesRenderStyle chartCategorySeriesRenderStyle) { + + this.chartCategorySeriesRenderStyle = chartCategorySeriesRenderStyle; + } + + /** + * Set the theme the style manager should use + * + * @param theme + */ + protected void setTheme(Theme theme) { + + this.theme = theme; + super.setAllStyles(); + } + + public Theme getTheme() { + + return theme; + } +} diff --git a/xchart/src/main/java/org/knowm/xchart/StyleManagerPie.java b/xchart/src/main/java/org/knowm/xchart/StyleManagerPie.java new file mode 100644 index 0000000000000000000000000000000000000000..2e3c8e6dd153f35befcb1bda22c62e402655a49f --- /dev/null +++ b/xchart/src/main/java/org/knowm/xchart/StyleManagerPie.java @@ -0,0 +1,76 @@ +/** + * Copyright 2015-2016 Knowm Inc. (http://knowm.org) and contributors. + * Copyright 2011-2015 Xeiam LLC (http://xeiam.com) and contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.knowm.xchart; + +import org.knowm.xchart.Series_Pie.ChartPieSeriesRenderStyle; +import org.knowm.xchart.internal.style.StyleManager; +import org.knowm.xchart.internal.style.Theme; + +/** + * @author timmolter + */ +public class StyleManagerPie extends StyleManager { + + private ChartPieSeriesRenderStyle chartPieSeriesRenderStyle; + + /** + * Constructor + */ + public StyleManagerPie() { + + this.setAllStyles(); + super.setAllStyles(); + } + + @Override + protected void setAllStyles() { + + chartPieSeriesRenderStyle = ChartPieSeriesRenderStyle.Pie; // set default to area + } + + public ChartPieSeriesRenderStyle getChartPieSeriesRenderStyle() { + + return chartPieSeriesRenderStyle; + } + + /** + * Sets the default series render style for the chart (line, scatter, area, etc.) You can override the series render style individually on each Series object. + * + * @param chartPieSeriesRenderStyle + */ + public void setChartPieSeriesRenderStyle(ChartPieSeriesRenderStyle chartPieSeriesRenderStyle) { + + this.chartPieSeriesRenderStyle = chartPieSeriesRenderStyle; + } + + /** + * Set the theme the style manager should use + * + * @param theme + */ + protected void setTheme(Theme theme) { + + this.theme = theme; + super.setAllStyles(); + } + + public Theme getTheme() { + + return theme; + } + +} diff --git a/xchart/src/main/java/org/knowm/xchart/StyleManagerXY.java b/xchart/src/main/java/org/knowm/xchart/StyleManagerXY.java new file mode 100644 index 0000000000000000000000000000000000000000..8f42c7846719ee3a2b9fc08a5380a37a910003a2 --- /dev/null +++ b/xchart/src/main/java/org/knowm/xchart/StyleManagerXY.java @@ -0,0 +1,76 @@ +/** + * Copyright 2015-2016 Knowm Inc. (http://knowm.org) and contributors. + * Copyright 2011-2015 Xeiam LLC (http://xeiam.com) and contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.knowm.xchart; + +import org.knowm.xchart.Series_XY.ChartXYSeriesRenderStyle; +import org.knowm.xchart.internal.style.StyleManagerAxesChart; +import org.knowm.xchart.internal.style.Theme; + +/** + * @author timmolter + */ +public class StyleManagerXY extends StyleManagerAxesChart { + + private ChartXYSeriesRenderStyle chartXYSeriesRenderStyle; + + /** + * Constructor + */ + public StyleManagerXY() { + + this.setAllStyles(); + super.setAllStyles(); + } + + @Override + protected void setAllStyles() { + + chartXYSeriesRenderStyle = ChartXYSeriesRenderStyle.Line; // set default to line + } + + public ChartXYSeriesRenderStyle getChartXYSeriesRenderStyle() { + + return chartXYSeriesRenderStyle; + } + + /** + * Sets the default series render style for the chart (line, scatter, area, etc.) You can override the series render style individually on each Series object. + * + * @param chartXYSeriesRenderStyle + */ + public void setChartXYSeriesRenderStyle(ChartXYSeriesRenderStyle chartXYSeriesRenderStyle) { + + this.chartXYSeriesRenderStyle = chartXYSeriesRenderStyle; + } + + /** + * Set the theme the style manager should use + * + * @param theme + */ + protected void setTheme(Theme theme) { + + this.theme = theme; + super.setAllStyles(); + } + + public Theme getTheme() { + + return theme; + } + +} diff --git a/xchart/src/main/java/org/knowm/xchart/SwingWrapper.java b/xchart/src/main/java/org/knowm/xchart/SwingWrapper.java index 121099c4ddc1826f3ac15a8fc94af714790cd2a7..f55fcf6a838b58194ed997937d4ad1e2608dc3ea 100644 --- a/xchart/src/main/java/org/knowm/xchart/SwingWrapper.java +++ b/xchart/src/main/java/org/knowm/xchart/SwingWrapper.java @@ -1,5 +1,5 @@ /** - * Copyright 2015 Knowm Inc. (http://knowm.org) and contributors. + * Copyright 2015-2016 Knowm Inc. (http://knowm.org) and contributors. * Copyright 2011-2015 Xeiam LLC (http://xeiam.com) and contributors. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -23,9 +23,11 @@ import java.util.List; import javax.swing.JFrame; import javax.swing.JPanel; +import org.knowm.xchart.internal.chartpart.Chart; + /** * A convenience class used to display a Chart in a barebones Swing application - * + * * @author timmolter */ public class SwingWrapper { @@ -38,7 +40,7 @@ public class SwingWrapper { /** * Constructor - * + * * @param chart */ public SwingWrapper(Chart chart) { @@ -48,7 +50,7 @@ public class SwingWrapper { /** * Constructor - The number of rows and columns will be calculated automatically Constructor - * + * * @param charts */ public SwingWrapper(List<Chart> charts) { @@ -61,7 +63,7 @@ public class SwingWrapper { /** * Constructor - * + * * @param charts * @param numRows - the number of rows * @param numColumns - the number of columns @@ -75,7 +77,7 @@ public class SwingWrapper { /** * Display the chart in a Swing JFrame - * + * * @param windowTitle the title of the window */ public JFrame displayChart(String windowTitle) { @@ -115,7 +117,7 @@ public class SwingWrapper { /** * Display the charts in a Swing JFrame - * + * * @param windowTitle the title of the window * @return the JFrame */ diff --git a/xchart/src/main/java/org/knowm/xchart/VectorGraphicsEncoder.java b/xchart/src/main/java/org/knowm/xchart/VectorGraphicsEncoder.java index 894336af4a766641043acce8942f901ce37765a4..df527049a9aa934df3cb79dd305ca724663404d9 100644 --- a/xchart/src/main/java/org/knowm/xchart/VectorGraphicsEncoder.java +++ b/xchart/src/main/java/org/knowm/xchart/VectorGraphicsEncoder.java @@ -1,5 +1,5 @@ /** - * Copyright 2015 Knowm Inc. (http://knowm.org) and contributors. + * Copyright 2015-2016 Knowm Inc. (http://knowm.org) and contributors. * Copyright 2011-2015 Xeiam LLC (http://xeiam.com) and contributors. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -19,6 +19,8 @@ package org.knowm.xchart; import java.io.FileOutputStream; import java.io.IOException; +import org.knowm.xchart.internal.chartpart.Chart; + import de.erichseifert.vectorgraphics2d.EPSGraphics2D; import de.erichseifert.vectorgraphics2d.PDFGraphics2D; import de.erichseifert.vectorgraphics2d.SVGGraphics2D; diff --git a/xchart/src/main/java/org/knowm/xchart/XChartPanel.java b/xchart/src/main/java/org/knowm/xchart/XChartPanel.java index a94b3fd27e90d7935fb0cf58998fe1cec502b9b6..ea534ec9420a90f4f32b1ba1bf2c191707a26a7f 100644 --- a/xchart/src/main/java/org/knowm/xchart/XChartPanel.java +++ b/xchart/src/main/java/org/knowm/xchart/XChartPanel.java @@ -1,5 +1,5 @@ /** - * Copyright 2015 Knowm Inc. (http://knowm.org) and contributors. + * Copyright 2015-2016 Knowm Inc. (http://knowm.org) and contributors. * Copyright 2011-2015 Xeiam LLC (http://xeiam.com) and contributors. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -29,6 +29,7 @@ import java.io.File; import java.io.IOException; import java.util.ArrayList; import java.util.List; +import java.util.Map; import javax.swing.AbstractAction; import javax.swing.JFileChooser; @@ -40,6 +41,8 @@ import javax.swing.filechooser.FileFilter; import org.knowm.xchart.BitmapEncoder.BitmapFormat; import org.knowm.xchart.VectorGraphicsEncoder.VectorGraphicsFormat; +import org.knowm.xchart.internal.Series; +import org.knowm.xchart.internal.chartpart.Chart; /** * A Swing JPanel that contains a Chart @@ -94,6 +97,7 @@ public class XChartPanel extends JPanel { } public Chart getChart() { + return this.chart; } @@ -290,7 +294,8 @@ public class XChartPanel extends JPanel { */ public Series updateSeries(String seriesName, List<?> newXData, List<? extends Number> newYData, List<? extends Number> newErrorBarData) { - Series series = chart.getSeriesMap().get(seriesName); + Map<String, Series_AxesChart> seriesMap = chart.getSeriesMap(); + Series_AxesChart series = seriesMap.get(seriesName); if (series == null) { throw new IllegalArgumentException("Series name >" + seriesName + "< not found!!!"); } diff --git a/xchart/src/main/java/org/knowm/xchart/internal/ChartBuilder.java b/xchart/src/main/java/org/knowm/xchart/internal/ChartBuilder.java new file mode 100644 index 0000000000000000000000000000000000000000..ddeb48283067888c0beabb25a3353acc2ff016ae --- /dev/null +++ b/xchart/src/main/java/org/knowm/xchart/internal/ChartBuilder.java @@ -0,0 +1,68 @@ +/** + * Copyright 2015-2016 Knowm Inc. (http://knowm.org) and contributors. + * Copyright 2011-2015 Xeiam LLC (http://xeiam.com) and contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.knowm.xchart.internal; + +import org.knowm.xchart.internal.chartpart.Chart; +import org.knowm.xchart.internal.style.StyleManager.ChartTheme; + +/** + * A "Builder" to make creating charts easier + * + * @author timmolter + */ +public abstract class ChartBuilder<T extends ChartBuilder<?, ?>, C extends Chart> { + + // ChartType chartType = ChartType.XY; + public int width = 800; + public int height = 600; + public String title = ""; + + public ChartTheme chartTheme = ChartTheme.XChart; + + /** + * Constructor + */ + public ChartBuilder() { + } + + public T width(int width) { + + this.width = width; + return (T) this; + } + + public T height(int height) { + + this.height = height; + return (T) this; + } + + public T title(String title) { + + this.title = title; + return (T) this; + } + + public T theme(ChartTheme chartTheme) { + + this.chartTheme = chartTheme; + return (T) this; + } + + public abstract C build(); + +} diff --git a/xchart/src/main/java/org/knowm/xchart/internal/Series.java b/xchart/src/main/java/org/knowm/xchart/internal/Series.java new file mode 100644 index 0000000000000000000000000000000000000000..4c29e2c87fb4c8a02f32b2be446456cdd9dd2c03 --- /dev/null +++ b/xchart/src/main/java/org/knowm/xchart/internal/Series.java @@ -0,0 +1,70 @@ +/** + * Copyright 2015-2016 Knowm Inc. (http://knowm.org) and contributors. + * Copyright 2011-2015 Xeiam LLC (http://xeiam.com) and contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.knowm.xchart.internal; + +import java.awt.Color; + +import org.knowm.xchart.internal.chartpart.RenderableSeries.LegendRenderType; +import org.knowm.xchart.internal.style.SeriesColorMarkerLineStyle; + +/** + * A Series containing X and Y data to be plotted on a Chart + * + * @author timmolter + */ +public abstract class Series { + + public abstract LegendRenderType getLegendRenderType(); + + private String name = ""; + + /** Fill Color */ + private Color fillColor; + + /** + * Constructor + * + * @param name + * @param seriesColorMarkerLineStyle + */ + public Series(String name, SeriesColorMarkerLineStyle seriesColorMarkerLineStyle) { + + if (name == null || name.length() < 1) { + throw new IllegalArgumentException("Series name cannot be null or zero-length!!!"); + } + this.name = name; + + fillColor = seriesColorMarkerLineStyle.getColor(); + + } + + public Color getFillColor() { + + return fillColor; + } + + public void setFillColor(Color fillColor) { + + this.fillColor = fillColor; + } + + public String getName() { + + return name; + } + +} diff --git a/xchart/src/main/java/org/knowm/xchart/internal/Utils.java b/xchart/src/main/java/org/knowm/xchart/internal/Utils.java index c18fdfeeaefec56241cc29e33b26f77a5d317ad9..9583c0039dd5b35081e143eed759869caaf67b43 100644 --- a/xchart/src/main/java/org/knowm/xchart/internal/Utils.java +++ b/xchart/src/main/java/org/knowm/xchart/internal/Utils.java @@ -1,5 +1,5 @@ /** - * Copyright 2015 Knowm Inc. (http://knowm.org) and contributors. + * Copyright 2015-2016 Knowm Inc. (http://knowm.org) and contributors. * Copyright 2011-2015 Xeiam LLC (http://xeiam.com) and contributors. * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/xchart/src/main/java/org/knowm/xchart/internal/chartpart/Axis.java b/xchart/src/main/java/org/knowm/xchart/internal/chartpart/Axis.java index 5eeb50756ba62166198d2da11088584c729a94b7..2d33c4e8db6f95ac1ed6793036678d57a0a0fab6 100644 --- a/xchart/src/main/java/org/knowm/xchart/internal/chartpart/Axis.java +++ b/xchart/src/main/java/org/knowm/xchart/internal/chartpart/Axis.java @@ -1,5 +1,5 @@ /** - * Copyright 2015 Knowm Inc. (http://knowm.org) and contributors. + * Copyright 2015-2016 Knowm Inc. (http://knowm.org) and contributors. * Copyright 2011-2015 Xeiam LLC (http://xeiam.com) and contributors. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -24,36 +24,47 @@ import java.awt.geom.AffineTransform; import java.awt.geom.Rectangle2D; import java.util.List; -import org.knowm.xchart.StyleManager.ChartType; -import org.knowm.xchart.StyleManager.LegendPosition; -import org.knowm.xchart.internal.chartpart.ChartInternal.ChartInternalType; +import org.knowm.xchart.Series_AxesChart; +import org.knowm.xchart.StyleManagerCategory; +import org.knowm.xchart.internal.Series; +import org.knowm.xchart.internal.style.StyleManagerAxesChart; +import org.knowm.xchart.internal.style.StyleManager.LegendPosition; /** * Axis * * @author timmolter */ -public class Axis implements ChartPart { +public class Axis<SM extends StyleManagerAxesChart, S extends Series> implements ChartPart { - public enum AxisType { + public enum AxisDataType { Number, Date, String; } - /** parent */ - private AxisPair axisPair; + private final Chart<StyleManagerAxesChart, Series_AxesChart> chart; + private Rectangle2D bounds; + + // TODO 3.0.0 use bounds only??? + /** the paint zone */ + private Rectangle2D paintZone; + + protected Rectangle2D getPaintZone() { + + return paintZone; + } - /** the axisType */ - private AxisType axisType; + /** the axisDataType */ + private AxisDataType axisDataType; /** the axis title */ - private AxisTitle axisTitle; + private AxisTitle<StyleManagerAxesChart, Series_AxesChart> axisTitle; /** the axis tick */ - private AxisTick axisTick; + private AxisTick<StyleManagerAxesChart, Series_AxesChart> axisTick; /** the axis tick calculator */ - private AxisTickCalculator axisTickCalculator; + private AxisTickCalculator_ axisTickCalculator; /** the axis direction */ private Direction direction; @@ -62,12 +73,6 @@ public class Axis implements ChartPart { private double max; - /** the bounds */ - private Rectangle2D bounds; - - /** the paint zone */ - private Rectangle2D paintZone; - /** An axis direction */ public enum Direction { @@ -81,21 +86,21 @@ public class Axis implements ChartPart { /** * Constructor * + * @param chart the Chart * @param direction the axis direction (X or Y) - * @param chart the chart */ - protected Axis(AxisPair axisPair, Direction direction) { + public Axis(Chart<StyleManagerAxesChart, Series_AxesChart> chart, Direction direction) { - this.axisPair = axisPair; + this.chart = chart; this.direction = direction; - axisTitle = new AxisTitle(this); - axisTick = new AxisTick(this); + axisTitle = new AxisTitle<StyleManagerAxesChart, Series_AxesChart>(chart, direction); + axisTick = new AxisTick<StyleManagerAxesChart, Series_AxesChart>(chart, direction); } /** * Reset the default min and max values in preparation for calculating the actual min and max */ - protected void resetMinMax() { + public void resetMinMax() { min = Double.MAX_VALUE; max = -Double.MAX_VALUE; @@ -105,7 +110,7 @@ public class Axis implements ChartPart { * @param min * @param max */ - protected void addMinMax(double min, double max) { + public void addMinMax(double min, double max) { // System.out.println(min); // System.out.println(max); @@ -121,18 +126,12 @@ public class Axis implements ChartPart { // System.out.println(this.max); } - protected void setAxisType(AxisType axisType) { + public void setAxisType(AxisDataType axisDataType) { - if (this.axisType != null && this.axisType != axisType) { + if (this.axisDataType != null && this.axisDataType != axisDataType) { throw new IllegalArgumentException("Different Axes (Date, Number, String) cannot be mixed on the same chart!!"); } - this.axisType = axisType; - } - - @Override - public Rectangle2D getBounds() { - - return bounds; + this.axisDataType = axisDataType; } @Override @@ -144,12 +143,6 @@ public class Axis implements ChartPart { // determine Axis bounds if (direction == Direction.Y) { // Y-Axis - gets called first - if (getChartInternal().getChartInternalType() == ChartInternalType.Pie) { - bounds = new Rectangle2D.Double(getChartInternal().getStyleManager().getChartPadding(), getChartInternal().getChartTitle().getSizeHint(), 0, getChartInternal().getHeight() - getChartInternal() - .getChartTitle().getSizeHint() - getChartInternal().getStyleManager().getPlotPadding() - getChartInternal().getStyleManager().getChartPadding()); - return; - } - // first determine the height of // calculate paint zone @@ -159,8 +152,9 @@ public class Axis implements ChartPart { // | // | // ---- - double xOffset = getChartInternal().getStyleManager().getChartPadding(); - double yOffset = getChartInternal().getChartTitle().getSizeHint(); + double xOffset = chart.getStyleManager().getChartPadding(); + double yOffset = chart.getChartTitle().getBounds().getHeight() < .1 ? chart.getStyleManager().getChartPadding() : chart.getChartTitle().getBounds().getHeight() + 2 * chart.getStyleManager() + .getChartPadding(); ///////////////////////// int i = 1; // just twice through is all it takes @@ -171,23 +165,21 @@ public class Axis implements ChartPart { double approximateXAxisWidth = - getChartInternal().getWidth() + chart.getWidth() - width // y-axis approx. width - - (getChartInternal().getStyleManager().getLegendPosition() == LegendPosition.OutsideE ? getChartInternal().getChartLegend().getLegendBoxWidth() : 0) + - (chart.getStyleManager().getLegendPosition() == LegendPosition.OutsideE ? chart.getChartLegend().getBounds().getWidth() : 0) - - 2 * getChartInternal().getStyleManager().getChartPadding() + - 2 * chart.getStyleManager().getChartPadding() - - (getChartInternal().getStyleManager().isYAxisTicksVisible() ? (getChartInternal().getStyleManager().getPlotPadding()) : 0) + - (chart.getStyleManager().isYAxisTicksVisible() ? (chart.getStyleManager().getPlotPadding()) : 0) - - (getChartInternal().getStyleManager().getLegendPosition() == LegendPosition.OutsideE && getChartInternal().getStyleManager().isLegendVisible() ? getChartInternal().getStyleManager() - .getChartPadding() : 0) + - (chart.getStyleManager().getLegendPosition() == LegendPosition.OutsideE && chart.getStyleManager().isLegendVisible() ? chart.getStyleManager().getChartPadding() : 0) ; - height = getChartInternal().getHeight() - yOffset - axisPair.getXAxis().getXAxisHeightHint(approximateXAxisWidth) - getChartInternal().getStyleManager().getPlotPadding() - getChartInternal() - .getStyleManager().getChartPadding(); + height = chart.getHeight() - yOffset - chart.getXAxis().getXAxisHeightHint(approximateXAxisWidth) - chart.getStyleManager().getPlotPadding() - chart.getStyleManager().getChartPadding(); width = getYAxisWidthHint(height); // System.out.println("width after: " + width); @@ -209,7 +201,7 @@ public class Axis implements ChartPart { xOffset = paintZone.getX(); yOffset = paintZone.getY(); - width = (getChartInternal().getStyleManager().isYAxisTitleVisible() ? axisTitle.getBounds().getWidth() : 0) + axisTick.getBounds().getWidth(); + width = (chart.getStyleManager().isYAxisTitleVisible() ? axisTitle.getBounds().getWidth() : 0) + axisTick.getBounds().getWidth(); height = paintZone.getHeight(); bounds = new Rectangle2D.Double(xOffset, yOffset, width, height); @@ -219,42 +211,34 @@ public class Axis implements ChartPart { } else { // X-Axis - if (getChartInternal().getChartInternalType() == ChartInternalType.Pie) { - bounds = new Rectangle2D.Double(getChartInternal().getStyleManager().getChartPadding(), getChartInternal().getHeight() - getChartInternal().getStyleManager().getChartPadding(), - getChartInternal().getWidth() - getChartInternal().getChartTitle().getSizeHint() - getChartInternal().getStyleManager().getPlotPadding() - (getChartInternal().getStyleManager() - .getLegendPosition() == LegendPosition.OutsideE ? getChartInternal().getChartLegend().getLegendBoxWidth() : 0), 0); - return; - } - // calculate paint zone // |____________________| - double xOffset = axisPair.getYAxis().getBounds().getWidth() + (getChartInternal().getStyleManager().isYAxisTicksVisible() ? getChartInternal().getStyleManager().getPlotPadding() : 0) - + getChartInternal().getStyleManager().getChartPadding(); - double yOffset = axisPair.getYAxis().getBounds().getY() + axisPair.getYAxis().getBounds().getHeight() + getChartInternal().getStyleManager().getPlotPadding(); + double xOffset = chart.getYAxis().getBounds().getWidth() + (chart.getStyleManager().isYAxisTicksVisible() ? chart.getStyleManager().getPlotPadding() : 0) + chart.getStyleManager() + .getChartPadding(); + double yOffset = chart.getYAxis().getBounds().getY() + chart.getYAxis().getBounds().getHeight() + chart.getStyleManager().getPlotPadding(); double width = - getChartInternal().getWidth() + chart.getWidth() - - axisPair.getYAxis().getBounds().getWidth() // y-axis was already painted + - chart.getYAxis().getBounds().getWidth() // y-axis was already painted - - (getChartInternal().getStyleManager().getLegendPosition() == LegendPosition.OutsideE ? getChartInternal().getChartLegend().getLegendBoxWidth() : 0) + - (chart.getStyleManager().getLegendPosition() == LegendPosition.OutsideE ? chart.getChartLegend().getBounds().getWidth() : 0) - - 2 * getChartInternal().getStyleManager().getChartPadding() + - 2 * chart.getStyleManager().getChartPadding() - - (getChartInternal().getStyleManager().isYAxisTicksVisible() ? (getChartInternal().getStyleManager().getPlotPadding()) : 0) + - (chart.getStyleManager().isYAxisTicksVisible() ? (chart.getStyleManager().getPlotPadding()) : 0) - - (getChartInternal().getStyleManager().getLegendPosition() == LegendPosition.OutsideE && getChartInternal().getStyleManager().isLegendVisible() ? getChartInternal().getStyleManager() - .getChartPadding() : 0) + - (chart.getStyleManager().getLegendPosition() == LegendPosition.OutsideE && chart.getStyleManager().isLegendVisible() ? chart.getStyleManager().getChartPadding() : 0) ; // double height = this.getXAxisHeightHint(width); // System.out.println("height: " + height); // the Y-Axis was already draw at this point so we know how much vertical room is left for the X-Axis - double height = getChartInternal().getHeight() - axisPair.getYAxis().getBounds().getY() - axisPair.getYAxis().getBounds().getHeight() - getChartInternal().getStyleManager().getChartPadding() - - getChartInternal().getStyleManager().getPlotPadding(); + double height = chart.getHeight() - chart.getYAxis().getBounds().getY() - chart.getYAxis().getBounds().getHeight() - chart.getStyleManager().getChartPadding() - chart.getStyleManager() + .getPlotPadding(); // System.out.println("height2: " + height2); Rectangle2D xAxisRectangle = new Rectangle2D.Double(xOffset, yOffset, width, height); @@ -276,6 +260,7 @@ public class Axis implements ChartPart { } + // TODO 3.0.0 use bounds instead /** * The vertical Y-Axis is drawn first, but to know the lower bounds of it, we need to know how high the X-Axis paint zone is going to be. Since the tick labels could be rotated, we need to actually * determine the tick labels first to get an idea of how tall the X-Axis tick labels will be. @@ -284,21 +269,17 @@ public class Axis implements ChartPart { */ private double getXAxisHeightHint(double workingSpace) { - if (getChartInternal().getChartInternalType() == ChartInternalType.Pie) { - return 0.0; - } - // Axis title double titleHeight = 0.0; - if (axisTitle.getText() != null && !axisTitle.getText().trim().equalsIgnoreCase("") && getChartInternal().getStyleManager().isXAxisTitleVisible()) { - TextLayout textLayout = new TextLayout(axisTitle.getText(), getChartInternal().getStyleManager().getAxisTitleFont(), new FontRenderContext(null, true, false)); + if (chart.getXAxisTitle() != null && !chart.getXAxisTitle().trim().equalsIgnoreCase("") && chart.getStyleManager().isXAxisTitleVisible()) { + TextLayout textLayout = new TextLayout(chart.getXAxisTitle(), chart.getStyleManager().getAxisTitleFont(), new FontRenderContext(null, true, false)); Rectangle2D rectangle = textLayout.getBounds(); - titleHeight = rectangle.getHeight() + getChartInternal().getStyleManager().getAxisTitlePadding(); + titleHeight = rectangle.getHeight() + chart.getStyleManager().getAxisTitlePadding(); } // Axis tick labels double axisTickLabelsHeight = 0.0; - if (getChartInternal().getStyleManager().isXAxisTicksVisible()) { + if (chart.getStyleManager().isXAxisTicksVisible()) { // get some real tick labels // System.out.println("XAxisHeightHint"); @@ -316,34 +297,29 @@ public class Axis implements ChartPart { // System.out.println("sampleLabel: " + sampleLabel); // get the height of the label including rotation - TextLayout textLayout = new TextLayout(sampleLabel.length() == 0 ? " " : sampleLabel, getChartInternal().getStyleManager().getAxisTickLabelsFont(), new FontRenderContext(null, true, false)); - AffineTransform rot = getChartInternal().getStyleManager().getXAxisLabelRotation() == 0 ? null : AffineTransform.getRotateInstance(-1 * Math.toRadians(getChartInternal().getStyleManager() - .getXAxisLabelRotation())); + TextLayout textLayout = new TextLayout(sampleLabel.length() == 0 ? " " : sampleLabel, chart.getStyleManager().getAxisTickLabelsFont(), new FontRenderContext(null, true, false)); + AffineTransform rot = chart.getStyleManager().getXAxisLabelRotation() == 0 ? null : AffineTransform.getRotateInstance(-1 * Math.toRadians(chart.getStyleManager().getXAxisLabelRotation())); Shape shape = textLayout.getOutline(rot); Rectangle2D rectangle = shape.getBounds(); - axisTickLabelsHeight = rectangle.getHeight() + getChartInternal().getStyleManager().getAxisTickPadding() + getChartInternal().getStyleManager().getAxisTickMarkLength(); + axisTickLabelsHeight = rectangle.getHeight() + chart.getStyleManager().getAxisTickPadding() + chart.getStyleManager().getAxisTickMarkLength(); } return titleHeight + axisTickLabelsHeight; } private double getYAxisWidthHint(double workingSpace) { - if (getChartInternal().getChartInternalType() == ChartInternalType.Pie) { - return 0.0; - } - // Axis title double titleHeight = 0.0; - if (axisTitle.getText() != null && !axisTitle.getText().trim().equalsIgnoreCase("") && getChartInternal().getStyleManager().isYAxisTitleVisible()) { - TextLayout textLayout = new TextLayout(axisTitle.getText(), getChartInternal().getStyleManager().getAxisTitleFont(), new FontRenderContext(null, true, false)); + if (chart.getyYAxisTitle() != null && !chart.getyYAxisTitle().trim().equalsIgnoreCase("") && chart.getStyleManager().isYAxisTitleVisible()) { + TextLayout textLayout = new TextLayout(chart.getyYAxisTitle(), chart.getStyleManager().getAxisTitleFont(), new FontRenderContext(null, true, false)); Rectangle2D rectangle = textLayout.getBounds(); - titleHeight = rectangle.getHeight() + getChartInternal().getStyleManager().getAxisTitlePadding(); + titleHeight = rectangle.getHeight() + chart.getStyleManager().getAxisTitlePadding(); } // Axis tick labels double axisTickLabelsHeight = 0.0; - if (getChartInternal().getStyleManager().isYAxisTicksVisible()) { + if (chart.getStyleManager().isYAxisTicksVisible()) { // get some real tick labels // System.out.println("XAxisHeightHint"); @@ -359,38 +335,37 @@ public class Axis implements ChartPart { } // get the height of the label including rotation - TextLayout textLayout = new TextLayout(sampleLabel.length() == 0 ? " " : sampleLabel, getChartInternal().getStyleManager().getAxisTickLabelsFont(), new FontRenderContext(null, true, false)); + TextLayout textLayout = new TextLayout(sampleLabel.length() == 0 ? " " : sampleLabel, chart.getStyleManager().getAxisTickLabelsFont(), new FontRenderContext(null, true, false)); Rectangle2D rectangle = textLayout.getBounds(); - axisTickLabelsHeight = rectangle.getWidth() + getChartInternal().getStyleManager().getAxisTickPadding() + getChartInternal().getStyleManager().getAxisTickMarkLength(); + axisTickLabelsHeight = rectangle.getWidth() + chart.getStyleManager().getAxisTickPadding() + chart.getStyleManager().getAxisTickMarkLength(); } return titleHeight + axisTickLabelsHeight; } - private AxisTickCalculator getAxisTickCalculator(double workingSpace) { + private AxisTickCalculator_ getAxisTickCalculator(double workingSpace) { // X-Axis if (getDirection() == Direction.X) { - if (getChartInternal().getChartInternalType() == ChartInternalType.Category) { + if (chart.getStyleManager() instanceof StyleManagerCategory) { + + List<?> categories = (List<?>) chart.getSeriesMap().values().iterator().next().getXData(); + AxisDataType axisType = chart.getAxisPair().getXAxis().getAxisDataType(); + + return new AxisTickCalculator_Category(getDirection(), workingSpace, categories, axisType, chart.getStyleManager()); - List<?> categories = (List<?>) getChartInternal().getSeriesMap().values().iterator().next().getXData(); - AxisType axisType = getChartInternal().getAxisPair().getXAxis().getAxisType(); - return new AxisTickCalculator_Category(getDirection(), workingSpace, categories, axisType, getChartInternal().getStyleManager()); - } - else if (getChartInternal().getChartInternalType() == ChartInternalType.Pie) { - return null; } - else if (getChartInternal().getChartInternalType() == ChartInternalType.XY && getAxisType() == AxisType.Date) { + else if (getAxisDataType() == AxisDataType.Date) { - return new AxisTickCalculator_Date(getDirection(), workingSpace, min, max, getChartInternal().getStyleManager()); + return new AxisTickCalculator_Date(getDirection(), workingSpace, min, max, chart.getStyleManager()); } - else if (getChartInternal().getStyleManager().isXAxisLogarithmic()) { + else if (chart.getStyleManager().isXAxisLogarithmic()) { - return new AxisTickCalculator_Logarithmic(getDirection(), workingSpace, min, max, getChartInternal().getStyleManager()); + return new AxisTickCalculator_Logarithmic(getDirection(), workingSpace, min, max, chart.getStyleManager()); } else { - return new AxisTickCalculator_Number(getDirection(), workingSpace, min, max, getChartInternal().getStyleManager()); + return new AxisTickCalculator_Number(getDirection(), workingSpace, min, max, chart.getStyleManager()); } } @@ -398,32 +373,23 @@ public class Axis implements ChartPart { // Y-Axis else { - if (getChartInternal().getChartInternalType() == ChartInternalType.Pie) { - return null; - } - else if (getChartInternal().getStyleManager().isYAxisLogarithmic() && getAxisType() != AxisType.Date) { + if (chart.getStyleManager().isYAxisLogarithmic() && getAxisDataType() != AxisDataType.Date) { - return new AxisTickCalculator_Logarithmic(getDirection(), workingSpace, min, max, getChartInternal().getStyleManager()); + return new AxisTickCalculator_Logarithmic(getDirection(), workingSpace, min, max, chart.getStyleManager()); } else { - return new AxisTickCalculator_Number(getDirection(), workingSpace, min, max, getChartInternal().getStyleManager()); + return new AxisTickCalculator_Number(getDirection(), workingSpace, min, max, chart.getStyleManager()); } } } - @Override - public ChartInternal getChartInternal() { - - return axisPair.getChartInternal(); - } - // Getters ///////////////////////////////////////////////// - public AxisType getAxisType() { + protected AxisDataType getAxisDataType() { - return axisType; + return axisDataType; } protected double getMin() { @@ -431,83 +397,44 @@ public class Axis implements ChartPart { return min; } - protected double getMax() { + protected void setMin(double min) { - return max; + this.min = min; } - public AxisTick getAxisTick() { + protected double getMax() { - return axisTick; + return max; } - public Direction getDirection() { + protected void setMax(double max) { - return direction; + this.max = max; } - protected Rectangle2D getPaintZone() { + protected AxisTick<StyleManagerAxesChart, Series_AxesChart> getAxisTick() { - return paintZone; + return axisTick; } - public AxisTitle getAxisTitle() { + protected Direction getDirection() { - return axisTitle; + return direction; } - protected void setAxisTitle(AxisTitle axisTitle) { + protected AxisTitle<StyleManagerAxesChart, Series_AxesChart> getAxisTitle() { - this.axisTitle = axisTitle; + return axisTitle; } - public AxisTickCalculator getAxisTickCalculator() { + public AxisTickCalculator_ getAxisTickCalculator() { return this.axisTickCalculator; } - public void overrideMinMax() { - - if (direction == Direction.X) { // X-Axis - - double overrideXAxisMinValue = min; - double overrideXAxisMaxValue = max; - - // override min and maxValue if specified - if (getChartInternal().getStyleManager().getXAxisMin() != null && getChartInternal().getStyleManager().getChartType() != ChartType.Bar) { // bar chart cannot have a max or min TODO is this true? - overrideXAxisMinValue = getChartInternal().getStyleManager().getXAxisMin(); - } - if (getChartInternal().getStyleManager().getXAxisMax() != null && getChartInternal().getStyleManager().getChartType() != ChartType.Bar) { // bar chart cannot have a max or min - overrideXAxisMaxValue = getChartInternal().getStyleManager().getXAxisMax(); - } - min = overrideXAxisMinValue; - max = overrideXAxisMaxValue; - } - else { - - double overrideYAxisMinValue = min; - double overrideYAxisMaxValue = max; - // override min/max value for bar charts' Y-Axis - if (getChartInternal().getStyleManager().getChartType() == ChartType.Bar) { // this is the Y-Axis for a bar chart - if (min > 0.0 && max > 0.0) { - overrideYAxisMinValue = 0.0; - } - if (min < 0.0 && max < 0.0) { - overrideYAxisMaxValue = 0.0; - } - } - - // override min and maxValue if specified - if (getChartInternal().getStyleManager().getYAxisMin() != null) { - overrideYAxisMinValue = getChartInternal().getStyleManager().getYAxisMin(); - } - if (getChartInternal().getStyleManager().getYAxisMax() != null) { - overrideYAxisMaxValue = getChartInternal().getStyleManager().getYAxisMax(); - } - min = overrideYAxisMinValue; - max = overrideYAxisMaxValue; - } + @Override + public Rectangle2D getBounds() { + return bounds; } - } diff --git a/xchart/src/main/java/org/knowm/xchart/internal/chartpart/AxisPair.java b/xchart/src/main/java/org/knowm/xchart/internal/chartpart/AxisPair.java index ca45d6ffa933006334189210a0c874a3a8a8d5bd..67edcd2f88c49731d203197cf0ab063a3a78a778 100644 --- a/xchart/src/main/java/org/knowm/xchart/internal/chartpart/AxisPair.java +++ b/xchart/src/main/java/org/knowm/xchart/internal/chartpart/AxisPair.java @@ -1,5 +1,5 @@ /** - * Copyright 2015 Knowm Inc. (http://knowm.org) and contributors. + * Copyright 2015-2016 Knowm Inc. (http://knowm.org) and contributors. * Copyright 2011-2015 Xeiam LLC (http://xeiam.com) and contributors. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -19,60 +19,139 @@ package org.knowm.xchart.internal.chartpart; import java.awt.Graphics2D; import java.awt.geom.Rectangle2D; +import org.knowm.xchart.Series_AxesChart; +import org.knowm.xchart.Series_Category.ChartCategorySeriesRenderStyle; +import org.knowm.xchart.internal.Series; +import org.knowm.xchart.internal.style.StyleManagerAxesChart; +import org.knowm.xchart.StyleManagerCategory; + /** * @author timmolter */ -public class AxisPair implements ChartPart { +public class AxisPair<SM extends StyleManagerAxesChart, S extends Series> implements ChartPart { - /** parent */ - private final ChartInternal chartInternal; + private final Chart<StyleManagerAxesChart, Series_AxesChart> chart; - private Axis xAxis; - private Axis yAxis; + private final Axis<StyleManagerAxesChart, Series_AxesChart> xAxis; + private final Axis<StyleManagerAxesChart, Series_AxesChart> yAxis; /** * Constructor * - * @param the parent chartInternal + * @param chart */ - public AxisPair(ChartInternal chartInternal) { + public AxisPair(Chart<StyleManagerAxesChart, Series_AxesChart> chart) { - this.chartInternal = chartInternal; + this.chart = chart; // add axes - xAxis = new Axis(this, Axis.Direction.X); - yAxis = new Axis(this, Axis.Direction.Y); + xAxis = new Axis<StyleManagerAxesChart, Series_AxesChart>(chart, Axis.Direction.X); + yAxis = new Axis<StyleManagerAxesChart, Series_AxesChart>(chart, Axis.Direction.Y); } @Override public void paint(Graphics2D g) { + prepareForPaint(); + yAxis.paint(g); xAxis.paint(g); } - @Override - public Rectangle2D getBounds() { - - return null; // should never be called + private void prepareForPaint() { + + // calculate axis min and max + xAxis.resetMinMax(); + yAxis.resetMinMax(); + for (Series_AxesChart series : chart.getSeriesMap().values()) { + // add min/max to axes + // System.out.println(series.getxMin()); + // System.out.println(series.getxMax()); + // System.out.println(series.getyMin()); + // System.out.println(series.getyMax()); + // System.out.println("****"); + xAxis.addMinMax(series.getXMin(), series.getXMax()); + yAxis.addMinMax(series.getYMin(), series.getYMax()); + } + + overrideMinMax(); + + // logarithmic sanity check + if (chart.getStyleManager().isXAxisLogarithmic() && xAxis.getMin() <= 0.0) { + throw new IllegalArgumentException("Series data (accounting for error bars too) cannot be less or equal to zero for a logarithmic X-Axis!!!"); + } + if (chart.getStyleManager().isYAxisLogarithmic() && yAxis.getMin() <= 0.0) { + // System.out.println(getMin()); + throw new IllegalArgumentException("Series data (accounting for error bars too) cannot be less or equal to zero for a logarithmic Y-Axis!!!"); + } } - @Override - public ChartInternal getChartInternal() { + public void overrideMinMax() { + + double overrideXAxisMinValue = xAxis.getMin(); + double overrideXAxisMaxValue = xAxis.getMax(); + double overrideYAxisMinValue = yAxis.getMin(); + double overrideYAxisMaxValue = yAxis.getMax(); + + if (chart.getStyleManager() instanceof StyleManagerCategory) { + + StyleManagerCategory styleManagerCategory = (StyleManagerCategory) chart.getStyleManager(); + if (styleManagerCategory.getChartCategorySeriesRenderStyle() == ChartCategorySeriesRenderStyle.Bar) { + // override min/max value for bar charts' Y-Axis + // There is a special case where it's desired to anchor the axis min or max to zero, like in the case of bar charts. This flag enables that feature. + if (yAxis.getMin() > 0.0) { + overrideYAxisMinValue = 0.0; + } + if (yAxis.getMax() < 0.0) { + overrideYAxisMaxValue = 0.0; + } + } + } + + // override min and maxValue if specified + if (chart.getStyleManager().getXAxisMin() != null) + + { + overrideXAxisMinValue = chart.getStyleManager().getXAxisMin(); + } + if (chart.getStyleManager().getXAxisMax() != null) + + { + overrideXAxisMaxValue = chart.getStyleManager().getXAxisMax(); + } + if (chart.getStyleManager().getYAxisMin() != null) + + { + overrideYAxisMinValue = chart.getStyleManager().getYAxisMin(); + } + if (chart.getStyleManager().getYAxisMax() != null) + + { + overrideYAxisMaxValue = chart.getStyleManager().getYAxisMax(); + } + + xAxis.setMin(overrideXAxisMinValue); + xAxis.setMax(overrideXAxisMaxValue); + yAxis.setMin(overrideYAxisMinValue); + yAxis.setMax(overrideYAxisMaxValue); - return chartInternal; } - // Getters ///////////////////////////////////////////////// + // Getters & Setters ///////////////////////////////////////////////// - public Axis getXAxis() { + protected Axis<StyleManagerAxesChart, Series_AxesChart> getXAxis() { return xAxis; } - public Axis getYAxis() { + protected Axis<StyleManagerAxesChart, Series_AxesChart> getYAxis() { return yAxis; } + @Override + public Rectangle2D getBounds() { + + return null; // should never be called + } } diff --git a/xchart/src/main/java/org/knowm/xchart/internal/chartpart/AxisTick.java b/xchart/src/main/java/org/knowm/xchart/internal/chartpart/AxisTick.java index 469d10c010484f38d8dced2e029b6d291f129a5b..38d09246bc63cbb416c244aa000fd578d934ee29 100644 --- a/xchart/src/main/java/org/knowm/xchart/internal/chartpart/AxisTick.java +++ b/xchart/src/main/java/org/knowm/xchart/internal/chartpart/AxisTick.java @@ -1,5 +1,5 @@ /** - * Copyright 2015 Knowm Inc. (http://knowm.org) and contributors. + * Copyright 2015-2016 Knowm Inc. (http://knowm.org) and contributors. * Copyright 2011-2015 Xeiam LLC (http://xeiam.com) and contributors. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -19,33 +19,38 @@ package org.knowm.xchart.internal.chartpart; import java.awt.Graphics2D; import java.awt.geom.Rectangle2D; +import org.knowm.xchart.Series_AxesChart; +import org.knowm.xchart.internal.Series; +import org.knowm.xchart.internal.chartpart.Axis.Direction; +import org.knowm.xchart.internal.style.StyleManagerAxesChart; + /** * An axis tick */ -public class AxisTick implements ChartPart { +public class AxisTick<SM extends StyleManagerAxesChart, S extends Series> implements ChartPart { - /** parent */ - private Axis axis; + private final Chart<StyleManagerAxesChart, Series_AxesChart> chart; + private Rectangle2D bounds; + private final Direction direction; /** the axisticklabels */ - private AxisTickLabels axisTickLabels; + private AxisTickLabels<StyleManagerAxesChart, Series_AxesChart> axisTickLabels; /** the axistickmarks */ - private AxisTickMarks axisTickMarks; - - /** the bounds */ - private Rectangle2D bounds = new Rectangle2D.Double(); + private AxisTickMarks<StyleManagerAxesChart, Series_AxesChart> axisTickMarks; /** * Constructor * - * @param axis + * @param chart + * @param direction */ - protected AxisTick(Axis axis) { + protected AxisTick(Chart<StyleManagerAxesChart, Series_AxesChart> chart, Direction direction) { - this.axis = axis; - axisTickLabels = new AxisTickLabels(this); - axisTickMarks = new AxisTickMarks(this); + this.chart = chart; + this.direction = direction; + axisTickLabels = new AxisTickLabels<StyleManagerAxesChart, Series_AxesChart>(chart, direction); + axisTickMarks = new AxisTickMarks<StyleManagerAxesChart, Series_AxesChart>(chart, direction); } @Override @@ -57,22 +62,7 @@ public class AxisTick implements ChartPart { @Override public void paint(Graphics2D g) { - // double workingSpace = 0.0; - // // Y-Axis - // if (axis.getDirection() == Axis.Direction.Y) { - // workingSpace = axis.getPaintZone().getHeight(); // number of pixels the axis has to work with for drawing AxisTicks - // // System.out.println("workingspace= " + workingSpace); - // } - // // X-Axis - // else if (axis.getDirection() == Axis.Direction.X) { - // workingSpace = axis.getPaintZone().getWidth(); // number of pixels the axis has to work with for drawing AxisTicks - // // System.out.println("workingspace= " + workingSpace); - // } - // - // System.out.println("AxisTick: " + axis.getDirection()); - // System.out.println("workingSpace: " + workingSpace); - - if (axis.getDirection() == Axis.Direction.Y && getChartInternal().getStyleManager().isYAxisTicksVisible()) { + if (direction == Axis.Direction.Y && chart.getStyleManager().isYAxisTicksVisible()) { axisTickLabels.paint(g); axisTickMarks.paint(g); @@ -83,7 +73,7 @@ public class AxisTick implements ChartPart { axisTickLabels.getBounds().getY(), - axisTickLabels.getBounds().getWidth() + getChartInternal().getStyleManager().getAxisTickPadding() + axisTickMarks.getBounds().getWidth(), + axisTickLabels.getBounds().getWidth() + chart.getStyleManager().getAxisTickPadding() + axisTickMarks.getBounds().getWidth(), axisTickMarks.getBounds().getHeight() @@ -93,7 +83,7 @@ public class AxisTick implements ChartPart { // g.draw(bounds); } - else if (axis.getDirection() == Axis.Direction.X && getChartInternal().getStyleManager().isXAxisTicksVisible()) { + else if (direction == Axis.Direction.X && chart.getStyleManager().isXAxisTicksVisible()) { axisTickLabels.paint(g); axisTickMarks.paint(g); @@ -106,7 +96,7 @@ public class AxisTick implements ChartPart { axisTickLabels.getBounds().getWidth(), - axisTickMarks.getBounds().getHeight() + getChartInternal().getStyleManager().getAxisTickPadding() + axisTickLabels.getBounds().getHeight() + axisTickMarks.getBounds().getHeight() + chart.getStyleManager().getAxisTickPadding() + axisTickLabels.getBounds().getHeight() ); @@ -114,23 +104,15 @@ public class AxisTick implements ChartPart { // g.draw(bounds); } + else { + bounds = new Rectangle2D.Double(); + } } - @Override - public ChartInternal getChartInternal() { - - return axis.getChartInternal(); - } - // Getters ///////////////////////////////////////////////// - public Axis getAxis() { - - return axis; - } - - public AxisTickLabels getAxisTickLabels() { + protected AxisTickLabels<StyleManagerAxesChart, Series_AxesChart> getAxisTickLabels() { return axisTickLabels; } diff --git a/xchart/src/main/java/org/knowm/xchart/internal/chartpart/AxisTickCalculator.java b/xchart/src/main/java/org/knowm/xchart/internal/chartpart/AxisTickCalculator_.java similarity index 90% rename from xchart/src/main/java/org/knowm/xchart/internal/chartpart/AxisTickCalculator.java rename to xchart/src/main/java/org/knowm/xchart/internal/chartpart/AxisTickCalculator_.java index 5a41416987210bec93779bd6d1cff4ece74e8db0..2ac60ffa6d9816ad4a3e78cec53fd7f9409c88b7 100644 --- a/xchart/src/main/java/org/knowm/xchart/internal/chartpart/AxisTickCalculator.java +++ b/xchart/src/main/java/org/knowm/xchart/internal/chartpart/AxisTickCalculator_.java @@ -1,5 +1,5 @@ /** - * Copyright 2015 Knowm Inc. (http://knowm.org) and contributors. + * Copyright 2015-2016 Knowm Inc. (http://knowm.org) and contributors. * Copyright 2011-2015 Xeiam LLC (http://xeiam.com) and contributors. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -24,13 +24,13 @@ import java.awt.geom.Rectangle2D; import java.util.LinkedList; import java.util.List; -import org.knowm.xchart.StyleManager; import org.knowm.xchart.internal.chartpart.Axis.Direction; +import org.knowm.xchart.internal.style.StyleManagerAxesChart; /** * @author timmolter */ -public abstract class AxisTickCalculator { +public abstract class AxisTickCalculator_ { /** the List of tick label position in pixels */ protected List<Double> tickLocations = new LinkedList<Double>();; @@ -46,7 +46,7 @@ public abstract class AxisTickCalculator { protected final double maxValue; - protected final StyleManager styleManager; + protected final StyleManagerAxesChart styleManager; /** * Constructor @@ -57,7 +57,7 @@ public abstract class AxisTickCalculator { * @param maxValue * @param styleManager */ - public AxisTickCalculator(Direction axisDirection, double workingSpace, double minValue, double maxValue, StyleManager styleManager) { + public AxisTickCalculator_(Direction axisDirection, double workingSpace, double minValue, double maxValue, StyleManagerAxesChart styleManager) { this.axisDirection = axisDirection; this.workingSpace = workingSpace; diff --git a/xchart/src/main/java/org/knowm/xchart/internal/chartpart/AxisTickCalculator_Category.java b/xchart/src/main/java/org/knowm/xchart/internal/chartpart/AxisTickCalculator_Category.java index c0bf69b19b80b1365c9015540a66fc7dfa2ff992..ff88d573d71f99fdfffaa10f739f46b85fb2480b 100644 --- a/xchart/src/main/java/org/knowm/xchart/internal/chartpart/AxisTickCalculator_Category.java +++ b/xchart/src/main/java/org/knowm/xchart/internal/chartpart/AxisTickCalculator_Category.java @@ -1,5 +1,5 @@ /** - * Copyright 2015 Knowm Inc. (http://knowm.org) and contributors. + * Copyright 2015-2016 Knowm Inc. (http://knowm.org) and contributors. * Copyright 2011-2015 Xeiam LLC (http://xeiam.com) and contributors. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -21,17 +21,17 @@ import java.text.SimpleDateFormat; import java.util.Date; import java.util.List; -import org.knowm.xchart.StyleManager; import org.knowm.xchart.internal.Utils; -import org.knowm.xchart.internal.chartpart.Axis.AxisType; +import org.knowm.xchart.internal.chartpart.Axis.AxisDataType; import org.knowm.xchart.internal.chartpart.Axis.Direction; +import org.knowm.xchart.internal.style.StyleManagerAxesChart; /** * This class encapsulates the logic to generate the axis tick mark and axis tick label data for rendering the axis ticks for String axes * * @author timmolter */ -public class AxisTickCalculator_Category extends AxisTickCalculator { +public class AxisTickCalculator_Category extends AxisTickCalculator_ { /** * Constructor @@ -42,14 +42,14 @@ public class AxisTickCalculator_Category extends AxisTickCalculator { * @param axisType * @param styleManager */ - public AxisTickCalculator_Category(Direction axisDirection, double workingSpace, List<?> categories, AxisType axisType, StyleManager styleManager) { + public AxisTickCalculator_Category(Direction axisDirection, double workingSpace, List<?> categories, AxisDataType axisType, StyleManagerAxesChart styleManager) { super(axisDirection, workingSpace, Double.NaN, Double.NaN, styleManager); calculate(categories, axisType); } - private void calculate(List<?> categories, AxisType axisType) { + private void calculate(List<?> categories, AxisDataType axisType) { // tick space - a percentage of the working space available for ticks int tickSpace = (int) (styleManager.getAxisTickSpacePercentage() * workingSpace); // in plot space @@ -64,10 +64,10 @@ public class AxisTickCalculator_Category extends AxisTickCalculator { // set up String formatters that may be encountered NumberFormatter numberFormatter = null; SimpleDateFormat simpleDateformat = null; - if (axisType == AxisType.Number) { + if (axisType == AxisDataType.Number) { numberFormatter = new NumberFormatter(styleManager); } - else if (axisType == AxisType.Date) { + else if (axisType == AxisDataType.Date) { if (styleManager.getDatePattern() == null) { throw new RuntimeException("You need to set the Date Formatting Pattern!!!"); } @@ -78,15 +78,15 @@ public class AxisTickCalculator_Category extends AxisTickCalculator { int counter = 0; for (Object category : categories) { - if (axisType == AxisType.String) { + if (axisType == AxisDataType.String) { tickLabels.add(category.toString()); double tickLabelPosition = margin + firstPosition + gridStep * counter++; tickLocations.add(tickLabelPosition); } - else if (axisType == AxisType.Number) { + else if (axisType == AxisDataType.Number) { tickLabels.add(numberFormatter.formatNumber(new BigDecimal(category.toString()), minValue, maxValue, axisDirection)); } - else if (axisType == AxisType.Date) { + else if (axisType == AxisDataType.Date) { tickLabels.add(simpleDateformat.format((((Date) category).getTime()))); } diff --git a/xchart/src/main/java/org/knowm/xchart/internal/chartpart/AxisTickCalculator_Date.java b/xchart/src/main/java/org/knowm/xchart/internal/chartpart/AxisTickCalculator_Date.java index 4b641abc0ce609191e9e69f78a0d005b1d9545a6..d0a6c5c1b17525873b5f62752257d9416438033e 100644 --- a/xchart/src/main/java/org/knowm/xchart/internal/chartpart/AxisTickCalculator_Date.java +++ b/xchart/src/main/java/org/knowm/xchart/internal/chartpart/AxisTickCalculator_Date.java @@ -1,5 +1,5 @@ /** - * Copyright 2015 Knowm Inc. (http://knowm.org) and contributors. + * Copyright 2015-2016 Knowm Inc. (http://knowm.org) and contributors. * Copyright 2011-2015 Xeiam LLC (http://xeiam.com) and contributors. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -21,16 +21,16 @@ import java.util.ArrayList; import java.util.List; import java.util.concurrent.TimeUnit; -import org.knowm.xchart.StyleManager; import org.knowm.xchart.internal.Utils; import org.knowm.xchart.internal.chartpart.Axis.Direction; +import org.knowm.xchart.internal.style.StyleManagerAxesChart; /** * This class encapsulates the logic to generate the axis tick mark and axis tick label data for rendering the axis ticks for date axes * * @author timmolter */ -public class AxisTickCalculator_Date extends AxisTickCalculator { +public class AxisTickCalculator_Date extends AxisTickCalculator_ { private static final long MILLIS_SCALE = TimeUnit.MILLISECONDS.toMillis(1L); private static final long SEC_SCALE = TimeUnit.SECONDS.toMillis(1L); @@ -108,7 +108,7 @@ public class AxisTickCalculator_Date extends AxisTickCalculator { * @param maxValue * @param styleManager */ - public AxisTickCalculator_Date(Direction axisDirection, double workingSpace, double minValue, double maxValue, StyleManager styleManager) { + public AxisTickCalculator_Date(Direction axisDirection, double workingSpace, double minValue, double maxValue, StyleManagerAxesChart styleManager) { super(axisDirection, workingSpace, minValue, maxValue, styleManager); diff --git a/xchart/src/main/java/org/knowm/xchart/internal/chartpart/AxisTickCalculator_Logarithmic.java b/xchart/src/main/java/org/knowm/xchart/internal/chartpart/AxisTickCalculator_Logarithmic.java index 28ef661a2f0a0f4271e5a97e2b781cdcfa9db875..61f092435a234d574bc6b961ff246f50b27cee37 100644 --- a/xchart/src/main/java/org/knowm/xchart/internal/chartpart/AxisTickCalculator_Logarithmic.java +++ b/xchart/src/main/java/org/knowm/xchart/internal/chartpart/AxisTickCalculator_Logarithmic.java @@ -1,5 +1,5 @@ /** - * Copyright 2015 Knowm Inc. (http://knowm.org) and contributors. + * Copyright 2015-2016 Knowm Inc. (http://knowm.org) and contributors. * Copyright 2011-2015 Xeiam LLC (http://xeiam.com) and contributors. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,16 +18,16 @@ package org.knowm.xchart.internal.chartpart; import java.math.BigDecimal; -import org.knowm.xchart.StyleManager; import org.knowm.xchart.internal.Utils; import org.knowm.xchart.internal.chartpart.Axis.Direction; +import org.knowm.xchart.internal.style.StyleManagerAxesChart; /** * This class encapsulates the logic to generate the axis tick mark and axis tick label data for rendering the axis ticks for logarithmic axes * * @author timmolter */ -public class AxisTickCalculator_Logarithmic extends AxisTickCalculator { +public class AxisTickCalculator_Logarithmic extends AxisTickCalculator_ { NumberFormatter numberFormatter = null; @@ -40,7 +40,7 @@ public class AxisTickCalculator_Logarithmic extends AxisTickCalculator { * @param maxValue * @param styleManager */ - public AxisTickCalculator_Logarithmic(Direction axisDirection, double workingSpace, double minValue, double maxValue, StyleManager styleManager) { + public AxisTickCalculator_Logarithmic(Direction axisDirection, double workingSpace, double minValue, double maxValue, StyleManagerAxesChart styleManager) { super(axisDirection, workingSpace, minValue, maxValue, styleManager); numberFormatter = new NumberFormatter(styleManager); diff --git a/xchart/src/main/java/org/knowm/xchart/internal/chartpart/AxisTickCalculator_Number.java b/xchart/src/main/java/org/knowm/xchart/internal/chartpart/AxisTickCalculator_Number.java index 4cbdce015560734524b693cd22077bb4987d353f..6f0c0637b3424d446ba08ca54270432669873ceb 100644 --- a/xchart/src/main/java/org/knowm/xchart/internal/chartpart/AxisTickCalculator_Number.java +++ b/xchart/src/main/java/org/knowm/xchart/internal/chartpart/AxisTickCalculator_Number.java @@ -1,5 +1,5 @@ /** - * Copyright 2015 Knowm Inc. (http://knowm.org) and contributors. + * Copyright 2015-2016 Knowm Inc. (http://knowm.org) and contributors. * Copyright 2011-2015 Xeiam LLC (http://xeiam.com) and contributors. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -19,16 +19,16 @@ package org.knowm.xchart.internal.chartpart; import java.math.BigDecimal; import java.math.RoundingMode; -import org.knowm.xchart.StyleManager; import org.knowm.xchart.internal.Utils; import org.knowm.xchart.internal.chartpart.Axis.Direction; +import org.knowm.xchart.internal.style.StyleManagerAxesChart; /** * 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 AxisTickCalculator_Number extends AxisTickCalculator { +public class AxisTickCalculator_Number extends AxisTickCalculator_ { NumberFormatter numberFormatter = null; @@ -41,7 +41,7 @@ public class AxisTickCalculator_Number extends AxisTickCalculator { * @param maxValue * @param styleManager */ - public AxisTickCalculator_Number(Direction axisDirection, double workingSpace, double minValue, double maxValue, StyleManager styleManager) { + public AxisTickCalculator_Number(Direction axisDirection, double workingSpace, double minValue, double maxValue, StyleManagerAxesChart styleManager) { super(axisDirection, workingSpace, minValue, maxValue, styleManager); numberFormatter = new NumberFormatter(styleManager); diff --git a/xchart/src/main/java/org/knowm/xchart/internal/chartpart/AxisTickLabels.java b/xchart/src/main/java/org/knowm/xchart/internal/chartpart/AxisTickLabels.java index 89fd605545fbcdfa45a5b859ed4ad34ed82d5fbe..6d53e601a812f15571782e1794ed8c776be03438 100644 --- a/xchart/src/main/java/org/knowm/xchart/internal/chartpart/AxisTickLabels.java +++ b/xchart/src/main/java/org/knowm/xchart/internal/chartpart/AxisTickLabels.java @@ -1,5 +1,5 @@ /** - * Copyright 2015 Knowm Inc. (http://knowm.org) and contributors. + * Copyright 2015-2016 Knowm Inc. (http://knowm.org) and contributors. * Copyright 2011-2015 Xeiam LLC (http://xeiam.com) and contributors. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -25,59 +25,58 @@ import java.awt.geom.Rectangle2D; import java.util.HashMap; import java.util.Map; +import org.knowm.xchart.Series_AxesChart; +import org.knowm.xchart.internal.Series; +import org.knowm.xchart.internal.chartpart.Axis.Direction; +import org.knowm.xchart.internal.style.StyleManagerAxesChart; + /** * Axis tick labels */ -public class AxisTickLabels implements ChartPart { - - /** parent */ - private final AxisTick axisTick; +public class AxisTickLabels<SM extends StyleManagerAxesChart, S extends Series> implements ChartPart { - /** the bounds */ - private Rectangle2D bounds = new Rectangle2D.Double(); + private final Chart<StyleManagerAxesChart, Series_AxesChart> chart; + private Rectangle2D bounds; + private final Direction direction; /** * Constructor * - * @param axisTick + * @param chart + * @param direction */ - protected AxisTickLabels(AxisTick axisTick) { + protected AxisTickLabels(Chart<StyleManagerAxesChart, Series_AxesChart> chart, Direction direction) { - this.axisTick = axisTick; - } - - @Override - public Rectangle2D getBounds() { - - return bounds; + this.chart = chart; + this.direction = direction; } @Override public void paint(Graphics2D g) { - g.setFont(getChartInternal().getStyleManager().getAxisTickLabelsFont()); + g.setFont(chart.getStyleManager().getAxisTickLabelsFont()); - g.setColor(getChartInternal().getStyleManager().getAxisTickLabelsColor()); + g.setColor(chart.getStyleManager().getAxisTickLabelsColor()); - if (axisTick.getAxis().getDirection() == Axis.Direction.Y && getChartInternal().getStyleManager().isYAxisTicksVisible()) { // Y-Axis + if (direction == Axis.Direction.Y && chart.getStyleManager().isYAxisTicksVisible()) { // Y-Axis - double xWidth = axisTick.getAxis().getAxisTitle().getBounds().getWidth(); - double xOffset = axisTick.getAxis().getAxisTitle().getBounds().getX() + xWidth; - double yOffset = axisTick.getAxis().getPaintZone().getY(); - double height = axisTick.getAxis().getPaintZone().getHeight(); + double xWidth = chart.getYAxis().getAxisTitle().getBounds().getWidth(); + double xOffset = chart.getYAxis().getAxisTitle().getBounds().getX() + xWidth; + double yOffset = chart.getYAxis().getPaintZone().getY(); + double height = chart.getYAxis().getPaintZone().getHeight(); double maxTickLabelWidth = 0; Map<Double, TextLayout> axisLabelTextLayouts = new HashMap<Double, TextLayout>(); - for (int i = 0; i < axisTick.getAxis().getAxisTickCalculator().getTickLabels().size(); i++) { + for (int i = 0; i < chart.getYAxis().getAxisTickCalculator().getTickLabels().size(); i++) { - String tickLabel = axisTick.getAxis().getAxisTickCalculator().getTickLabels().get(i); + String tickLabel = chart.getYAxis().getAxisTickCalculator().getTickLabels().get(i); // System.out.println("** " + tickLabel); - double tickLocation = axisTick.getAxis().getAxisTickCalculator().getTickLocations().get(i); + double tickLocation = chart.getYAxis().getAxisTickCalculator().getTickLocations().get(i); double flippedTickLocation = yOffset + height - tickLocation; if (tickLabel != null && flippedTickLocation > yOffset && flippedTickLocation < yOffset + height) { // some are null for logarithmic axes FontRenderContext frc = g.getFontRenderContext(); - TextLayout axisLabelTextLayout = new TextLayout(tickLabel, getChartInternal().getStyleManager().getAxisTickLabelsFont(), frc); + TextLayout axisLabelTextLayout = new TextLayout(tickLabel, chart.getStyleManager().getAxisTickLabelsFont(), frc); Rectangle2D tickLabelBounds = axisLabelTextLayout.getBounds(); double boundWidth = tickLabelBounds.getWidth(); if (boundWidth > maxTickLabelWidth) { @@ -99,7 +98,7 @@ public class AxisTickLabels implements ChartPart { AffineTransform at = new AffineTransform(); double boundWidth = tickLabelBounds.getWidth(); double xPos; - switch (getChartInternal().getStyleManager().getYAxisLabelAlignment()) { + switch (chart.getStyleManager().getYAxisLabelAlignment()) { case Right: xPos = xOffset + maxTickLabelWidth - boundWidth; break; @@ -124,37 +123,37 @@ public class AxisTickLabels implements ChartPart { } // X-Axis - else if (axisTick.getAxis().getDirection() == Axis.Direction.X && getChartInternal().getStyleManager().isXAxisTicksVisible()) { + else if (direction == Axis.Direction.X && chart.getStyleManager().isXAxisTicksVisible()) { - double xOffset = axisTick.getAxis().getPaintZone().getX(); - double yOffset = axisTick.getAxis().getAxisTitle().getBounds().getY(); - double width = axisTick.getAxis().getPaintZone().getWidth(); + double xOffset = chart.getXAxis().getPaintZone().getX(); + double yOffset = chart.getXAxis().getAxisTitle().getBounds().getY(); + double width = chart.getXAxis().getPaintZone().getWidth(); double maxTickLabelHeight = 0; // System.out.println("axisTick.getTickLabels().size(): " + axisTick.getTickLabels().size()); - for (int i = 0; i < axisTick.getAxis().getAxisTickCalculator().getTickLabels().size(); i++) { + for (int i = 0; i < chart.getXAxis().getAxisTickCalculator().getTickLabels().size(); i++) { - String tickLabel = axisTick.getAxis().getAxisTickCalculator().getTickLabels().get(i); + String tickLabel = chart.getXAxis().getAxisTickCalculator().getTickLabels().get(i); // System.out.println("tickLabel: " + tickLabel); - double tickLocation = axisTick.getAxis().getAxisTickCalculator().getTickLocations().get(i); + double tickLocation = chart.getXAxis().getAxisTickCalculator().getTickLocations().get(i); double shiftedTickLocation = xOffset + tickLocation; // discard null and out of bounds labels if (tickLabel != null && shiftedTickLocation > xOffset && shiftedTickLocation < xOffset + width) { // some are null for logarithmic axes FontRenderContext frc = g.getFontRenderContext(); - TextLayout textLayout = new TextLayout(tickLabel, getChartInternal().getStyleManager().getAxisTickLabelsFont(), frc); + TextLayout textLayout = new TextLayout(tickLabel, chart.getStyleManager().getAxisTickLabelsFont(), frc); // System.out.println(textLayout.getOutline(null).getBounds().toString()); // Shape shape = v.getOutline(); - AffineTransform rot = AffineTransform.getRotateInstance(-1 * Math.toRadians(getChartInternal().getStyleManager().getXAxisLabelRotation()), 0, 0); + AffineTransform rot = AffineTransform.getRotateInstance(-1 * Math.toRadians(chart.getStyleManager().getXAxisLabelRotation()), 0, 0); Shape shape = textLayout.getOutline(rot); Rectangle2D tickLabelBounds = shape.getBounds2D(); AffineTransform orig = g.getTransform(); AffineTransform at = new AffineTransform(); double xPos; - switch (getChartInternal().getStyleManager().getXAxisLabelAlignment()) { + switch (chart.getStyleManager().getXAxisLabelAlignment()) { case Left: xPos = shiftedTickLocation; break; @@ -166,7 +165,7 @@ public class AxisTickLabels implements ChartPart { xPos = shiftedTickLocation - tickLabelBounds.getWidth() / 2.0; } // System.out.println("tickLabelBounds: " + tickLabelBounds.toString()); - double shiftX = -1 * tickLabelBounds.getX() * Math.sin(Math.toRadians(getChartInternal().getStyleManager().getXAxisLabelRotation())); + double shiftX = -1 * tickLabelBounds.getX() * Math.sin(Math.toRadians(chart.getStyleManager().getXAxisLabelRotation())); double shiftY = -1 * (tickLabelBounds.getY() + tickLabelBounds.getHeight()); // System.out.println(shiftX); // System.out.println("shiftY: " + shiftY); @@ -196,12 +195,15 @@ public class AxisTickLabels implements ChartPart { // g.draw(bounds); } + else { + bounds = new Rectangle2D.Double(); + } } @Override - public ChartInternal getChartInternal() { + public Rectangle2D getBounds() { - return axisTick.getChartInternal(); + return bounds; } } diff --git a/xchart/src/main/java/org/knowm/xchart/internal/chartpart/AxisTickMarks.java b/xchart/src/main/java/org/knowm/xchart/internal/chartpart/AxisTickMarks.java index 1c05c65bcf158b3760501abc8974966cd5de6f8a..b593da4cf13f86713152b16dd0e67034a2e6d663 100644 --- a/xchart/src/main/java/org/knowm/xchart/internal/chartpart/AxisTickMarks.java +++ b/xchart/src/main/java/org/knowm/xchart/internal/chartpart/AxisTickMarks.java @@ -1,5 +1,5 @@ /** - * Copyright 2015 Knowm Inc. (http://knowm.org) and contributors. + * Copyright 2015-2016 Knowm Inc. (http://knowm.org) and contributors. * Copyright 2011-2015 Xeiam LLC (http://xeiam.com) and contributors. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -21,116 +21,119 @@ import java.awt.Shape; import java.awt.geom.Line2D; import java.awt.geom.Rectangle2D; +import org.knowm.xchart.Series_AxesChart; +import org.knowm.xchart.internal.Series; +import org.knowm.xchart.internal.chartpart.Axis.Direction; +import org.knowm.xchart.internal.style.StyleManagerAxesChart; + /** * Axis tick marks. This includes the little tick marks and the line that hugs the plot area. */ -public class AxisTickMarks implements ChartPart { - - /** parent */ - private AxisTick axisTick; +public class AxisTickMarks<SM extends StyleManagerAxesChart, S extends Series> implements ChartPart { - /** the bounds */ - private Rectangle2D bounds = new Rectangle2D.Double(); + private final Chart<StyleManagerAxesChart, Series_AxesChart> chart; + private Rectangle2D bounds; + private final Direction direction; /** * Constructor * - * @param axisTick + * @param chart + * @param direction */ - protected AxisTickMarks(AxisTick axisTick) { - - this.axisTick = axisTick; - } - - @Override - public Rectangle2D getBounds() { + protected AxisTickMarks(Chart<StyleManagerAxesChart, Series_AxesChart> chart, Direction direction) { - return bounds; + this.chart = chart; + this.direction = direction; } @Override public void paint(Graphics2D g) { - g.setColor(getChartInternal().getStyleManager().getAxisTickMarksColor()); - g.setStroke(getChartInternal().getStyleManager().getAxisTickMarksStroke()); + g.setColor(chart.getStyleManager().getAxisTickMarksColor()); + g.setStroke(chart.getStyleManager().getAxisTickMarksStroke()); - if (axisTick.getAxis().getDirection() == Axis.Direction.Y && getChartInternal().getStyleManager().isYAxisTicksVisible()) { // Y-Axis + if (direction == Axis.Direction.Y && chart.getStyleManager().isYAxisTicksVisible()) { // Y-Axis - double xOffset = axisTick.getAxisTickLabels().getBounds().getX() + axisTick.getAxisTickLabels().getBounds().getWidth() + getChartInternal().getStyleManager().getAxisTickPadding(); - double yOffset = axisTick.getAxis().getPaintZone().getY(); + double xOffset = chart.getYAxis().getAxisTick().getAxisTickLabels().getBounds().getX() + chart.getYAxis().getAxisTick().getAxisTickLabels().getBounds().getWidth() + chart.getStyleManager() + .getAxisTickPadding(); + double yOffset = chart.getYAxis().getPaintZone().getY(); // bounds - bounds = new Rectangle2D.Double(xOffset, yOffset, getChartInternal().getStyleManager().getAxisTickMarkLength(), axisTick.getAxis().getPaintZone().getHeight()); + bounds = new Rectangle2D.Double(xOffset, yOffset, chart.getStyleManager().getAxisTickMarkLength(), chart.getYAxis().getPaintZone().getHeight()); // g.setColor(Color.yellow); // g.draw(bounds); // tick marks - if (getChartInternal().getStyleManager().isAxisTicksMarksVisible()) { + if (chart.getStyleManager().isAxisTicksMarksVisible()) { - for (int i = 0; i < axisTick.getAxis().getAxisTickCalculator().getTickLabels().size(); i++) { + for (int i = 0; i < chart.getYAxis().getAxisTickCalculator().getTickLabels().size(); i++) { - double tickLocation = axisTick.getAxis().getAxisTickCalculator().getTickLocations().get(i); - double flippedTickLocation = yOffset + axisTick.getAxis().getPaintZone().getHeight() - tickLocation; + double tickLocation = chart.getYAxis().getAxisTickCalculator().getTickLocations().get(i); + double flippedTickLocation = yOffset + chart.getYAxis().getPaintZone().getHeight() - tickLocation; if (flippedTickLocation > bounds.getY() && flippedTickLocation < bounds.getY() + bounds.getHeight()) { - Shape line = new Line2D.Double(xOffset, flippedTickLocation, xOffset + getChartInternal().getStyleManager().getAxisTickMarkLength(), flippedTickLocation); + Shape line = new Line2D.Double(xOffset, flippedTickLocation, xOffset + chart.getStyleManager().getAxisTickMarkLength(), flippedTickLocation); g.draw(line); } } } // Line - if (getChartInternal().getStyleManager().isAxisTicksLineVisible()) { + if (chart.getStyleManager().isAxisTicksLineVisible()) { - Shape line = new Line2D.Double(xOffset + getChartInternal().getStyleManager().getAxisTickMarkLength(), yOffset, xOffset + getChartInternal().getStyleManager().getAxisTickMarkLength(), yOffset - + axisTick.getAxis().getPaintZone().getHeight()); + Shape line = new Line2D.Double(xOffset + chart.getStyleManager().getAxisTickMarkLength(), yOffset, xOffset + chart.getStyleManager().getAxisTickMarkLength(), yOffset + chart.getYAxis() + .getPaintZone().getHeight()); g.draw(line); } } // X-Axis - else if (axisTick.getAxis().getDirection() == Axis.Direction.X && getChartInternal().getStyleManager().isXAxisTicksVisible()) { + else if (direction == Axis.Direction.X && chart.getStyleManager().isXAxisTicksVisible()) { - double xOffset = axisTick.getAxis().getPaintZone().getX(); - double yOffset = axisTick.getAxisTickLabels().getBounds().getY() - getChartInternal().getStyleManager().getAxisTickPadding(); + double xOffset = chart.getXAxis().getPaintZone().getX(); + double yOffset = chart.getXAxis().getAxisTick().getAxisTickLabels().getBounds().getY() - chart.getStyleManager().getAxisTickPadding(); // bounds - bounds = new Rectangle2D.Double(xOffset, yOffset - getChartInternal().getStyleManager().getAxisTickMarkLength(), axisTick.getAxis().getPaintZone().getWidth(), getChartInternal().getStyleManager() - .getAxisTickMarkLength()); - // g.setColor(Color.yellow); - // g.draw(bounds); + bounds = new Rectangle2D.Double(xOffset, yOffset - chart.getStyleManager().getAxisTickMarkLength(), chart.getXAxis().getPaintZone().getWidth(), chart.getStyleManager().getAxisTickMarkLength()); + // g.setColor(Color.yellow); + // g.draw(bounds); // tick marks - if (getChartInternal().getStyleManager().isAxisTicksMarksVisible()) { + if (chart.getStyleManager().isAxisTicksMarksVisible()) { - for (int i = 0; i < axisTick.getAxis().getAxisTickCalculator().getTickLabels().size(); i++) { + for (int i = 0; i < chart.getXAxis().getAxisTickCalculator().getTickLabels().size(); i++) { - double tickLocation = axisTick.getAxis().getAxisTickCalculator().getTickLocations().get(i); + double tickLocation = chart.getXAxis().getAxisTickCalculator().getTickLocations().get(i); double shiftedTickLocation = xOffset + tickLocation; if (shiftedTickLocation > bounds.getX() && shiftedTickLocation < bounds.getX() + bounds.getWidth()) { - Shape line = new Line2D.Double(shiftedTickLocation, yOffset, xOffset + tickLocation, yOffset - getChartInternal().getStyleManager().getAxisTickMarkLength()); + Shape line = new Line2D.Double(shiftedTickLocation, yOffset, xOffset + tickLocation, yOffset - chart.getStyleManager().getAxisTickMarkLength()); g.draw(line); } } } // Line - if (getChartInternal().getStyleManager().isAxisTicksLineVisible()) { + if (chart.getStyleManager().isAxisTicksLineVisible()) { - g.setStroke(getChartInternal().getStyleManager().getAxisTickMarksStroke()); - g.drawLine((int) xOffset, (int) (yOffset - getChartInternal().getStyleManager().getAxisTickMarkLength()), (int) (xOffset + axisTick.getAxis().getPaintZone().getWidth()), (int) (yOffset - - getChartInternal().getStyleManager().getAxisTickMarkLength())); + g.setStroke(chart.getStyleManager().getAxisTickMarksStroke()); + g.drawLine((int) xOffset, (int) (yOffset - chart.getStyleManager().getAxisTickMarkLength()), (int) (xOffset + chart.getXAxis().getPaintZone().getWidth()), (int) (yOffset - chart + .getStyleManager().getAxisTickMarkLength())); } } + else { + bounds = new Rectangle2D.Double(); + } + } @Override - public ChartInternal getChartInternal() { + public Rectangle2D getBounds() { - return axisTick.getChartInternal(); + return bounds; } } diff --git a/xchart/src/main/java/org/knowm/xchart/internal/chartpart/AxisTitle.java b/xchart/src/main/java/org/knowm/xchart/internal/chartpart/AxisTitle.java index 92dfb716ff4799572f438c405e02ffc8a242946c..2f11a24e6942077ee043d5513a3f4b924eb9f26f 100644 --- a/xchart/src/main/java/org/knowm/xchart/internal/chartpart/AxisTitle.java +++ b/xchart/src/main/java/org/knowm/xchart/internal/chartpart/AxisTitle.java @@ -1,5 +1,5 @@ /** - * Copyright 2015 Knowm Inc. (http://knowm.org) and contributors. + * Copyright 2015-2016 Knowm Inc. (http://knowm.org) and contributors. * Copyright 2011-2015 Xeiam LLC (http://xeiam.com) and contributors. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -23,34 +23,30 @@ import java.awt.font.TextLayout; import java.awt.geom.AffineTransform; import java.awt.geom.Rectangle2D; +import org.knowm.xchart.Series_AxesChart; +import org.knowm.xchart.internal.Series; +import org.knowm.xchart.internal.chartpart.Axis.Direction; +import org.knowm.xchart.internal.style.StyleManagerAxesChart; + /** * AxisTitle */ -public class AxisTitle implements ChartPart { - - /** parent */ - private final Axis axis; - - /** the title text */ - private String text = ""; // default to "" +public class AxisTitle<SM extends StyleManagerAxesChart, S extends Series> implements ChartPart { - /** the bounds */ + private final Chart<StyleManagerAxesChart, Series_AxesChart> chart; private Rectangle2D bounds; + private final Direction direction; /** * Constructor * - * @param axis the axis + * @param chart the Chart + * @param direction the Direction */ - protected AxisTitle(Axis axis) { - - this.axis = axis; - } + protected AxisTitle(Chart<StyleManagerAxesChart, Series_AxesChart> chart, Direction direction) { - @Override - public Rectangle2D getBounds() { - - return bounds; + this.chart = chart; + this.direction = direction; } @Override @@ -58,21 +54,21 @@ public class AxisTitle implements ChartPart { bounds = new Rectangle2D.Double(); - g.setColor(getChartInternal().getStyleManager().getChartFontColor()); - g.setFont(getChartInternal().getStyleManager().getAxisTitleFont()); + g.setColor(chart.getStyleManager().getChartFontColor()); + g.setFont(chart.getStyleManager().getAxisTitleFont()); - if (axis.getDirection() == Axis.Direction.Y) { + if (direction == Axis.Direction.Y) { - if (text != null && !text.trim().equalsIgnoreCase("") && getChartInternal().getStyleManager().isYAxisTitleVisible()) { + if (chart.getyYAxisTitle() != null && !chart.getyYAxisTitle().trim().equalsIgnoreCase("") && chart.getStyleManager().isYAxisTitleVisible()) { FontRenderContext frc = g.getFontRenderContext(); - TextLayout nonRotatedTextLayout = new TextLayout(text, getChartInternal().getStyleManager().getAxisTitleFont(), frc); + TextLayout nonRotatedTextLayout = new TextLayout(chart.getyYAxisTitle(), chart.getStyleManager().getAxisTitleFont(), frc); Rectangle2D nonRotatedRectangle = nonRotatedTextLayout.getBounds(); // /////////////////////////////////////////////// - int xOffset = (int) (axis.getPaintZone().getX() + nonRotatedRectangle.getHeight()); - int yOffset = (int) ((axis.getPaintZone().getHeight() + nonRotatedRectangle.getWidth()) / 2.0 + axis.getPaintZone().getY()); + int xOffset = (int) (chart.getYAxis().getPaintZone().getX() + nonRotatedRectangle.getHeight()); + int yOffset = (int) ((chart.getYAxis().getPaintZone().getHeight() + nonRotatedRectangle.getWidth()) / 2.0 + chart.getYAxis().getPaintZone().getY()); AffineTransform rot = AffineTransform.getRotateInstance(-1 * Math.PI / 2, 0, 0); Shape shape = nonRotatedTextLayout.getOutline(rot); @@ -89,27 +85,27 @@ public class AxisTitle implements ChartPart { // System.out.println(nonRotatedRectangle.getHeight()); // bounds - bounds = new Rectangle2D.Double(xOffset - nonRotatedRectangle.getHeight(), yOffset - nonRotatedRectangle.getWidth(), nonRotatedRectangle.getHeight() + getChartInternal().getStyleManager() + bounds = new Rectangle2D.Double(xOffset - nonRotatedRectangle.getHeight(), yOffset - nonRotatedRectangle.getWidth(), nonRotatedRectangle.getHeight() + chart.getStyleManager() .getAxisTitlePadding(), nonRotatedRectangle.getWidth()); // g.setColor(Color.blue); // g.draw(bounds); } else { - bounds = new Rectangle2D.Double(axis.getPaintZone().getX(), axis.getPaintZone().getY(), 0, axis.getPaintZone().getHeight()); + bounds = new Rectangle2D.Double(chart.getYAxis().getPaintZone().getX(), chart.getYAxis().getPaintZone().getY(), 0, chart.getYAxis().getPaintZone().getHeight()); } } else { - if (text != null && !text.trim().equalsIgnoreCase("") && getChartInternal().getStyleManager().isXAxisTitleVisible()) { + if (chart.getXAxisTitle() != null && !chart.getXAxisTitle().trim().equalsIgnoreCase("") && chart.getStyleManager().isXAxisTitleVisible()) { FontRenderContext frc = g.getFontRenderContext(); - TextLayout textLayout = new TextLayout(text, getChartInternal().getStyleManager().getAxisTitleFont(), frc); + TextLayout textLayout = new TextLayout(chart.getXAxisTitle(), chart.getStyleManager().getAxisTitleFont(), frc); Rectangle2D rectangle = textLayout.getBounds(); // System.out.println(rectangle); - double xOffset = axis.getPaintZone().getX() + (axis.getPaintZone().getWidth() - rectangle.getWidth()) / 2.0; - double yOffset = axis.getPaintZone().getY() + axis.getPaintZone().getHeight() - rectangle.getHeight(); + double xOffset = chart.getXAxis().getPaintZone().getX() + (chart.getXAxis().getPaintZone().getWidth() - rectangle.getWidth()) / 2.0; + double yOffset = chart.getXAxis().getPaintZone().getY() + chart.getXAxis().getPaintZone().getHeight() - rectangle.getHeight(); // textLayout.draw(g, (float) xOffset, (float) (yOffset - rectangle.getY())); Shape shape = textLayout.getOutline(null); @@ -120,14 +116,14 @@ public class AxisTitle implements ChartPart { g.fill(shape); g.setTransform(orig); - bounds = new Rectangle2D.Double(xOffset, yOffset - getChartInternal().getStyleManager().getAxisTitlePadding(), rectangle.getWidth(), rectangle.getHeight() + getChartInternal().getStyleManager() - .getAxisTitlePadding()); + bounds = new Rectangle2D.Double(xOffset, yOffset - chart.getStyleManager().getAxisTitlePadding(), rectangle.getWidth(), rectangle.getHeight() + chart.getStyleManager().getAxisTitlePadding()); // g.setColor(Color.blue); // g.draw(bounds); } else { - bounds = new Rectangle2D.Double(axis.getPaintZone().getX(), axis.getPaintZone().getY() + axis.getPaintZone().getHeight(), axis.getPaintZone().getWidth(), 0); + bounds = new Rectangle2D.Double(chart.getXAxis().getPaintZone().getX(), chart.getXAxis().getPaintZone().getY() + chart.getXAxis().getPaintZone().getHeight(), chart.getXAxis().getPaintZone() + .getWidth(), 0); // g.setColor(Color.blue); // g.draw(bounds); @@ -136,20 +132,8 @@ public class AxisTitle implements ChartPart { } @Override - public ChartInternal getChartInternal() { - - return axis.getChartInternal(); - } - - // Getters ///////////////////////////////////////////////// - - public String getText() { - - return text; - } - - public void setText(String text) { + public Rectangle2D getBounds() { - this.text = text; + return bounds; } } diff --git a/xchart/src/main/java/org/knowm/xchart/internal/chartpart/Chart.java b/xchart/src/main/java/org/knowm/xchart/internal/chartpart/Chart.java new file mode 100644 index 0000000000000000000000000000000000000000..0736256dba44938ab9f04f2842103bd59f01cf06 --- /dev/null +++ b/xchart/src/main/java/org/knowm/xchart/internal/chartpart/Chart.java @@ -0,0 +1,210 @@ +/** + * Copyright 2015-2016 Knowm Inc. (http://knowm.org) and contributors. + * Copyright 2011-2015 Xeiam LLC (http://xeiam.com) and contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.knowm.xchart.internal.chartpart; + +import java.awt.Graphics2D; +import java.util.ArrayList; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; + +import org.knowm.xchart.internal.Series; +import org.knowm.xchart.internal.style.StyleManager; + +/** + * An XChart Chart + * + * @author timmolter + */ +public abstract class Chart<SM extends StyleManager, S extends Series> { + + public abstract void paint(Graphics2D g); // TODO 3.0.0 combine with ChartPart? + + public abstract void paint(Graphics2D g, int width, int height); + + protected SM styleManager; + + /** Meta Data */ + private int width; + private int height; + private String title; + private String xAxisTitle; + private String yAxisTitle; + + /** Chart Parts */ + protected ChartTitle chartTitle; + protected Legend chartLegend; + protected Plot_ plot; + protected AxisPair axisPair; + + protected Map<String, S> seriesMap = new LinkedHashMap<String, S>(); + + /** + * Constructor + * + * @param width + * @param height + * @param styleManager + */ + public Chart(int width, int height, SM styleManager) { + + this.width = width; + this.height = height; + this.styleManager = styleManager; + + this.chartTitle = new ChartTitle(this); + } + + public List<Double> getNumberListFromDoubleArray(double[] data) { + + if (data == null) { + return null; + } + + List<Double> dataNumber = null; + if (data != null) { + dataNumber = new ArrayList<Double>(); + for (double d : data) { + dataNumber.add(new Double(d)); + } + } + return dataNumber; + } + + public List<Double> getNumberListFromIntArray(int[] data) { + + if (data == null) { + return null; + } + + List<Double> dataNumber = null; + if (data != null) { + dataNumber = new ArrayList<Double>(); + for (double d : data) { + dataNumber.add(new Double(d)); + } + } + return dataNumber; + } + + public List<Double> getGeneratedData(int length) { + + List<Double> generatedData = new ArrayList<Double>(); + for (int i = 1; i < length + 1; i++) { + generatedData.add((double) i); + } + return generatedData; + } + + /** Meta Data Getters and Setters */ + public int getWidth() { + + return width; + } + + public void setWidth(int width) { + + this.width = width; + } + + public int getHeight() { + + return height; + } + + public void setHeight(int height) { + + this.height = height; + } + + public String getTitle() { + + return title; + } + + public void setTitle(String title) { + + this.title = title; + } + + public String getXAxisTitle() { + + return xAxisTitle; + } + + public void setXAxisTitle(String xAxisTitle) { + + this.xAxisTitle = xAxisTitle; + } + + public String getyYAxisTitle() { + + return yAxisTitle; + } + + public void setYAxisTitle(String yAxisTitle) { + + this.yAxisTitle = yAxisTitle; + } + + /** Chart Parts Getters */ + + protected ChartTitle getChartTitle() { + + return chartTitle; + } + + protected Legend getChartLegend() { + + return chartLegend; + } + + protected Plot_ getPlot() { + + return plot; + } + + protected Axis getXAxis() { + + return axisPair.getXAxis(); + } + + protected Axis getYAxis() { + + return axisPair.getYAxis(); + } + + public AxisPair getAxisPair() { + + return axisPair; + } + + public Map<String, S> getSeriesMap() { + + return seriesMap; + } + + /** + * Gets the Chart's style manager, which can be used to customize the Chart's appearance + * + * @return the style manager + */ + public SM getStyleManager() { + + return styleManager; + } +} diff --git a/xchart/src/main/java/org/knowm/xchart/internal/chartpart/ChartInternal.java b/xchart/src/main/java/org/knowm/xchart/internal/chartpart/ChartInternal.java deleted file mode 100644 index c3780597a7f387833253cca1b3a299cb8edcecbc..0000000000000000000000000000000000000000 --- a/xchart/src/main/java/org/knowm/xchart/internal/chartpart/ChartInternal.java +++ /dev/null @@ -1,435 +0,0 @@ -/** - * Copyright 2015 Knowm Inc. (http://knowm.org) and contributors. - * Copyright 2011-2015 Xeiam LLC (http://xeiam.com) and contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.knowm.xchart.internal.chartpart; - -import java.awt.Graphics2D; -import java.awt.RenderingHints; -import java.awt.Shape; -import java.awt.geom.Rectangle2D; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Date; -import java.util.Iterator; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; - -import org.knowm.xchart.Series; -import org.knowm.xchart.StyleManager; -import org.knowm.xchart.internal.chartpart.Axis.AxisType; - -/** - * @author timmolter - */ -public class ChartInternal { - - private int width; - private int height; - - protected enum ChartInternalType { - - XY, Category, Pie - } - - private ChartInternalType chartInternalType = null; - - private Map<String, Series> seriesMap = new LinkedHashMap<String, Series>(); - - private final StyleManager styleManager; - - // Chart Parts - private Legend chartLegend; - private AxisPair axisPair; - private Plot plot; - private ChartTitle chartTitle; - - /** - * Constructor - * - * @param width - * @param height - */ - public ChartInternal(int width, int height) { - - this.width = width; - this.height = height; - - styleManager = new StyleManager(); - - chartLegend = new Legend(this); - axisPair = new AxisPair(this); - plot = new Plot(this); - chartTitle = new ChartTitle(this); - } - - /** - * @param seriesName - * @param xData - * @param yData - * @param errorBars - * @return Series - */ - public Series addSeries(String seriesName, List<?> xData, List<? extends Number> yData, List<? extends Number> errorBars) { - - if (chartInternalType != null && chartInternalType != ChartInternalType.XY) { - throw new IllegalArgumentException("Cannot mix x-y, category and/or pie series types! Don't call addSeries() and/or addCategorySeries() and/or addPieSeries() for the same chart!"); - } - chartInternalType = ChartInternalType.XY; - - // Sanity checks - sanityCheck(seriesName, xData, yData, errorBars); - - Series series = null; - if (xData != null) { - - // Sanity check - if (xData.size() != yData.size()) { - throw new IllegalArgumentException("X and Y-Axis sizes are not the same!!!"); - } - - // inspect the series to see what kind of data it contains (Number, Date) - AxisType axisType = setXAxisType(xData); - if (!(axisType == AxisType.Number || axisType == AxisType.Date)) { - throw new IllegalArgumentException("X-Axis data must be of type Number or Date for X-Y chart types!!!"); - } - - axisPair.getYAxis().setAxisType(AxisType.Number); - series = new Series(seriesName, xData, axisPair.getXAxis().getAxisType(), yData, axisPair.getYAxis().getAxisType(), errorBars, styleManager.getSeriesColorMarkerLineStyleCycler() - .getNextSeriesColorMarkerLineStyle()); - } - else { // generate xData - List<Double> generatedXData = new ArrayList<Double>(); - for (int i = 1; i < yData.size() + 1; i++) { - generatedXData.add((double) i); - } - axisPair.getXAxis().setAxisType(AxisType.Number); - axisPair.getYAxis().setAxisType(AxisType.Number); - series = new Series(seriesName, generatedXData, axisPair.getXAxis().getAxisType(), yData, axisPair.getYAxis().getAxisType(), errorBars, styleManager.getSeriesColorMarkerLineStyleCycler() - .getNextSeriesColorMarkerLineStyle()); - } - - // set series type - setSeriesType(series); - - if (seriesMap.keySet().contains(seriesName)) { - throw new IllegalArgumentException("Series name >" + seriesName + "< has already been used. Use unique names for each series!!!"); - } - - seriesMap.put(seriesName, series); - - return series; - } - - /** - * @param seriesName - * @param xData - * @param yData - * @param errorBars - * @return Series - */ - public Series addCategorySeries(String seriesName, List<?> xData, List<? extends Number> yData, List<? extends Number> errorBars) { - - if (chartInternalType != null && chartInternalType != ChartInternalType.Category) { - throw new IllegalArgumentException("Cannot mix x-y, category and/or pie series types! Don't call addSeries() and/or addCategorySeries() and/or addPieSeries() for the same chart!"); - } - chartInternalType = ChartInternalType.Category; - - // Sanity checks - sanityCheck(seriesName, xData, yData, errorBars); - if (xData == null) { - throw new IllegalArgumentException("Y-Axis data cannot be null!!!"); - } - if (xData.size() != yData.size()) { - throw new IllegalArgumentException("X and Y-Axis sizes are not the same!!!"); - } - // verify all series have exactly the same xAxis - if (seriesMap.size() > 0) { // there was already a series added - if (!seriesMap.entrySet().iterator().next().getValue().getXData().equals(xData)) { - throw new IllegalArgumentException("X-Axis data must exactly match all other Series X-Axis data for Category Charts!!"); - } - } - - // inspect the series to see what kind of data it contains (Number, Date, String) - setXAxisType(xData); - - axisPair.getYAxis().setAxisType(AxisType.Number); - Series series = new Series(seriesName, xData, axisPair.getXAxis().getAxisType(), yData, axisPair.getYAxis().getAxisType(), errorBars, styleManager.getSeriesColorMarkerLineStyleCycler() - .getNextSeriesColorMarkerLineStyle()); - - // set series type - setSeriesType(series); - - if (seriesMap.keySet().contains(seriesName)) { - throw new IllegalArgumentException("Series name >" + seriesName + "< has already been used. Use unique names for each series!!!"); - } - seriesMap.put(seriesName, series); - - return series; - } - - public Series addPieSeries(String sliceName, Number value) { - - if (chartInternalType != null && chartInternalType != ChartInternalType.Pie) { - throw new IllegalArgumentException("Cannot mix x-y, category and/or pie series types! Don't call addSeries() and/or addCategorySeries() and/or addPieSeries() for the same chart!"); - } - chartInternalType = ChartInternalType.Pie; - - axisPair.getXAxis().setAxisType(AxisType.String); - - axisPair.getYAxis().setAxisType(AxisType.Number); - Series series = new Series(sliceName, Arrays.asList(new String[] { sliceName }), axisPair.getXAxis().getAxisType(), Arrays.asList(new Number[] { value }), axisPair.getYAxis().getAxisType(), null, - styleManager.getSeriesColorMarkerLineStyleCycler().getNextSeriesColorMarkerLineStyle()); - - // set series type - setSeriesType(series); - - if (seriesMap.keySet().contains(sliceName)) { - throw new IllegalArgumentException("Series name >" + sliceName + "< has already been used. Use unique names for each series!!!"); - } - seriesMap.put(sliceName, series); - - return series; - } - - private void sanityCheck(String seriesName, List<?> xData, List<? extends Number> yData, List<? extends Number> errorBars) { - - if (seriesName == null) { - throw new IllegalArgumentException("Series Name cannot be null!!!"); - } - if (yData == null) { - throw new IllegalArgumentException("Y-Axis data cannot be null!!!"); - } - if (yData.size() == 0) { - throw new IllegalArgumentException("Y-Axis data cannot be empty!!!"); - } - if (xData != null && xData.size() == 0) { - throw new IllegalArgumentException("X-Axis data cannot be empty!!!"); - } - if (errorBars != null && errorBars.size() != yData.size()) { - throw new IllegalArgumentException("errorbars and Y-Axis sizes are not the same!!!"); - } - - } - - /** - * Sets the axis type based on the data contained in the xData argument - * - * @param xData - * @return - */ - private AxisType setXAxisType(List<?> xData) { - - AxisType axisType; - - Iterator<?> itr = xData.iterator(); - Object dataPoint = itr.next(); - if (dataPoint instanceof Number) { - axisType = AxisType.Number; - axisPair.getXAxis().setAxisType(axisType); - } - else if (dataPoint instanceof Date) { - axisType = AxisType.Date; - axisPair.getXAxis().setAxisType(axisType); - } - else if (dataPoint instanceof String) { - axisType = AxisType.String; - axisPair.getXAxis().setAxisType(axisType); - } - else { - throw new IllegalArgumentException("Series data must be either Number, Date or String type!!!"); - } - return axisType; - } - - /** - * set series type based on chart type, but only if it's not explicitly set on the series yet. - * - * @param series - */ - private void setSeriesType(Series series) { - - switch (getStyleManager().getChartType()) { - case Line: - if (series.getSeriesType() == null) { - series.setSeriesType(Series.SeriesType.Line); - } - break; - case Area: - if (series.getSeriesType() == null) { - series.setSeriesType(Series.SeriesType.Area); - } - break; - case Scatter: - if (series.getSeriesType() == null) { - series.setSeriesType(Series.SeriesType.Scatter); - } - break; - case Bar: - if (series.getSeriesType() == null) { - series.setSeriesType(Series.SeriesType.Bar); - } - break; - case Pie: - if (series.getSeriesType() == null) { - series.setSeriesType(Series.SeriesType.Pie); - } - break; - default: - if (series.getSeriesType() == null) { - series.setSeriesType(Series.SeriesType.Line); - } - break; - } - } - - /** - * @param g - * @param width - * @param height - */ - public void paint(Graphics2D g, int width, int height) { - - this.width = width; - this.height = height; - paint(g); - } - - /** - * @param g - */ - public void paint(Graphics2D g) { - - // Sanity checks - if (getSeriesMap().isEmpty()) { - throw new RuntimeException("No series defined for Chart!!!"); - } - - // calc axis min and max - axisPair.getXAxis().resetMinMax(); - axisPair.getYAxis().resetMinMax(); - for (Series series : getSeriesMap().values()) { - // add min/max to axes - // System.out.println(series.getxMin()); - // System.out.println(series.getxMax()); - // System.out.println(series.getyMin()); - // System.out.println(series.getyMax()); - // System.out.println("****"); - axisPair.getXAxis().addMinMax(series.getXMin(), series.getXMax()); - axisPair.getYAxis().addMinMax(series.getYMin(), series.getYMax()); - } - - axisPair.getXAxis().overrideMinMax(); - axisPair.getYAxis().overrideMinMax(); - - // logarithmic - - if (getStyleManager().isXAxisLogarithmic() && axisPair.getXAxis().getMin() <= 0.0) { - throw new IllegalArgumentException("Series data (accounting for error bars too) cannot be less or equal to zero for a logarithmic X-Axis!!!"); - } - if (getStyleManager().isYAxisLogarithmic() && axisPair.getYAxis().getMin() <= 0.0) { - // System.out.println(axisPair.getyAxis().getMin()); - throw new IllegalArgumentException("Series data (accounting for error bars too) cannot be less or equal to zero for a logarithmic Y-Axis!!!"); - } - - // paint chart main background - g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); // global rendering hint - g.setColor(styleManager.getChartBackgroundColor()); - Shape rect = new Rectangle2D.Double(0, 0, width, height); - g.fill(rect); - - // now that we added all the series, we can calculate the legend size - chartLegend.determineLegendBoxSize(); - - axisPair.paint(g); - plot.paint(g); - chartTitle.paint(g); - chartLegend.paint(g); - - g.dispose(); - } - - /** - * for internal usage - * - * @return - */ - public ChartTitle getChartTitle() { - - return chartTitle; - } - - /** - * for internal usage - * - * @return - */ - protected Legend getChartLegend() { - - return chartLegend; - } - - /** - * for internal usage - * - * @return - */ - public AxisPair getAxisPair() { - - return axisPair; - } - - /** - * for internal usage - * - * @return - */ - protected Plot getPlot() { - - return plot; - } - - public ChartInternalType getChartInternalType() { - - return chartInternalType; - } - - public int getWidth() { - - return width; - } - - public int getHeight() { - - return height; - } - - public Map<String, Series> getSeriesMap() { - - return seriesMap; - } - - /** - * Gets the Chart's style manager, which can be used to customize the Chart's appearance - * - * @return the style manager - */ - public StyleManager getStyleManager() { - - return styleManager; - } - -} diff --git a/xchart/src/main/java/org/knowm/xchart/internal/chartpart/ChartPart.java b/xchart/src/main/java/org/knowm/xchart/internal/chartpart/ChartPart.java index 6cba8ff526accffbc761be8ecfc538fdcfc1d2a5..fb251d4ec1ce294bdd5c8edb4b19c94d4b268334 100644 --- a/xchart/src/main/java/org/knowm/xchart/internal/chartpart/ChartPart.java +++ b/xchart/src/main/java/org/knowm/xchart/internal/chartpart/ChartPart.java @@ -1,5 +1,5 @@ /** - * Copyright 2015 Knowm Inc. (http://knowm.org) and contributors. + * Copyright 2015-2016 Knowm Inc. (http://knowm.org) and contributors. * Copyright 2011-2015 Xeiam LLC (http://xeiam.com) and contributors. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -21,7 +21,7 @@ import java.awt.geom.Rectangle2D; /** * All components of a chart that need to be painted should implement this interface - * + * * @author timmolter */ public interface ChartPart { @@ -30,6 +30,4 @@ public interface ChartPart { public void paint(final Graphics2D g); - public ChartInternal getChartInternal(); - } diff --git a/xchart/src/main/java/org/knowm/xchart/internal/chartpart/ChartTitle.java b/xchart/src/main/java/org/knowm/xchart/internal/chartpart/ChartTitle.java index 4bfe55aa91a66a525586034c2fce091f94ffdaf4..5772a09c4418784a2b6104e231b1dec9bc1dc300 100644 --- a/xchart/src/main/java/org/knowm/xchart/internal/chartpart/ChartTitle.java +++ b/xchart/src/main/java/org/knowm/xchart/internal/chartpart/ChartTitle.java @@ -1,5 +1,5 @@ /** - * Copyright 2015 Knowm Inc. (http://knowm.org) and contributors. + * Copyright 2015-2016 Knowm Inc. (http://knowm.org) and contributors. * Copyright 2011-2015 Xeiam LLC (http://xeiam.com) and contributors. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -29,39 +29,70 @@ import java.awt.geom.Rectangle2D; */ public class ChartTitle implements ChartPart { - /** parent */ - private final ChartInternal chartInternal; - - /** the title text */ - private String text = ""; // default to "" - - /** the bounds */ + private final Chart<?, ?> chart; private Rectangle2D bounds; /** * Constructor * - * @param chartInternal + * @param chart */ - public ChartTitle(ChartInternal chartInternal) { + public ChartTitle(Chart<?, ?> chart) { - this.chartInternal = chartInternal; + this.chart = chart; } - /** - * set the chart title's text - * - * @param text - */ - public void setText(String text) { + @Override + public void paint(Graphics2D g) { - if (text.trim().equalsIgnoreCase("")) { - chartInternal.getStyleManager().setChartTitleVisible(false); + g.setFont(chart.getStyleManager().getChartTitleFont()); + + if (!chart.getStyleManager().isChartTitleVisible() || chart.getTitle().length() == 0) { + return; } - else { - chartInternal.getStyleManager().setChartTitleVisible(true); + + // create rectangle first for sizing + FontRenderContext frc = g.getFontRenderContext(); + TextLayout textLayout = new TextLayout(chart.getTitle(), chart.getStyleManager().getChartTitleFont(), frc); + Rectangle2D textBounds = textLayout.getBounds(); + + double xOffset = chart.getPlot().getBounds().getX(); // of plot left edge + double yOffset = chart.getStyleManager().getChartPadding(); + + // title box + if (chart.getStyleManager().isChartTitleBoxVisible()) { + + // paint the chart title box + double chartTitleBoxWidth = chart.getPlot().getBounds().getWidth(); + double chartTitleBoxHeight = textBounds.getHeight() + 2 * chart.getStyleManager().getChartTitlePadding(); + + g.setStroke(new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL)); + Shape rect = new Rectangle2D.Double(xOffset, yOffset, chartTitleBoxWidth, chartTitleBoxHeight); + g.setColor(chart.getStyleManager().getChartTitleBoxBackgroundColor()); + g.fill(rect); + g.setColor(chart.getStyleManager().getChartTitleBoxBorderColor()); + g.draw(rect); } - this.text = text; + + // paint title + xOffset = chart.getPlot().getBounds().getX() + (chart.getPlot().getBounds().getWidth() - textBounds.getWidth()) / 2.0; + yOffset = chart.getStyleManager().getChartPadding() - textBounds.getY() + chart.getStyleManager().getChartTitlePadding(); + + bounds = new Rectangle2D.Double(xOffset, yOffset + textBounds.getY(), textBounds.getWidth(), textBounds.getHeight()); + // g.setColor(Color.green); + // g.draw(bounds); + + g.setColor(chart.getStyleManager().getChartFontColor()); + // textLayout.draw(g, xOffset, yOffset); + + Shape shape = textLayout.getOutline(null); + AffineTransform orig = g.getTransform(); + AffineTransform at = new AffineTransform(); + at.translate(xOffset, yOffset); + g.transform(at); + g.fill(shape); + g.setTransform(orig); + } /** @@ -69,81 +100,30 @@ public class ChartTitle implements ChartPart { * * @return */ - protected int getSizeHint() { + private Rectangle2D getBoundsHint() { - if (chartInternal.getStyleManager().isChartTitleVisible()) { + if (chart.getStyleManager().isChartTitleVisible() && chart.getTitle().length() > 0) { - TextLayout textLayout = new TextLayout(text, chartInternal.getStyleManager().getChartTitleFont(), new FontRenderContext(null, true, false)); + TextLayout textLayout = new TextLayout(chart.getTitle(), chart.getStyleManager().getChartTitleFont(), new FontRenderContext(null, true, false)); Rectangle2D rectangle = textLayout.getBounds(); - int titleHeight = (int) ((chartInternal.getStyleManager().isChartTitleVisible() ? rectangle.getHeight() : 0)); - return chartInternal.getStyleManager().getChartPadding() + 2 * chartInternal.getStyleManager().getChartTitlePadding() + titleHeight; + double width = 2 * chart.getStyleManager().getChartTitlePadding() + rectangle.getWidth(); + double height = 2 * chart.getStyleManager().getChartTitlePadding() + rectangle.getHeight(); + return new Rectangle2D.Double(Double.NaN, Double.NaN, width, height); // Double.NaN indicates not sure yet. + } else { - // TODO make this zero - return chartInternal.getStyleManager().getChartPadding(); - } - } - - @Override - public void paint(Graphics2D g) { - - g.setFont(chartInternal.getStyleManager().getChartTitleFont()); - - if (chartInternal.getStyleManager().isChartTitleVisible()) { - - // create rectangle first for sizing - FontRenderContext frc = g.getFontRenderContext(); - TextLayout textLayout = new TextLayout(text, chartInternal.getStyleManager().getChartTitleFont(), frc); - Rectangle2D rectangle = textLayout.getBounds(); - - double xOffset = (int) chartInternal.getPlot().getBounds().getX(); - double yOffset = chartInternal.getStyleManager().getChartPadding(); - - if (chartInternal.getStyleManager().isChartTitleBoxVisible()) { - - // paint the chart title box - double chartTitleBoxWidth = chartInternal.getPlot().getBounds().getWidth(); - double chartTitleBoxHeight = rectangle.getHeight() + 2 * chartInternal.getStyleManager().getChartTitlePadding(); - - g.setStroke(new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL)); - Shape rect = new Rectangle2D.Double(xOffset, yOffset, chartTitleBoxWidth, chartTitleBoxHeight); - g.setColor(chartInternal.getStyleManager().getChartTitleBoxBackgroundColor()); - g.fill(rect); - g.setColor(chartInternal.getStyleManager().getChartTitleBoxBorderColor()); - g.draw(rect); - } - - // paint title - xOffset = chartInternal.getPlot().getBounds().getX() + (chartInternal.getPlot().getBounds().getWidth() - rectangle.getWidth()) / 2.0; - yOffset = chartInternal.getStyleManager().getChartPadding() - rectangle.getY() + chartInternal.getStyleManager().getChartTitlePadding(); - - bounds = new Rectangle2D.Double(xOffset, yOffset + rectangle.getY(), rectangle.getWidth(), rectangle.getHeight()); - // g.setColor(Color.green); - // g.draw(bounds); - - g.setColor(chartInternal.getStyleManager().getChartFontColor()); - // textLayout.draw(g, xOffset, yOffset); - - Shape shape = textLayout.getOutline(null); - AffineTransform orig = g.getTransform(); - AffineTransform at = new AffineTransform(); - at.translate(xOffset, yOffset); - g.transform(at); - g.fill(shape); - g.setTransform(orig); + // TODO make this zero, need to account for null bounds then when laying out plot + // return chart.getStyleManager().getChartPadding(); + return new Rectangle2D.Double(); // Constructs a new Rectangle2D, initialized to location (0, 0) and size (0, 0). } - } @Override public Rectangle2D getBounds() { - return null; // this should never be needed - } - - @Override - public ChartInternal getChartInternal() { - - return chartInternal; + if (bounds == null) { // was not drawn fully yet, just need the height hint. The Plot object will be asking for it. + bounds = getBoundsHint(); + } + return bounds; } } \ No newline at end of file diff --git a/xchart/src/main/java/org/knowm/xchart/internal/chartpart/Legend.java b/xchart/src/main/java/org/knowm/xchart/internal/chartpart/Legend.java index 80ef017a98c7c9668cd2ce65afee0c5671c41f62..e5310d1ed79b00959b1e4a12308d977c568d2202 100644 --- a/xchart/src/main/java/org/knowm/xchart/internal/chartpart/Legend.java +++ b/xchart/src/main/java/org/knowm/xchart/internal/chartpart/Legend.java @@ -1,5 +1,5 @@ /** - * Copyright 2015 Knowm Inc. (http://knowm.org) and contributors. + * Copyright 2015-2016 Knowm Inc. (http://knowm.org) and contributors. * Copyright 2011-2015 Xeiam LLC (http://xeiam.com) and contributors. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -16,289 +16,127 @@ */ package org.knowm.xchart.internal.chartpart; -import java.awt.BasicStroke; import java.awt.Graphics2D; import java.awt.Shape; import java.awt.font.FontRenderContext; import java.awt.font.TextLayout; -import java.awt.geom.AffineTransform; -import java.awt.geom.Line2D; import java.awt.geom.Rectangle2D; import java.util.LinkedHashMap; import java.util.Map; -import org.knowm.xchart.Series; +import org.knowm.xchart.internal.Series; +import org.knowm.xchart.internal.chartpart.RenderableSeries.LegendRenderType; +import org.knowm.xchart.internal.style.StyleManager; /** * @author timmolter */ -public class Legend implements ChartPart { +public abstract class Legend<SM extends StyleManager, S extends Series> implements ChartPart { - private static final int LEGEND_MARGIN = 6; - private static final int BOX_SIZE = 20; - private static final int MULTI_LINE_SPACE = 3; + public abstract double getSeriesLegendRenderGraphicHeight(Series series); - private double legendBoxWidth = 0.0; - private double legendBoxHeight = 0.0; + protected static final int LEGEND_MARGIN = 6; + protected static final int BOX_SIZE = 20; + protected static final int MULTI_LINE_SPACE = 3; - /** - * parent - */ - private final ChartInternal chartInternal; + protected Rectangle2D bounds = null; - /** - * the bounds - */ - private Rectangle2D bounds; + protected Chart<SM, S> chart; /** * Constructor * - * @param chartInternal - */ - public Legend(ChartInternal chartInternal) { - - this.chartInternal = chartInternal; - } - - /** - * determine the width and height of the chart legend + * @param chart */ - public void determineLegendBoxSize() { - - if (!chartInternal.getStyleManager().isLegendVisible()) { - return; - } - - boolean containsBarOrPie = false; - - // determine legend text content max width - double legendTextContentMaxWidth = 0; - - // determine legend content height - double legendContentHeight = 0; - - for (Series series : chartInternal.getSeriesMap().values()) { + public Legend(Chart<SM, S> chart) { - Map<String, Rectangle2D> seriesBounds = getSeriesTextBounds(series); + this.chart = chart; - double blockHeight = 0; - for (Map.Entry<String, Rectangle2D> entry : seriesBounds.entrySet()) { - blockHeight += entry.getValue().getHeight() + MULTI_LINE_SPACE; - legendTextContentMaxWidth = Math.max(legendTextContentMaxWidth, entry.getValue().getWidth()); - } - - blockHeight -= MULTI_LINE_SPACE; - blockHeight = Math.max(blockHeight, (series.getSeriesType() == Series.SeriesType.Bar || series.getSeriesType() == Series.SeriesType.Pie) ? BOX_SIZE : getChartInternal().getStyleManager() - .getMarkerSize()); - - legendContentHeight += blockHeight + getChartInternal().getStyleManager().getLegendPadding(); - - if (series.getSeriesType() == Series.SeriesType.Bar || series.getSeriesType() == Series.SeriesType.Pie) { - containsBarOrPie = true; - } - } - - // determine legend content width - double legendContentWidth = 0; - if (!containsBarOrPie) { - legendContentWidth = getChartInternal().getStyleManager().getLegendSeriesLineLength() + getChartInternal().getStyleManager().getLegendPadding() + legendTextContentMaxWidth; - } - else { - legendContentWidth = BOX_SIZE + getChartInternal().getStyleManager().getLegendPadding() + legendTextContentMaxWidth; - } - - // Legend Box - legendBoxWidth = legendContentWidth + 2 * getChartInternal().getStyleManager().getLegendPadding(); - legendBoxHeight = legendContentHeight + 1 * getChartInternal().getStyleManager().getLegendPadding(); } @Override public void paint(Graphics2D g) { - if (!getChartInternal().getStyleManager().isLegendVisible()) { + if (!chart.getStyleManager().isLegendVisible()) { return; } // if the area to draw a chart on is so small, don't even bother - if (chartInternal.getPlot().getBounds().getWidth() < 30) { + if (chart.getPlot().getBounds().getWidth() < 30) { return; } - bounds = new Rectangle2D.Double(); - // g.setFont(chartInternal.getStyleManager().getLegendFont()); - - // legend draw position - double xOffset = 0; - double yOffset = 0; - switch (getChartInternal().getStyleManager().getLegendPosition()) { - case OutsideE: - xOffset = chartInternal.getWidth() - legendBoxWidth - getChartInternal().getStyleManager().getChartPadding(); - yOffset = chartInternal.getPlot().getBounds().getY() + (chartInternal.getPlot().getBounds().getHeight() - legendBoxHeight) / 2.0; - break; - case InsideNW: - xOffset = chartInternal.getPlot().getBounds().getX() + LEGEND_MARGIN; - yOffset = chartInternal.getPlot().getBounds().getY() + LEGEND_MARGIN; - break; - case InsideNE: - xOffset = chartInternal.getPlot().getBounds().getX() + chartInternal.getPlot().getBounds().getWidth() - legendBoxWidth - LEGEND_MARGIN; - yOffset = chartInternal.getPlot().getBounds().getY() + LEGEND_MARGIN; - break; - case InsideSE: - xOffset = chartInternal.getPlot().getBounds().getX() + chartInternal.getPlot().getBounds().getWidth() - legendBoxWidth - LEGEND_MARGIN; - yOffset = chartInternal.getPlot().getBounds().getY() + chartInternal.getPlot().getBounds().getHeight() - legendBoxHeight - LEGEND_MARGIN; - break; - case InsideSW: - xOffset = chartInternal.getPlot().getBounds().getX() + LEGEND_MARGIN; - yOffset = chartInternal.getPlot().getBounds().getY() + chartInternal.getPlot().getBounds().getHeight() - legendBoxHeight - LEGEND_MARGIN; - break; - case InsideN: - xOffset = chartInternal.getPlot().getBounds().getX() + (chartInternal.getPlot().getBounds().getWidth() - legendBoxWidth) / 2 + LEGEND_MARGIN; - yOffset = chartInternal.getPlot().getBounds().getY() + LEGEND_MARGIN; - break; - - default: - break; + // We call get bounds hint because sometimes the Axis object needs it to know it's bounds (if Legend is outside Plot). If it's null, we just need to calulate it before painting, because the paint + // methods needs the bounds. + if (bounds == null) { // No other part asked for the bounds yet. Probably because it's an "inside" legend location + bounds = getBoundsHint(); // Actually, the only information contained in thsi bounds is the width and height. + } + } + + /** + * determine the width and height of the chart legend + */ + public Rectangle2D getBoundsHint() { + + if (!chart.getStyleManager().isLegendVisible()) { + return new Rectangle2D.Double(); // Constructs a new Rectangle2D, initialized to location (0, 0) and size (0, 0). } - g.setStroke(new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 10.0f, new float[] { 3.0f, 0.0f }, 0.0f)); + boolean containsBox = false; - Shape rect = new Rectangle2D.Double(xOffset + 1, yOffset + 1, legendBoxWidth - 2, legendBoxHeight - 2); - g.setColor(getChartInternal().getStyleManager().getLegendBackgroundColor()); - g.fill(rect); - g.setColor(getChartInternal().getStyleManager().getLegendBorderColor()); - g.draw(rect); + // determine legend text content max width + double legendTextContentMaxWidth = 0; - // Draw legend content inside legend box - double startx = xOffset + getChartInternal().getStyleManager().getLegendPadding(); - double starty = yOffset + getChartInternal().getStyleManager().getLegendPadding(); + // determine total legend content height + double legendContentHeight = 0; - for (Series series : chartInternal.getSeriesMap().values()) { + // TODO 3.0.0 figure out this warning. + Map<String, S> map = chart.getSeriesMap(); + for (Series series : map.values()) { Map<String, Rectangle2D> seriesTextBounds = getSeriesTextBounds(series); - float blockHeight = 0; - double legendTextContentMaxWidth = 0; + double legendEntryHeight = 0; // could be multi-line for (Map.Entry<String, Rectangle2D> entry : seriesTextBounds.entrySet()) { - blockHeight += entry.getValue().getHeight() + MULTI_LINE_SPACE; + legendEntryHeight += entry.getValue().getHeight() + MULTI_LINE_SPACE; legendTextContentMaxWidth = Math.max(legendTextContentMaxWidth, entry.getValue().getWidth()); } - blockHeight -= MULTI_LINE_SPACE; - - blockHeight = Math.max(blockHeight, (series.getSeriesType() == Series.SeriesType.Bar || series.getSeriesType() == Series.SeriesType.Pie) ? BOX_SIZE : getChartInternal().getStyleManager() - .getMarkerSize()); - - if (series.getSeriesType() != Series.SeriesType.Bar && series.getSeriesType() != Series.SeriesType.Pie) { - - // paint line - if (series.getSeriesType() != Series.SeriesType.Scatter && series.getStroke() != null) { - g.setColor(series.getStrokeColor()); - g.setStroke(series.getStroke()); - Shape line = new Line2D.Double(startx, starty + blockHeight / 2.0, startx + getChartInternal().getStyleManager().getLegendSeriesLineLength(), starty + blockHeight / 2.0); - g.draw(line); - } - - // // debug box - // Rectangle2D boundsTemp = new Rectangle2D.Double(startx, starty, styleManager.getLegendSeriesLineLength(), blockHeight); - // g.setStroke(new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL)); - // g.setColor(Color.red); - // g.draw(boundsTemp); - - // paint marker - if (series.getMarker() != null) { - g.setColor(series.getMarkerColor()); - series.getMarker().paint(g, startx + getChartInternal().getStyleManager().getLegendSeriesLineLength() / 2.0, starty + blockHeight / 2.0, getChartInternal().getStyleManager() - .getMarkerSize()); - - } - } - else { // bar/pie type series - - // paint little box - if (series.getStroke() != null) { - g.setColor(series.getStrokeColor()); - Shape rectSmall = new Rectangle2D.Double(startx, starty, BOX_SIZE, BOX_SIZE); - g.fill(rectSmall); - } - // // debug box - // Rectangle2D boundsTemp = new Rectangle2D.Double(startx, starty, BOX_SIZE, BOX_SIZE); - // g.setStroke(new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL)); - // g.setColor(Color.red); - // g.draw(boundsTemp); - } - - // paint series text ///////////////////////////////////////////////////// - g.setColor(chartInternal.getStyleManager().getChartFontColor()); - - double multiLineOffset = 0.0; - if (series.getSeriesType() != Series.SeriesType.Bar && series.getSeriesType() != Series.SeriesType.Pie) { + legendEntryHeight -= MULTI_LINE_SPACE; // subtract away the bottom MULTI_LINE_SPACE + legendEntryHeight = Math.max(legendEntryHeight, (getSeriesLegendRenderGraphicHeight(series))); - double x = startx + getChartInternal().getStyleManager().getLegendSeriesLineLength() + getChartInternal().getStyleManager().getLegendPadding(); - for (Map.Entry<String, Rectangle2D> entry : seriesTextBounds.entrySet()) { + legendContentHeight += legendEntryHeight + chart.getStyleManager().getLegendPadding(); - double height = entry.getValue().getHeight(); - double centerOffsetY = (Math.max(getChartInternal().getStyleManager().getMarkerSize(), height) - height) / 2.0; - - FontRenderContext frc = g.getFontRenderContext(); - TextLayout tl = new TextLayout(entry.getKey(), getChartInternal().getStyleManager().getLegendFont(), frc); - Shape shape = tl.getOutline(null); - AffineTransform orig = g.getTransform(); - AffineTransform at = new AffineTransform(); - at.translate(x, starty + height + centerOffsetY + multiLineOffset); - g.transform(at); - g.fill(shape); - g.setTransform(orig); - - // // debug box - // Rectangle2D boundsTemp = new Rectangle2D.Double(x, starty + centerOffsetY + multiLineOffset, entry.getValue().getWidth(), height); - // g.setColor(Color.blue); - // g.draw(boundsTemp); - - multiLineOffset += height + MULTI_LINE_SPACE; - } - - starty += blockHeight + getChartInternal().getStyleManager().getLegendPadding(); - } - else { // bar/pie type series - - final double x = startx + BOX_SIZE + getChartInternal().getStyleManager().getLegendPadding(); - for (Map.Entry<String, Rectangle2D> entry : seriesTextBounds.entrySet()) { - - double height = entry.getValue().getHeight(); - double centerOffsetY = (Math.max(BOX_SIZE, height) - height) / 2.0; - - FontRenderContext frc = g.getFontRenderContext(); - TextLayout tl = new TextLayout(entry.getKey(), getChartInternal().getStyleManager().getLegendFont(), frc); - Shape shape = tl.getOutline(null); - AffineTransform orig = g.getTransform(); - AffineTransform at = new AffineTransform(); - at.translate(x, starty + height + centerOffsetY + multiLineOffset); - g.transform(at); - g.fill(shape); - g.setTransform(orig); - - // // debug box - // Rectangle2D boundsTemp = new Rectangle2D.Double(x, starty + centerOffsetY, entry.getValue().getWidth(), height); - // g.setColor(Color.blue); - // g.draw(boundsTemp); - multiLineOffset += height + MULTI_LINE_SPACE; - - } - starty += blockHeight + getChartInternal().getStyleManager().getLegendPadding(); + if (series.getLegendRenderType() == LegendRenderType.Box) { + containsBox = true; } - } - // bounds - bounds = new Rectangle2D.Double(xOffset, yOffset, legendBoxWidth, legendBoxHeight); + // determine legend content width + double legendContentWidth = 0; + if (!containsBox) { + legendContentWidth = chart.getStyleManager().getLegendSeriesLineLength() + chart.getStyleManager().getLegendPadding() + legendTextContentMaxWidth; + } + else { + legendContentWidth = BOX_SIZE + chart.getStyleManager().getLegendPadding() + legendTextContentMaxWidth; + } - // g.setColor(Color.blue); - // g.draw(bounds); + // Legend Box + double width = legendContentWidth + 2 * chart.getStyleManager().getLegendPadding(); + double height = legendContentHeight + 1 * chart.getStyleManager().getLegendPadding(); + return new Rectangle2D.Double(Double.NaN, Double.NaN, width, height); // Double.NaN indicates not sure yet. } - private Map<String, Rectangle2D> getSeriesTextBounds(Series series) { + // TODO possibly cache the first hint result, so as to not re-calculate this. + /** + * Normally each legend entry just has one line of text, but it can be made multi-line by adding "\\n". This method returns a Map for each single legend entry, which is normally just a Map with one + * single entry. + * + * @param series + * @return + */ + protected Map<String, Rectangle2D> getSeriesTextBounds(Series series) { // FontMetrics fontMetrics = g.getFontMetrics(getChartPainter().getStyleManager().getLegendFont()); // float fontDescent = fontMetrics.getDescent(); @@ -306,8 +144,8 @@ public class Legend implements ChartPart { String lines[] = series.getName().split("\\n"); Map<String, Rectangle2D> seriesTextBounds = new LinkedHashMap<String, Rectangle2D>(lines.length); for (String line : lines) { - TextLayout tl = new TextLayout(line, getChartInternal().getStyleManager().getLegendFont(), new FontRenderContext(null, true, false)); - Shape shape = tl.getOutline(null); + TextLayout textLayout = new TextLayout(line, chart.getStyleManager().getLegendFont(), new FontRenderContext(null, true, false)); + Shape shape = textLayout.getOutline(null); Rectangle2D bounds = shape.getBounds2D(); // System.out.println(tl.getAscent()); // System.out.println(tl.getDescent()); @@ -319,26 +157,4 @@ public class Legend implements ChartPart { return seriesTextBounds; } - public double getLegendBoxWidth() { - - return legendBoxWidth; - } - - public double getLegendBoxHeight() { - - return legendBoxHeight; - } - - @Override - public Rectangle2D getBounds() { - - return bounds; - } - - @Override - public ChartInternal getChartInternal() { - - return chartInternal; - } - } diff --git a/xchart/src/main/java/org/knowm/xchart/internal/chartpart/LegendAxesChart.java b/xchart/src/main/java/org/knowm/xchart/internal/chartpart/LegendAxesChart.java new file mode 100644 index 0000000000000000000000000000000000000000..2ef9fae3bf78b0c747e219a5eff7a14724555fb2 --- /dev/null +++ b/xchart/src/main/java/org/knowm/xchart/internal/chartpart/LegendAxesChart.java @@ -0,0 +1,248 @@ +/** + * Copyright 2015-2016 Knowm Inc. (http://knowm.org) and contributors. + * Copyright 2011-2015 Xeiam LLC (http://xeiam.com) and contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.knowm.xchart.internal.chartpart; + +import java.awt.BasicStroke; +import java.awt.Graphics2D; +import java.awt.Shape; +import java.awt.font.FontRenderContext; +import java.awt.font.TextLayout; +import java.awt.geom.AffineTransform; +import java.awt.geom.Line2D; +import java.awt.geom.Rectangle2D; +import java.util.Map; + +import org.knowm.xchart.Series_AxesChart; +import org.knowm.xchart.Series_XY; +import org.knowm.xchart.internal.Series; +import org.knowm.xchart.internal.chartpart.RenderableSeries.LegendRenderType; +import org.knowm.xchart.internal.style.StyleManagerAxesChart; + +/** + * @author timmolter + */ +public class LegendAxesChart<SM extends StyleManagerAxesChart, S extends Series> extends Legend { + + StyleManagerAxesChart styleManagerAxesChart; + + /** + * Constructor + * + * @param chart + */ + public LegendAxesChart(Chart<StyleManagerAxesChart, Series_XY> chart) { + + super(chart); + styleManagerAxesChart = chart.getStyleManager(); + } + + @Override + public void paint(Graphics2D g) { + + super.paint(g); + + // legend draw position + double xOffset = 0; + double yOffset = 0; + switch (chart.getStyleManager().getLegendPosition()) { + case OutsideE: + xOffset = chart.getWidth() - bounds.getWidth() - chart.getStyleManager().getChartPadding(); + yOffset = chart.getPlot().getBounds().getY() + (chart.getPlot().getBounds().getHeight() - bounds.getHeight()) / 2.0; + break; + case InsideNW: + xOffset = chart.getPlot().getBounds().getX() + LEGEND_MARGIN; + yOffset = chart.getPlot().getBounds().getY() + LEGEND_MARGIN; + break; + case InsideNE: + xOffset = chart.getPlot().getBounds().getX() + chart.getPlot().getBounds().getWidth() - bounds.getWidth() - LEGEND_MARGIN; + yOffset = chart.getPlot().getBounds().getY() + LEGEND_MARGIN; + break; + case InsideSE: + xOffset = chart.getPlot().getBounds().getX() + chart.getPlot().getBounds().getWidth() - bounds.getWidth() - LEGEND_MARGIN; + yOffset = chart.getPlot().getBounds().getY() + chart.getPlot().getBounds().getHeight() - bounds.getHeight() - LEGEND_MARGIN; + break; + case InsideSW: + xOffset = chart.getPlot().getBounds().getX() + LEGEND_MARGIN; + yOffset = chart.getPlot().getBounds().getY() + chart.getPlot().getBounds().getHeight() - bounds.getHeight() - LEGEND_MARGIN; + break; + case InsideN: + xOffset = chart.getPlot().getBounds().getX() + (chart.getPlot().getBounds().getWidth() - bounds.getWidth()) / 2 + LEGEND_MARGIN; + yOffset = chart.getPlot().getBounds().getY() + LEGEND_MARGIN; + break; + + default: + break; + } + + // TODO need this stroke? + g.setStroke(new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 10.0f, new float[] { 3.0f, 0.0f }, 0.0f)); + + // draw legend box background and border + Shape rect = new Rectangle2D.Double(xOffset + 1, yOffset + 1, bounds.getWidth() - 2, bounds.getHeight() - 2); + g.setColor(chart.getStyleManager().getLegendBackgroundColor()); + g.fill(rect); + g.setColor(chart.getStyleManager().getLegendBorderColor()); + g.draw(rect); + + // Draw legend content inside legend box + double startx = xOffset + chart.getStyleManager().getLegendPadding(); + double starty = yOffset + chart.getStyleManager().getLegendPadding(); + + // TODO 3.0.0 figure out this warning. + Map<String, Series_AxesChart> map = chart.getSeriesMap(); + for (Series_AxesChart series : map.values()) { + + Map<String, Rectangle2D> seriesTextBounds = getSeriesTextBounds(series); + + float legendEntryHeight = 0; + double legendTextContentMaxWidth = 0; // TODO 3.0.0 don't need this + for (Map.Entry<String, Rectangle2D> entry : seriesTextBounds.entrySet()) { + legendEntryHeight += entry.getValue().getHeight() + MULTI_LINE_SPACE; + legendTextContentMaxWidth = Math.max(legendTextContentMaxWidth, entry.getValue().getWidth()); + } + legendEntryHeight -= MULTI_LINE_SPACE; + + legendEntryHeight = Math.max(legendEntryHeight, (series.getLegendRenderType() == LegendRenderType.Box ? BOX_SIZE : styleManagerAxesChart.getMarkerSize())); + + // ////// paint series render graphic ///////// + + // paint line and marker + if (series.getLegendRenderType() != LegendRenderType.Box) { + + // paint line + if (series.getLegendRenderType() == LegendRenderType.Line && series.getStroke() != null) { + g.setColor(series.getStrokeColor()); + g.setStroke(series.getStroke()); + Shape line = new Line2D.Double(startx, starty + legendEntryHeight / 2.0, startx + chart.getStyleManager().getLegendSeriesLineLength(), starty + legendEntryHeight / 2.0); + g.draw(line); + } + + // // debug box + // Rectangle2D boundsTemp = new Rectangle2D.Double(startx, starty, styleManager.getLegendSeriesLineLength(), blockHeight); + // g.setStroke(new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL)); + // g.setColor(Color.red); + // g.draw(boundsTemp); + + // paint marker + if (series.getMarker() != null) { + g.setColor(series.getMarkerColor()); + series.getMarker().paint(g, startx + chart.getStyleManager().getLegendSeriesLineLength() / 2.0, starty + legendEntryHeight / 2.0, styleManagerAxesChart.getMarkerSize()); + + } + } + else { // bar/pie type series + + // paint little box + if (series.getStroke() != null) { + g.setColor(series.getStrokeColor()); + Shape rectSmall = new Rectangle2D.Double(startx, starty, BOX_SIZE, BOX_SIZE); + g.fill(rectSmall); + } + // // debug box + // Rectangle2D boundsTemp = new Rectangle2D.Double(startx, starty, BOX_SIZE, BOX_SIZE); + // g.setStroke(new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL)); + // g.setColor(Color.red); + // g.draw(boundsTemp); + } + + // + // ////// paint series text ///////// + + g.setColor(chart.getStyleManager().getChartFontColor()); + + double multiLineOffset = 0.0; + + if (series.getLegendRenderType() != LegendRenderType.Box) { + + double x = startx + chart.getStyleManager().getLegendSeriesLineLength() + chart.getStyleManager().getLegendPadding(); + for (Map.Entry<String, Rectangle2D> entry : seriesTextBounds.entrySet()) { + + double height = entry.getValue().getHeight(); + double centerOffsetY = (Math.max(styleManagerAxesChart.getMarkerSize(), height) - height) / 2.0; + + FontRenderContext frc = g.getFontRenderContext(); + TextLayout tl = new TextLayout(entry.getKey(), chart.getStyleManager().getLegendFont(), frc); + Shape shape = tl.getOutline(null); + AffineTransform orig = g.getTransform(); + AffineTransform at = new AffineTransform(); + at.translate(x, starty + height + centerOffsetY + multiLineOffset); + g.transform(at); + g.fill(shape); + g.setTransform(orig); + + // // debug box + // Rectangle2D boundsTemp = new Rectangle2D.Double(x, starty + centerOffsetY + multiLineOffset, entry.getValue().getWidth(), height); + // g.setColor(Color.blue); + // g.draw(boundsTemp); + + multiLineOffset += height + MULTI_LINE_SPACE; + } + + } + else { // bar/pie type series + + final double x = startx + BOX_SIZE + chart.getStyleManager().getLegendPadding(); + for (Map.Entry<String, Rectangle2D> entry : seriesTextBounds.entrySet()) { + + double height = entry.getValue().getHeight(); + double centerOffsetY = (Math.max(BOX_SIZE, height) - height) / 2.0; + + FontRenderContext frc = g.getFontRenderContext(); + TextLayout tl = new TextLayout(entry.getKey(), chart.getStyleManager().getLegendFont(), frc); + Shape shape = tl.getOutline(null); + AffineTransform orig = g.getTransform(); + AffineTransform at = new AffineTransform(); + at.translate(x, starty + height + centerOffsetY + multiLineOffset); + g.transform(at); + g.fill(shape); + g.setTransform(orig); + + // // debug box + // Rectangle2D boundsTemp = new Rectangle2D.Double(x, starty + centerOffsetY, entry.getValue().getWidth(), height); + // g.setColor(Color.blue); + // g.draw(boundsTemp); + multiLineOffset += height + MULTI_LINE_SPACE; + + } + } + starty += legendEntryHeight + chart.getStyleManager().getLegendPadding(); + + } + + // bounds + bounds = new Rectangle2D.Double(xOffset, yOffset, bounds.getWidth(), bounds.getHeight()); + + // g.setColor(Color.blue); + // g.draw(bounds); + + } + + @Override + public Rectangle2D getBounds() { + + if (bounds == null) { // was not drawn fully yet, just need the height hint. The Axis object may be asking for it. + bounds = getBoundsHint(); + } + return bounds; + } + + @Override + public double getSeriesLegendRenderGraphicHeight(Series series) { + + return series.getLegendRenderType() == LegendRenderType.Box ? BOX_SIZE : styleManagerAxesChart.getMarkerSize(); + } +} diff --git a/xchart/src/main/java/org/knowm/xchart/internal/chartpart/LegendPie.java b/xchart/src/main/java/org/knowm/xchart/internal/chartpart/LegendPie.java new file mode 100644 index 0000000000000000000000000000000000000000..33cbabcfa14c832c16b734e2a885094b47b93631 --- /dev/null +++ b/xchart/src/main/java/org/knowm/xchart/internal/chartpart/LegendPie.java @@ -0,0 +1,193 @@ +/** + * Copyright 2015-2016 Knowm Inc. (http://knowm.org) and contributors. + * Copyright 2011-2015 Xeiam LLC (http://xeiam.com) and contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.knowm.xchart.internal.chartpart; + +import java.awt.BasicStroke; +import java.awt.Graphics2D; +import java.awt.Shape; +import java.awt.font.FontRenderContext; +import java.awt.font.TextLayout; +import java.awt.geom.AffineTransform; +import java.awt.geom.Rectangle2D; +import java.util.Map; + +import org.knowm.xchart.Series_Pie; +import org.knowm.xchart.StyleManagerPie; +import org.knowm.xchart.internal.Series; +import org.knowm.xchart.internal.style.StyleManagerAxesChart; + +/** + * @author timmolter + */ +public class LegendPie<SM extends StyleManagerAxesChart, S extends Series> extends Legend { + + StyleManagerPie styleManagerPie; + + /** + * Constructor + * + * @param chart + */ + public LegendPie(Chart<StyleManagerPie, Series_Pie> chart) { + + super(chart); + styleManagerPie = chart.getStyleManager(); + } + + @Override + public void paint(Graphics2D g) { + + super.paint(g); + + // legend draw position + double xOffset = 0; + double yOffset = 0; + switch (chart.getStyleManager().getLegendPosition()) { + case OutsideE: + xOffset = chart.getWidth() - bounds.getWidth() - chart.getStyleManager().getChartPadding(); + yOffset = chart.getPlot().getBounds().getY() + (chart.getPlot().getBounds().getHeight() - bounds.getHeight()) / 2.0; + break; + case InsideNW: + xOffset = chart.getPlot().getBounds().getX() + LEGEND_MARGIN; + yOffset = chart.getPlot().getBounds().getY() + LEGEND_MARGIN; + break; + case InsideNE: + xOffset = chart.getPlot().getBounds().getX() + chart.getPlot().getBounds().getWidth() - bounds.getWidth() - LEGEND_MARGIN; + yOffset = chart.getPlot().getBounds().getY() + LEGEND_MARGIN; + break; + case InsideSE: + xOffset = chart.getPlot().getBounds().getX() + chart.getPlot().getBounds().getWidth() - bounds.getWidth() - LEGEND_MARGIN; + yOffset = chart.getPlot().getBounds().getY() + chart.getPlot().getBounds().getHeight() - bounds.getHeight() - LEGEND_MARGIN; + break; + case InsideSW: + xOffset = chart.getPlot().getBounds().getX() + LEGEND_MARGIN; + yOffset = chart.getPlot().getBounds().getY() + chart.getPlot().getBounds().getHeight() - bounds.getHeight() - LEGEND_MARGIN; + break; + case InsideN: + xOffset = chart.getPlot().getBounds().getX() + (chart.getPlot().getBounds().getWidth() - bounds.getWidth()) / 2 + LEGEND_MARGIN; + yOffset = chart.getPlot().getBounds().getY() + LEGEND_MARGIN; + break; + + default: + break; + } + + // TODO need this stroke? + g.setStroke(new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 10.0f, new float[] { 3.0f, 0.0f }, 0.0f)); + + // draw legend box background and border + Shape rect = new Rectangle2D.Double(xOffset + 1, yOffset + 1, bounds.getWidth() - 2, bounds.getHeight() - 2); + g.setColor(chart.getStyleManager().getLegendBackgroundColor()); + g.fill(rect); + g.setColor(chart.getStyleManager().getLegendBorderColor()); + g.draw(rect); + + // Draw legend content inside legend box + double startx = xOffset + chart.getStyleManager().getLegendPadding(); + double starty = yOffset + chart.getStyleManager().getLegendPadding(); + + // TODO 3.0.0 figure out this warning. + Map<String, Series> map = chart.getSeriesMap(); + for (Series series : map.values()) { + + Map<String, Rectangle2D> seriesTextBounds = getSeriesTextBounds(series); + + float legendEntryHeight = 0; + double legendTextContentMaxWidth = 0; // TODO 3.0.0 don't need this + for (Map.Entry<String, Rectangle2D> entry : seriesTextBounds.entrySet()) { + legendEntryHeight += entry.getValue().getHeight() + MULTI_LINE_SPACE; + legendTextContentMaxWidth = Math.max(legendTextContentMaxWidth, entry.getValue().getWidth()); + } + legendEntryHeight -= MULTI_LINE_SPACE; + + legendEntryHeight = Math.max(legendEntryHeight, BOX_SIZE); + + // ////// paint series render graphic ///////// + + // bar/pie type series + + // paint little box + if (series.getFillColor() != null) { + g.setColor(series.getFillColor()); + Shape rectSmall = new Rectangle2D.Double(startx, starty, BOX_SIZE, BOX_SIZE); + g.fill(rectSmall); + } + // // debug box + // Rectangle2D boundsTemp = new Rectangle2D.Double(startx, starty, BOX_SIZE, BOX_SIZE); + // g.setStroke(new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL)); + // g.setColor(Color.red); + // g.draw(boundsTemp); + + // + // ////// paint series text ///////// + + g.setColor(chart.getStyleManager().getChartFontColor()); + + double multiLineOffset = 0.0; + + // bar/pie type series + + final double x = startx + BOX_SIZE + chart.getStyleManager().getLegendPadding(); + for (Map.Entry<String, Rectangle2D> entry : seriesTextBounds.entrySet()) { + + double height = entry.getValue().getHeight(); + double centerOffsetY = (Math.max(BOX_SIZE, height) - height) / 2.0; + + FontRenderContext frc = g.getFontRenderContext(); + TextLayout tl = new TextLayout(entry.getKey(), chart.getStyleManager().getLegendFont(), frc); + Shape shape = tl.getOutline(null); + AffineTransform orig = g.getTransform(); + AffineTransform at = new AffineTransform(); + at.translate(x, starty + height + centerOffsetY + multiLineOffset); + g.transform(at); + g.fill(shape); + g.setTransform(orig); + + // // debug box + // Rectangle2D boundsTemp = new Rectangle2D.Double(x, starty + centerOffsetY, entry.getValue().getWidth(), height); + // g.setColor(Color.blue); + // g.draw(boundsTemp); + multiLineOffset += height + MULTI_LINE_SPACE; + + } + starty += legendEntryHeight + chart.getStyleManager().getLegendPadding(); + + } + + // bounds + bounds = new Rectangle2D.Double(xOffset, yOffset, bounds.getWidth(), bounds.getHeight()); + + // g.setColor(Color.blue); + // g.draw(bounds); + + } + + @Override + public Rectangle2D getBounds() { + + if (bounds == null) { // was not drawn fully yet, just need the height hint. The Axis object may be asking for it. + bounds = getBoundsHint(); + } + return bounds; + } + + @Override + public double getSeriesLegendRenderGraphicHeight(Series series) { + + return BOX_SIZE; + } +} diff --git a/xchart/src/main/java/org/knowm/xchart/internal/chartpart/NumberFormatter.java b/xchart/src/main/java/org/knowm/xchart/internal/chartpart/NumberFormatter.java index b926a52258a7b47de01fbbc07e2cb8cd63ab7de2..223add217a69fdb908379348530076b67e62110c 100644 --- a/xchart/src/main/java/org/knowm/xchart/internal/chartpart/NumberFormatter.java +++ b/xchart/src/main/java/org/knowm/xchart/internal/chartpart/NumberFormatter.java @@ -1,5 +1,5 @@ /** - * Copyright 2015 Knowm Inc. (http://knowm.org) and contributors. + * Copyright 2015-2016 Knowm Inc. (http://knowm.org) and contributors. * Copyright 2011-2015 Xeiam LLC (http://xeiam.com) and contributors. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -20,20 +20,20 @@ import java.math.BigDecimal; import java.text.DecimalFormat; import java.text.NumberFormat; -import org.knowm.xchart.StyleManager; import org.knowm.xchart.internal.chartpart.Axis.Direction; +import org.knowm.xchart.internal.style.StyleManagerAxesChart; /** * @author timmolter */ public class NumberFormatter { - private final StyleManager styleManager; + private final StyleManagerAxesChart styleManager; /** * Constructor */ - public NumberFormatter(StyleManager styleManager) { + public NumberFormatter(StyleManagerAxesChart styleManager) { this.styleManager = styleManager; } diff --git a/xchart/src/main/java/org/knowm/xchart/internal/chartpart/Plot.java b/xchart/src/main/java/org/knowm/xchart/internal/chartpart/Plot.java deleted file mode 100644 index 0dfb9a8ae3850e90bda34f7d843cab0e10d50e5b..0000000000000000000000000000000000000000 --- a/xchart/src/main/java/org/knowm/xchart/internal/chartpart/Plot.java +++ /dev/null @@ -1,104 +0,0 @@ -/** - * Copyright 2015 Knowm Inc. (http://knowm.org) and contributors. - * Copyright 2011-2015 Xeiam LLC (http://xeiam.com) and contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.knowm.xchart.internal.chartpart; - -import java.awt.Graphics2D; -import java.awt.geom.Rectangle2D; - -import org.knowm.xchart.StyleManager.ChartType; -import org.knowm.xchart.internal.chartpart.ChartInternal.ChartInternalType; - -/** - * @author timmolter - */ -public class Plot implements ChartPart { - - /** parent */ - private final ChartInternal chartInternal; - - /** the bounds */ - private Rectangle2D bounds; - - private PlotSurface plotSurface; - - private PlotContent plotContent; - - /** - * Constructor - * - * @param chartInternal - */ - public Plot(ChartInternal chartInternal) { - - this.chartInternal = chartInternal; - this.plotSurface = new PlotSurface(this); - } - - @Override - public Rectangle2D getBounds() { - - return bounds; - } - - @Override - public void paint(Graphics2D g) { - - bounds = new Rectangle2D.Double(); - - // calculate bounds - double xOffset = chartInternal.getAxisPair().getYAxis().getBounds().getX() - - + chartInternal.getAxisPair().getYAxis().getBounds().getWidth() - - + (chartInternal.getStyleManager().isYAxisTicksVisible() ? (chartInternal.getStyleManager().getPlotPadding()) : 0) - - ; - - double yOffset = chartInternal.getAxisPair().getYAxis().getBounds().getY(); - double width = chartInternal.getAxisPair().getXAxis().getBounds().getWidth(); - double height = chartInternal.getAxisPair().getYAxis().getBounds().getHeight(); - bounds = new Rectangle2D.Double(xOffset, yOffset, width, height); - // g.setColor(Color.green); - // g.draw(bounds); - - plotSurface.paint(g); - - if (getChartInternal().getChartInternalType() == ChartInternalType.Category) { - if (getChartInternal().getStyleManager().getChartType() == ChartType.Bar) { - this.plotContent = new PlotContentCategoricalChart_Bar(this); - } - - else { - this.plotContent = new PlotContentCategoricalChart_Line_Area_Scatter(this); - } - } - else if (getChartInternal().getChartInternalType() == ChartInternalType.Pie) { - this.plotContent = new PlotContentCategoricalChart_Pie(this); - } - else { - this.plotContent = new PlotContentNumericalChart(this); - } - plotContent.paint(g); - - } - - @Override - public ChartInternal getChartInternal() { - - return chartInternal; - } -} diff --git a/xchart/src/main/java/org/knowm/xchart/internal/chartpart/PlotContent.java b/xchart/src/main/java/org/knowm/xchart/internal/chartpart/PlotContent_.java similarity index 67% rename from xchart/src/main/java/org/knowm/xchart/internal/chartpart/PlotContent.java rename to xchart/src/main/java/org/knowm/xchart/internal/chartpart/PlotContent_.java index de74676a44b0934355828dc1f256e8e8030b92c3..0f506b5c6ff7c622e687365d3da18576a9129f85 100644 --- a/xchart/src/main/java/org/knowm/xchart/internal/chartpart/PlotContent.java +++ b/xchart/src/main/java/org/knowm/xchart/internal/chartpart/PlotContent_.java @@ -1,5 +1,5 @@ /** - * Copyright 2015 Knowm Inc. (http://knowm.org) and contributors. + * Copyright 2015-2016 Knowm Inc. (http://knowm.org) and contributors. * Copyright 2011-2015 Xeiam LLC (http://xeiam.com) and contributors. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -20,42 +20,32 @@ import java.awt.BasicStroke; import java.awt.Stroke; import java.awt.geom.Rectangle2D; -import org.knowm.xchart.StyleManager; +import org.knowm.xchart.internal.Series; +import org.knowm.xchart.internal.style.StyleManagerAxesChart; /** * @author timmolter */ -public abstract class PlotContent implements ChartPart { +public abstract class PlotContent_<SM extends StyleManagerAxesChart, S extends Series> implements ChartPart { - /** parent */ - protected Plot plot; - - StyleManager styleManager; + protected final Chart<SM, S> chart; protected final Stroke errorBarStroke = new BasicStroke(1.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL); /** * Constructor * - * @param plot + * @param chart - The Chart */ - protected PlotContent(Plot plot) { - - this.plot = plot; + protected PlotContent_(Chart<SM, S> chart) { - styleManager = getChartInternal().getStyleManager(); + this.chart = chart; } @Override public Rectangle2D getBounds() { - return plot.getBounds(); - } - - @Override - public ChartInternal getChartInternal() { - - return plot.getChartInternal(); + return chart.getPlot().getBounds(); } } diff --git a/xchart/src/main/java/org/knowm/xchart/internal/chartpart/PlotContentCategoricalChart_Bar.java b/xchart/src/main/java/org/knowm/xchart/internal/chartpart/PlotContent_Category_Bar.java similarity index 76% rename from xchart/src/main/java/org/knowm/xchart/internal/chartpart/PlotContentCategoricalChart_Bar.java rename to xchart/src/main/java/org/knowm/xchart/internal/chartpart/PlotContent_Category_Bar.java index 8a9470a6aa13802eb59370e56c5956d2331cf878..965272d79638c3b6d873292da902cd6349cea734 100644 --- a/xchart/src/main/java/org/knowm/xchart/internal/chartpart/PlotContentCategoricalChart_Bar.java +++ b/xchart/src/main/java/org/knowm/xchart/internal/chartpart/PlotContent_Category_Bar.java @@ -1,5 +1,5 @@ /** - * Copyright 2015 Knowm Inc. (http://knowm.org) and contributors. + * Copyright 2015-2016 Knowm Inc. (http://knowm.org) and contributors. * Copyright 2011-2015 Xeiam LLC (http://xeiam.com) and contributors. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -23,61 +23,63 @@ import java.awt.geom.Path2D; import java.awt.geom.Rectangle2D; import java.util.Collection; import java.util.Iterator; +import java.util.Map; -import org.knowm.xchart.Series; -import org.knowm.xchart.Series.SeriesType; +import org.knowm.xchart.Series_Category; +import org.knowm.xchart.Series_Category.ChartCategorySeriesRenderStyle; +import org.knowm.xchart.StyleManagerCategory; +import org.knowm.xchart.internal.Series; import org.knowm.xchart.internal.Utils; +import org.knowm.xchart.internal.style.StyleManager; /** * @author timmolter */ -public class PlotContentCategoricalChart_Bar extends PlotContent { +public class PlotContent_Category_Bar<SM extends StyleManager, S extends Series> extends PlotContent_ { + + StyleManagerCategory styleManagerCategory; /** * Constructor * * @param plot */ - protected PlotContentCategoricalChart_Bar(Plot plot) { + protected PlotContent_Category_Bar(Chart<StyleManagerCategory, Series_Category> chart) { - super(plot); + super(chart); + this.styleManagerCategory = chart.getStyleManager(); } @Override public void paint(Graphics2D g) { - // logarithmic - if (getChartInternal().getStyleManager().isYAxisLogarithmic()) { - throw new IllegalArgumentException("Category Charts cannot have logarithmic axes!!! (Not Yet Implemented)"); - } - - Rectangle2D bounds = plot.getBounds(); + Rectangle2D bounds = getBounds(); // g.setStroke(new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL)); // g.setColor(Color.red); // g.draw(bounds); // this is for preventing the series to be drawn outside the plot area if min and max is overridden to fall inside the data range - Rectangle2D rectangle = new Rectangle2D.Double(0, 0, getChartInternal().getWidth(), getChartInternal().getHeight()); + Rectangle2D rectangle = new Rectangle2D.Double(0, 0, chart.getWidth(), chart.getHeight()); // g.setStroke(new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL)); // g.setColor(Color.green); // g.draw(rectangle); g.setClip(bounds.createIntersection(rectangle)); // X-Axis - double xTickSpace = styleManager.getAxisTickSpacePercentage() * bounds.getWidth(); + double xTickSpace = styleManagerCategory.getAxisTickSpacePercentage() * bounds.getWidth(); double xLeftMargin = Utils.getTickStartOffset(bounds.getWidth(), xTickSpace); // Y-Axis - double yTickSpace = styleManager.getAxisTickSpacePercentage() * bounds.getHeight(); + double yTickSpace = styleManagerCategory.getAxisTickSpacePercentage() * bounds.getHeight(); double yTopMargin = Utils.getTickStartOffset(bounds.getHeight(), yTickSpace); - int numCategories = getChartInternal().getSeriesMap().values().iterator().next().getXData().size(); + Map<String, Series_Category> seriesMap = chart.getSeriesMap(); + int numCategories = seriesMap.values().iterator().next().getXData().size(); double gridStep = xTickSpace / numCategories; - double yMin = getChartInternal().getAxisPair().getYAxis().getMin(); - double yMax = getChartInternal().getAxisPair().getYAxis().getMax(); + double yMin = chart.getAxisPair().getYAxis().getMin(); + double yMax = chart.getAxisPair().getYAxis().getMax(); - // TODO only for bar charts necessary // figure out the general form of the chart int chartForm = 1; // 1=positive, -1=negative, 0=span if (yMin > 0.0 && yMax > 0.0) { @@ -95,12 +97,7 @@ public class PlotContentCategoricalChart_Bar extends PlotContent { // plot series int seriesCounter = 0; - for (Series series : getChartInternal().getSeriesMap().values()) { - - // sanity check - if (Series.SeriesType.Area.equals(series.getSeriesType()) || Series.SeriesType.Pie.equals(series.getSeriesType())) { - throw new RuntimeException("Category-Bar charts only accept Bar, Line and Scatter series types!!!"); - } + for (Series_Category series : seriesMap.values()) { // for line series double previousX = -Double.MAX_VALUE; @@ -171,21 +168,21 @@ public class PlotContentCategoricalChart_Bar extends PlotContent { double xOffset; double barWidth; - if (getChartInternal().getStyleManager().isBarsOverlapped()) { - double barWidthPercentage = getChartInternal().getStyleManager().getBarWidthPercentage(); + if (styleManagerCategory.isBarsOverlapped()) { + double barWidthPercentage = styleManagerCategory.getBarWidthPercentage(); barWidth = gridStep * barWidthPercentage; double barMargin = gridStep * (1 - barWidthPercentage) / 2; xOffset = bounds.getX() + xLeftMargin + gridStep * categoryCounter++ + barMargin; } else { - double barWidthPercentage = getChartInternal().getStyleManager().getBarWidthPercentage(); - barWidth = gridStep / getChartInternal().getSeriesMap().size() * barWidthPercentage; + double barWidthPercentage = styleManagerCategory.getBarWidthPercentage(); + barWidth = gridStep / chart.getSeriesMap().size() * barWidthPercentage; double barMargin = gridStep * (1 - barWidthPercentage) / 2; xOffset = bounds.getX() + xLeftMargin + gridStep * categoryCounter++ + seriesCounter * barWidth + barMargin; } // paint series - if (series.getSeriesType() == SeriesType.Bar) { + if (series.getChartCategorySeriesRenderStyle() == ChartCategorySeriesRenderStyle.Bar) { // paint bar g.setColor(series.getStrokeColor()); Path2D.Double path = new Path2D.Double(); @@ -195,7 +192,7 @@ public class PlotContentCategoricalChart_Bar extends PlotContent { path.lineTo(xOffset, zeroOffset); path.closePath(); g.setStroke(series.getStroke()); - if (getChartInternal().getStyleManager().isBarFilled()) { + if (styleManagerCategory.isBarFilled()) { g.fill(path); } else { @@ -205,7 +202,7 @@ public class PlotContentCategoricalChart_Bar extends PlotContent { else { // paint line - if (Series.SeriesType.Line.equals(series.getSeriesType())) { + if (series.getChartCategorySeriesRenderStyle() == ChartCategorySeriesRenderStyle.Line) { if (series.getStroke() != null) { @@ -223,7 +220,7 @@ public class PlotContentCategoricalChart_Bar extends PlotContent { // paint marker if (series.getMarker() != null) { g.setColor(series.getMarkerColor()); - series.getMarker().paint(g, previousX, previousY, getChartInternal().getStyleManager().getMarkerSize()); + series.getMarker().paint(g, previousX, previousY, styleManagerCategory.getMarkerSize()); } } @@ -235,11 +232,11 @@ public class PlotContentCategoricalChart_Bar extends PlotContent { double eb = ebItr.next().doubleValue(); // set error bar style - if (getChartInternal().getStyleManager().isErrorBarsColorSeriesColor()) { + if (styleManagerCategory.isErrorBarsColorSeriesColor()) { g.setColor(series.getStrokeColor()); } else { - g.setColor(getChartInternal().getStyleManager().getErrorBarsColor()); + g.setColor(styleManagerCategory.getErrorBarsColor()); } g.setStroke(errorBarStroke); diff --git a/xchart/src/main/java/org/knowm/xchart/internal/chartpart/PlotContentCategoricalChart_Line_Area_Scatter.java b/xchart/src/main/java/org/knowm/xchart/internal/chartpart/PlotContent_Category_Line_Area_Scatter.java similarity index 76% rename from xchart/src/main/java/org/knowm/xchart/internal/chartpart/PlotContentCategoricalChart_Line_Area_Scatter.java rename to xchart/src/main/java/org/knowm/xchart/internal/chartpart/PlotContent_Category_Line_Area_Scatter.java index e8be8fe07a861c8df65cde344e5fa3bd5d2004f9..34e739cd1eea081023adf6ced2836b92604514c3 100644 --- a/xchart/src/main/java/org/knowm/xchart/internal/chartpart/PlotContentCategoricalChart_Line_Area_Scatter.java +++ b/xchart/src/main/java/org/knowm/xchart/internal/chartpart/PlotContent_Category_Line_Area_Scatter.java @@ -1,5 +1,5 @@ /** - * Copyright 2015 Knowm Inc. (http://knowm.org) and contributors. + * Copyright 2015-2016 Knowm Inc. (http://knowm.org) and contributors. * Copyright 2011-2015 Xeiam LLC (http://xeiam.com) and contributors. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -23,34 +23,42 @@ import java.awt.geom.Path2D; import java.awt.geom.Rectangle2D; import java.util.Collection; import java.util.Iterator; +import java.util.Map; -import org.knowm.xchart.Series; +import org.knowm.xchart.Series_Category; +import org.knowm.xchart.Series_Category.ChartCategorySeriesRenderStyle; +import org.knowm.xchart.StyleManagerCategory; +import org.knowm.xchart.internal.Series; import org.knowm.xchart.internal.Utils; +import org.knowm.xchart.internal.style.StyleManager; /** * @author timmolter */ -public class PlotContentCategoricalChart_Line_Area_Scatter extends PlotContent { +public class PlotContent_Category_Line_Area_Scatter<SM extends StyleManager, S extends Series> extends PlotContent_ { + + StyleManagerCategory styleManagerCategory; /** * Constructor * * @param plot */ - protected PlotContentCategoricalChart_Line_Area_Scatter(Plot plot) { + protected PlotContent_Category_Line_Area_Scatter(Chart<StyleManagerCategory, Series_Category> chart) { - super(plot); + super(chart); + this.styleManagerCategory = styleManagerCategory; } @Override public void paint(Graphics2D g) { // logarithmic - // if (getChartInternal().getStyleManager().isYAxisLogarithmic()) { + // if (styleManagerCategory.isYAxisLogarithmic()) { // throw new IllegalArgumentException("Category Charts cannot have logarithmic axes!!! (Not Yet Implemented)"); // } - Rectangle2D bounds = plot.getBounds(); + Rectangle2D bounds = getBounds(); // g.setStroke(new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL)); // g.setColor(Color.red); // g.draw(bounds); @@ -67,7 +75,7 @@ public class PlotContentCategoricalChart_Line_Area_Scatter extends PlotContent { // g.setColor(Color.green); // g.draw(rectangle); - Rectangle2D rectangle = new Rectangle2D.Double(0, 0, getChartInternal().getWidth(), getChartInternal().getHeight()); + Rectangle2D rectangle = new Rectangle2D.Double(0, 0, chart.getWidth(), chart.getHeight()); // g.setStroke(new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL)); // g.setColor(Color.green); // g.draw(rectangle); @@ -76,38 +84,34 @@ public class PlotContentCategoricalChart_Line_Area_Scatter extends PlotContent { // g.setClip(bounds.createIntersection(g.getClipBounds())); // X-Axis - double xTickSpace = styleManager.getAxisTickSpacePercentage() * bounds.getWidth(); + double xTickSpace = styleManagerCategory.getAxisTickSpacePercentage() * bounds.getWidth(); double xLeftMargin = Utils.getTickStartOffset((int) bounds.getWidth(), xTickSpace); // Y-Axis - double yTickSpace = styleManager.getAxisTickSpacePercentage() * bounds.getHeight(); + double yTickSpace = styleManagerCategory.getAxisTickSpacePercentage() * bounds.getHeight(); double yTopMargin = Utils.getTickStartOffset((int) bounds.getHeight(), yTickSpace); - double xMin = getChartInternal().getAxisPair().getXAxis().getMin(); - double xMax = getChartInternal().getAxisPair().getXAxis().getMax(); - double yMin = getChartInternal().getAxisPair().getYAxis().getMin(); - double yMax = getChartInternal().getAxisPair().getYAxis().getMax(); + double xMin = chart.getAxisPair().getXAxis().getMin(); + double xMax = chart.getAxisPair().getXAxis().getMax(); + double yMin = chart.getAxisPair().getYAxis().getMin(); + double yMax = chart.getAxisPair().getYAxis().getMax(); // logarithmic - if (getChartInternal().getStyleManager().isXAxisLogarithmic()) { + if (styleManagerCategory.isXAxisLogarithmic()) { xMin = Math.log10(xMin); xMax = Math.log10(xMax); } - if (getChartInternal().getStyleManager().isYAxisLogarithmic()) { + if (styleManagerCategory.isYAxisLogarithmic()) { yMin = Math.log10(yMin); yMax = Math.log10(yMax); } - int numCategories = getChartInternal().getSeriesMap().values().iterator().next().getXData().size(); - double gridStep = xTickSpace / numCategories; - - for (Series series : getChartInternal().getSeriesMap().values()) { + Map<String, Series_Category> map = chart.getSeriesMap(); - // sanity check + int numCategories = map.size(); + double gridStep = xTickSpace / numCategories; - if (Series.SeriesType.Bar.equals(series.getSeriesType()) || Series.SeriesType.Pie.equals(series.getSeriesType())) { - throw new RuntimeException("Category-Line,Scatter,Area charts only accept Line, Scatter, and Area series types!!!"); - } + for (Series_Category series : map.values()) { // data points Collection<? extends Number> yData = series.getYData(); @@ -143,7 +147,7 @@ public class PlotContentCategoricalChart_Line_Area_Scatter extends PlotContent { double y = 0.0; // System.out.println(y); - if (getChartInternal().getStyleManager().isYAxisLogarithmic()) { + if (styleManagerCategory.isYAxisLogarithmic()) { y = Math.log10(yOrig); } else { @@ -167,7 +171,7 @@ public class PlotContentCategoricalChart_Line_Area_Scatter extends PlotContent { // System.out.println("---"); // paint line - if (Series.SeriesType.Line.equals(series.getSeriesType()) || Series.SeriesType.Area.equals(series.getSeriesType())) { + if (ChartCategorySeriesRenderStyle.Line.equals(series.getChartCategorySeriesRenderStyle()) || ChartCategorySeriesRenderStyle.Area.equals(series.getChartCategorySeriesRenderStyle())) { if (series.getStroke() != null) { @@ -181,7 +185,7 @@ public class PlotContentCategoricalChart_Line_Area_Scatter extends PlotContent { } // paint area - if (Series.SeriesType.Area.equals(series.getSeriesType())) { + if (ChartCategorySeriesRenderStyle.Area.equals(series.getChartCategorySeriesRenderStyle())) { if (previousX != -Double.MAX_VALUE && previousY != -Double.MAX_VALUE) { @@ -206,7 +210,7 @@ public class PlotContentCategoricalChart_Line_Area_Scatter extends PlotContent { // paint marker if (series.getMarker() != null) { g.setColor(series.getMarkerColor()); - series.getMarker().paint(g, xOffset, yOffset, getChartInternal().getStyleManager().getMarkerSize()); + series.getMarker().paint(g, xOffset, yOffset, styleManagerCategory.getMarkerSize()); } // paint error bars @@ -215,17 +219,17 @@ public class PlotContentCategoricalChart_Line_Area_Scatter extends PlotContent { double eb = ebItr.next().doubleValue(); // set error bar style - if (getChartInternal().getStyleManager().isErrorBarsColorSeriesColor()) { + if (styleManagerCategory.isErrorBarsColorSeriesColor()) { g.setColor(series.getStrokeColor()); } else { - g.setColor(getChartInternal().getStyleManager().getErrorBarsColor()); + g.setColor(styleManagerCategory.getErrorBarsColor()); } g.setStroke(errorBarStroke); // Top value double topValue = 0.0; - if (getChartInternal().getStyleManager().isYAxisLogarithmic()) { + if (styleManagerCategory.isYAxisLogarithmic()) { topValue = yOrig + eb; topValue = Math.log10(topValue); } @@ -237,7 +241,7 @@ public class PlotContentCategoricalChart_Line_Area_Scatter extends PlotContent { // Bottom value double bottomValue = 0.0; - if (getChartInternal().getStyleManager().isYAxisLogarithmic()) { + if (styleManagerCategory.isYAxisLogarithmic()) { bottomValue = yOrig - eb; // System.out.println(bottomValue); bottomValue = Math.log10(bottomValue); diff --git a/xchart/src/main/java/org/knowm/xchart/internal/chartpart/PlotContentCategoricalChart_Pie.java b/xchart/src/main/java/org/knowm/xchart/internal/chartpart/PlotContent_Pie.java similarity index 73% rename from xchart/src/main/java/org/knowm/xchart/internal/chartpart/PlotContentCategoricalChart_Pie.java rename to xchart/src/main/java/org/knowm/xchart/internal/chartpart/PlotContent_Pie.java index 5d694dc232f2b765408ebcb41a9e4984ae4aac2a..647dd74cb94292ee6f9e5bab5105b254015d5aed 100644 --- a/xchart/src/main/java/org/knowm/xchart/internal/chartpart/PlotContentCategoricalChart_Pie.java +++ b/xchart/src/main/java/org/knowm/xchart/internal/chartpart/PlotContent_Pie.java @@ -1,5 +1,5 @@ /** - * Copyright 2015 Knowm Inc. (http://knowm.org) and contributors. + * Copyright 2015-2016 Knowm Inc. (http://knowm.org) and contributors. * Copyright 2011-2015 Xeiam LLC (http://xeiam.com) and contributors. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -19,29 +19,36 @@ package org.knowm.xchart.internal.chartpart; import java.awt.Graphics2D; import java.awt.geom.Arc2D; import java.awt.geom.Rectangle2D; +import java.util.Map; -import org.knowm.xchart.Series; +import org.knowm.xchart.Series_Pie; +import org.knowm.xchart.StyleManagerPie; +import org.knowm.xchart.internal.Series; +import org.knowm.xchart.internal.style.StyleManager; /** * @author timmolter */ -public class PlotContentCategoricalChart_Pie extends PlotContent { +public class PlotContent_Pie<SM extends StyleManager, S extends Series> extends PlotContent_ { + + StyleManagerPie styleManagerPie; /** * Constructor * * @param plot */ - protected PlotContentCategoricalChart_Pie(Plot plot) { + protected PlotContent_Pie(Chart<StyleManagerPie, Series_Pie> chart) { - super(plot); + super(chart); + styleManagerPie = chart.getStyleManager(); } @Override public void paint(Graphics2D g) { // plot area bounds - Rectangle2D bounds = plot.getBounds(); + Rectangle2D bounds = getBounds(); // g.setStroke(new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL)); // g.setColor(Color.red); // g.draw(bounds); @@ -51,8 +58,8 @@ public class PlotContentCategoricalChart_Pie extends PlotContent { return; } - // clip bounds TODO Do we need this? - Rectangle2D rectangle = new Rectangle2D.Double(0, 0, getChartInternal().getWidth(), getChartInternal().getHeight()); + // clip bounds TODO Do we need this? Can we move it to the parent class for all subclasses? + Rectangle2D rectangle = new Rectangle2D.Double(0, 0, chart.getWidth(), chart.getHeight()); // g.setStroke(new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL)); // g.setColor(Color.green); // g.draw(rectangle); @@ -69,27 +76,28 @@ public class PlotContentCategoricalChart_Pie extends PlotContent { // get total double total = 0.0; - for (Series series : getChartInternal().getSeriesMap().values()) { - String x = (String) series.getXData().iterator().next(); - Number y = series.getYData().iterator().next(); + // TODO 3.0.0 figure out this warning. + Map<String, Series_Pie> map = chart.getSeriesMap(); + for (Series_Pie series : map.values()) { - total += y.doubleValue(); + total += series.getValue().doubleValue(); } // draw pie slices double curValue = 0.0; double startAngle = 0; - for (Series series : getChartInternal().getSeriesMap().values()) { + // TODO 3.0.0 figure out this warning. + map = chart.getSeriesMap(); + for (Series_Pie series : map.values()) { - // String x = (String) series.getXData().iterator().next(); - Number y = series.getYData().iterator().next(); + Number y = series.getValue(); startAngle = (curValue * 360 / total); double arcAngle = (y.doubleValue() * 360 / total); g.setColor(series.getFillColor()); g.fill(new Arc2D.Double(pieBounds.getX(), pieBounds.getY(), pieBounds.getWidth(), pieBounds.getHeight(), startAngle, arcAngle, Arc2D.PIE)); - g.setColor(getChartInternal().getStyleManager().getPlotBackgroundColor()); + g.setColor(styleManagerPie.getPlotBackgroundColor()); g.draw(new Arc2D.Double(pieBounds.getX(), pieBounds.getY(), pieBounds.getWidth(), pieBounds.getHeight(), startAngle, arcAngle, Arc2D.PIE)); curValue += y.doubleValue(); } diff --git a/xchart/src/main/java/org/knowm/xchart/internal/chartpart/PlotContentNumericalChart.java b/xchart/src/main/java/org/knowm/xchart/internal/chartpart/PlotContent_XY.java similarity index 76% rename from xchart/src/main/java/org/knowm/xchart/internal/chartpart/PlotContentNumericalChart.java rename to xchart/src/main/java/org/knowm/xchart/internal/chartpart/PlotContent_XY.java index ac9a5c858786d1b5efda0e9337e9e237b87bf9e9..dd5664ef2237114a45c42743b75a74e897d54957 100644 --- a/xchart/src/main/java/org/knowm/xchart/internal/chartpart/PlotContentNumericalChart.java +++ b/xchart/src/main/java/org/knowm/xchart/internal/chartpart/PlotContent_XY.java @@ -1,5 +1,5 @@ /** - * Copyright 2015 Knowm Inc. (http://knowm.org) and contributors. + * Copyright 2015-2016 Knowm Inc. (http://knowm.org) and contributors. * Copyright 2011-2015 Xeiam LLC (http://xeiam.com) and contributors. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -24,30 +24,38 @@ import java.awt.geom.Rectangle2D; import java.util.Collection; import java.util.Date; import java.util.Iterator; +import java.util.Map; -import org.knowm.xchart.Series; +import org.knowm.xchart.Series_XY; +import org.knowm.xchart.Series_XY.ChartXYSeriesRenderStyle; +import org.knowm.xchart.StyleManagerXY; +import org.knowm.xchart.internal.Series; import org.knowm.xchart.internal.Utils; -import org.knowm.xchart.internal.chartpart.Axis.AxisType; +import org.knowm.xchart.internal.chartpart.Axis.AxisDataType; +import org.knowm.xchart.internal.style.StyleManagerAxesChart; /** * @author timmolter */ -public class PlotContentNumericalChart extends PlotContent { +public class PlotContent_XY<SM extends StyleManagerAxesChart, S extends Series> extends PlotContent_ { + + StyleManagerXY styleManagerXY; /** * Constructor * - * @param plot + * @param chart */ - protected PlotContentNumericalChart(Plot plot) { + protected PlotContent_XY(Chart<StyleManagerXY, Series_XY> chart) { - super(plot); + super(chart); + styleManagerXY = chart.getStyleManager(); } @Override public void paint(Graphics2D g) { - Rectangle2D bounds = plot.getBounds(); + Rectangle2D bounds = getBounds(); // g.setStroke(new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL)); // g.setColor(Color.red); // g.draw(bounds); @@ -64,7 +72,7 @@ public class PlotContentNumericalChart extends PlotContent { // g.setColor(Color.green); // g.draw(rectangle); - Rectangle2D rectangle = new Rectangle2D.Double(0, 0, getChartInternal().getWidth(), getChartInternal().getHeight()); + Rectangle2D rectangle = new Rectangle2D.Double(0, 0, chart.getWidth(), chart.getHeight()); // g.setStroke(new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL)); // g.setColor(Color.green); // g.draw(rectangle); @@ -73,34 +81,31 @@ public class PlotContentNumericalChart extends PlotContent { // g.setClip(bounds.createIntersection(g.getClipBounds())); // X-Axis - double xTickSpace = styleManager.getAxisTickSpacePercentage() * bounds.getWidth(); + double xTickSpace = styleManagerXY.getAxisTickSpacePercentage() * bounds.getWidth(); double xLeftMargin = Utils.getTickStartOffset((int) bounds.getWidth(), xTickSpace); // Y-Axis - double yTickSpace = styleManager.getAxisTickSpacePercentage() * bounds.getHeight(); + double yTickSpace = styleManagerXY.getAxisTickSpacePercentage() * bounds.getHeight(); double yTopMargin = Utils.getTickStartOffset((int) bounds.getHeight(), yTickSpace); - double xMin = getChartInternal().getAxisPair().getXAxis().getMin(); - double xMax = getChartInternal().getAxisPair().getXAxis().getMax(); - double yMin = getChartInternal().getAxisPair().getYAxis().getMin(); - double yMax = getChartInternal().getAxisPair().getYAxis().getMax(); + double xMin = chart.getXAxis().getMin(); + double xMax = chart.getXAxis().getMax(); + double yMin = chart.getYAxis().getMin(); + double yMax = chart.getYAxis().getMax(); // logarithmic - if (getChartInternal().getStyleManager().isXAxisLogarithmic()) { + if (styleManagerXY.isXAxisLogarithmic()) { xMin = Math.log10(xMin); xMax = Math.log10(xMax); } - if (getChartInternal().getStyleManager().isYAxisLogarithmic()) { + if (styleManagerXY.isYAxisLogarithmic()) { yMin = Math.log10(yMin); yMax = Math.log10(yMax); } - for (Series series : getChartInternal().getSeriesMap().values()) { - - // sanity check - if (Series.SeriesType.Bar.equals(series.getSeriesType())) { - throw new RuntimeException("X-Y charts only accept Line, Scatter, and Area series types!!!"); - } + // TODO 3.0.0 figure out this warning. + Map<String, Series_XY> map = chart.getSeriesMap(); + for (Series_XY series : map.values()) { // data points Collection<?> xData = series.getXData(); @@ -121,14 +126,14 @@ public class PlotContentNumericalChart extends PlotContent { while (xItr.hasNext()) { double x = 0.0; - if (getChartInternal().getAxisPair().getXAxis().getAxisType() == AxisType.Number) { + if (chart.getXAxis().getAxisDataType() == AxisDataType.Number) { x = ((Number) xItr.next()).doubleValue(); } - else if (getChartInternal().getAxisPair().getXAxis().getAxisType() == AxisType.Date) { + else if (chart.getXAxis().getAxisDataType() == AxisDataType.Date) { x = ((Date) xItr.next()).getTime(); } // System.out.println(x); - if (getChartInternal().getStyleManager().isXAxisLogarithmic()) { + if (styleManagerXY.isXAxisLogarithmic()) { x = Math.log10(x); } // System.out.println(x); @@ -150,7 +155,7 @@ public class PlotContentNumericalChart extends PlotContent { double y = 0.0; // System.out.println(y); - if (getChartInternal().getStyleManager().isYAxisLogarithmic()) { + if (styleManagerXY.isYAxisLogarithmic()) { y = Math.log10(yOrig); } else { @@ -180,8 +185,10 @@ public class PlotContentNumericalChart extends PlotContent { // System.out.println("---"); // paint line - if (Series.SeriesType.Line.equals(series.getSeriesType()) || Series.SeriesType.Area.equals(series.getSeriesType())) { + boolean isSeriesLineOrArea = (ChartXYSeriesRenderStyle.Line == series.getChartXYSeriesRenderStyle()) || (ChartXYSeriesRenderStyle.Area == series.getChartXYSeriesRenderStyle()); + + if (isSeriesLineOrArea) { if (series.getStroke() != null) { if (previousX != -Double.MAX_VALUE && previousY != -Double.MAX_VALUE) { @@ -194,7 +201,7 @@ public class PlotContentNumericalChart extends PlotContent { } // paint area - if (Series.SeriesType.Area.equals(series.getSeriesType())) { + if (ChartXYSeriesRenderStyle.Area == series.getChartXYSeriesRenderStyle()) { if (previousX != -Double.MAX_VALUE && previousY != -Double.MAX_VALUE) { @@ -217,9 +224,9 @@ public class PlotContentNumericalChart extends PlotContent { previousY = yOffset; // paint marker - if (series.getMarker() != null) { + if (series.getMarker() != null) { // if set to Marker.NONE, the marker is null g.setColor(series.getMarkerColor()); - series.getMarker().paint(g, xOffset, yOffset, getChartInternal().getStyleManager().getMarkerSize()); + series.getMarker().paint(g, xOffset, yOffset, styleManagerXY.getMarkerSize()); } // paint error bars @@ -228,17 +235,17 @@ public class PlotContentNumericalChart extends PlotContent { double eb = ebItr.next().doubleValue(); // set error bar style - if (getChartInternal().getStyleManager().isErrorBarsColorSeriesColor()) { + if (styleManagerXY.isErrorBarsColorSeriesColor()) { g.setColor(series.getStrokeColor()); } else { - g.setColor(getChartInternal().getStyleManager().getErrorBarsColor()); + g.setColor(styleManagerXY.getErrorBarsColor()); } g.setStroke(errorBarStroke); // Top value double topValue = 0.0; - if (getChartInternal().getStyleManager().isYAxisLogarithmic()) { + if (styleManagerXY.isYAxisLogarithmic()) { topValue = yOrig + eb; topValue = Math.log10(topValue); } @@ -250,7 +257,7 @@ public class PlotContentNumericalChart extends PlotContent { // Bottom value double bottomValue = 0.0; - if (getChartInternal().getStyleManager().isYAxisLogarithmic()) { + if (styleManagerXY.isYAxisLogarithmic()) { bottomValue = yOrig - eb; // System.out.println(bottomValue); bottomValue = Math.log10(bottomValue); diff --git a/xchart/src/main/java/org/knowm/xchart/internal/chartpart/PlotSurface.java b/xchart/src/main/java/org/knowm/xchart/internal/chartpart/PlotSurface.java index ad6f11f50d3546756ee6e27e1f204e164888e1f0..bbbf0dee6d76f3ef34c7c21be0599e4c34ae324f 100644 --- a/xchart/src/main/java/org/knowm/xchart/internal/chartpart/PlotSurface.java +++ b/xchart/src/main/java/org/knowm/xchart/internal/chartpart/PlotSurface.java @@ -1,5 +1,5 @@ /** - * Copyright 2015 Knowm Inc. (http://knowm.org) and contributors. + * Copyright 2015-2016 Knowm Inc. (http://knowm.org) and contributors. * Copyright 2011-2015 Xeiam LLC (http://xeiam.com) and contributors. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -16,138 +16,31 @@ */ package org.knowm.xchart.internal.chartpart; -import java.awt.Graphics2D; -import java.awt.Shape; -import java.awt.geom.Line2D; import java.awt.geom.Rectangle2D; -import java.util.List; -import org.knowm.xchart.StyleManager.ChartType; -import org.knowm.xchart.internal.chartpart.ChartInternal.ChartInternalType; +import org.knowm.xchart.internal.Series; +import org.knowm.xchart.internal.style.StyleManager; /** - * Draws the plot background, the plot border and the horizontal and vertical grid lines - * * @author timmolter */ -public class PlotSurface implements ChartPart { +public abstract class PlotSurface<SM extends StyleManager, S extends Series> implements ChartPart { - /** parent */ - private Plot plot; + protected final Chart<SM, S> chart; /** * Constructor * - * @param plot + * @param chart */ - protected PlotSurface(Plot plot) { + protected PlotSurface(Chart<SM, S> chart) { - this.plot = plot; + this.chart = chart; } @Override public Rectangle2D getBounds() { - return plot.getBounds(); + return chart.getPlot().getBounds(); } - - @Override - public void paint(Graphics2D g) { - - Rectangle2D bounds = plot.getBounds(); - - // paint plot background - Shape rect = new Rectangle2D.Double(bounds.getX(), bounds.getY(), bounds.getWidth(), bounds.getHeight()); - g.setColor(getChartInternal().getStyleManager().getPlotBackgroundColor()); - g.fill(rect); - - // paint plot border - if (getChartInternal().getStyleManager().isPlotBorderVisible()) { - g.setColor(getChartInternal().getStyleManager().getPlotBorderColor()); - // g.setStroke(getChartPainter().getStyleManager().getAxisTickMarksStroke()); - g.draw(rect); - } - - // paint grid lines and/or inner plot ticks - if (getChartInternal().getAxisPair().getYAxis().getAxisTickCalculator() == null) {// like for Pie Charts - return; - } - - // horizontal - if (getChartInternal().getStyleManager().isPlotGridHorizontalLinesVisible() || getChartInternal().getStyleManager().isPlotTicksMarksVisible()) { - List<Double> yAxisTickLocations = getChartInternal().getAxisPair().getYAxis().getAxisTickCalculator().getTickLocations(); - for (int i = 0; i < yAxisTickLocations.size(); i++) { - - double yOffset = bounds.getY() + bounds.getHeight() - yAxisTickLocations.get(i); - - if (yOffset > bounds.getY() && yOffset < bounds.getY() + bounds.getHeight()) { - - // draw lines - if (getChartInternal().getStyleManager().isPlotGridHorizontalLinesVisible()) { - - g.setColor(getChartInternal().getStyleManager().getPlotGridLinesColor()); - g.setStroke(getChartInternal().getStyleManager().getPlotGridLinesStroke()); - Shape line = new Line2D.Double(bounds.getX(), yOffset, bounds.getX() + bounds.getWidth(), yOffset); - g.draw(line); - } - - // tick marks - if (getChartInternal().getStyleManager().isPlotTicksMarksVisible()) { - - g.setColor(getChartInternal().getStyleManager().getAxisTickMarksColor()); - g.setStroke(getChartInternal().getStyleManager().getAxisTickMarksStroke()); - Shape line = new Line2D.Double(bounds.getX(), yOffset, bounds.getX() + getChartInternal().getStyleManager().getAxisTickMarkLength(), yOffset); - g.draw(line); - line = new Line2D.Double(bounds.getX() + bounds.getWidth(), yOffset, bounds.getX() + bounds.getWidth() - getChartInternal().getStyleManager().getAxisTickMarkLength(), yOffset); - g.draw(line); - } - } - } - } - - // vertical - if ((getChartInternal().getChartInternalType() == ChartInternalType.XY || (getChartInternal().getChartInternalType() == ChartInternalType.Category && getChartInternal().getStyleManager() - .getChartType() != ChartType.Bar))) { - - if ((getChartInternal().getStyleManager().isPlotGridVerticalLinesVisible() || getChartInternal().getStyleManager().isPlotTicksMarksVisible())) { - - List<Double> xAxisTickLocations = getChartInternal().getAxisPair().getXAxis().getAxisTickCalculator().getTickLocations(); - for (int i = 0; i < xAxisTickLocations.size(); i++) { - - double tickLocation = xAxisTickLocations.get(i); - double xOffset = bounds.getX() + tickLocation; - - if (xOffset > bounds.getX() && xOffset < bounds.getX() + bounds.getWidth()) { - - // draw lines - if (getChartInternal().getStyleManager().isPlotGridVerticalLinesVisible()) { - g.setColor(getChartInternal().getStyleManager().getPlotGridLinesColor()); - g.setStroke(getChartInternal().getStyleManager().getPlotGridLinesStroke()); - - Shape line = new Line2D.Double(xOffset, bounds.getY(), xOffset, bounds.getY() + bounds.getHeight()); - g.draw(line); - } - // tick marks - if (getChartInternal().getStyleManager().isPlotTicksMarksVisible()) { - - g.setColor(getChartInternal().getStyleManager().getAxisTickMarksColor()); - g.setStroke(getChartInternal().getStyleManager().getAxisTickMarksStroke()); - - Shape line = new Line2D.Double(xOffset, bounds.getY(), xOffset, bounds.getY() + getChartInternal().getStyleManager().getAxisTickMarkLength()); - g.draw(line); - line = new Line2D.Double(xOffset, bounds.getY() + bounds.getHeight(), xOffset, bounds.getY() + bounds.getHeight() - getChartInternal().getStyleManager().getAxisTickMarkLength()); - g.draw(line); - } - } - } - } - } - } - - @Override - public ChartInternal getChartInternal() { - - return plot.getChartInternal(); - } - } diff --git a/xchart/src/main/java/org/knowm/xchart/internal/chartpart/PlotSurfaceAxesChart.java b/xchart/src/main/java/org/knowm/xchart/internal/chartpart/PlotSurfaceAxesChart.java new file mode 100644 index 0000000000000000000000000000000000000000..e17923cc12034f190c3d7935bb196697f50e9005 --- /dev/null +++ b/xchart/src/main/java/org/knowm/xchart/internal/chartpart/PlotSurfaceAxesChart.java @@ -0,0 +1,138 @@ +/** + * Copyright 2015-2016 Knowm Inc. (http://knowm.org) and contributors. + * Copyright 2011-2015 Xeiam LLC (http://xeiam.com) and contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.knowm.xchart.internal.chartpart; + +import java.awt.Graphics2D; +import java.awt.Shape; +import java.awt.geom.Line2D; +import java.awt.geom.Rectangle2D; +import java.util.List; + +import org.knowm.xchart.Series_XY; +import org.knowm.xchart.internal.Series; +import org.knowm.xchart.internal.style.StyleManager; +import org.knowm.xchart.internal.style.StyleManagerAxesChart; + +/** + * Draws the plot background, the plot border and the horizontal and vertical grid lines + * + * @author timmolter + */ +public class PlotSurfaceAxesChart<SM extends StyleManager, S extends Series> extends PlotSurface { + + private final StyleManagerAxesChart styleManagerAxesChart; + + /** + * Constructor + * + * @param chart + */ + protected PlotSurfaceAxesChart(Chart<StyleManagerAxesChart, Series_XY> chart) { + + super(chart); + this.styleManagerAxesChart = chart.getStyleManager(); + } + + @Override + public void paint(Graphics2D g) { + + Rectangle2D bounds = getBounds(); + + // paint plot background + Shape rect = new Rectangle2D.Double(bounds.getX(), bounds.getY(), bounds.getWidth(), bounds.getHeight()); + g.setColor(styleManagerAxesChart.getPlotBackgroundColor()); + g.fill(rect); + + // paint plot border + if (styleManagerAxesChart.isPlotBorderVisible()) { + g.setColor(styleManagerAxesChart.getPlotBorderColor()); + // g.setStroke(getChartPainter().getStyleManager().getAxisTickMarksStroke()); + g.draw(rect); + } + + // paint grid lines and/or inner plot ticks + + // horizontal + if (styleManagerAxesChart.isPlotGridHorizontalLinesVisible() || styleManagerAxesChart.isPlotTicksMarksVisible()) { + + List<Double> yAxisTickLocations = chart.getYAxis().getAxisTickCalculator().getTickLocations(); + for (int i = 0; i < yAxisTickLocations.size(); i++) { + + double yOffset = bounds.getY() + bounds.getHeight() - yAxisTickLocations.get(i); + + if (yOffset > bounds.getY() && yOffset < bounds.getY() + bounds.getHeight()) { + + // draw lines + if (styleManagerAxesChart.isPlotGridHorizontalLinesVisible()) { + + g.setColor(styleManagerAxesChart.getPlotGridLinesColor()); + g.setStroke(styleManagerAxesChart.getPlotGridLinesStroke()); + Shape line = new Line2D.Double(bounds.getX(), yOffset, bounds.getX() + bounds.getWidth(), yOffset); + g.draw(line); + } + + // tick marks + if (styleManagerAxesChart.isPlotTicksMarksVisible()) { + + g.setColor(styleManagerAxesChart.getAxisTickMarksColor()); + g.setStroke(styleManagerAxesChart.getAxisTickMarksStroke()); + Shape line = new Line2D.Double(bounds.getX(), yOffset, bounds.getX() + styleManagerAxesChart.getAxisTickMarkLength(), yOffset); + g.draw(line); + line = new Line2D.Double(bounds.getX() + bounds.getWidth(), yOffset, bounds.getX() + bounds.getWidth() - styleManagerAxesChart.getAxisTickMarkLength(), yOffset); + g.draw(line); + } + } + } + } + + // vertical + + if ((styleManagerAxesChart.isPlotGridVerticalLinesVisible() || styleManagerAxesChart.isPlotTicksMarksVisible())) { + + List<Double> xAxisTickLocations = chart.getXAxis().getAxisTickCalculator().getTickLocations(); + for (int i = 0; i < xAxisTickLocations.size(); i++) { + + double tickLocation = xAxisTickLocations.get(i); + double xOffset = bounds.getX() + tickLocation; + + if (xOffset > bounds.getX() && xOffset < bounds.getX() + bounds.getWidth()) { + + // draw lines + if (styleManagerAxesChart.isPlotGridVerticalLinesVisible()) { + g.setColor(styleManagerAxesChart.getPlotGridLinesColor()); + g.setStroke(styleManagerAxesChart.getPlotGridLinesStroke()); + + Shape line = new Line2D.Double(xOffset, bounds.getY(), xOffset, bounds.getY() + bounds.getHeight()); + g.draw(line); + } + // tick marks + if (styleManagerAxesChart.isPlotTicksMarksVisible()) { + + g.setColor(styleManagerAxesChart.getAxisTickMarksColor()); + g.setStroke(styleManagerAxesChart.getAxisTickMarksStroke()); + + Shape line = new Line2D.Double(xOffset, bounds.getY(), xOffset, bounds.getY() + styleManagerAxesChart.getAxisTickMarkLength()); + g.draw(line); + line = new Line2D.Double(xOffset, bounds.getY() + bounds.getHeight(), xOffset, bounds.getY() + bounds.getHeight() - styleManagerAxesChart.getAxisTickMarkLength()); + g.draw(line); + } + } + } + } + } + +} diff --git a/xchart/src/main/java/org/knowm/xchart/internal/chartpart/PlotSurfacePie.java b/xchart/src/main/java/org/knowm/xchart/internal/chartpart/PlotSurfacePie.java new file mode 100644 index 0000000000000000000000000000000000000000..8c48d76d003e32f2935a1eecd07558243d2a332d --- /dev/null +++ b/xchart/src/main/java/org/knowm/xchart/internal/chartpart/PlotSurfacePie.java @@ -0,0 +1,67 @@ +/** + * Copyright 2015-2016 Knowm Inc. (http://knowm.org) and contributors. + * Copyright 2011-2015 Xeiam LLC (http://xeiam.com) and contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.knowm.xchart.internal.chartpart; + +import java.awt.Graphics2D; +import java.awt.Shape; +import java.awt.geom.Rectangle2D; + +import org.knowm.xchart.Series_Pie; +import org.knowm.xchart.StyleManagerPie; +import org.knowm.xchart.internal.Series; +import org.knowm.xchart.internal.style.StyleManager; + +/** + * Draws the plot background and the plot border + * + * @author timmolter + */ +public class PlotSurfacePie<SM extends StyleManager, S extends Series> extends PlotSurface { + + private final StyleManagerPie styleManagerPie; + + /** + * Constructor + * + * @param chart + */ + protected PlotSurfacePie(Chart<StyleManagerPie, Series_Pie> chart) { + + super(chart); + this.styleManagerPie = chart.getStyleManager(); + } + + @Override + public void paint(Graphics2D g) { + + Rectangle2D bounds = getBounds(); + + // paint plot background + Shape rect = new Rectangle2D.Double(bounds.getX(), bounds.getY(), bounds.getWidth(), bounds.getHeight()); + g.setColor(styleManagerPie.getPlotBackgroundColor()); + g.fill(rect); + + // paint plot border + if (styleManagerPie.isPlotBorderVisible()) { + g.setColor(styleManagerPie.getPlotBorderColor()); + // g.setStroke(getChartPainter().getStyleManager().getAxisTickMarksStroke()); + g.draw(rect); + } + + } + +} diff --git a/xchart/src/main/java/org/knowm/xchart/internal/chartpart/Plot_.java b/xchart/src/main/java/org/knowm/xchart/internal/chartpart/Plot_.java new file mode 100644 index 0000000000000000000000000000000000000000..eea3f4848ad941f289740c6bda9ec3d5d51176cd --- /dev/null +++ b/xchart/src/main/java/org/knowm/xchart/internal/chartpart/Plot_.java @@ -0,0 +1,79 @@ +/** + * Copyright 2015-2016 Knowm Inc. (http://knowm.org) and contributors. + * Copyright 2011-2015 Xeiam LLC (http://xeiam.com) and contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.knowm.xchart.internal.chartpart; + +import java.awt.Graphics2D; +import java.awt.geom.Rectangle2D; + +import org.knowm.xchart.internal.Series; +import org.knowm.xchart.internal.style.StyleManager; + +/** + * @author timmolter + */ +public class Plot_<SM extends StyleManager, S extends Series> implements ChartPart { + + protected final Chart<SM, S> chart; + protected Rectangle2D bounds; + + protected PlotSurface plotSurface; + protected PlotContent_ plotContent; + + /** + * Constructor + * + * @param chart + */ + public Plot_(Chart<SM, S> chart) { + + this.chart = chart; + } + + @Override + public void paint(Graphics2D g) { + + // g.setColor(Color.green); + // g.draw(bounds); + + plotSurface.paint(g); + plotContent.paint(g); + + // if (chart.getChartType() == Chart.ChartType.Category) { + // if (((StyleManagerCategory) chart.getStyleManager()).getChartCategorySeriesType() == ChartCategorySeriesType.Bar) { + // this.plotContent = new PlotContentCategoricalChart_Bar(this); + // } + // + // else { + // this.plotContent = new PlotContentCategoricalChart_Line_Area_Scatter(this); + // } + // } + // else if (chart.getChartType() == Chart.ChartType.Pie) { + // this.plotContent = new PlotContentCategoricalChart_Pie(this); + // } + // else { + // this.plotContent = new PlotContentXYChart(chart); + // } + // plotContent.paint(g); + + } + + @Override + public Rectangle2D getBounds() { + + return bounds; + } +} diff --git a/xchart/src/main/java/org/knowm/xchart/internal/chartpart/Plot_AxesChart.java b/xchart/src/main/java/org/knowm/xchart/internal/chartpart/Plot_AxesChart.java new file mode 100644 index 0000000000000000000000000000000000000000..a099890119fef1d8665c78b7be982eb2fd8a5b9f --- /dev/null +++ b/xchart/src/main/java/org/knowm/xchart/internal/chartpart/Plot_AxesChart.java @@ -0,0 +1,61 @@ +/** + * Copyright 2015-2016 Knowm Inc. (http://knowm.org) and contributors. + * Copyright 2011-2015 Xeiam LLC (http://xeiam.com) and contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.knowm.xchart.internal.chartpart; + +import java.awt.Graphics2D; +import java.awt.geom.Rectangle2D; + +import org.knowm.xchart.Series_XY; +import org.knowm.xchart.internal.Series; +import org.knowm.xchart.internal.style.StyleManager; +import org.knowm.xchart.internal.style.StyleManagerAxesChart; + +/** + * @author timmolter + */ +public class Plot_AxesChart<SM extends StyleManager, S extends Series> extends Plot_ { + + StyleManagerAxesChart styleManagerAxesChart; + + /** + * Constructor + * + * @param chart + */ + public Plot_AxesChart(Chart<StyleManagerAxesChart, Series_XY> chart) { + + super(chart); + styleManagerAxesChart = chart.getStyleManager(); + this.plotSurface = new PlotSurfaceAxesChart<StyleManagerAxesChart, Series_XY>(chart); + } + + @Override + public void paint(Graphics2D g) { + + // calculate bounds + double xOffset = chart.getYAxis().getBounds().getX() + chart.getYAxis().getBounds().getWidth() + + + (styleManagerAxesChart.isYAxisTicksVisible() ? styleManagerAxesChart.getPlotPadding() : 0); + + double yOffset = chart.getYAxis().getBounds().getY(); + double width = chart.getXAxis().getBounds().getWidth(); + double height = chart.getYAxis().getBounds().getHeight(); + bounds = new Rectangle2D.Double(xOffset, yOffset, width, height); + + super.paint(g); + } +} diff --git a/xchart/src/main/java/org/knowm/xchart/internal/chartpart/Plot_Category.java b/xchart/src/main/java/org/knowm/xchart/internal/chartpart/Plot_Category.java new file mode 100644 index 0000000000000000000000000000000000000000..c400eafbc28cc6ccfddcb144d6aefc6acd6e8af0 --- /dev/null +++ b/xchart/src/main/java/org/knowm/xchart/internal/chartpart/Plot_Category.java @@ -0,0 +1,53 @@ +/** + * Copyright 2015-2016 Knowm Inc. (http://knowm.org) and contributors. + * Copyright 2011-2015 Xeiam LLC (http://xeiam.com) and contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.knowm.xchart.internal.chartpart; + +import org.knowm.xchart.Series_Category; +import org.knowm.xchart.Series_Category.ChartCategorySeriesRenderStyle; +import org.knowm.xchart.internal.Series; +import org.knowm.xchart.internal.style.StyleManagerAxesChart; +import org.knowm.xchart.StyleManagerCategory; + +/** + * @author timmolter + */ +public class Plot_Category<SM extends StyleManagerAxesChart, S extends Series> extends Plot_AxesChart { + + /** + * Constructor + * + * @param chart + */ + public Plot_Category(Chart<StyleManagerCategory, Series_Category> chart) { + + super(chart); + + StyleManagerCategory styleManagerCategory = chart.getStyleManager(); + + if (ChartCategorySeriesRenderStyle.Bar.equals(styleManagerCategory.getChartCategorySeriesRenderStyle())) { + + this.plotContent = new PlotContent_Category_Bar<StyleManagerCategory, Series_Category>(chart); + + } + else { + this.plotContent = new PlotContent_Category_Line_Area_Scatter<StyleManagerCategory, Series_Category>(chart); + + } + + } + +} diff --git a/xchart/src/main/java/org/knowm/xchart/internal/chartpart/Plot_Pie.java b/xchart/src/main/java/org/knowm/xchart/internal/chartpart/Plot_Pie.java new file mode 100644 index 0000000000000000000000000000000000000000..17bd0444b81e14a340b755069d34356c689f19cd --- /dev/null +++ b/xchart/src/main/java/org/knowm/xchart/internal/chartpart/Plot_Pie.java @@ -0,0 +1,69 @@ +/** + * Copyright 2015-2016 Knowm Inc. (http://knowm.org) and contributors. + * Copyright 2011-2015 Xeiam LLC (http://xeiam.com) and contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.knowm.xchart.internal.chartpart; + +import java.awt.Graphics2D; +import java.awt.geom.Rectangle2D; + +import org.knowm.xchart.Series_Pie; +import org.knowm.xchart.StyleManagerPie; +import org.knowm.xchart.internal.Series; +import org.knowm.xchart.internal.style.StyleManager; +import org.knowm.xchart.internal.style.StyleManager.LegendPosition; + +/** + * @author timmolter + */ +public class Plot_Pie<SM extends StyleManager, S extends Series> extends Plot_ { + + /** + * Constructor + * + * @param chart + */ + public Plot_Pie(Chart<StyleManagerPie, Series_Pie> chart) { + + super(chart); + this.plotContent = new PlotContent_Pie<StyleManagerPie, Series_Pie>(chart); + this.plotSurface = new PlotSurfacePie<StyleManagerPie, Series_Pie>(chart); + } + + @Override + public void paint(Graphics2D g) { + + // calculate bounds + double xOffset = chart.getStyleManager().getChartPadding(); + + double yOffset = chart.getChartTitle().getBounds().getY() + chart.getStyleManager().getChartPadding(); + + double width = + + chart.getWidth() + + - (chart.getStyleManager().getLegendPosition() == LegendPosition.OutsideE ? chart.getChartLegend().getBounds().getWidth() : 0) + + - 2 * chart.getStyleManager().getChartPadding() + + - (chart.getStyleManager().getLegendPosition() == LegendPosition.OutsideE && chart.getStyleManager().isLegendVisible() ? chart.getStyleManager().getChartPadding() : 0); + + double height = chart.getHeight() - chart.getChartTitle().getBounds().getHeight() - 2 * chart.getStyleManager().getChartPadding(); + + bounds = new Rectangle2D.Double(xOffset, yOffset, width, height); + + super.paint(g); + } +} diff --git a/xchart/src/main/java/org/knowm/xchart/internal/chartpart/Plot_XY.java b/xchart/src/main/java/org/knowm/xchart/internal/chartpart/Plot_XY.java new file mode 100644 index 0000000000000000000000000000000000000000..d4a42677103e48ed912683de8803725ac9434f27 --- /dev/null +++ b/xchart/src/main/java/org/knowm/xchart/internal/chartpart/Plot_XY.java @@ -0,0 +1,40 @@ +/** + * Copyright 2015-2016 Knowm Inc. (http://knowm.org) and contributors. + * Copyright 2011-2015 Xeiam LLC (http://xeiam.com) and contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.knowm.xchart.internal.chartpart; + +import org.knowm.xchart.Series_XY; +import org.knowm.xchart.StyleManagerXY; +import org.knowm.xchart.internal.Series; +import org.knowm.xchart.internal.style.StyleManagerAxesChart; + +/** + * @author timmolter + */ +public class Plot_XY<SM extends StyleManagerAxesChart, S extends Series> extends Plot_AxesChart { + + /** + * Constructor + * + * @param chart + */ + public Plot_XY(Chart<StyleManagerXY, Series_XY> chart) { + + super(chart); + this.plotContent = new PlotContent_XY<StyleManagerXY, Series_XY>(chart); + } + +} diff --git a/xchart/src/main/java/org/knowm/xchart/internal/chartpart/RenderableSeries.java b/xchart/src/main/java/org/knowm/xchart/internal/chartpart/RenderableSeries.java new file mode 100644 index 0000000000000000000000000000000000000000..ec94c8b89aab575fbea394527f6afe13b090827c --- /dev/null +++ b/xchart/src/main/java/org/knowm/xchart/internal/chartpart/RenderableSeries.java @@ -0,0 +1,31 @@ +/** + * Copyright 2015-2016 Knowm Inc. (http://knowm.org) and contributors. + * Copyright 2011-2015 Xeiam LLC (http://xeiam.com) and contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.knowm.xchart.internal.chartpart; + +/** + * @author timmolter + */ +public interface RenderableSeries { + + public enum LegendRenderType { + + Line, Scatter, Box + } + + public LegendRenderType getLegendRenderType(); + +} diff --git a/xchart/src/main/java/org/knowm/xchart/internal/package-info.java b/xchart/src/main/java/org/knowm/xchart/internal/package-info.java index 0e49633f8469f65b341ef469630f3fe42caa9f44..294b21ec7e7ff3d719223dfc51bfb55706931af9 100644 --- a/xchart/src/main/java/org/knowm/xchart/internal/package-info.java +++ b/xchart/src/main/java/org/knowm/xchart/internal/package-info.java @@ -1,10 +1,13 @@ /** - * Copyright 2015 Knowm Inc. (http://knowm.org) and contributors. + * Copyright 2015-2016 Knowm Inc. (http://knowm.org) and contributors. * Copyright 2011-2015 Xeiam LLC (http://xeiam.com) and contributors. + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. diff --git a/xchart/src/main/java/org/knowm/xchart/internal/style/GGPlot2Theme.java b/xchart/src/main/java/org/knowm/xchart/internal/style/GGPlot2Theme.java index ac9a333526090be89bef6f9e5decd8c5ac780299..aa23de61a5b6717bfc8acc36cb62e3d7e14becc8 100644 --- a/xchart/src/main/java/org/knowm/xchart/internal/style/GGPlot2Theme.java +++ b/xchart/src/main/java/org/knowm/xchart/internal/style/GGPlot2Theme.java @@ -1,5 +1,5 @@ /** - * Copyright 2015 Knowm Inc. (http://knowm.org) and contributors. + * Copyright 2015-2016 Knowm Inc. (http://knowm.org) and contributors. * Copyright 2011-2015 Xeiam LLC (http://xeiam.com) and contributors. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -24,10 +24,9 @@ import java.util.ArrayList; import java.util.List; import org.knowm.xchart.ChartColor; -import org.knowm.xchart.SeriesColor; import org.knowm.xchart.SeriesLineStyle; import org.knowm.xchart.SeriesMarker; -import org.knowm.xchart.StyleManager.LegendPosition; +import org.knowm.xchart.internal.style.StyleManager.LegendPosition; /** * @author timmolter @@ -35,20 +34,20 @@ import org.knowm.xchart.StyleManager.LegendPosition; public class GGPlot2Theme implements Theme { // The color blind friendly palette - // public static SeriesColor BLACK = new SeriesColor(0, 0, 0, 255); - // public static SeriesColor ORANGE = new SeriesColor(230, 159, 0, 255); - // public static SeriesColor SKY_BLUE = new SeriesColor(86, 180, 233, 255); - // public static SeriesColor BLUISH_GREEN = new SeriesColor(0, 158, 115, 255); - // public static SeriesColor YELLOW = new SeriesColor(240, 228, 66, 255); - // public static SeriesColor BLUE = new SeriesColor(0, 114, 178, 255); - // public static SeriesColor VERMILLION = new SeriesColor(213, 94, 0, 255); - // public static SeriesColor REDDISH_PURPLE = new SeriesColor(204, 121, 167, 255); - - public static SeriesColor RED = new SeriesColor(248, 118, 109, 255); - public static SeriesColor YELLOW_GREEN = new SeriesColor(163, 165, 0, 255); - public static SeriesColor GREEN = new SeriesColor(0, 191, 125, 255); - public static SeriesColor BLUE = new SeriesColor(0, 176, 246, 255); - public static SeriesColor PURPLE = new SeriesColor(231, 107, 243, 255); + // public static Color BLACK = new Color(0, 0, 0, 255); + // public static Color ORANGE = new Color(230, 159, 0, 255); + // public static Color SKY_BLUE = new Color(86, 180, 233, 255); + // public static Color BLUISH_GREEN = new Color(0, 158, 115, 255); + // public static Color YELLOW = new Color(240, 228, 66, 255); + // public static Color BLUE = new Color(0, 114, 178, 255); + // public static Color VERMILLION = new Color(213, 94, 0, 255); + // public static Color REDDISH_PURPLE = new Color(204, 121, 167, 255); + + public static Color RED = new Color(248, 118, 109, 255); + public static Color YELLOW_GREEN = new Color(163, 165, 0, 255); + public static Color GREEN = new Color(0, 191, 125, 255); + public static Color BLUE = new Color(0, 176, 246, 255); + public static Color PURPLE = new Color(231, 107, 243, 255); // Chart Style /////////////////////////////// @@ -73,7 +72,7 @@ public class GGPlot2Theme implements Theme { @Override public SeriesColorMarkerLineStyleCycler getSeriesColorMarkerLineStyleCycler() { - return new XChartSeriesColorMarkerLineStyleCycler(); + return new XChartColorMarkerLineStyleCycler(); } // Chart Title /////////////////////////////// @@ -361,13 +360,13 @@ public class GGPlot2Theme implements Theme { return false; } - public class XChartSeriesColorMarkerLineStyleCycler extends SeriesColorMarkerLineStyleCycler { + public class XChartColorMarkerLineStyleCycler extends SeriesColorMarkerLineStyleCycler { @Override - public List<SeriesColor> getSeriesColorList() { + public List<Color> getColorList() { // 1. Color - List<SeriesColor> seriesColorMap = new ArrayList<SeriesColor>(); + List<Color> seriesColorMap = new ArrayList<Color>(); // The color blind friendly palette // seriesColorMap.add(BLACK); diff --git a/xchart/src/main/java/org/knowm/xchart/internal/style/MatlabTheme.java b/xchart/src/main/java/org/knowm/xchart/internal/style/MatlabTheme.java index 8996dde5939b078e418665ef002f3fce255cd57e..dfacbea5a90095b41bea635e4b9dee1b9bc1772b 100644 --- a/xchart/src/main/java/org/knowm/xchart/internal/style/MatlabTheme.java +++ b/xchart/src/main/java/org/knowm/xchart/internal/style/MatlabTheme.java @@ -1,5 +1,5 @@ /** - * Copyright 2015 Knowm Inc. (http://knowm.org) and contributors. + * Copyright 2015-2016 Knowm Inc. (http://knowm.org) and contributors. * Copyright 2011-2015 Xeiam LLC (http://xeiam.com) and contributors. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -24,23 +24,22 @@ import java.util.ArrayList; import java.util.List; import org.knowm.xchart.ChartColor; -import org.knowm.xchart.SeriesColor; import org.knowm.xchart.SeriesLineStyle; import org.knowm.xchart.SeriesMarker; -import org.knowm.xchart.StyleManager.LegendPosition; +import org.knowm.xchart.internal.style.StyleManager.LegendPosition; /** * @author timmolter */ public class MatlabTheme implements Theme { - public static SeriesColor BLUE = new SeriesColor(0, 0, 255, 255); - public static SeriesColor GREEN = new SeriesColor(0, 128, 0, 255); - public static SeriesColor RED = new SeriesColor(255, 0, 0, 255); - public static SeriesColor TURQUOISE = new SeriesColor(0, 191, 191, 255); - public static SeriesColor MAGENTA = new SeriesColor(191, 0, 191, 255); - public static SeriesColor YELLOW = new SeriesColor(191, 191, 0, 255); - public static SeriesColor DARK_GREY = new SeriesColor(64, 64, 64, 255); + public static Color BLUE = new Color(0, 0, 255, 255); + public static Color GREEN = new Color(0, 128, 0, 255); + public static Color RED = new Color(255, 0, 0, 255); + public static Color TURQUOISE = new Color(0, 191, 191, 255); + public static Color MAGENTA = new Color(191, 0, 191, 255); + public static Color YELLOW = new Color(191, 191, 0, 255); + public static Color DARK_GREY = new Color(64, 64, 64, 255); // Chart Style /////////////////////////////// @@ -65,7 +64,7 @@ public class MatlabTheme implements Theme { @Override public SeriesColorMarkerLineStyleCycler getSeriesColorMarkerLineStyleCycler() { - return new MatlabSeriesColorMarkerLineStyleCycler(); + return new MatlabColorMarkerLineStyleCycler(); } // Chart Title /////////////////////////////// @@ -354,13 +353,13 @@ public class MatlabTheme implements Theme { return false; } - public class MatlabSeriesColorMarkerLineStyleCycler extends SeriesColorMarkerLineStyleCycler { + public class MatlabColorMarkerLineStyleCycler extends SeriesColorMarkerLineStyleCycler { @Override - public List<SeriesColor> getSeriesColorList() { + public List<Color> getColorList() { // 1. Color - List<SeriesColor> seriesColorMap = new ArrayList<SeriesColor>(); + List<Color> seriesColorMap = new ArrayList<Color>(); seriesColorMap.add(BLUE); seriesColorMap.add(GREEN); seriesColorMap.add(RED); diff --git a/xchart/src/main/java/org/knowm/xchart/internal/style/SeriesColorMarkerLineStyle.java b/xchart/src/main/java/org/knowm/xchart/internal/style/SeriesColorMarkerLineStyle.java index 6ddf7871318b65a62b09ded0a69721d339d26edb..d8752d97cf1fb82c1a499cbb19516a7f57287c48 100644 --- a/xchart/src/main/java/org/knowm/xchart/internal/style/SeriesColorMarkerLineStyle.java +++ b/xchart/src/main/java/org/knowm/xchart/internal/style/SeriesColorMarkerLineStyle.java @@ -1,5 +1,5 @@ /** - * Copyright 2015 Knowm Inc. (http://knowm.org) and contributors. + * Copyright 2015-2016 Knowm Inc. (http://knowm.org) and contributors. * Copyright 2011-2015 Xeiam LLC (http://xeiam.com) and contributors. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -19,7 +19,7 @@ package org.knowm.xchart.internal.style; import java.awt.BasicStroke; import java.awt.Color; -import org.knowm.xchart.internal.markers.Marker; +import org.knowm.xchart.internal.style.markers.Marker; /** * A DTO to hold the Series' Color, Marker, and LineStyle diff --git a/xchart/src/main/java/org/knowm/xchart/internal/style/SeriesColorMarkerLineStyleCycler.java b/xchart/src/main/java/org/knowm/xchart/internal/style/SeriesColorMarkerLineStyleCycler.java index 31399dcb7a329a27aa8f162421d313d6e84e1f40..f2c56b067d27167af8677451b5e00468296237bf 100644 --- a/xchart/src/main/java/org/knowm/xchart/internal/style/SeriesColorMarkerLineStyleCycler.java +++ b/xchart/src/main/java/org/knowm/xchart/internal/style/SeriesColorMarkerLineStyleCycler.java @@ -1,5 +1,5 @@ /** - * Copyright 2015 Knowm Inc. (http://knowm.org) and contributors. + * Copyright 2015-2016 Knowm Inc. (http://knowm.org) and contributors. * Copyright 2011-2015 Xeiam LLC (http://xeiam.com) and contributors. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -16,9 +16,9 @@ */ package org.knowm.xchart.internal.style; +import java.awt.Color; import java.util.List; -import org.knowm.xchart.SeriesColor; import org.knowm.xchart.SeriesLineStyle; import org.knowm.xchart.SeriesMarker; @@ -31,14 +31,14 @@ import org.knowm.xchart.SeriesMarker; */ public abstract class SeriesColorMarkerLineStyleCycler { - public abstract List<SeriesColor> getSeriesColorList(); + public abstract List<Color> getColorList(); public abstract List<SeriesMarker> getSeriesMarkerList(); public abstract List<SeriesLineStyle> getLineStyleList(); - /** a List holding the SeriesColors */ - private final List<SeriesColor> seriesColorList; + /** a List holding the Colors */ + private final List<Color> seriesColorList; /** a map holding the SeriesMarkers */ private final List<SeriesMarker> seriesMarkerList; @@ -56,15 +56,15 @@ public abstract class SeriesColorMarkerLineStyleCycler { */ public SeriesColorMarkerLineStyleCycler() { - seriesColorList = getSeriesColorList(); + seriesColorList = getColorList(); seriesMarkerList = getSeriesMarkerList(); seriesLineStyleList = getLineStyleList(); } /** - * Get the next SeriesColorMarkerLineStyle + * Get the next ColorMarkerLineStyle * - * @return the next SeriesColorMarkerLineStyle + * @return the next ColorMarkerLineStyle */ public SeriesColorMarkerLineStyle getNextSeriesColorMarkerLineStyle() { @@ -73,7 +73,7 @@ public abstract class SeriesColorMarkerLineStyleCycler { colorCounter = 0; strokeCounter++; } - SeriesColor seriesColor = seriesColorList.get(colorCounter++); + Color seriesColor = seriesColorList.get(colorCounter++); // 2. Stroke - cycle through strokes one by one but only after a color cycle if (strokeCounter >= seriesLineStyleList.size()) { @@ -87,6 +87,6 @@ public abstract class SeriesColorMarkerLineStyleCycler { } SeriesMarker marker = seriesMarkerList.get(markerCounter++); - return new SeriesColorMarkerLineStyle(seriesColor.getColor(), marker.getMarker(), seriesLineStyle.getBasicStroke()); + return new SeriesColorMarkerLineStyle(seriesColor, marker.getMarker(), seriesLineStyle.getBasicStroke()); } } diff --git a/xchart/src/main/java/org/knowm/xchart/internal/style/StyleManager.java b/xchart/src/main/java/org/knowm/xchart/internal/style/StyleManager.java new file mode 100644 index 0000000000000000000000000000000000000000..2aa2689e91dbd6266fd8dff998943f8e2db573ff --- /dev/null +++ b/xchart/src/main/java/org/knowm/xchart/internal/style/StyleManager.java @@ -0,0 +1,429 @@ +/** + * Copyright 2015-2016 Knowm Inc. (http://knowm.org) and contributors. + * Copyright 2011-2015 Xeiam LLC (http://xeiam.com) and contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.knowm.xchart.internal.style; + +import java.awt.Color; +import java.awt.Font; + +/** + * The StyleManager is used to manage all things related to styling of the vast number of Chart components + * + * @author timmolter + */ +public abstract class StyleManager { + + public enum LegendPosition { + + OutsideE, InsideNW, InsideNE, InsideSE, InsideSW, InsideN + } + + public enum ChartTheme { + + XChart, GGPlot2, Matlab; + + public Theme newInstance(ChartTheme chartTheme) { + + switch (chartTheme) { + case GGPlot2: + return new GGPlot2Theme(); + + case Matlab: + return new MatlabTheme(); + + case XChart: + default: + return new XChartTheme(); + } + } + } + + public enum TextAlignment { + + Left, Centre, Right; + } + + /** the default Theme */ + protected Theme theme = new XChartTheme(); + + // Chart Style /////////////////////////////// + private Color chartBackgroundColor; + private Color chartFontColor; + private int chartPadding; + private SeriesColorMarkerLineStyleCycler seriesColorMarkerLineStyleCycler; + + // Chart Title /////////////////////////////// + private Font chartTitleFont; + private boolean isChartTitleVisible; + private boolean isChartTitleBoxVisible; + private Color chartTitleBoxBackgroundColor; + private Color chartTitleBoxBorderColor; + private int chartTitlePadding; + + // Chart Legend /////////////////////////////// + private boolean isLegendVisible; + private Color legendBackgroundColor; + private Color legendBorderColor; + private Font legendFont; + private int legendPadding; + private int legendSeriesLineLength; + private LegendPosition legendPosition; + + // Chart Plot Area /////////////////////////////// + private Color plotBackgroundColor; + private Color plotBorderColor; + private boolean isPlotBorderVisible; + + protected void setAllStyles() { + + // Chart Style /////////////////////////////// + chartBackgroundColor = theme.getChartBackgroundColor(); + chartFontColor = theme.getChartFontColor(); + chartPadding = theme.getChartPadding(); + seriesColorMarkerLineStyleCycler = theme.getSeriesColorMarkerLineStyleCycler(); + + // Chart Title /////////////////////////////// + chartTitleFont = theme.getChartTitleFont(); + isChartTitleVisible = theme.isChartTitleVisible(); + isChartTitleBoxVisible = theme.isChartTitleBoxVisible(); + chartTitleBoxBackgroundColor = theme.getChartTitleBoxBackgroundColor(); + chartTitleBoxBorderColor = theme.getChartTitleBoxBorderColor(); + chartTitlePadding = theme.getChartTitlePadding(); + + // legend + isLegendVisible = theme.isLegendVisible(); + legendBackgroundColor = theme.getLegendBackgroundColor(); + legendBorderColor = theme.getLegendBorderColor(); + legendFont = theme.getLegendFont(); + legendPadding = theme.getLegendPadding(); + legendSeriesLineLength = theme.getLegendSeriesLineLength(); + legendPosition = theme.getLegendPosition(); + + // Chart Plot Area /////////////////////////////// + plotBackgroundColor = theme.getPlotBackgroundColor(); + plotBorderColor = theme.getPlotBorderColor(); + isPlotBorderVisible = theme.isPlotBorderVisible(); + } + + // Chart Style /////////////////////////////// + + /** + * Set the chart background color - the part around the edge of the chart + * + * @param color + */ + public void setChartBackgroundColor(Color color) { + + this.chartBackgroundColor = color; + } + + public Color getChartBackgroundColor() { + + return chartBackgroundColor; + } + + /** + * Set the chart font color. includes: Chart title, axes label, legend + * + * @param color + */ + public void setChartFontColor(Color color) { + + this.chartFontColor = color; + } + + public Color getChartFontColor() { + + return chartFontColor; + } + + /** + * Set the chart padding + * + * @param chartPadding + */ + public void setChartPadding(int chartPadding) { + + this.chartPadding = chartPadding; + } + + public int getChartPadding() { + + return chartPadding; + } + + public SeriesColorMarkerLineStyleCycler getSeriesColorMarkerLineStyleCycler() { + + return seriesColorMarkerLineStyleCycler; + } + + public void setSeriesColorMarkerLineStyleCycler(SeriesColorMarkerLineStyleCycler seriesColorMarkerLineStyleCycler) { + + this.seriesColorMarkerLineStyleCycler = seriesColorMarkerLineStyleCycler; + } + + // Chart Title /////////////////////////////// + + /** + * Set the chart title font + * + * @param font + */ + public void setChartTitleFont(Font chartTitleFont) { + + this.chartTitleFont = chartTitleFont; + } + + public Font getChartTitleFont() { + + return chartTitleFont; + } + + /** + * Set the chart title visibility + * + * @param isChartTitleVisible + */ + public void setChartTitleVisible(boolean isChartTitleVisible) { + + this.isChartTitleVisible = isChartTitleVisible; + } + + public boolean isChartTitleVisible() { + + return isChartTitleVisible; + } + + /** + * Set the chart title box visibility + * + * @param isChartTitleBoxVisible + */ + public void setChartTitleBoxVisible(boolean isChartTitleBoxVisible) { + + this.isChartTitleBoxVisible = isChartTitleBoxVisible; + } + + public boolean isChartTitleBoxVisible() { + + return isChartTitleBoxVisible; + } + + /** + * set the chart title box background color + * + * @param chartTitleBoxBackgroundColor + */ + public void setChartTitleBoxBackgroundColor(Color chartTitleBoxBackgroundColor) { + + this.chartTitleBoxBackgroundColor = chartTitleBoxBackgroundColor; + } + + public Color getChartTitleBoxBackgroundColor() { + + return chartTitleBoxBackgroundColor; + } + + /** + * set the chart title box border color + * + * @param chartTitleBoxBorderColor + */ + public void setChartTitleBoxBorderColor(Color chartTitleBoxBorderColor) { + + this.chartTitleBoxBorderColor = chartTitleBoxBorderColor; + } + + public Color getChartTitleBoxBorderColor() { + + return chartTitleBoxBorderColor; + } + + /** + * set the chart title padding; the space between the chart title and the plot area + * + * @param chartTitlePadding + */ + public void setChartTitlePadding(int chartTitlePadding) { + + this.chartTitlePadding = chartTitlePadding; + } + + public int getChartTitlePadding() { + + return chartTitlePadding; + } + + // Chart Legend /////////////////////////////// + + /** + * Set the chart legend background color + * + * @param color + */ + public void setLegendBackgroundColor(Color color) { + + this.legendBackgroundColor = color; + } + + public Color getLegendBackgroundColor() { + + return legendBackgroundColor; + } + + /** + * Set the chart legend border color + * + * @return + */ + public Color getLegendBorderColor() { + + return legendBorderColor; + } + + public void setLegendBorderColor(Color legendBorderColor) { + + this.legendBorderColor = legendBorderColor; + } + + /** + * Set the chart legend font + * + * @param font + */ + public void setLegendFont(Font font) { + + this.legendFont = font; + } + + public Font getLegendFont() { + + return legendFont; + } + + /** + * Set the chart legend visibility + * + * @param isLegendVisible + */ + public void setLegendVisible(boolean isLegendVisible) { + + this.isLegendVisible = isLegendVisible; + } + + public boolean isLegendVisible() { + + return isLegendVisible; + } + + /** + * Set the chart legend padding + * + * @param legendPadding + */ + public void setLegendPadding(int legendPadding) { + + this.legendPadding = legendPadding; + } + + public int getLegendPadding() { + + return legendPadding; + } + + /** + * Set the chart legend series line length + * + * @param legendPadding + */ + public void setLegendSeriesLineLength(int legendSeriesLineLength) { + + if (legendSeriesLineLength < 0) { + this.legendSeriesLineLength = 0; + } + else { + this.legendSeriesLineLength = legendSeriesLineLength; + } + } + + public int getLegendSeriesLineLength() { + + return legendSeriesLineLength; + } + + /** + * sets the legend position + * + * @param legendPosition + */ + public void setLegendPosition(LegendPosition legendPosition) { + + this.legendPosition = legendPosition; + } + + public LegendPosition getLegendPosition() { + + return legendPosition; + } + + // Chart Plot /////////////////////////////// + + /** + * set the plot area's background color + * + * @param plotBackgroundColor + */ + public void setPlotBackgroundColor(Color plotBackgroundColor) { + + this.plotBackgroundColor = plotBackgroundColor; + } + + public Color getPlotBackgroundColor() { + + return plotBackgroundColor; + } + + /** + * set the plot area's border color + * + * @param plotBorderColor + */ + public void setPlotBorderColor(Color plotBorderColor) { + + this.plotBorderColor = plotBorderColor; + } + + public Color getPlotBorderColor() { + + return plotBorderColor; + } + + /** + * sets the visibility of the border around the plot area + * + * @param isPlotBorderVisible + */ + public void setPlotBorderVisible(boolean isPlotBorderVisible) { + + this.isPlotBorderVisible = isPlotBorderVisible; + } + + public boolean isPlotBorderVisible() { + + return isPlotBorderVisible; + } + +} diff --git a/xchart/src/main/java/org/knowm/xchart/StyleManager.java b/xchart/src/main/java/org/knowm/xchart/internal/style/StyleManagerAxesChart.java similarity index 65% rename from xchart/src/main/java/org/knowm/xchart/StyleManager.java rename to xchart/src/main/java/org/knowm/xchart/internal/style/StyleManagerAxesChart.java index b7c0acfbf2bee32930fde289f17e04d8ec9fe327..61635c09e8839a90672a5dc18d1235bf348bf01f 100644 --- a/xchart/src/main/java/org/knowm/xchart/StyleManager.java +++ b/xchart/src/main/java/org/knowm/xchart/internal/style/StyleManagerAxesChart.java @@ -1,5 +1,5 @@ /** - * Copyright 2015 Knowm Inc. (http://knowm.org) and contributors. + * Copyright 2015-2016 Knowm Inc. (http://knowm.org) and contributors. * Copyright 2011-2015 Xeiam LLC (http://xeiam.com) and contributors. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.knowm.xchart; +package org.knowm.xchart.internal.style; import java.awt.Color; import java.awt.Font; @@ -22,79 +22,10 @@ import java.awt.Stroke; import java.util.Locale; import java.util.TimeZone; -import org.knowm.xchart.internal.style.GGPlot2Theme; -import org.knowm.xchart.internal.style.MatlabTheme; -import org.knowm.xchart.internal.style.SeriesColorMarkerLineStyleCycler; -import org.knowm.xchart.internal.style.Theme; -import org.knowm.xchart.internal.style.XChartTheme; - /** - * The StyleManager is used to manage all things related to styling of the vast number of Chart components - * * @author timmolter */ -public class StyleManager { - - public enum ChartType { - - Line, Scatter, Area, Bar, Pie - } - - public enum LegendPosition { - - OutsideE, InsideNW, InsideNE, InsideSE, InsideSW, InsideN - } - - public enum ChartTheme { - - XChart, GGPlot2, Matlab; - - public Theme newInstance(ChartTheme chartTheme) { - - switch (chartTheme) { - case GGPlot2: - return new GGPlot2Theme(); - - case Matlab: - return new MatlabTheme(); - - case XChart: - default: - return new XChartTheme(); - } - } - } - - public enum TextAlignment { - Left, Centre, Right; - } - - /** the default Theme */ - private Theme theme = new XChartTheme(); - - // Chart Style /////////////////////////////// - private ChartType chartType; - private Color chartBackgroundColor; - public Color chartFontColor; - private int chartPadding; - private SeriesColorMarkerLineStyleCycler seriesColorMarkerLineStyleCycler; - - // Chart Title /////////////////////////////// - private Font chartTitleFont; - private boolean isChartTitleVisible; - private boolean isChartTitleBoxVisible; - private Color chartTitleBoxBackgroundColor; - private Color chartTitleBoxBorderColor; - private int chartTitlePadding; - - // Chart Legend /////////////////////////////// - private boolean isLegendVisible; - private Color legendBackgroundColor; - private Color legendBorderColor; - private Font legendFont; - private int legendPadding; - private int legendSeriesLineLength; - private LegendPosition legendPosition; +public abstract class StyleManagerAxesChart extends StyleManager { // Chart Axes /////////////////////////////// private boolean xAxisTitleVisible; @@ -128,9 +59,6 @@ public class StyleManager { // Chart Plot Area /////////////////////////////// private boolean isPlotGridHorizontalLinesVisible; private boolean isPlotGridVerticalLinesVisible; - private Color plotBackgroundColor; - private Color plotBorderColor; - private boolean isPlotBorderVisible; private boolean isPlotTicksMarksVisible; private Color plotGridLinesColor; private Stroke plotGridLinesStroke; @@ -155,39 +83,10 @@ public class StyleManager { private String xAxisDecimalPattern; private String yAxisDecimalPattern; - /** - * Constructor - */ - public StyleManager() { - - setAllStyles(); - } - - private void setAllStyles() { - - // Chart Style /////////////////////////////// - chartType = ChartType.Line; - chartBackgroundColor = theme.getChartBackgroundColor(); - chartFontColor = theme.getChartFontColor(); - chartPadding = theme.getChartPadding(); - seriesColorMarkerLineStyleCycler = theme.getSeriesColorMarkerLineStyleCycler(); + @Override + protected void setAllStyles() { - // Chart Title /////////////////////////////// - chartTitleFont = theme.getChartTitleFont(); - isChartTitleVisible = theme.isChartTitleVisible(); - isChartTitleBoxVisible = theme.isChartTitleBoxVisible(); - chartTitleBoxBackgroundColor = theme.getChartTitleBoxBackgroundColor(); - chartTitleBoxBorderColor = theme.getChartTitleBoxBorderColor(); - chartTitlePadding = theme.getChartTitlePadding(); - - // legend - isLegendVisible = theme.isLegendVisible(); - legendBackgroundColor = theme.getLegendBackgroundColor(); - legendBorderColor = theme.getLegendBorderColor(); - legendFont = theme.getLegendFont(); - legendPadding = theme.getLegendPadding(); - legendSeriesLineLength = theme.getLegendSeriesLineLength(); - legendPosition = theme.getLegendPosition(); + super.setAllStyles(); // axes xAxisTitleVisible = theme.isXAxisTitleVisible(); @@ -213,14 +112,11 @@ public class StyleManager { xAxisMax = null; yAxisMin = null; yAxisMax = null; - axisTickSpacePercentage = .95; + axisTickSpacePercentage = .92; // Chart Plot Area /////////////////////////////// isPlotGridVerticalLinesVisible = theme.isPlotGridVerticalLinesVisible(); isPlotGridHorizontalLinesVisible = theme.isPlotGridHorizontalLinesVisible(); - plotBackgroundColor = theme.getPlotBackgroundColor(); - plotBorderColor = theme.getPlotBorderColor(); - isPlotBorderVisible = theme.isPlotBorderVisible(); isPlotTicksMarksVisible = theme.isPlotTicksMarksVisible(); plotGridLinesColor = theme.getPlotGridLinesColor(); plotGridLinesStroke = theme.getPlotGridLinesStroke(); @@ -231,7 +127,6 @@ public class StyleManager { isBarFilled = theme.isBarFilled(); // Line, Scatter, Area Charts /////////////////////////////// - markerSize = theme.getMarkerSize(); // Error Bars /////////////////////////////// @@ -247,298 +142,6 @@ public class StyleManager { yAxisDecimalPattern = null; } - /** - * Set the theme the style manager should use - * - * @param theme - */ - protected void setTheme(Theme theme) { - - this.theme = theme; - setAllStyles(); - } - - public Theme getTheme() { - - return theme; - } - - // 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 - * - * @param color - */ - public void setChartBackgroundColor(Color color) { - - this.chartBackgroundColor = color; - } - - public Color getChartBackgroundColor() { - - return chartBackgroundColor; - } - - /** - * Set the chart font color. includes: Chart title, axes label, legend - * - * @param color - */ - public void setChartFontColor(Color color) { - - this.chartFontColor = color; - } - - public Color getChartFontColor() { - - return chartFontColor; - } - - /** - * Set the chart padding - * - * @param chartPadding - */ - public void setChartPadding(int chartPadding) { - - this.chartPadding = chartPadding; - } - - public int getChartPadding() { - - return chartPadding; - } - - public SeriesColorMarkerLineStyleCycler getSeriesColorMarkerLineStyleCycler() { - - return seriesColorMarkerLineStyleCycler; - } - - public void setSeriesColorMarkerLineStyleCycler(SeriesColorMarkerLineStyleCycler seriesColorMarkerLineStyleCycler) { - - this.seriesColorMarkerLineStyleCycler = seriesColorMarkerLineStyleCycler; - } - - // Chart Title /////////////////////////////// - - /** - * Set the chart title font - * - * @param font - */ - public void setChartTitleFont(Font chartTitleFont) { - - this.chartTitleFont = chartTitleFont; - } - - public Font getChartTitleFont() { - - return chartTitleFont; - } - - /** - * Set the chart title visibility - * - * @param isChartTitleVisible - */ - public void setChartTitleVisible(boolean isChartTitleVisible) { - - this.isChartTitleVisible = isChartTitleVisible; - } - - public boolean isChartTitleVisible() { - - return isChartTitleVisible; - } - - /** - * Set the chart title box visibility - * - * @param isChartTitleBoxVisible - */ - public void setChartTitleBoxVisible(boolean isChartTitleBoxVisible) { - - this.isChartTitleBoxVisible = isChartTitleBoxVisible; - } - - public boolean isChartTitleBoxVisible() { - - return isChartTitleBoxVisible; - } - - /** - * set the chart title box background color - * - * @param chartTitleBoxBackgroundColor - */ - public void setChartTitleBoxBackgroundColor(Color chartTitleBoxBackgroundColor) { - - this.chartTitleBoxBackgroundColor = chartTitleBoxBackgroundColor; - } - - public Color getChartTitleBoxBackgroundColor() { - - return chartTitleBoxBackgroundColor; - } - - /** - * set the chart title box border color - * - * @param chartTitleBoxBorderColor - */ - public void setChartTitleBoxBorderColor(Color chartTitleBoxBorderColor) { - - this.chartTitleBoxBorderColor = chartTitleBoxBorderColor; - } - - public Color getChartTitleBoxBorderColor() { - - return chartTitleBoxBorderColor; - } - - /** - * set the chart title padding; the space between the chart title and the plot area - * - * @param chartTitlePadding - */ - public void setChartTitlePadding(int chartTitlePadding) { - - this.chartTitlePadding = chartTitlePadding; - } - - public int getChartTitlePadding() { - - return chartTitlePadding; - } - - // Chart Legend /////////////////////////////// - - /** - * Set the chart legend background color - * - * @param color - */ - public void setLegendBackgroundColor(Color color) { - - this.legendBackgroundColor = color; - } - - public Color getLegendBackgroundColor() { - - return legendBackgroundColor; - } - - /** - * Set the chart legend border color - * - * @return - */ - public Color getLegendBorderColor() { - - return legendBorderColor; - } - - public void setLegendBorderColor(Color legendBorderColor) { - - this.legendBorderColor = legendBorderColor; - } - - /** - * Set the chart legend font - * - * @param font - */ - public void setLegendFont(Font font) { - - this.legendFont = font; - } - - public Font getLegendFont() { - - return legendFont; - } - - /** - * Set the chart legend visibility - * - * @param isLegendVisible - */ - public void setLegendVisible(boolean isLegendVisible) { - - this.isLegendVisible = isLegendVisible; - } - - public boolean isLegendVisible() { - - return isLegendVisible; - } - - /** - * Set the chart legend padding - * - * @param legendPadding - */ - public void setLegendPadding(int legendPadding) { - - this.legendPadding = legendPadding; - } - - public int getLegendPadding() { - - return legendPadding; - } - - /** - * Set the chart legend series line length - * - * @param legendPadding - */ - public void setLegendSeriesLineLength(int legendSeriesLineLength) { - - if (legendSeriesLineLength < 0) { - this.legendSeriesLineLength = 0; - } - else { - this.legendSeriesLineLength = legendSeriesLineLength; - } - } - - public int getLegendSeriesLineLength() { - - return legendSeriesLineLength; - } - - /** - * sets the legend position - * - * @param legendPosition - */ - public void setLegendPosition(LegendPosition legendPosition) { - - this.legendPosition = legendPosition; - } - - public LegendPosition getLegendPosition() { - - return legendPosition; - } - // Chart Axes /////////////////////////////// /** @@ -561,6 +164,7 @@ public class StyleManager { * * @param isVisible */ + public void setYAxisTitleVisible(boolean yAxisTitleVisible) { this.yAxisTitleVisible = yAxisTitleVisible; @@ -576,6 +180,7 @@ public class StyleManager { * * @param isVisible */ + public void setAxisTitlesVisible(boolean isVisible) { this.xAxisTitleVisible = isVisible; @@ -587,6 +192,7 @@ public class StyleManager { * * @param axisTitleFont */ + public void setAxisTitleFont(Font axisTitleFont) { this.axisTitleFont = axisTitleFont; @@ -634,6 +240,7 @@ public class StyleManager { * * @param isVisible */ + public void setAxisTicksVisible(boolean isVisible) { this.xAxisTicksVisible = isVisible; @@ -645,6 +252,7 @@ public class StyleManager { * * @param foxAxisTicksFontnt */ + public void setAxisTickLabelsFont(Font axisTicksFont) { this.axisTickLabelsFont = axisTicksFont; @@ -660,6 +268,7 @@ public class StyleManager { * * @param axisTickMarkLength */ + public void setAxisTickMarkLength(int axisTickMarkLength) { this.axisTickMarkLength = axisTickMarkLength; @@ -675,6 +284,7 @@ public class StyleManager { * * @param axisTickPadding */ + public void setAxisTickPadding(int axisTickPadding) { this.axisTickPadding = axisTickPadding; @@ -690,6 +300,7 @@ public class StyleManager { * * @param axisTickColor */ + public void setAxisTickMarksColor(Color axisTickColor) { this.axisTickMarksColor = axisTickColor; @@ -705,6 +316,7 @@ public class StyleManager { * * @param axisTickMarksStroke */ + public void setAxisTickMarksStroke(Stroke axisTickMarksStroke) { this.axisTickMarksStroke = axisTickMarksStroke; @@ -720,6 +332,7 @@ public class StyleManager { * * @param axisTickLabelsColor */ + public void setAxisTickLabelsColor(Color axisTickLabelsColor) { this.axisTickLabelsColor = axisTickLabelsColor; @@ -735,6 +348,7 @@ public class StyleManager { * * @param isAxisTicksLineVisible */ + public void setAxisTicksLineVisible(boolean isAxisTicksLineVisible) { this.isAxisTicksLineVisible = isAxisTicksLineVisible; @@ -750,6 +364,7 @@ public class StyleManager { * * @param isAxisTicksMarksVisible */ + public void setAxisTicksMarksVisible(boolean isAxisTicksMarksVisible) { this.isAxisTicksMarksVisible = isAxisTicksMarksVisible; @@ -765,6 +380,7 @@ public class StyleManager { * * @param plotPadding */ + public void setPlotPadding(int plotPadding) { this.plotPadding = plotPadding; @@ -780,6 +396,7 @@ public class StyleManager { * * @param axisTitlePadding */ + public void setAxisTitlePadding(int axisTitlePadding) { this.axisTitlePadding = axisTitlePadding; @@ -795,6 +412,7 @@ public class StyleManager { * * @param xAxisTickMarkSpacingHint */ + public void setXAxisTickMarkSpacingHint(int xAxisTickMarkSpacingHint) { this.xAxisTickMarkSpacingHint = xAxisTickMarkSpacingHint; @@ -810,6 +428,7 @@ public class StyleManager { * * @param xAxisTickMarkSpacingHint */ + public void setYAxisTickMarkSpacingHint(int yAxisTickMarkSpacingHint) { this.yAxisTickMarkSpacingHint = yAxisTickMarkSpacingHint; @@ -825,6 +444,7 @@ public class StyleManager { * * @param isxAxisLogarithmic */ + public void setXAxisLogarithmic(boolean isXAxisLogarithmic) { this.isXAxisLogarithmic = isXAxisLogarithmic; @@ -840,6 +460,7 @@ public class StyleManager { * * @param isyAxisLogarithmic */ + public void setYAxisLogarithmic(boolean isYAxisLogarithmic) { this.isYAxisLogarithmic = isYAxisLogarithmic; @@ -937,6 +558,7 @@ public class StyleManager { * * @param isPlotGridLinesVisible */ + public void setPlotGridLinesVisible(boolean isPlotGridLinesVisible) { this.isPlotGridHorizontalLinesVisible = isPlotGridLinesVisible; @@ -953,6 +575,7 @@ public class StyleManager { * * @param isPlotGridLinesVisible */ + public void setPlotGridHorizontalLinesVisible(boolean isPlotGridHorizontalLinesVisible) { this.isPlotGridHorizontalLinesVisible = isPlotGridHorizontalLinesVisible; @@ -968,6 +591,7 @@ public class StyleManager { * * @param isPlotGridLinesVisible */ + public void setPlotGridVerticalLinesVisible(boolean isPlotGridVerticalLinesVisible) { this.isPlotGridVerticalLinesVisible = isPlotGridVerticalLinesVisible; @@ -978,56 +602,12 @@ public class StyleManager { return isPlotGridVerticalLinesVisible; } - /** - * set the plot area's background color - * - * @param plotBackgroundColor - */ - public void setPlotBackgroundColor(Color plotBackgroundColor) { - - this.plotBackgroundColor = plotBackgroundColor; - } - - public Color getPlotBackgroundColor() { - - return plotBackgroundColor; - } - - /** - * set the plot area's border color - * - * @param plotBorderColor - */ - public void setPlotBorderColor(Color plotBorderColor) { - - this.plotBorderColor = plotBorderColor; - } - - public Color getPlotBorderColor() { - - return plotBorderColor; - } - - /** - * sets the visibility of the border around the plot area - * - * @param isPlotBorderVisible - */ - public void setPlotBorderVisible(boolean isPlotBorderVisible) { - - this.isPlotBorderVisible = isPlotBorderVisible; - } - - public boolean isPlotBorderVisible() { - - return isPlotBorderVisible; - } - /** * sets the visibility of the ticks marks inside the plot area * * @param isPlotTicksMarksVisible */ + public void setPlotTicksMarksVisible(boolean isPlotTicksMarksVisible) { this.isPlotTicksMarksVisible = isPlotTicksMarksVisible; @@ -1043,6 +623,7 @@ public class StyleManager { * * @param plotGridLinesColor */ + public void setPlotGridLinesColor(Color plotGridLinesColor) { this.plotGridLinesColor = plotGridLinesColor; @@ -1058,6 +639,7 @@ public class StyleManager { * * @param plotGridLinesStroke */ + public void setPlotGridLinesStroke(Stroke plotGridLinesStroke) { this.plotGridLinesStroke = plotGridLinesStroke; @@ -1075,6 +657,7 @@ public class StyleManager { * * @param barWidthPercentage */ + public void setBarWidthPercentage(double barWidthPercentage) { this.barWidthPercentage = barWidthPercentage; @@ -1090,6 +673,7 @@ public class StyleManager { * * @param isBarsOverlapped */ + public void setBarsOverlapped(boolean isBarsOverlapped) { this.isBarsOverlapped = isBarsOverlapped; @@ -1105,6 +689,7 @@ public class StyleManager { * * @param isBarFilled */ + public void setBarFilled(boolean isBarFilled) { this.isBarFilled = isBarFilled; @@ -1122,6 +707,7 @@ public class StyleManager { * * @param markerSize */ + public void setMarkerSize(int markerSize) { this.markerSize = markerSize; @@ -1139,6 +725,7 @@ public class StyleManager { * * @param errorBarsColor */ + public void setErrorBarsColor(Color errorBarsColor) { this.errorBarsColor = errorBarsColor; @@ -1154,6 +741,7 @@ public class StyleManager { * * @return */ + public void setErrorBarsColorSeriesColor(boolean isErrorBarsColorSeriesColor) { this.isErrorBarsColorSeriesColor = isErrorBarsColorSeriesColor; @@ -1171,6 +759,7 @@ public class StyleManager { * * @param locale - the locale to use when formatting Strings and dates for the axis tick labels */ + public void setLocale(Locale locale) { this.locale = locale; @@ -1186,6 +775,7 @@ public class StyleManager { * * @param timezone the timezone to use when formatting date data */ + public void setTimezone(TimeZone timezone) { this.timezone = timezone; @@ -1201,6 +791,7 @@ public class StyleManager { * * @param pattern - the pattern describing the date and time format */ + public void setDatePattern(String datePattern) { this.datePattern = datePattern; @@ -1216,6 +807,7 @@ public class StyleManager { * * @param pattern - the pattern describing the decimal format */ + public void setDecimalPattern(String decimalPattern) { this.decimalPattern = decimalPattern; @@ -1236,6 +828,7 @@ public class StyleManager { * * @param xAxisDecimalPattern */ + public void setXAxisDecimalPattern(String xAxisDecimalPattern) { this.xAxisDecimalPattern = xAxisDecimalPattern; @@ -1251,6 +844,7 @@ public class StyleManager { * * @param yAxisDecimalPattern */ + public void setYAxisDecimalPattern(String yAxisDecimalPattern) { this.yAxisDecimalPattern = yAxisDecimalPattern; diff --git a/xchart/src/main/java/org/knowm/xchart/internal/style/Theme.java b/xchart/src/main/java/org/knowm/xchart/internal/style/Theme.java index 84dfdff38f40fd9df292ed8d9378f1f9e9df1cc0..3b0f6981e940a82d3bc340aacaf511d253f0c5c2 100644 --- a/xchart/src/main/java/org/knowm/xchart/internal/style/Theme.java +++ b/xchart/src/main/java/org/knowm/xchart/internal/style/Theme.java @@ -1,5 +1,5 @@ /** - * Copyright 2015 Knowm Inc. (http://knowm.org) and contributors. + * Copyright 2015-2016 Knowm Inc. (http://knowm.org) and contributors. * Copyright 2011-2015 Xeiam LLC (http://xeiam.com) and contributors. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -20,7 +20,7 @@ import java.awt.Color; import java.awt.Font; import java.awt.Stroke; -import org.knowm.xchart.StyleManager.LegendPosition; +import org.knowm.xchart.internal.style.StyleManager.LegendPosition; /** * @author timmolter @@ -37,6 +37,8 @@ public interface Theme { public SeriesColorMarkerLineStyleCycler getSeriesColorMarkerLineStyleCycler(); + // public List<Color> getSeriesColors(); + // Chart Title /////////////////////////////// public Font getChartTitleFont(); diff --git a/xchart/src/main/java/org/knowm/xchart/internal/style/XChartTheme.java b/xchart/src/main/java/org/knowm/xchart/internal/style/XChartTheme.java index ff561f759a671b1501bc76cc22e7fdff35f04baf..0c1bcba638fb799a5d56eefc84b90a72ad07707f 100644 --- a/xchart/src/main/java/org/knowm/xchart/internal/style/XChartTheme.java +++ b/xchart/src/main/java/org/knowm/xchart/internal/style/XChartTheme.java @@ -1,5 +1,5 @@ /** - * Copyright 2015 Knowm Inc. (http://knowm.org) and contributors. + * Copyright 2015-2016 Knowm Inc. (http://knowm.org) and contributors. * Copyright 2011-2015 Xeiam LLC (http://xeiam.com) and contributors. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -25,40 +25,16 @@ import java.util.EnumSet; import java.util.List; import org.knowm.xchart.ChartColor; -import org.knowm.xchart.SeriesColor; import org.knowm.xchart.SeriesLineStyle; import org.knowm.xchart.SeriesMarker; -import org.knowm.xchart.StyleManager.LegendPosition; +import org.knowm.xchart.internal.style.StyleManager.LegendPosition; +import org.knowm.xchart.internal.style.colors.XChartSeriesColors; /** * @author timmolter */ public class XChartTheme implements Theme { - // original XChart colors - // public static SeriesColor BLUE = new SeriesColor(0, 55, 255, 180); - // public static SeriesColor ORANGE = new SeriesColor(255, 172, 0, 180); - // public static SeriesColor PURPLE = new SeriesColor(128, 0, 255, 180); - // public static SeriesColor GREEN = new SeriesColor(0, 205, 0, 180); - // public static SeriesColor RED = new SeriesColor(205, 0, 0, 180); - // public static SeriesColor YELLOW = new SeriesColor(255, 215, 0, 180); - // public static SeriesColor MAGENTA = new SeriesColor(255, 0, 255, 180); - // public static SeriesColor PINK = new SeriesColor(255, 166, 201, 180); - // public static SeriesColor LIGHT_GREY = new SeriesColor(207, 207, 207, 180); - // public static SeriesColor CYAN = new SeriesColor(0, 255, 255, 180); - // public static SeriesColor BROWN = new SeriesColor(102, 56, 10, 180); - // public static SeriesColor BLACK = new SeriesColor(0, 0, 0, 180); - - // printer-friendly colors from http://colorbrewer2.org/ - public static SeriesColor RED = new SeriesColor(228, 26, 28, 180); - public static SeriesColor GREEN = new SeriesColor(55, 126, 184, 180); - public static SeriesColor BLUE = new SeriesColor(77, 175, 74, 180); - public static SeriesColor PURPLE = new SeriesColor(152, 78, 163, 180); - public static SeriesColor ORANGE = new SeriesColor(255, 127, 0, 180); - // public static SeriesColor YELLOW = new SeriesColor(255, 255, 51, 180); - // public static SeriesColor BROWN = new SeriesColor(166, 86, 40, 180); - // public static SeriesColor PINK = new SeriesColor(247, 129, 191, 180); - // Chart Style /////////////////////////////// @Override @@ -82,7 +58,7 @@ public class XChartTheme implements Theme { @Override public SeriesColorMarkerLineStyleCycler getSeriesColorMarkerLineStyleCycler() { - return new XChartSeriesColorMarkerLineStyleCycler(); + return new XChartColorMarkerLineStyleCycler(); } // Chart Title /////////////////////////////// @@ -370,36 +346,12 @@ public class XChartTheme implements Theme { return false; } - public class XChartSeriesColorMarkerLineStyleCycler extends SeriesColorMarkerLineStyleCycler { + public class XChartColorMarkerLineStyleCycler extends SeriesColorMarkerLineStyleCycler { @Override - public List<SeriesColor> getSeriesColorList() { - - // 1. Color - List<SeriesColor> seriesColorMap = new ArrayList<SeriesColor>(); - // seriesColorMap.add(BLUE); - // seriesColorMap.add(ORANGE); - // seriesColorMap.add(PURPLE); - // seriesColorMap.add(GREEN); - // seriesColorMap.add(RED); - // seriesColorMap.add(YELLOW); - // seriesColorMap.add(MAGENTA); - // seriesColorMap.add(PINK); - // seriesColorMap.add(LIGHT_GREY); - // seriesColorMap.add(CYAN); - // seriesColorMap.add(BROWN); - // seriesColorMap.add(BLACK); - - seriesColorMap.add(RED); - seriesColorMap.add(GREEN); - seriesColorMap.add(BLUE); - seriesColorMap.add(PURPLE); - seriesColorMap.add(ORANGE); - // seriesColorMap.add(YELLOW); - // seriesColorMap.add(BROWN); - // seriesColorMap.add(PINK); - - return seriesColorMap; + public List<Color> getColorList() { + + return new XChartSeriesColors().getSeriesColors(); } @Override diff --git a/xchart/src/main/java/org/knowm/xchart/internal/style/colors/PrinterFriendlySeriesColors.java b/xchart/src/main/java/org/knowm/xchart/internal/style/colors/PrinterFriendlySeriesColors.java new file mode 100644 index 0000000000000000000000000000000000000000..fd3ad0674e0dcfa32d6f4b7ae057dd42ab4ca766 --- /dev/null +++ b/xchart/src/main/java/org/knowm/xchart/internal/style/colors/PrinterFriendlySeriesColors.java @@ -0,0 +1,57 @@ +/** + * Copyright 2015-2016 Knowm Inc. (http://knowm.org) and contributors. + * Copyright 2011-2015 Xeiam LLC (http://xeiam.com) and contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.knowm.xchart.internal.style.colors; + +import java.awt.Color; +import java.util.ArrayList; +import java.util.List; + +/** + * @author timmolter + */ +public class PrinterFriendlySeriesColors { + + // printer-friendly colors from http://colorbrewer2.org/ + public static Color RED = new Color(228, 26, 28, 180); + public static Color GREEN = new Color(55, 126, 184, 180); + public static Color BLUE = new Color(77, 175, 74, 180); + public static Color PURPLE = new Color(152, 78, 163, 180); + public static Color ORANGE = new Color(255, 127, 0, 180); + // public static Color YELLOW = new Color(255, 255, 51, 180); + // public static Color BROWN = new Color(166, 86, 40, 180); + // public static Color PINK = new Color(247, 129, 191, 180); + + List<Color> seriesColors = new ArrayList<Color>(); + + /** + * Constructor + */ + public PrinterFriendlySeriesColors() { + + seriesColors.add(RED); + seriesColors.add(GREEN); + seriesColors.add(BLUE); + seriesColors.add(PURPLE); + seriesColors.add(ORANGE); + + } + + public List<Color> getSeriesColors() { + + return seriesColors; + } +} diff --git a/xchart/src/main/java/org/knowm/xchart/internal/style/colors/XChartSeriesColors.java b/xchart/src/main/java/org/knowm/xchart/internal/style/colors/XChartSeriesColors.java new file mode 100644 index 0000000000000000000000000000000000000000..7adf13a01796e7d7566120c4b212e9775563b510 --- /dev/null +++ b/xchart/src/main/java/org/knowm/xchart/internal/style/colors/XChartSeriesColors.java @@ -0,0 +1,68 @@ +/** + * Copyright 2015-2016 Knowm Inc. (http://knowm.org) and contributors. + * Copyright 2011-2015 Xeiam LLC (http://xeiam.com) and contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.knowm.xchart.internal.style.colors; + +import java.awt.Color; +import java.util.ArrayList; +import java.util.List; + +/** + * @author timmolter + */ +public class XChartSeriesColors { + + // original XChart colors + public static Color BLUE = new Color(0, 55, 255, 180); + public static Color ORANGE = new Color(255, 172, 0, 180); + public static Color PURPLE = new Color(128, 0, 255, 180); + public static Color GREEN = new Color(0, 205, 0, 180); + public static Color RED = new Color(205, 0, 0, 180); + public static Color YELLOW = new Color(255, 215, 0, 180); + public static Color MAGENTA = new Color(255, 0, 255, 180); + public static Color PINK = new Color(255, 166, 201, 180); + public static Color LIGHT_GREY = new Color(207, 207, 207, 180); + public static Color CYAN = new Color(0, 255, 255, 180); + public static Color BROWN = new Color(102, 56, 10, 180); + public static Color BLACK = new Color(0, 0, 0, 180); + + List<Color> seriesColors = new ArrayList<Color>(); + + /** + * Constructor + */ + public XChartSeriesColors() { + + seriesColors.add(BLUE); + seriesColors.add(ORANGE); + seriesColors.add(PURPLE); + seriesColors.add(GREEN); + seriesColors.add(RED); + seriesColors.add(YELLOW); + seriesColors.add(MAGENTA); + seriesColors.add(PINK); + seriesColors.add(LIGHT_GREY); + seriesColors.add(CYAN); + seriesColors.add(BROWN); + seriesColors.add(BLACK); + + } + + public List<Color> getSeriesColors() { + + return seriesColors; + } +} diff --git a/xchart/src/main/java/org/knowm/xchart/internal/markers/Circle.java b/xchart/src/main/java/org/knowm/xchart/internal/style/markers/Circle.java similarity index 90% rename from xchart/src/main/java/org/knowm/xchart/internal/markers/Circle.java rename to xchart/src/main/java/org/knowm/xchart/internal/style/markers/Circle.java index 21f69c1a887f1913cddb83b976d977cedc784bac..f493b62a104758689cec193531c1f4ef6b981411 100644 --- a/xchart/src/main/java/org/knowm/xchart/internal/markers/Circle.java +++ b/xchart/src/main/java/org/knowm/xchart/internal/style/markers/Circle.java @@ -1,5 +1,5 @@ /** - * Copyright 2015 Knowm Inc. (http://knowm.org) and contributors. + * Copyright 2015-2016 Knowm Inc. (http://knowm.org) and contributors. * Copyright 2011-2015 Xeiam LLC (http://xeiam.com) and contributors. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.knowm.xchart.internal.markers; +package org.knowm.xchart.internal.style.markers; import java.awt.Graphics2D; import java.awt.Shape; diff --git a/xchart/src/main/java/org/knowm/xchart/internal/markers/Diamond.java b/xchart/src/main/java/org/knowm/xchart/internal/style/markers/Diamond.java similarity index 91% rename from xchart/src/main/java/org/knowm/xchart/internal/markers/Diamond.java rename to xchart/src/main/java/org/knowm/xchart/internal/style/markers/Diamond.java index 3b1f83f9f648f7b71deb31c9c4f2c5b247e2fb05..81bfa5972ffc62dd41b78c3889d0a90ff56c9551 100644 --- a/xchart/src/main/java/org/knowm/xchart/internal/markers/Diamond.java +++ b/xchart/src/main/java/org/knowm/xchart/internal/style/markers/Diamond.java @@ -1,5 +1,5 @@ /** - * Copyright 2015 Knowm Inc. (http://knowm.org) and contributors. + * Copyright 2015-2016 Knowm Inc. (http://knowm.org) and contributors. * Copyright 2011-2015 Xeiam LLC (http://xeiam.com) and contributors. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.knowm.xchart.internal.markers; +package org.knowm.xchart.internal.style.markers; import java.awt.Graphics2D; import java.awt.geom.Path2D; diff --git a/xchart/src/main/java/org/knowm/xchart/internal/markers/Marker.java b/xchart/src/main/java/org/knowm/xchart/internal/style/markers/Marker.java similarity index 88% rename from xchart/src/main/java/org/knowm/xchart/internal/markers/Marker.java rename to xchart/src/main/java/org/knowm/xchart/internal/style/markers/Marker.java index 702f01cf0554027e28fe1ff9c82cd903b5a8a62c..a0c73c19f3a24cd13c9b536d6a89b843462d985b 100644 --- a/xchart/src/main/java/org/knowm/xchart/internal/markers/Marker.java +++ b/xchart/src/main/java/org/knowm/xchart/internal/style/markers/Marker.java @@ -1,5 +1,5 @@ /** - * Copyright 2015 Knowm Inc. (http://knowm.org) and contributors. + * Copyright 2015-2016 Knowm Inc. (http://knowm.org) and contributors. * Copyright 2011-2015 Xeiam LLC (http://xeiam.com) and contributors. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.knowm.xchart.internal.markers; +package org.knowm.xchart.internal.style.markers; import java.awt.BasicStroke; import java.awt.Graphics2D; diff --git a/xchart/src/main/java/org/knowm/xchart/internal/markers/Square.java b/xchart/src/main/java/org/knowm/xchart/internal/style/markers/Square.java similarity index 90% rename from xchart/src/main/java/org/knowm/xchart/internal/markers/Square.java rename to xchart/src/main/java/org/knowm/xchart/internal/style/markers/Square.java index 54df5050ab524f44d564dc8e189d37aaac7834d4..b6b86d0e3d2a6f50bb2b9618a7d9bc9c2e81a66a 100644 --- a/xchart/src/main/java/org/knowm/xchart/internal/markers/Square.java +++ b/xchart/src/main/java/org/knowm/xchart/internal/style/markers/Square.java @@ -1,5 +1,5 @@ /** - * Copyright 2015 Knowm Inc. (http://knowm.org) and contributors. + * Copyright 2015-2016 Knowm Inc. (http://knowm.org) and contributors. * Copyright 2011-2015 Xeiam LLC (http://xeiam.com) and contributors. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.knowm.xchart.internal.markers; +package org.knowm.xchart.internal.style.markers; import java.awt.Graphics2D; import java.awt.Shape; diff --git a/xchart/src/main/java/org/knowm/xchart/internal/markers/TriangleDown.java b/xchart/src/main/java/org/knowm/xchart/internal/style/markers/TriangleDown.java similarity index 91% rename from xchart/src/main/java/org/knowm/xchart/internal/markers/TriangleDown.java rename to xchart/src/main/java/org/knowm/xchart/internal/style/markers/TriangleDown.java index 856286374396c81edb440ddb10c36900ed5adbe0..cb8279e1be753330eb85e1370f7d1a602c7ea15e 100644 --- a/xchart/src/main/java/org/knowm/xchart/internal/markers/TriangleDown.java +++ b/xchart/src/main/java/org/knowm/xchart/internal/style/markers/TriangleDown.java @@ -1,5 +1,5 @@ /** - * Copyright 2015 Knowm Inc. (http://knowm.org) and contributors. + * Copyright 2015-2016 Knowm Inc. (http://knowm.org) and contributors. * Copyright 2011-2015 Xeiam LLC (http://xeiam.com) and contributors. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.knowm.xchart.internal.markers; +package org.knowm.xchart.internal.style.markers; import java.awt.Graphics2D; import java.awt.geom.Path2D; diff --git a/xchart/src/main/java/org/knowm/xchart/internal/markers/TriangleUp.java b/xchart/src/main/java/org/knowm/xchart/internal/style/markers/TriangleUp.java similarity index 91% rename from xchart/src/main/java/org/knowm/xchart/internal/markers/TriangleUp.java rename to xchart/src/main/java/org/knowm/xchart/internal/style/markers/TriangleUp.java index 1a69b41376e88eac0e206c6dbc4feb5b21d3b8e1..4a73f344aabddd50faeb4f5d72df06fa188ac805 100644 --- a/xchart/src/main/java/org/knowm/xchart/internal/markers/TriangleUp.java +++ b/xchart/src/main/java/org/knowm/xchart/internal/style/markers/TriangleUp.java @@ -1,5 +1,5 @@ /** - * Copyright 2015 Knowm Inc. (http://knowm.org) and contributors. + * Copyright 2015-2016 Knowm Inc. (http://knowm.org) and contributors. * Copyright 2011-2015 Xeiam LLC (http://xeiam.com) and contributors. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.knowm.xchart.internal.markers; +package org.knowm.xchart.internal.style.markers; import java.awt.Graphics2D; import java.awt.geom.Path2D; diff --git a/xchart/src/test/java/org/knowm/xchart/HistogramTest.java b/xchart/src/test/java/org/knowm/xchart/HistogramTest.java index 45454358fa748891036ab1e1ba1963e53ad97f5c..d7e2f0a4ffbcbe09f1e3f953e32ac211b9ba5d07 100644 --- a/xchart/src/test/java/org/knowm/xchart/HistogramTest.java +++ b/xchart/src/test/java/org/knowm/xchart/HistogramTest.java @@ -1,5 +1,5 @@ /** - * Copyright 2015 Knowm Inc. (http://knowm.org) and contributors. + * Copyright 2015-2016 Knowm Inc. (http://knowm.org) and contributors. * Copyright 2011-2015 Xeiam LLC (http://xeiam.com) and contributors. * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/xchart/src/test/java/org/knowm/xchart/StyleManagerTest.java b/xchart/src/test/java/org/knowm/xchart/StyleManagerTest.java deleted file mode 100644 index bcaaf767f201cec201050a369af478c3506646d6..0000000000000000000000000000000000000000 --- a/xchart/src/test/java/org/knowm/xchart/StyleManagerTest.java +++ /dev/null @@ -1,67 +0,0 @@ -package org.knowm.xchart; - -import org.junit.Before; -import org.junit.Test; - -import static org.fest.assertions.api.Assertions.assertThat; - -public class StyleManagerTest { - - private StyleManager styleManager; - - @Before - public void setUp() { - styleManager = new StyleManager(); - } - - @SuppressWarnings("deprecation") - @Test - public void setPlotGridLinesVisibleTestWithFalse(){ - styleManager.setPlotGridLinesVisible(false); - assertThat(styleManager.isPlotGridLinesVisible()).isFalse(); - assertThat(styleManager.isPlotGridHorizontalLinesVisible()).isFalse(); - assertThat(styleManager.isPlotGridVerticalLinesVisible()).isFalse(); - } - - @SuppressWarnings("deprecation") - @Test - public void setPlotGridLinesVisibleTestWithTrue(){ - styleManager.setPlotGridHorizontalLinesVisible(true); - assertThat(styleManager.isPlotGridLinesVisible()).isTrue(); - assertThat(styleManager.isPlotGridHorizontalLinesVisible()).isTrue(); - assertThat(styleManager.isPlotGridVerticalLinesVisible()).isTrue(); - } - - @SuppressWarnings("deprecation") - @Test - public void setPlotGridHorizontalLinesVisibleTestWithFalse(){ - styleManager.setPlotGridHorizontalLinesVisible(false); - assertThat(styleManager.isPlotGridHorizontalLinesVisible()).isFalse(); - assertThat(styleManager.isPlotGridLinesVisible()).isFalse(); - } - - @SuppressWarnings("deprecation") - @Test - public void setPlotGridHorizontalLinesVisibleTestWithTrue(){ - styleManager.setPlotGridLinesVisible(true); - assertThat(styleManager.isPlotGridHorizontalLinesVisible()).isTrue(); - assertThat(styleManager.isPlotGridLinesVisible()).isTrue(); - } - - @SuppressWarnings("deprecation") - @Test - public void setPlotGridVerticalLinesVisibleTestWithFalse(){ - styleManager.setPlotGridVerticalLinesVisible(false); - assertThat(styleManager.isPlotGridVerticalLinesVisible()).isFalse(); - assertThat(styleManager.isPlotGridLinesVisible()).isFalse(); - } - - @SuppressWarnings("deprecation") - @Test - public void setPlotGridVerticalLinesVisibleTestWithTrue(){ - styleManager.setPlotGridVerticalLinesVisible(true); - assertThat(styleManager.isPlotGridVerticalLinesVisible()).isTrue(); - assertThat(styleManager.isPlotGridLinesVisible()).isTrue(); - } - -}