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..9ea08386be3d313a706ad52a39306417b713f6bd 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,8 @@ XChart is a light weight Java library for plotting data. +**NOTE: Version 3.0.0 is currently under development and close to release. There are many API changes in 3.0.0, so if you want to use the develop snapshot jars, make sure to use the example code on the develop branch as a guide! For version 2.6.1, make sure to read the README file on the master branch!** + ## Description XChart is a light-weight and convenient library for plotting data designed to go from data to chart in the least amount of time possible and to take the guess-work out of customizing the chart style. @@ -57,9 +59,10 @@ XChart ships with three different themes: Default **XChart**, **GGPlot2** and ** * [x] Area charts * [x] Bar charts * [x] Histogram charts +* [x] Pie charts * [x] Error bars * [x] Logarithmic axes -* [x] Date and category X-Axis +* [x] Number, Date and category X-Axis * [x] Multiple series * [x] Extensive customization * [x] Themes - XChart, GGPlot2, Matlab @@ -109,7 +112,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..f9af8b53e776bf75d0102e2f843575d5b9813c07 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"); @@ -60,6 +60,8 @@ import org.knowm.xchart.demo.charts.line.LineChart05; import org.knowm.xchart.demo.charts.line.LineChart06; import org.knowm.xchart.demo.charts.line.LineChart07; import org.knowm.xchart.demo.charts.pie.PieChart01; +import org.knowm.xchart.demo.charts.pie.PieChart02; +import org.knowm.xchart.demo.charts.pie.PieChart03; import org.knowm.xchart.demo.charts.realtime.RealtimeChart01; import org.knowm.xchart.demo.charts.realtime.RealtimeChart02; import org.knowm.xchart.demo.charts.realtime.RealtimeChart03; @@ -67,6 +69,7 @@ import org.knowm.xchart.demo.charts.scatter.ScatterChart01; import org.knowm.xchart.demo.charts.scatter.ScatterChart02; import org.knowm.xchart.demo.charts.scatter.ScatterChart03; import org.knowm.xchart.demo.charts.scatter.ScatterChart04; +import org.knowm.xchart.demo.charts.stick.StickChart01; import org.knowm.xchart.demo.charts.theme.ThemeChart01; import org.knowm.xchart.demo.charts.theme.ThemeChart02; import org.knowm.xchart.demo.charts.theme.ThemeChart03; @@ -227,6 +230,12 @@ public class XChartDemo extends JPanel implements TreeSelectionListener { defaultMutableTreeNode = new DefaultMutableTreeNode(new ChartInfo("PieChart01 - Pie Chart with 4 Slices", new PieChart01().getChart())); category.add(defaultMutableTreeNode); + defaultMutableTreeNode = new DefaultMutableTreeNode(new ChartInfo("PieChart02 - Pie Chart Custom Color Palette", new PieChart02().getChart())); + category.add(defaultMutableTreeNode); + + defaultMutableTreeNode = new DefaultMutableTreeNode(new ChartInfo("PieChart03 - Pie Chart Custom GGPlot2 Theme", new PieChart03().getChart())); + category.add(defaultMutableTreeNode); + // Line category category = new DefaultMutableTreeNode("Line Charts"); top.add(category); @@ -299,6 +308,13 @@ public class XChartDemo extends JPanel implements TreeSelectionListener { defaultMutableTreeNode = new DefaultMutableTreeNode(new ChartInfo("BarChart09 - Category chart with Bar, Line and Scatter Series", new BarChart09().getChart())); category.add(defaultMutableTreeNode); + // Stick category + category = new DefaultMutableTreeNode("Stick Charts"); + top.add(category); + + defaultMutableTreeNode = new DefaultMutableTreeNode(new ChartInfo("StickChart01 - Stick", new StickChart01().getChart())); + category.add(defaultMutableTreeNode); + // Theme category category = new DefaultMutableTreeNode("Chart Themes"); top.add(category); 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..e7ea68043a7dd5b04aff2d05cd27eeb87e652df8 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.ChartBuilder_XY; +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.Styler.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 ChartBuilder_XY().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().setAxisTitlesVisible(false); - + chart.getStyler().setLegendPosition(LegendPosition.InsideNE); + chart.getStyler().setAxisTitlesVisible(false); + chart.getStyler().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..3a8196751360cbef6ee90a51ef630e564d0b7f39 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.ChartBuilder_XY; +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.Styler.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 ChartBuilder_XY().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,7 +74,8 @@ public class AreaChart02 implements ExampleChart { chart.addSeries("a", xData, yData); // Customize Chart - chart.getStyleManager().setLegendPosition(LegendPosition.InsideNW); + chart.getStyler().setChartXYSeriesRenderStyle(ChartXYSeriesRenderStyle.Area); + chart.getStyler().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..d553bdb674fc63192ec1fad99f8366e0e471cf42 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.SeriesMarker; -import org.knowm.xchart.StyleManager; -import org.knowm.xchart.StyleManager.ChartType; -import org.knowm.xchart.StyleManager.LegendPosition; +import org.knowm.xchart.Chart_XY; +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.Styler; +import org.knowm.xchart.internal.style.Styler.LegendPosition; +import org.knowm.xchart.internal.style.markers.SeriesMarkers; /** * 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.getStyler().setLegendPosition(LegendPosition.InsideNW); + chart.getStyler().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,24 +78,24 @@ 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); - seriesLiability.setMarker(SeriesMarker.NONE); - seriesLiability.setSeriesType(Series.SeriesType.Area); + Series_XY seriesLiability = chart.addSeries("Liability", xAges, yLiability); + seriesLiability.setMarker(SeriesMarkers.NONE); + seriesLiability.setChartXYSeriesRenderStyle(Series_XY.ChartXYSeriesRenderStyle.Area); - Series seriesPercentile75th = chart.addSeries("75th Percentile", xAges, yPercentile75th); - seriesPercentile75th.setMarker(SeriesMarker.NONE); + Series_XY seriesPercentile75th = chart.addSeries("75th Percentile", xAges, yPercentile75th); + seriesPercentile75th.setMarker(SeriesMarkers.NONE); - Series seriesPercentile50th = chart.addSeries("50th Percentile", xAges, yPercentile50th); - seriesPercentile50th.setMarker(SeriesMarker.NONE); + Series_XY seriesPercentile50th = chart.addSeries("50th Percentile", xAges, yPercentile50th); + seriesPercentile50th.setMarker(SeriesMarkers.NONE); - Series seriesPercentile25th = chart.addSeries("25th Percentile", xAges, yPercentile25th); - seriesPercentile25th.setMarker(SeriesMarker.NONE); + Series_XY seriesPercentile25th = chart.addSeries("25th Percentile", xAges, yPercentile25th); + seriesPercentile25th.setMarker(SeriesMarkers.NONE); - chart.getStyleManager().setYAxisLabelAlignment(StyleManager.TextAlignment.Right); - chart.getStyleManager().setYAxisDecimalPattern("$ #,###.##"); + chart.getStyler().setYAxisLabelAlignment(Styler.TextAlignment.Right); + chart.getStyler().setYAxisDecimalPattern("$ #,###.##"); - chart.getStyleManager().setPlotPadding(0); - chart.getStyleManager().setAxisTickSpacePercentage(.95); + chart.getStyler().setPlotMargin(0); + chart.getStyler().setPlotContentSize(.95); // chart.getStyleManager().setYAxisMax(1620725 * 1.15); // We want to ensure there is a % of padding on the top of the chart return chart; } 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..94ca7f9d9a14edcec9c44a656d7e42e41984e1f4 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,22 +18,23 @@ 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.Styler.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 + * <li>Bars touch X-Axis */ public class BarChart01 implements ExampleChart { @@ -48,11 +49,12 @@ 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); + chart.getStyler().setLegendPosition(LegendPosition.InsideNW); + chart.getStyler().setPlotContentSize(1.0); return chart; } 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..0a855449ec11c6d0cb96cf157c8fe2d201298ad0 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.style.MatlabTheme; +import org.knowm.xchart.internal.chartpart.Chart; +import org.knowm.xchart.internal.style.Styler.ChartTheme; +import org.knowm.xchart.internal.style.colors.MatlabSeriesColors; /** * 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,11 +75,11 @@ 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.setLineColor(MatlabTheme.RED); - chart.getStyleManager().setPlotGridLinesVisible(false); - chart.getStyleManager().setBarFilled(false); - chart.getStyleManager().setDatePattern("YYYY"); + Series_Category series = chart.addSeries("Model 77", xData, yData); + series.setLineColor(MatlabSeriesColors.RED); + chart.getStyler().setPlotGridLinesVisible(false); + chart.getStyler().setBarFilled(false); + chart.getStyler().setDatePattern("YYYY"); return chart; } 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..ac7517e7c1b7c10d87b76848b7588683bebdef19 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,12 +48,12 @@ 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); + chart.getStyler().setYAxisMin(5); + chart.getStyler().setYAxisMax(70); return chart; } 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..23086e033415b233bc7eddf503bdf820eb5033b2 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.Styler.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..07d92467a846d6cc9b2d29e664bf0fdba48212e7 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.Styler.LegendPosition; /** * Histogram Overlapped @@ -49,17 +49,17 @@ 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); - chart.getStyleManager().setBarWidthPercentage(.96); - chart.getStyleManager().setBarsOverlapped(true); + chart.getStyler().setLegendPosition(LegendPosition.InsideNW); + chart.getStyler().setBarWidthPercentage(.96); + chart.getStyler().setBarsOverlapped(true); return chart; } 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..75447932da5d1d7c9d42869f5a76fd01b05032f6 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.Styler.LegendPosition; /** * Histogram Not Overlapped @@ -50,16 +50,16 @@ 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); - chart.getStyleManager().setBarWidthPercentage(.96); + chart.getStyler().setLegendPosition(LegendPosition.InsideNW); + chart.getStyler().setBarWidthPercentage(.96); return chart; } 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..d31e558940c632afa8615977c5a070b7ae1daf0b 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.Styler.LegendPosition; /** * Histogram with Error Bars @@ -49,14 +49,14 @@ 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); - chart.getStyleManager().setBarWidthPercentage(.96); + chart.getStyler().setLegendPosition(LegendPosition.InsideNW); + chart.getStyler().setBarWidthPercentage(.96); return chart; } 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..e4212a6562034e7c74a99321d7a5abaa7850270d 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.Styler.ChartTheme; +import org.knowm.xchart.internal.style.Styler.LegendPosition; /** * Category chart with Bar, Line and Scatter Series @@ -50,19 +50,19 @@ 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); - chart.getStyleManager().setBarWidthPercentage(.55); - chart.getStyleManager().setBarsOverlapped(true); + chart.getStyler().setLegendPosition(LegendPosition.InsideNW); + chart.getStyler().setBarWidthPercentage(.55); + chart.getStyler().setBarsOverlapped(true); return chart; } 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..8b6074550ce7c196f04950c4b3a8201e2cc111f4 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.SeriesMarker; +import org.knowm.xchart.ChartBuilder_XY; +import org.knowm.xchart.Chart_XY; +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.markers.SeriesMarkers; /** * Millisecond Scale @@ -52,8 +53,8 @@ public class DateChart01 implements ExampleChart { public Chart getChart() { // Create Chart - Chart chart = new ChartBuilder().width(800).height(600).title("Millisecond Scale").build(); - chart.getStyleManager().setLegendVisible(false); + Chart_XY chart = new ChartBuilder_XY().width(800).height(600).title("Millisecond Scale").build(); + chart.getStyler().setLegendVisible(false); Random random = new Random(); @@ -76,8 +77,8 @@ public class DateChart01 implements ExampleChart { yData.add(Math.random() * i); } - Series series = chart.addSeries("blah", xData, yData); - series.setMarker(SeriesMarker.NONE); + Series_XY series = chart.addSeries("blah", xData, yData); + series.setMarker(SeriesMarkers.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..7468de5f60613ba4cc56dc3d7b560e9ace3be106 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.ChartBuilder_XY; +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,8 +46,8 @@ public class DateChart02 implements ExampleChart { public Chart getChart() { // Create Chart - Chart chart = new ChartBuilder().width(800).height(600).title("Second Scale").build(); - chart.getStyleManager().setLegendVisible(false); + Chart_XY chart = new ChartBuilder_XY().width(800).height(600).title("Second Scale").build(); + chart.getStyler().setLegendVisible(false); // generate data List<Date> xData = new ArrayList<Date>(); 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..d3d70a9dc78a18ad03c12940913495e94f7c6253 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.ChartBuilder_XY; +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,8 +46,8 @@ public class DateChart03 implements ExampleChart { public Chart getChart() { // Create Chart - Chart chart = new ChartBuilder().width(800).height(600).title("Minute Scale").build(); - chart.getStyleManager().setLegendVisible(false); + Chart_XY chart = new ChartBuilder_XY().width(800).height(600).title("Minute Scale").build(); + chart.getStyler().setLegendVisible(false); // generate data List<Date> xData = new ArrayList<Date>(); 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..b8b9b5cade6cbf338d90960f0f945d039d45b4ee 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.ChartBuilder_XY; +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,8 +46,8 @@ public class DateChart04 implements ExampleChart { public Chart getChart() { // Create Chart - Chart chart = new ChartBuilder().width(800).height(600).title("Hour Scale").build(); - chart.getStyleManager().setLegendVisible(false); + Chart_XY chart = new ChartBuilder_XY().width(800).height(600).title("Hour Scale").build(); + chart.getStyler().setLegendVisible(false); // generate data List<Date> xData = new ArrayList<Date>(); 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..ae1cea1657567c06516a52ca93d227138954a0b7 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.ChartBuilder_XY; +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,8 +46,8 @@ public class DateChart05 implements ExampleChart { public Chart getChart() { // Create Chart - Chart chart = new ChartBuilder().width(800).height(600).title("Day Scale").build(); - chart.getStyleManager().setLegendVisible(false); + Chart_XY chart = new ChartBuilder_XY().width(800).height(600).title("Day Scale").build(); + chart.getStyler().setLegendVisible(false); // generate data List<Date> xData = new ArrayList<Date>(); 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..5b0f347014f1bbc4e01ccde588d8a4598a76bed1 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.ChartBuilder_XY; +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,8 +46,8 @@ public class DateChart06 implements ExampleChart { public Chart getChart() { // Create Chart - Chart chart = new ChartBuilder().width(800).height(600).title("Month Scale").build(); - chart.getStyleManager().setLegendVisible(false); + Chart_XY chart = new ChartBuilder_XY().width(800).height(600).title("Month Scale").build(); + chart.getStyler().setLegendVisible(false); // generate data List<Date> xData = new ArrayList<Date>(); 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..fcf751c545e7a3efc321ec0e6d5e6fd77384b37f 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.ChartBuilder_XY; +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,8 +46,8 @@ public class DateChart07 implements ExampleChart { public Chart getChart() { // Create Chart - Chart chart = new ChartBuilder().width(800).height(600).title("Year Scale").build(); - chart.getStyleManager().setLegendVisible(false); + Chart_XY chart = new ChartBuilder_XY().width(800).height(600).title("Year Scale").build(); + chart.getStyler().setLegendVisible(false); // generate data List<Date> xData = new ArrayList<Date>(); 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..24b527a517ebde91bb318ee2b13599e06ebaf1ab 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.ChartBuilder_XY; +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,10 +51,10 @@ public class DateChart08 implements ExampleChart { public Chart getChart() { // Create Chart - Chart chart = new ChartBuilder().width(800).height(600).title("Rotated Tick Labels").build(); - chart.getStyleManager().setLegendVisible(false); - chart.getStyleManager().setXAxisLabelRotation(60); - chart.getStyleManager().setDatePattern("yyyy-MM-dd"); + Chart_XY chart = new ChartBuilder_XY().width(800).height(600).title("Rotated Tick Labels").build(); + chart.getStyler().setLegendVisible(false); + chart.getStyler().setXAxisLabelRotation(60); + chart.getStyler().setDatePattern("yyyy-MM-dd"); // generate data List<Date> xData = new ArrayList<Date>(); List<Double> yData = new ArrayList<Double>(); 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..9571bbea00cd8e0d66bedaa7a3d780dd3804f839 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.ChartBuilder_XY; +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.Styler.LegendPosition; /** * Logarithmic Y-Axis @@ -55,14 +56,14 @@ public class LineChart01 implements ExampleChart { } // Create Chart - Chart chart = new ChartBuilder().width(800).height(600).build(); + Chart_XY chart = new ChartBuilder_XY().width(800).height(600).title("Powers of Ten").xAxisTitle("Power").yAxisTitle("Value").build(); // Customize Chart - chart.getStyleManager().setChartTitleVisible(false); - chart.getStyleManager().setLegendPosition(LegendPosition.InsideNW); - chart.getStyleManager().setYAxisLogarithmic(true); + chart.getStyler().setChartTitleVisible(true); + chart.getStyler().setLegendPosition(LegendPosition.InsideNW); + chart.getStyler().setYAxisLogarithmic(true); // chart.getStyleManager().setXAxisLabelAlignment(TextAlignment.Right); - chart.getStyleManager().setXAxisLabelRotation(45); + chart.getStyler().setXAxisLabelRotation(45); // chart.getStyleManager().setXAxisLabelRotation(90); // chart.getStyleManager().setXAxisLabelRotation(0); 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..a8d5d3bf5e01f5a9e13f481b8eb009c8362ff5d6 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.SeriesLineStyle; -import org.knowm.xchart.SeriesMarker; +import org.knowm.xchart.Chart_XY; +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; +import org.knowm.xchart.internal.style.lines.SeriesLines; +import org.knowm.xchart.internal.style.markers.SeriesMarkers; /** * Sine wave with customized series style @@ -57,18 +58,18 @@ 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); + chart.getStyler().setChartTitleVisible(false); + chart.getStyler().setLegendVisible(false); // Series 1 - Series series1 = chart.addSeries("y=sin(x)", xData, yData); - series1.setLineColor(XChartTheme.PURPLE); - series1.setLineStyle(SeriesLineStyle.DASH_DASH); - series1.setMarkerColor(XChartTheme.GREEN); - series1.setMarker(SeriesMarker.SQUARE); + Series_XY series1 = chart.addSeries("y=sin(x)", xData, yData); + series1.setLineColor(XChartSeriesColors.PURPLE); + series1.setLineStyle(SeriesLines.DASH_DASH); + series1.setMarkerColor(XChartSeriesColors.GREEN); + series1.setMarker(SeriesMarkers.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..5cd3fb80f51c0e8d168cbf6ca7abd12ff533a0a0 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.SeriesLineStyle; -import org.knowm.xchart.SeriesMarker; -import org.knowm.xchart.StyleManager.LegendPosition; +import org.knowm.xchart.Chart_XY; +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.Styler.LegendPosition; +import org.knowm.xchart.internal.style.colors.ChartColor; +import org.knowm.xchart.internal.style.colors.XChartSeriesColors; +import org.knowm.xchart.internal.style.lines.SeriesLines; +import org.knowm.xchart.internal.style.markers.SeriesMarkers; /** * 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,40 +73,40 @@ 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)); - chart.getStyleManager().setPlotGridLinesColor(new Color(255, 255, 255)); - chart.getStyleManager().setChartBackgroundColor(Color.WHITE); - chart.getStyleManager().setLegendBackgroundColor(Color.PINK); - chart.getStyleManager().setChartFontColor(Color.MAGENTA); - chart.getStyleManager().setChartTitleBoxBackgroundColor(new Color(0, 222, 0)); - chart.getStyleManager().setChartTitleBoxVisible(true); - chart.getStyleManager().setChartTitleBoxBorderColor(Color.BLACK); - chart.getStyleManager().setPlotGridLinesVisible(false); - - chart.getStyleManager().setAxisTickPadding(20); - - chart.getStyleManager().setAxisTickMarkLength(15); - - chart.getStyleManager().setPlotPadding(20); - - chart.getStyleManager().setChartTitleFont(new Font(Font.MONOSPACED, Font.BOLD, 24)); - chart.getStyleManager().setLegendFont(new Font(Font.SERIF, Font.PLAIN, 18)); - chart.getStyleManager().setLegendPosition(LegendPosition.InsideSE); - chart.getStyleManager().setLegendSeriesLineLength(12); - chart.getStyleManager().setAxisTitleFont(new Font(Font.SANS_SERIF, Font.ITALIC, 18)); - chart.getStyleManager().setAxisTickLabelsFont(new Font(Font.SERIF, Font.PLAIN, 11)); - chart.getStyleManager().setDatePattern("dd-MMM"); - chart.getStyleManager().setDecimalPattern("#0.000"); - chart.getStyleManager().setLocale(Locale.GERMAN); - - Series series = chart.addSeries("Fake Data", xData, yData); - series.setLineColor(XChartTheme.BLUE); + chart.getStyler().setPlotBackgroundColor(ChartColor.getAWTColor(ChartColor.GREY)); + chart.getStyler().setPlotGridLinesColor(new Color(255, 255, 255)); + chart.getStyler().setChartBackgroundColor(Color.WHITE); + chart.getStyler().setLegendBackgroundColor(Color.PINK); + chart.getStyler().setChartFontColor(Color.MAGENTA); + chart.getStyler().setChartTitleBoxBackgroundColor(new Color(0, 222, 0)); + chart.getStyler().setChartTitleBoxVisible(true); + chart.getStyler().setChartTitleBoxBorderColor(Color.BLACK); + chart.getStyler().setPlotGridLinesVisible(false); + + chart.getStyler().setAxisTickPadding(20); + + chart.getStyler().setAxisTickMarkLength(15); + + chart.getStyler().setPlotMargin(20); + + chart.getStyler().setChartTitleFont(new Font(Font.MONOSPACED, Font.BOLD, 24)); + chart.getStyler().setLegendFont(new Font(Font.SERIF, Font.PLAIN, 18)); + chart.getStyler().setLegendPosition(LegendPosition.InsideSE); + chart.getStyler().setLegendSeriesLineLength(12); + chart.getStyler().setAxisTitleFont(new Font(Font.SANS_SERIF, Font.ITALIC, 18)); + chart.getStyler().setAxisTickLabelsFont(new Font(Font.SERIF, Font.PLAIN, 11)); + chart.getStyler().setDatePattern("dd-MMM"); + chart.getStyler().setDecimalPattern("#0.000"); + chart.getStyler().setLocale(Locale.GERMAN); + + 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); + series.setMarker(SeriesMarkers.CIRCLE); + series.setLineStyle(SeriesLines.SOLID); return chart; } 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..6d024a6d067e083b7b9eac21ad1ada45f3e13747 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.SeriesLineStyle; -import org.knowm.xchart.SeriesMarker; +import org.knowm.xchart.Chart_XY; +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; +import org.knowm.xchart.internal.style.lines.SeriesLines; +import org.knowm.xchart.internal.style.markers.SeriesMarkers; /** * 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); + chart.getStyler().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.setLineStyle(SeriesLineStyle.SOLID); - series.setMarker(SeriesMarker.CIRCLE); - series.setMarkerColor(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(SeriesLines.SOLID); + series.setMarker(SeriesMarkers.CIRCLE); + 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..6cf8e42adccd41302829e29f743baafd7af7ac19 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.SeriesLineStyle; -import org.knowm.xchart.SeriesMarker; -import org.knowm.xchart.StyleManager.LegendPosition; +import org.knowm.xchart.Chart_XY; +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.Styler.LegendPosition; +import org.knowm.xchart.internal.style.lines.SeriesLines; +import org.knowm.xchart.internal.style.markers.SeriesMarkers; /** * Scatter and Line @@ -49,35 +50,35 @@ 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); + chart.getStyler().setLegendPosition(LegendPosition.InsideSW); double[] xData = new double[] { 0.0, 1.0, 2.0, 3.0, 4.0, 5, 6 }; 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.setLineStyle(SeriesLineStyle.NONE); - series.setMarker(SeriesMarker.DIAMOND); + Series_XY series = chart.addSeries("A", xData, yData); + series.setLineStyle(SeriesLines.NONE); + series.setMarker(SeriesMarkers.DIAMOND); series.setMarkerColor(Color.BLACK); - Series series2 = chart.addSeries("B", xData, yData2); - series2.setMarker(SeriesMarker.NONE); - series2.setLineStyle(SeriesLineStyle.DASH_DASH); + Series_XY series2 = chart.addSeries("B", xData, yData2); + series2.setMarker(SeriesMarkers.NONE); + series2.setLineStyle(SeriesLines.DASH_DASH); series2.setLineColor(Color.BLACK); - chart.getStyleManager().setYAxisLogarithmic(true); + chart.getStyler().setYAxisLogarithmic(true); - chart.getStyleManager().setYAxisMin(0.01); - chart.getStyleManager().setYAxisMax(1000); + chart.getStyler().setYAxisMin(0.01); + chart.getStyler().setYAxisMax(1000); - chart.getStyleManager().setXAxisMin(2); - chart.getStyleManager().setXAxisMax(7); + chart.getStyler().setXAxisMin(2); + chart.getStyler().setXAxisMax(7); return chart; } 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..59ab0cacddd20598ae2759f109b727621b293a5d 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.SeriesLineStyle; -import org.knowm.xchart.SeriesMarker; +import org.knowm.xchart.Chart_XY; +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.lines.SeriesLines; +import org.knowm.xchart.internal.style.markers.SeriesMarkers; /** * Logarithmic Y-Axis with Error Bars @@ -53,23 +54,23 @@ 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); + chart.getStyler().setYAxisLogarithmic(true); - chart.getStyleManager().setYAxisMin(.08); + chart.getStyler().setYAxisMin(.08); - chart.getStyleManager().setYAxisMax(1000); + chart.getStyler().setYAxisMax(1000); - chart.getStyleManager().setErrorBarsColor(Color.black); + chart.getStyler().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.setLineStyle(SeriesLines.SOLID); - series1.setMarker(SeriesMarker.DIAMOND); + series1.setMarker(SeriesMarkers.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..79f67c2155c473930de95c93d2a89c35334f84bc 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.SeriesMarker; -import org.knowm.xchart.StyleManager.ChartTheme; -import org.knowm.xchart.StyleManager.ChartType; -import org.knowm.xchart.StyleManager.LegendPosition; +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.Styler.ChartTheme; +import org.knowm.xchart.internal.style.Styler.LegendPosition; +import org.knowm.xchart.internal.style.markers.SeriesMarkers; /** * Line chart with multiple Category Series @@ -36,6 +36,7 @@ import org.knowm.xchart.demo.charts.ExampleChart; * <ul> * <li>A Line Chart created from multiple category series types * <li>GGPlot2 Theme + * <li>disabling some series shown in legend */ public class LineChart07 implements ExampleChart { @@ -50,17 +51,17 @@ 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.getStyler().setChartCategorySeriesRenderStyle(ChartCategorySeriesRenderStyle.Line); // Customize Chart - chart.setChartTitle("ThreadPoolBenchmark"); + chart.setTitle("ThreadPoolBenchmark"); chart.setXAxisTitle("Threads"); chart.setYAxisTitle("Executions"); - chart.getStyleManager().setXAxisLabelRotation(270); - chart.getStyleManager().setLegendPosition(LegendPosition.OutsideE); - chart.getStyleManager().setBarWidthPercentage(0); - chart.getStyleManager().setBarsOverlapped(true); + chart.getStyler().setXAxisLabelRotation(270); + chart.getStyler().setLegendPosition(LegendPosition.OutsideE); + chart.getStyler().setBarWidthPercentage(0); + chart.getStyler().setBarsOverlapped(true); // Declare data List<String> xAxisKeys = Arrays.asList(new String[] { "release-0.5", "release-0.6", "release-0.7", "release-0.8", "release-0.9", "release-1.0.0", "release-1.1.0", "release-1.2.0", "release-1.3.0", @@ -95,11 +96,10 @@ 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.setMarker(SeriesMarker.NONE); - series.setSeriesType(SeriesType.Line); + Series_Category series = chart.addSeries(seriesNames[i], xAxisKeys, Arrays.asList(dataPerSeries[i])); + series.setMarker(SeriesMarkers.NONE); + series.setShowInLegend(i % 2 == 0); } - chart.getStyleManager().setYAxisLogarithmic(true); return chart; } 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..3ff1032eb61bbde2a74820c0d0bab4726925f481 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.ChartBuilder_Pie; +import org.knowm.xchart.Chart_Pie; import org.knowm.xchart.SwingWrapper; import org.knowm.xchart.demo.charts.ExampleChart; @@ -28,27 +27,26 @@ import org.knowm.xchart.demo.charts.ExampleChart; * Demonstrates the following: * <ul> * <li>Pie Chart - * <li>ChartBuilder + * <li>ChartBuilderPie */ -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 ChartBuilder_Pie().width(400).height(500).title(getClass().getSimpleName()).build(); + chart.addSeries("Pennies", 100); + chart.addSeries("Nickels", 100); + chart.addSeries("Dimes", 100); + chart.addSeries("Quarters", 100); return chart; } diff --git a/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/pie/PieChart02.java b/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/pie/PieChart02.java new file mode 100644 index 0000000000000000000000000000000000000000..2e3ff91472c30c5a92829d5ca51118a15571674f --- /dev/null +++ b/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/pie/PieChart02.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.demo.charts.pie; + +import java.awt.Color; + +import org.knowm.xchart.ChartBuilder_Pie; +import org.knowm.xchart.Chart_Pie; +import org.knowm.xchart.SwingWrapper; +import org.knowm.xchart.demo.charts.ExampleChart; + +/** + * Pie Chart Custom Color Palette + * <p> + * Demonstrates the following: + * <ul> + * <li>Pie Chart + * <li>ChartBuilderPie + * <li>Custom series palette + */ +public class PieChart02 implements ExampleChart<Chart_Pie> { + + public static void main(String[] args) { + + ExampleChart<Chart_Pie> exampleChart = new PieChart02(); + Chart_Pie chart = exampleChart.getChart(); + new SwingWrapper(chart).displayChart(); + } + + @Override + public Chart_Pie getChart() { + + // Create Chart + Chart_Pie chart = new ChartBuilder_Pie().width(800).height(600).title(getClass().getSimpleName()).build(); + chart.addSeries("Gold", 24); + chart.addSeries("Silver", 21); + chart.addSeries("Platinum", 39); + chart.addSeries("Copper", 17); + chart.addSeries("Zinc", 40); + + Color[] sliceColors = new Color[] { new Color(224, 68, 14), new Color(230, 105, 62), new Color(236, 143, 110), new Color(243, 180, 159), new Color(246, 199, 182) }; + chart.getStyler().setSeriesColors(sliceColors); + + return chart; + } + +} diff --git a/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/pie/PieChart03.java b/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/pie/PieChart03.java new file mode 100644 index 0000000000000000000000000000000000000000..7028df25ac1293b1c3e8fa7d77c098d62e77d38d --- /dev/null +++ b/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/pie/PieChart03.java @@ -0,0 +1,63 @@ +/** + * 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.demo.charts.pie; + +import org.knowm.xchart.ChartBuilder_Pie; +import org.knowm.xchart.Chart_Pie; +import org.knowm.xchart.Styler_Pie.AnnotationType; +import org.knowm.xchart.SwingWrapper; +import org.knowm.xchart.demo.charts.ExampleChart; +import org.knowm.xchart.internal.style.Styler.ChartTheme; + +/** + * Pie Chart with 5 Slices and customization + * <p> + * Demonstrates the following: + * <ul> + * <li>Pie Chart + * <li>ChartBuilderPie + * <li>GGPlot2 Theme + */ +public class PieChart03 implements ExampleChart<Chart_Pie> { + + public static void main(String[] args) { + + ExampleChart<Chart_Pie> exampleChart = new PieChart03(); + Chart_Pie chart = exampleChart.getChart(); + new SwingWrapper(chart).displayChart(); + } + + @Override + public Chart_Pie getChart() { + + // Create Chart + Chart_Pie chart = new ChartBuilder_Pie().width(400).height(500).title(getClass().getSimpleName()).theme(ChartTheme.GGPlot2).build(); + chart.addSeries("Prague", 2); + chart.addSeries("Dresden", 4); + chart.addSeries("Munich", 34); + chart.addSeries("Hamburg", 22); + chart.addSeries("Berlin", 29); + + chart.getStyler().setLegendVisible(false); + chart.getStyler().setAnnotationType(AnnotationType.LabelAndPercentage); + chart.getStyler().setAnnotationDistance(1.15); + chart.getStyler().setPlotContentSize(.7); + + 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..6ecbef2cad6d629a34237f8d719d403668af6ede 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.Styler.LegendPosition; /** * Gaussian Blob @@ -58,13 +59,13 @@ 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.getStyler().setChartXYSeriesRenderStyle(ChartXYSeriesRenderStyle.Scatter); // Customize Chart - chart.getStyleManager().setChartTitleVisible(false); - chart.getStyleManager().setLegendPosition(LegendPosition.InsideSW); - chart.getStyleManager().setMarkerSize(16); + chart.getStyler().setChartTitleVisible(false); + chart.getStyler().setLegendPosition(LegendPosition.InsideSW); + chart.getStyler().setMarkerSize(16); // Series chart.addSeries("Gaussian Blob", xData, yData); 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..230cb384f7d9a721f6b2317bc004babbb80ee4bb 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.Styler.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,13 +62,13 @@ public class ScatterChart02 implements ExampleChart { } // Create Chart - Chart chart = new Chart(800, 600); - chart.setChartTitle("Logarithmic Data"); - chart.getStyleManager().setChartType(ChartType.Scatter); - chart.getStyleManager().setXAxisLogarithmic(true); + Chart_XY chart = new Chart_XY(800, 600); + chart.setTitle("Logarithmic Data"); + chart.getStyler().setChartXYSeriesRenderStyle(ChartXYSeriesRenderStyle.Scatter); + chart.getStyler().setXAxisLogarithmic(true); // Customize Chart - chart.getStyleManager().setLegendPosition(LegendPosition.InsideN); + chart.getStyler().setLegendPosition(LegendPosition.InsideN); // Series chart.addSeries("logarithmic data", xData, yData); 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..5c4cbeaf0b256c144c5794a021d778730b8c8b18 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.SeriesMarker; -import org.knowm.xchart.StyleManager.ChartType; +import org.knowm.xchart.ChartBuilder_XY; +import org.knowm.xchart.Chart_XY; +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.markers.SeriesMarkers; /** * Error Bars @@ -63,18 +63,18 @@ 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 ChartBuilder_XY().width(800).height(600).title("ScatterChart04").xAxisTitle("X").yAxisTitle("Y").build(); // Customize Chart - chart.getStyleManager().setChartTitleVisible(false); - chart.getStyleManager().setLegendVisible(false); - chart.getStyleManager().setAxisTitlesVisible(false); - chart.getStyleManager().setXAxisDecimalPattern("0.0000000"); + chart.getStyler().setChartTitleVisible(false); + chart.getStyler().setLegendVisible(false); + chart.getStyler().setAxisTitlesVisible(false); + chart.getStyler().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); + series.setMarker(SeriesMarkers.SQUARE); return chart; } diff --git a/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/stick/StickChart01.java b/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/stick/StickChart01.java new file mode 100644 index 0000000000000000000000000000000000000000..cd73181d724b3dd33a46d595b6ad65b1f7093be5 --- /dev/null +++ b/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/stick/StickChart01.java @@ -0,0 +1,69 @@ +/** + * Copyright 2013 Xeiam LLC. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.knowm.xchart.demo.charts.stick; + +import java.util.ArrayList; +import java.util.List; + +import org.knowm.xchart.ChartBuilder_Category; +import org.knowm.xchart.Chart_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.Styler.LegendPosition; + +/** + * Stick Chart + * <p> + * Demonstrates the following: + * <ul> + * <li>Stick category series render type + */ +public class StickChart01 implements ExampleChart { + + public static void main(String[] args) { + + ExampleChart exampleChart = new StickChart01(); + Chart chart = exampleChart.getChart(); + new SwingWrapper(chart).displayChart(); + } + + @Override + public Chart getChart() { + + // generates Log data + List<Integer> xData = new ArrayList<Integer>(); + List<Integer> yData = new ArrayList<Integer>(); + for (int i = -3; i <= 24; i++) { + xData.add(i); + yData.add(i); + } + + // Create Chart + Chart_Category chart = new ChartBuilder_Category().width(800).height(600).title("Stick").build(); + + // Customize Chart + chart.getStyler().setChartTitleVisible(true); + chart.getStyler().setLegendPosition(LegendPosition.InsideNW); + chart.getStyler().setChartCategorySeriesRenderStyle(ChartCategorySeriesRenderStyle.Stick); + + // Series + chart.addSeries("data", xData, yData); + + return chart; + } +} \ No newline at end of file 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..ac794c7894d6f7a805991edc1773c17f5c46a5de 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,13 +58,13 @@ public class ThemeChart01 implements ExampleChart { } // Customize Chart - chart.setChartTitle("XChart Theme"); + chart.setTitle("XChart Theme"); chart.setXAxisTitle("X"); chart.setYAxisTitle("Y"); String seriesName = "y=" + 2 * i + "x-" + i * b + "b"; chart.addSeries(seriesName, xData, yData); - chart.getStyleManager().setMarkerSize(11); + chart.getStyler().setMarkerSize(11); } return chart; 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..868e25d3955e9342f7885b9f278a163b30140391 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.ChartBuilder_XY; +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.Styler.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 ChartBuilder_XY().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..38b28ee876b8836c3daa9125abec1658129a3c0f 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.ChartBuilder_XY; +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.Styler.ChartTheme; /** * Matlab Theme @@ -51,9 +52,9 @@ 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.getStyleManager().setPlotGridLinesVisible(false); - chart.getStyleManager().setXAxisTickMarkSpacingHint(100); + Chart_XY chart = new ChartBuilder_XY().width(800).height(600).theme(ChartTheme.Matlab).title("Matlab Theme").xAxisTitle("X").yAxisTitle("Y").build(); + chart.getStyler().setPlotGridLinesVisible(false); + chart.getStyler().setXAxisTickMarkSpacingHint(100); // generate data List<Date> xData = new ArrayList<Date>(); List<Double> y1Data = new ArrayList<Double>(); 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..51eaa940f0fad62dfac4804a9a68240bc0cfc556 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.SeriesLineStyle; -import org.knowm.xchart.SeriesMarker; +import org.knowm.xchart.Chart_XY; +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; +import org.knowm.xchart.internal.style.lines.SeriesLines; +import org.knowm.xchart.internal.style.markers.SeriesMarkers; /** * @author timmolter @@ -44,39 +44,39 @@ 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 + mychart.getStyler().setYAxisLogarithmic(true); // set log or linear Y axis - mychart.getStyleManager().setYAxisMin(.08); + mychart.getStyler().setYAxisMin(.08); - mychart.getStyleManager().setYAxisMax(1000); + mychart.getStyler().setYAxisMax(1000); - mychart.getStyleManager().setErrorBarsColor(Color.black); + mychart.getStyler().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); + series1.setLineStyle(SeriesLines.SOLID); - series1.setMarker(SeriesMarker.DIAMOND); + series1.setMarker(SeriesMarkers.DIAMOND); series1.setMarkerColor(Color.MAGENTA); - series2.setLineStyle(SeriesLineStyle.DASH_DASH); + series2.setLineStyle(SeriesLines.DASH_DASH); - series2.setMarker(SeriesMarker.NONE); + series2.setMarker(SeriesMarkers.NONE); - series2.setLineColor(XChartTheme.RED); + series2.setLineColor(XChartSeriesColors.RED); - series3.setLineStyle(SeriesLineStyle.DASH_DASH); + series3.setLineStyle(SeriesLines.DASH_DASH); - series3.setMarker(SeriesMarker.NONE); + series3.setMarker(SeriesMarkers.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..fd4a58311cfb53cc5578ced6a791134278934c34 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.SeriesLineStyle; -import org.knowm.xchart.SeriesMarker; +import org.knowm.xchart.Chart_XY; +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; +import org.knowm.xchart.internal.style.lines.SeriesLines; +import org.knowm.xchart.internal.style.markers.SeriesMarkers; /** * @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); - 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); - series1.setLineStyle(SeriesLineStyle.SOLID); - series1.setMarker(SeriesMarker.DIAMOND); + Chart_XY mychart = new Chart_XY(900, 700); + mychart.getStyler().setYAxisMin(0); + mychart.getStyler().setYAxisMax(150); + mychart.getStyler().setErrorBarsColor(Color.black); + 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(SeriesLines.SOLID); + series1.setMarker(SeriesMarkers.DIAMOND); series1.setMarkerColor(Color.MAGENTA); - series2.setLineStyle(SeriesLineStyle.DASH_DASH); - series2.setMarker(SeriesMarker.NONE); - series2.setLineColor(XChartTheme.RED); - series3.setLineStyle(SeriesLineStyle.DASH_DASH); - series3.setMarker(SeriesMarker.NONE); - series3.setLineColor(XChartTheme.RED); + series2.setLineStyle(SeriesLines.DASH_DASH); + series2.setMarker(SeriesMarkers.NONE); + series2.setLineColor(XChartSeriesColors.RED); + series3.setLineStyle(SeriesLines.DASH_DASH); + series3.setMarker(SeriesMarkers.NONE); + 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..c923833137bf079fca499637afb0f2aeb18ead6e 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.SeriesMarker; +import org.knowm.xchart.ChartBuilder_XY; +import org.knowm.xchart.Chart_XY; +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; +import org.knowm.xchart.internal.style.markers.SeriesMarkers; /** * 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 ChartBuilder_XY().xAxisTitle("X").yAxisTitle("Y").width(600).height(400).build(); + chart.getStyler().setYAxisMin(-10); + chart.getStyler().setYAxisMax(10); + chart.getStyler().setPlotGridHorizontalLinesVisible(false); + Series_XY series = chart.addSeries("" + i, null, getRandomWalk(200)); + series.setMarker(SeriesMarkers.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..a1608009af7d9d2147f6125b63549ffdf8a0bf53 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.SeriesMarker; +import org.knowm.xchart.ChartBuilder_XY; +import org.knowm.xchart.Chart_XY; +import org.knowm.xchart.Series_XY; import org.knowm.xchart.SwingWrapper; +import org.knowm.xchart.internal.chartpart.Chart; +import org.knowm.xchart.internal.style.markers.SeriesMarkers; /** * Create a Chart matrix - * + * * @author timmolter */ public class Example0WithoutVerticalAndHorizontalLines { @@ -39,13 +40,13 @@ 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.getStyleManager().setYAxisMin(-10); - chart.getStyleManager().setYAxisMax(10); - chart.getStyleManager().setPlotGridVerticalLinesVisible(false); - chart.getStyleManager().setPlotGridHorizontalLinesVisible(false); - Series series = chart.addSeries("" + i, null, getRandomWalk(200)); - series.setMarker(SeriesMarker.NONE); + Chart_XY chart = new ChartBuilder_XY().xAxisTitle("X").yAxisTitle("Y").width(600).height(400).build(); + chart.getStyler().setYAxisMin(-10); + chart.getStyler().setYAxisMax(10); + chart.getStyler().setPlotGridVerticalLinesVisible(false); + chart.getStyler().setPlotGridHorizontalLinesVisible(false); + Series_XY series = chart.addSeries("" + i, null, getRandomWalk(200)); + series.setMarker(SeriesMarkers.NONE); charts.add(chart); } new SwingWrapper(charts).displayChartMatrix(); @@ -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..ae2e8b8d10c566cc2e31b7d5a05b7ba292e91491 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.SeriesMarker; +import org.knowm.xchart.ChartBuilder_XY; +import org.knowm.xchart.Chart_XY; +import org.knowm.xchart.Series_XY; import org.knowm.xchart.SwingWrapper; +import org.knowm.xchart.internal.chartpart.Chart; +import org.knowm.xchart.internal.style.markers.SeriesMarkers; /** * 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 ChartBuilder_XY().xAxisTitle("X").yAxisTitle("Y").width(600).height(400).build(); + chart.getStyler().setYAxisMin(-10); + chart.getStyler().setYAxisMax(10); + chart.getStyler().setPlotGridVerticalLinesVisible(false); + Series_XY series = chart.addSeries("" + i, null, getRandomWalk(200)); + series.setMarker(SeriesMarkers.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..3d6bbd685231b6b8c62163455bcbe9deacea3597 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,11 +18,11 @@ 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.SeriesMarker; +import org.knowm.xchart.Chart_XY; +import org.knowm.xchart.Series_XY; import org.knowm.xchart.VectorGraphicsEncoder; import org.knowm.xchart.VectorGraphicsEncoder.VectorGraphicsFormat; +import org.knowm.xchart.internal.style.markers.SeriesMarkers; /** * Creates a simple Chart and saves it as a PNG and JPEG image file. @@ -34,12 +34,12 @@ 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); - series.setMarker(SeriesMarker.CIRCLE); + chart.setXAxisTitle("Y"); + Series_XY series = chart.addSeries("y(x)", null, yData); + series.setMarker(SeriesMarkers.CIRCLE); BitmapEncoder.saveBitmap(chart, "./Sample_Chart", BitmapFormat.PNG); BitmapEncoder.saveBitmap(chart, "./Sample_Chart", BitmapFormat.JPG); 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..aff6fe7e3fa78376e2f68ceda9128cf1995e6f9c 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.SeriesMarker; +import org.knowm.xchart.ChartBuilder_XY; +import org.knowm.xchart.Chart_XY; +import org.knowm.xchart.Series_XY; import org.knowm.xchart.SwingWrapper; +import org.knowm.xchart.internal.chartpart.Chart; +import org.knowm.xchart.internal.style.markers.SeriesMarkers; /** * Create a Chart matrix - * + * * @author timmolter */ public class Example2 { @@ -39,11 +40,11 @@ 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.getStyleManager().setYAxisMin(-10); - chart.getStyleManager().setYAxisMax(10); - Series series = chart.addSeries("" + i, null, getRandomWalk(200)); - series.setMarker(SeriesMarker.NONE); + Chart_XY chart = new ChartBuilder_XY().xAxisTitle("X").yAxisTitle("Y").width(600).height(400).build(); + chart.getStyler().setYAxisMin(-10); + chart.getStyler().setYAxisMax(10); + Series_XY series = chart.addSeries("" + i, null, getRandomWalk(200)); + series.setMarker(SeriesMarkers.NONE); charts.add(chart); } new SwingWrapper(charts).displayChartMatrix(); @@ -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..221edb8af2021c7cdd29dff7796ad31abeadf08b 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,9 +32,9 @@ 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); + chart.getStyler().setLegendVisible(false); new SwingWrapper(chart).displayChart(); } diff --git a/xchart-demo/src/main/java/org/knowm/xchart/standalone/TestForIssue127.java b/xchart-demo/src/main/java/org/knowm/xchart/standalone/TestForIssue127.java new file mode 100644 index 0000000000000000000000000000000000000000..6b63bf154a2caa5eb86ca5be627060aacb80960b --- /dev/null +++ b/xchart-demo/src/main/java/org/knowm/xchart/standalone/TestForIssue127.java @@ -0,0 +1,72 @@ +/** + * 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.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 org.knowm.xchart.ChartBuilder_XY; +import org.knowm.xchart.Chart_XY; +import org.knowm.xchart.SwingWrapper; + +/** + * @author timmolter + */ +public class TestForIssue127 { + + public static void main(String[] args) throws InterruptedException, ParseException { + + int[] x = new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13 }; + int[] y = new int[] { 1, 0, 1, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 1 }; + // 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_XY chart = new ChartBuilder_XY().width(640).height(480).xAxisTitle("x").yAxisTitle("y").build(); + chart.setTitle("TEst"); + chart.getStyler().setLegendVisible(false); + new SwingWrapper(chart).displayChart(); + Thread.sleep(1000); + + chart.addSeries("test", x, y); + new SwingWrapper(chart).displayChart(); + Thread.sleep(1000); + + chart.removeSeries("test"); + new SwingWrapper(chart).displayChart(); + Thread.sleep(1000); + + DateFormat sdf = new SimpleDateFormat("dd-HH-mm"); + + List<Date> xDate = new ArrayList<Date>(); + xDate.add(sdf.parse("25-01-00")); + xDate.add(sdf.parse("25-02-00")); + xDate.add(sdf.parse("25-03-00")); + List<Double> yDate = new ArrayList<Double>(); + yDate.add(2d); + yDate.add(3d); + yDate.add(5d); + chart.addSeries("test2", xDate, yDate); + new SwingWrapper(chart).displayChart(); + Thread.sleep(1000); + + } + +} 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..ce10a7db5003278c300beb3d6dc46a15a5729842 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.SeriesLineStyle; -import org.knowm.xchart.StyleManager; -import org.knowm.xchart.StyleManager.LegendPosition; +import org.knowm.xchart.Chart_XY; import org.knowm.xchart.SwingWrapper; +import org.knowm.xchart.internal.style.Styler; +import org.knowm.xchart.internal.style.Styler.LegendPosition; +import org.knowm.xchart.internal.style.lines.SeriesLines; /** * @author timmolter @@ -31,8 +31,8 @@ public class TestForIssue83 { public static void main(String[] args) throws IOException { - final Chart chart = new Chart(500, 580); - final StyleManager styleManager = chart.getStyleManager(); + final Chart_XY chart = new Chart_XY(500, 580); + final Styler styleManager = chart.getStyler(); styleManager.setLegendPosition(LegendPosition.InsideNW); styleManager.setLegendVisible(false); @@ -51,7 +51,7 @@ public class TestForIssue83 { 40.45, 40.49, 40.47, 40.59, 40.55, 40.55, 40.35, 40.32, 40.57, 40.33, 40.34, 40.57, 40.38, 40.39, 40.53, 40.33, 40.41, 40.56, 40.37, 40.46, 40.44, 40.47, 40.31, 40.36, 40.55, 40.36, 40.31, 40.6, 40.39, 40.46, 40.49, 40.42, 40.58, 40.44, 40.38, 40.53, 40.5, 40.32, 40.6, 40.33, 40.41, 40.41, 40.53, 40.35, 40.57, 40.46, 40.56, 40.55, 40.34, 40.49, 40.51, 40.32, 40.37, 40.57, 40.5, 40.35, 40.43, 40.38, 40.58, 40.52, 40.59, 40.49, 40.55, 40.56, 40.53, 40.47, 40.41 }; - chart.addSeries("Results", keys, values).setLineStyle(SeriesLineStyle.NONE); + chart.addSeries("Results", keys, values).setLineStyle(SeriesLines.NONE); // BitmapEncoder.saveBitmap(chart, "example", BitmapFormat.PNG); new SwingWrapper(chart).displayChart(); 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..763e14a2381840f61b2cb2f77b0c93e28aeddcc6 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.Styler_XY; import org.knowm.xchart.SwingWrapper; +import org.knowm.xchart.internal.style.Styler.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); + Styler_XY manager = chart.getStyler(); 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..9ff2fa1b5e95350229a13bbdcec73617aebbc68e 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"); @@ -25,21 +25,23 @@ import java.io.Writer; import java.util.Collection; import java.util.Iterator; +import org.knowm.xchart.internal.Series_AxesChart; + /** * 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 +73,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..6a5f1c06e2410fd12d077f04fe3555224882a07b 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.Styler.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/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/ChartBuilder_Pie.java b/xchart/src/main/java/org/knowm/xchart/ChartBuilder_Pie.java new file mode 100644 index 0000000000000000000000000000000000000000..44dcd609c88757a55ce2bae4407bd565bf2baebd --- /dev/null +++ b/xchart/src/main/java/org/knowm/xchart/ChartBuilder_Pie.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 ChartBuilder_Pie extends ChartBuilder<ChartBuilder_Pie, Chart_Pie> { + + public ChartBuilder_Pie() { + + } + + /** + * 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/ChartBuilder_XY.java b/xchart/src/main/java/org/knowm/xchart/ChartBuilder_XY.java new file mode 100644 index 0000000000000000000000000000000000000000..1e3c55ea29a7ade42b0b5318f816d4140af999fb --- /dev/null +++ b/xchart/src/main/java/org/knowm/xchart/ChartBuilder_XY.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_XY extends ChartBuilder<ChartBuilder_XY, Chart_XY> { + + String xAxisTitle = ""; + String yAxisTitle = ""; + + public ChartBuilder_XY() { + + } + + public ChartBuilder_XY xAxisTitle(String xAxisTitle) { + + this.xAxisTitle = xAxisTitle; + return this; + } + + public ChartBuilder_XY 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/Chart_Category.java b/xchart/src/main/java/org/knowm/xchart/Chart_Category.java new file mode 100644 index 0000000000000000000000000000000000000000..938746d4900798aae85def748ecbbcf1882903fd --- /dev/null +++ b/xchart/src/main/java/org/knowm/xchart/Chart_Category.java @@ -0,0 +1,287 @@ +/** + * 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.AxisPair; +import org.knowm.xchart.internal.chartpart.Chart; +import org.knowm.xchart.internal.chartpart.Legend_AxesChart; +import org.knowm.xchart.internal.chartpart.Plot_Category; +import org.knowm.xchart.internal.style.SeriesColorMarkerLineStyle; +import org.knowm.xchart.internal.style.SeriesColorMarkerLineStyleCycler; +import org.knowm.xchart.internal.style.Styler.ChartTheme; +import org.knowm.xchart.internal.style.Theme_; + +/** + * @author timmolter + */ +public class Chart_Category extends Chart<Styler_Category, 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 Styler_Category()); + axisPair = new AxisPair(this); + plot = new Plot_Category(this); + legend = new Legend_AxesChart(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); + styler.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); + } + else { // generate xData + series = new Series_Category(seriesName, getGeneratedData(yData.size()), yData, errorBars); + } + + seriesMap.put(seriesName, series); + + // getXAxis().setAxisType(series.getxAxisDataType()); + // 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(getStyler().getChartCategorySeriesRenderStyle()); + } + } + setSeriesStyles(); + + // paint chart main background + g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); // global rendering hint + g.setColor(styler.getChartBackgroundColor()); + Shape rect = new Rectangle2D.Double(0, 0, getWidth(), getHeight()); + g.fill(rect); + + axisPair.paint(g); + plot.paint(g); + chartTitle.paint(g); + legend.paint(g); + + g.dispose(); + } + + /** + * set the series color, marker and line style based on theme + */ + public void setSeriesStyles() { + + SeriesColorMarkerLineStyleCycler seriesColorMarkerLineStyleCycler = new SeriesColorMarkerLineStyleCycler(getStyler().getSeriesColors(), getStyler().getSeriesMarkers(), getStyler() + .getSeriesLines()); + for (Series_Category series : getSeriesMap().values()) { + + SeriesColorMarkerLineStyle seriesColorMarkerLineStyle = seriesColorMarkerLineStyleCycler.getNextSeriesColorMarkerLineStyle(); + + if (series.getLineStyle() == null) { // wasn't set manually + series.setLineStyle(seriesColorMarkerLineStyle.getStroke()); + } + if (series.getLineColor() == null) { // wasn't set manually + series.setLineColor(seriesColorMarkerLineStyle.getColor()); + } + if (series.getFillColor() == null) { // wasn't set manually + series.setFillColor(seriesColorMarkerLineStyle.getColor()); + } + if (series.getMarker() == null) { // wasn't set manually + series.setMarker(seriesColorMarkerLineStyle.getMarker()); + } + if (series.getMarkerColor() == null) { // wasn't set manually + series.setMarkerColor(seriesColorMarkerLineStyle.getColor()); + } + } + } + +} 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..26bb75fb8c456983a135af21db9fc79bcfbd1b0d --- /dev/null +++ b/xchart/src/main/java/org/knowm/xchart/Chart_Pie.java @@ -0,0 +1,161 @@ +/** + * 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.Legend_Pie; +import org.knowm.xchart.internal.chartpart.Plot_Pie; +import org.knowm.xchart.internal.style.SeriesColorMarkerLineStyle; +import org.knowm.xchart.internal.style.SeriesColorMarkerLineStyleCycler; +import org.knowm.xchart.internal.style.Styler.ChartTheme; +import org.knowm.xchart.internal.style.Theme_; + +/** + * @author timmolter + */ +public class Chart_Pie extends Chart<Styler_Pie, 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 Styler_Pie()); + plot = new Plot_Pie(this); + legend = new Legend_Pie(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); + styler.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(ChartBuilder_Pie 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_Pie addSeries(String seriesName, Number value) { + + Series_Pie series = new Series_Pie(seriesName, value); + + 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(getStyler().getChartPieSeriesRenderStyle()); + } + } + setSeriesStyles(); + + // paint chart main background + g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); // global rendering hint + g.setColor(styler.getChartBackgroundColor()); + Shape rect = new Rectangle2D.Double(0, 0, getWidth(), getHeight()); + g.fill(rect); + + plot.paint(g); + chartTitle.paint(g); + legend.paint(g); + + g.dispose(); + } + + /** + * set the series color based on theme + */ + public void setSeriesStyles() { + + SeriesColorMarkerLineStyleCycler seriesColorMarkerLineStyleCycler = new SeriesColorMarkerLineStyleCycler(getStyler().getSeriesColors(), getStyler().getSeriesMarkers(), + getStyler().getSeriesLines()); + for (Series series : getSeriesMap().values()) { + + SeriesColorMarkerLineStyle seriesColorMarkerLineStyle = seriesColorMarkerLineStyleCycler.getNextSeriesColorMarkerLineStyle(); + + if (series.getFillColor() == null) { // wasn't set manually + series.setFillColor(seriesColorMarkerLineStyle.getColor()); + } + } + } + +} 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..127b329182c09e6b7c9d61112f856bf0e14ffc92 --- /dev/null +++ b/xchart/src/main/java/org/knowm/xchart/Chart_XY.java @@ -0,0 +1,287 @@ +/** + * 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.AxisPair; +import org.knowm.xchart.internal.chartpart.Chart; +import org.knowm.xchart.internal.chartpart.Legend_AxesChart; +import org.knowm.xchart.internal.chartpart.Plot_XY; +import org.knowm.xchart.internal.style.SeriesColorMarkerLineStyle; +import org.knowm.xchart.internal.style.SeriesColorMarkerLineStyleCycler; +import org.knowm.xchart.internal.style.Styler.ChartTheme; +import org.knowm.xchart.internal.style.Theme_; + +/** + * @author timmolter + */ +public class Chart_XY extends Chart<Styler_XY, 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 Styler_XY()); + axisPair = new AxisPair(this); + plot = new Plot_XY(this); + legend = new Legend_AxesChart(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); + styler.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(ChartBuilder_XY 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); + } + else { // generate xData + series = new Series_XY(seriesName, getGeneratedData(yData.size()), yData, errorBars); + } + + seriesMap.put(seriesName, series); + + // getXAxis().setAxisType(series.getxAxisDataType()); + // 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 chartXYSeriesRenderStyle = seriesXY.getChartXYSeriesRenderStyle(); // would be directly set + if (chartXYSeriesRenderStyle == null) { // wasn't overridden, use default from Style Manager + seriesXY.setChartXYSeriesRenderStyle(getStyler().getChartXYSeriesRenderStyle()); + } + } + setSeriesStyles(); + + // paint chart main background + g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); // global rendering hint + g.setColor(styler.getChartBackgroundColor()); + Shape rect = new Rectangle2D.Double(0, 0, getWidth(), getHeight()); + g.fill(rect); + + axisPair.paint(g); + plot.paint(g); + chartTitle.paint(g); + legend.paint(g); + + g.dispose(); + } + + /** + * set the series color, marker and line style based on theme + */ + public void setSeriesStyles() { + + SeriesColorMarkerLineStyleCycler seriesColorMarkerLineStyleCycler = new SeriesColorMarkerLineStyleCycler(getStyler().getSeriesColors(), getStyler().getSeriesMarkers(), getStyler() + .getSeriesLines()); + for (Series_XY series : getSeriesMap().values()) { + + SeriesColorMarkerLineStyle seriesColorMarkerLineStyle = seriesColorMarkerLineStyleCycler.getNextSeriesColorMarkerLineStyle(); + + if (series.getLineStyle() == null) { // wasn't set manually + series.setLineStyle(seriesColorMarkerLineStyle.getStroke()); + } + if (series.getLineColor() == null) { // wasn't set manually + series.setLineColor(seriesColorMarkerLineStyle.getColor()); + } + if (series.getFillColor() == null) { // wasn't set manually + series.setFillColor(seriesColorMarkerLineStyle.getColor()); + } + if (series.getMarker() == null) { // wasn't set manually + series.setMarker(seriesColorMarkerLineStyle.getMarker()); + } + if (series.getMarkerColor() == null) { // wasn't set manually + series.setMarkerColor(seriesColorMarkerLineStyle.getColor()); + } + } + } + +} diff --git a/xchart/src/main/java/org/knowm/xchart/Histogram.java b/xchart/src/main/java/org/knowm/xchart/Histogram.java index c22d2234a80a78468377ed5de6eb05059443c214..8b1fdc6d7816895490b56cda17d9e205a3c81769 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"); @@ -22,7 +22,7 @@ import java.util.Iterator; import java.util.List; /** - * This class can be used to create histogram data for histogram bar charts + * This class can be used to create histogram * * @author timmolter */ diff --git a/xchart/src/main/java/org/knowm/xchart/QuickChart.java b/xchart/src/main/java/org/knowm/xchart/QuickChart.java index bf795a2d5c8517e6f2441cff154ec84be09cd6f8..45060305769b4b55486aa7582b352ff8c187c441 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,9 @@ package org.knowm.xchart; import java.util.List; +import org.knowm.xchart.internal.chartpart.Chart; +import org.knowm.xchart.internal.style.markers.SeriesMarkers; + /** * A convenience class for making Charts with one line of code * @@ -71,24 +74,24 @@ 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]); } else { - chart.getStyleManager().setLegendVisible(false); + chart.getStyler().setLegendVisible(false); series = chart.addSeries(" " + i, xData, yData[i]); } - series.setMarker(SeriesMarker.NONE); + series.setMarker(SeriesMarkers.NONE); } return chart; @@ -108,15 +111,15 @@ 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.setMarker(SeriesMarker.NONE); + Series_XY series = chart.addSeries(seriesName, xData, yData); + series.setMarker(SeriesMarkers.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 deleted file mode 100644 index e3130074e3e8ea15ec5cea59515ee2a4e6463e52..0000000000000000000000000000000000000000 --- a/xchart/src/main/java/org/knowm/xchart/SeriesLineStyle.java +++ /dev/null @@ -1,92 +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.BasicStroke; - -/** - * Pre-defined Line Styles used for Series Lines - * - * @author timmolter - */ -public enum SeriesLineStyle { - - /** NONE */ - NONE(-1, null), - - /** SOLID */ - SOLID(0, new BasicStroke(2.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER)), - - /** DASH_DOT */ - DASH_DOT(1, new BasicStroke(2.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10.0f, new float[] { 3.0f, 1.0f }, 0.0f)), - - /** DASH_DASH */ - DASH_DASH(2, new BasicStroke(2.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10.0f, new float[] { 3.0f, 3.0f }, 0.0f)), - - /** DOT_DOT */ - DOT_DOT(3, new BasicStroke(2.0f, BasicStroke.CAP_BUTT, BasicStroke.CAP_ROUND, 10.0f, new float[] { 2.0f }, 0.0f)); - - /** The index */ - private int index; - - /** The basicStroke */ - private BasicStroke basicStroke; - - /** - * Constructor - * - * @param index - * @param basicStroke - */ - private SeriesLineStyle(int index, BasicStroke basicStroke) { - - this.index = index; - this.basicStroke = basicStroke; - } - - /** - * Gets the SeriesLineStyle's index - * - * @return - */ - public Integer getIndex() { - - return index; - } - - /** - * Gets the SeriesLineStyle's BasicStroke - * - * @return the BasicStroke - */ - public BasicStroke getBasicStroke() { - - return basicStroke; - } - - /** - * Get an AWT Stroke - * - * @param seriesMarker - * @return an AWT Stroke - */ - public static BasicStroke getBasicStroke(SeriesLineStyle seriesMarker) { - - return seriesMarker.basicStroke; - } - -} diff --git a/xchart/src/main/java/org/knowm/xchart/SeriesMarker.java b/xchart/src/main/java/org/knowm/xchart/SeriesMarker.java deleted file mode 100644 index 5bd00b225470435942cf39432436a4c3cc1e9d65..0000000000000000000000000000000000000000 --- a/xchart/src/main/java/org/knowm/xchart/SeriesMarker.java +++ /dev/null @@ -1,89 +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.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; - -/** - * Pre-defined Markers used for Series Lines - * - * @author timmolter - */ -public enum SeriesMarker { - - /** NONE */ - NONE(-1, null), - - /** CIRCLE */ - CIRCLE(0, new Circle()), - - /** DIAMOND */ - DIAMOND(1, new Diamond()), - - /** SQUARE */ - SQUARE(2, new Square()), - - /** TRIANGLE_DOWN */ - TRIANGLE_DOWN(3, new TriangleDown()), - - /** TRIANGLE_UP */ - TRIANGLE_UP(4, new TriangleUp()); - - /** The index */ - private int index; - - /** The Marker */ - private Marker marker; - - /** - * Constructor - * - * @param index - * @param marker - */ - private SeriesMarker(int index, Marker marker) { - - this.index = index; - this.marker = marker; - } - - /** - * Gets the SeriesMarker index - * - * @return - */ - public Integer getIndex() { - - return index; - } - - /** - * Gets the SeriesMarker marker - * - * @return - */ - public Marker getMarker() { - - return marker; - } - -} 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..ee1f5fd7c2c739e0b41e5e6092a16818a5d1717f --- /dev/null +++ b/xchart/src/main/java/org/knowm/xchart/Series_Category.java @@ -0,0 +1,113 @@ +/** + * 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.Series_AxesChart; +import org.knowm.xchart.internal.chartpart.Axis.AxisDataType; +import org.knowm.xchart.internal.chartpart.RenderableSeries; +import org.knowm.xchart.internal.chartpart.RenderableSeries.LegendRenderType; + +/** + * A Series containing category 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), + + Stick(LegendRenderType.Line); + + 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 + */ + public Series_Category(String name, List<?> xData, List<? extends Number> yData, List<? extends Number> errorBars) { + + super(name, xData, yData, errorBars); + + } + + 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..85f94f1716f472c8aea861919734da6a71072948 --- /dev/null +++ b/xchart/src/main/java/org/knowm/xchart/Series_Pie.java @@ -0,0 +1,89 @@ +/** + * 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; + +/** + * 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 + */ + public Series_Pie(String name, Number value) { + + super(name); + 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..9cb871d3add7bb6856017322307ae7f7ae758225 --- /dev/null +++ b/xchart/src/main/java/org/knowm/xchart/Series_XY.java @@ -0,0 +1,101 @@ +/** + * 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.Series_AxesChart; +import org.knowm.xchart.internal.chartpart.RenderableSeries; +import org.knowm.xchart.internal.chartpart.RenderableSeries.LegendRenderType; + +/** + * 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 + */ + public Series_XY(String name, List<?> xData, List<? extends Number> yData, List<? extends Number> errorBars) { + + super(name, xData, yData, errorBars); + } + + 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/Styler_Category.java b/xchart/src/main/java/org/knowm/xchart/Styler_Category.java new file mode 100644 index 0000000000000000000000000000000000000000..a5a0bd0c92124edabe4eb2ab4c7685042ff46c3b --- /dev/null +++ b/xchart/src/main/java/org/knowm/xchart/Styler_Category.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.Styler_AxesChart; +import org.knowm.xchart.internal.style.Theme_; + +/** + * @author timmolter + */ +public class Styler_Category extends Styler_AxesChart { + + private ChartCategorySeriesRenderStyle chartCategorySeriesRenderStyle; + + /** + * Constructor + */ + public Styler_Category() { + + this.setAllStyles(); + super.setAllStyles(); + } + + @Override + protected void setAllStyles() { + + this.chartCategorySeriesRenderStyle = ChartCategorySeriesRenderStyle.Bar; // set default to bar + } + + public ChartCategorySeriesRenderStyle getChartCategorySeriesRenderStyle() { + + return chartCategorySeriesRenderStyle; + } + + /** + * Sets the default series render style for the chart (bar, stick, line, scatter, area, etc.) You can override the series render style individually on each Series object. + * + * @param chartCategorySeriesRenderStyle + */ + public void setChartCategorySeriesRenderStyle(ChartCategorySeriesRenderStyle chartCategorySeriesRenderStyle) { + + this.chartCategorySeriesRenderStyle = chartCategorySeriesRenderStyle; + } + + /** + * Set the theme the styler 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/Styler_Pie.java b/xchart/src/main/java/org/knowm/xchart/Styler_Pie.java new file mode 100644 index 0000000000000000000000000000000000000000..8e0acb807f6dd6c1a5284c1ddf6ef558f094461e --- /dev/null +++ b/xchart/src/main/java/org/knowm/xchart/Styler_Pie.java @@ -0,0 +1,168 @@ +/** + * 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.Font; + +import org.knowm.xchart.Series_Pie.ChartPieSeriesRenderStyle; +import org.knowm.xchart.internal.style.Styler; +import org.knowm.xchart.internal.style.Theme_; + +/** + * @author timmolter + */ +public class Styler_Pie extends Styler { + + private ChartPieSeriesRenderStyle chartPieSeriesRenderStyle; + + public enum AnnotationType { + + Percentage, Label, LabelAndPercentage + } + + private boolean isCircular; + private double startAngleInDegrees; + private Font annotationFont; + private double annotationDistance; + private AnnotationType annotationType; + + /** + * Constructor + */ + public Styler_Pie() { + + this.setAllStyles(); + super.setAllStyles(); + } + + @Override + protected void setAllStyles() { + + chartPieSeriesRenderStyle = ChartPieSeriesRenderStyle.Pie; // set default to pie, donut may be a future one + isCircular = theme.isCircular(); + annotationFont = theme.getPieFont(); + annotationDistance = theme.getAnnotationDistance(); + annotationType = theme.getAnnotationType(); + } + + 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; + } + + public boolean isCircular() { + + return isCircular; + } + + /** + * Sets whether or not the pie chart is forced to be circular. Otherwise it's shape is oval, matching the containing plot. + * + * @param isCircular + */ + public void setCircular(boolean isCircular) { + + this.isCircular = isCircular; + } + + public double getStartAngleInDegrees() { + + return startAngleInDegrees; + } + + /** + * Sets the start angle in degrees. Zero degrees is straight up. + * + * @param startAngleInDegrees + */ + public void setStartAngleInDegrees(double startAngleInDegrees) { + + this.startAngleInDegrees = startAngleInDegrees; + } + + public Font getAnnotationFont() { + + return annotationFont; + } + + /** + * Sets the font used on the Pie Chart's annotations + * + * @param pieFont + */ + public void setAnnotationFont(Font pieFont) { + + this.annotationFont = pieFont; + } + + public double getAnnotationDistance() { + + return annotationDistance; + } + + /** + * Sets the distance of the pie chart's annotation where 0 is the center, 1 is at the edge and greater than 1 is outside of the pie chart. + * + * @param annotationDistance + */ + public void setAnnotationDistance(double annotationDistance) { + + this.annotationDistance = annotationDistance; + } + + public AnnotationType getAnnotationType() { + + return annotationType; + } + + /** + * Sets the Pie chart's annotation type + * + * @param annotationType + */ + public void setAnnotationType(AnnotationType annotationType) { + + this.annotationType = annotationType; + } + + /** + * Set the theme the styler 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/Styler_XY.java b/xchart/src/main/java/org/knowm/xchart/Styler_XY.java new file mode 100644 index 0000000000000000000000000000000000000000..d000c37e145b0f94b2534516c1d381220d92d395 --- /dev/null +++ b/xchart/src/main/java/org/knowm/xchart/Styler_XY.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.Styler_AxesChart; +import org.knowm.xchart.internal.style.Theme_; + +/** + * @author timmolter + */ +public class Styler_XY extends Styler_AxesChart { + + private ChartXYSeriesRenderStyle chartXYSeriesRenderStyle; + + /** + * Constructor + */ + public Styler_XY() { + + 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 styler 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..34434c22fdd1884a878a389ce80ce65149375bbf 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,9 @@ 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.Series_AxesChart; +import org.knowm.xchart.internal.chartpart.Chart; /** * A Swing JPanel that contains a Chart @@ -94,6 +98,7 @@ public class XChartPanel extends JPanel { } public Chart getChart() { + return this.chart; } @@ -290,7 +295,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..00d3a5ca0e89a8395308aed62aec4e325ad14a64 --- /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.Styler.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..128b3a59e29c44a5851586220887a43760e055c4 --- /dev/null +++ b/xchart/src/main/java/org/knowm/xchart/internal/Series.java @@ -0,0 +1,77 @@ +/** + * 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; + +/** + * A Series containing data to be plotted on a Chart + * + * @author timmolter + */ +public abstract class Series { + + public abstract LegendRenderType getLegendRenderType(); + + private final String name; + + private Color fillColor; + + private boolean showInLegend; + + /** + * Constructor + * + * @param name + * @param seriesColorMarkerLineStyle + */ + public Series(String name) { + + if (name == null || name.length() < 1) { + throw new IllegalArgumentException("Series name cannot be null or zero-length!!!"); + } + this.name = name; + } + + public Color getFillColor() { + + return fillColor; + } + + public void setFillColor(Color fillColor) { + + this.fillColor = fillColor; + } + + public String getName() { + + return name; + } + + public boolean isShowInLegend() { + + return showInLegend; + } + + public void setShowInLegend(boolean showInLegend) { + + this.showInLegend = showInLegend; + } + +} diff --git a/xchart/src/main/java/org/knowm/xchart/Series.java b/xchart/src/main/java/org/knowm/xchart/internal/Series_AxesChart.java similarity index 65% rename from xchart/src/main/java/org/knowm/xchart/Series.java rename to xchart/src/main/java/org/knowm/xchart/internal/Series_AxesChart.java index 574c71cbcbd3540d2e3acb3d2e5816ac257656e7..02a9900d329e6385bee168b83959ce95916f384b 100644 --- a/xchart/src/main/java/org/knowm/xchart/Series.java +++ b/xchart/src/main/java/org/knowm/xchart/internal/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"); @@ -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; import java.awt.BasicStroke; import java.awt.Color; @@ -23,30 +23,23 @@ 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.style.SeriesColorMarkerLineStyle; +import org.knowm.xchart.internal.chartpart.Axis.AxisDataType; +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 +61,6 @@ public class Series { /** Line Color */ private Color strokeColor; - /** Fill Colour */ - private Color fillColor; - /** Marker Style */ private Marker marker; @@ -86,29 +76,57 @@ public class Series { * @param yData * @param yAxisType * @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) { + + super(name); - 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 +135,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 +148,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) { @@ -177,17 +195,6 @@ public class Series { return new double[] { min, max }; } - /** - * Set the line style of the series - * - * @param seriesLineStyle - */ - public Series setLineStyle(SeriesLineStyle seriesLineStyle) { - - stroke = SeriesLineStyle.getBasicStroke(seriesLineStyle); - return this; - } - /** * Set the line style of the series * @@ -199,17 +206,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 * @@ -226,20 +222,9 @@ public class Series { * * @param seriesMarker */ - public Series setMarker(SeriesMarker seriesMarker) { - - this.marker = seriesMarker.getMarker(); - return this; - } - - /** - * Sets the marker color for the series - * - * @param seriesColor - */ - public Series setMarkerColor(SeriesColor seriesColor) { + public Series setMarker(Marker seriesMarker) { - this.markerColor = seriesColor.getColor(); + this.marker = seriesMarker; return this; } @@ -254,24 +239,24 @@ public class Series { return this; } - public SeriesType getSeriesType() { + public Collection<?> getXData() { - return seriesType; + return xData; } - public void setSeriesType(SeriesType seriesType) { + public AxisDataType getxAxisDataType() { - this.seriesType = seriesType; + return xAxisType; } - public Collection<?> getXData() { + public Collection<? extends Number> getYData() { - return xData; + return yData; } - public Collection<? extends Number> getYData() { + public AxisDataType getyAxisDataType() { - return yData; + return yAxisType; } public Collection<? extends Number> getErrorBars() { @@ -299,7 +284,7 @@ public class Series { return yMax; } - public BasicStroke getStroke() { + public BasicStroke getLineStyle() { return stroke; } @@ -309,7 +294,7 @@ public class Series { return marker; } - public Color getStrokeColor() { + public Color getLineColor() { return strokeColor; } @@ -319,57 +304,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/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..a64f978020b14bc73f8fe4a8f4081f5052fa7acd 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.Styler_Category; +import org.knowm.xchart.internal.Series; +import org.knowm.xchart.internal.Series_AxesChart; +import org.knowm.xchart.internal.style.Styler.LegendPosition; +import org.knowm.xchart.internal.style.Styler_AxesChart; /** * Axis * * @author timmolter */ -public class Axis implements ChartPart { +public class Axis<ST extends Styler_AxesChart, S extends Series> implements ChartPart { - public enum AxisType { + public enum AxisDataType { Number, Date, String; } - /** parent */ - private AxisPair axisPair; + private final Chart<Styler_AxesChart, Series_AxesChart> chart; + private Rectangle2D bounds; + + // TODO 3.0.0 use bounds only??? + /** the paint zone */ + private Rectangle2D paintZone; + + protected Rectangle2D getPaintZone() { - /** the axisType */ - private AxisType axisType; + return paintZone; + } + + /** the axisDataType */ + private AxisDataType axisDataType; /** the axis title */ - private AxisTitle axisTitle; + private AxisTitle<Styler_AxesChart, Series_AxesChart> axisTitle; /** the axis tick */ - private AxisTick axisTick; + private AxisTick<Styler_AxesChart, 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,15 +86,16 @@ 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<Styler_AxesChart, 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<Styler_AxesChart, Series_AxesChart>(chart, direction); + axisTick = new AxisTick<Styler_AxesChart, Series_AxesChart>(chart, direction); + // resetMinMax(); } /** @@ -121,20 +127,6 @@ public class Axis implements ChartPart { // System.out.println(this.max); } - protected void setAxisType(AxisType axisType) { - - if (this.axisType != null && this.axisType != axisType) { - throw new IllegalArgumentException("Different Axes (Date, Number, String) cannot be mixed on the same chart!!"); - } - this.axisType = axisType; - } - - @Override - public Rectangle2D getBounds() { - - return bounds; - } - @Override public void paint(Graphics2D g) { @@ -144,12 +136,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 +145,10 @@ public class Axis implements ChartPart { // | // | // ---- - double xOffset = getChartInternal().getStyleManager().getChartPadding(); - double yOffset = getChartInternal().getChartTitle().getSizeHint(); + double xOffset = chart.getStyler().getChartPadding(); + // double yOffset = chart.getChartTitle().getBounds().getHeight() < .1 ? chart.getStyler().getChartPadding() : chart.getChartTitle().getBounds().getHeight() + // + chart.getStyler().getChartPadding(); + double yOffset = chart.getChartTitle().getBounds().getHeight() + chart.getStyler().getChartPadding(); ///////////////////////// int i = 1; // just twice through is all it takes @@ -171,23 +159,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.getStyler().getLegendPosition() == LegendPosition.OutsideE ? chart.getLegend().getBounds().getWidth() : 0) - - 2 * getChartInternal().getStyleManager().getChartPadding() + - 2 * chart.getStyler().getChartPadding() - - (getChartInternal().getStyleManager().isYAxisTicksVisible() ? (getChartInternal().getStyleManager().getPlotPadding()) : 0) + - (chart.getStyler().isYAxisTicksVisible() ? (chart.getStyler().getPlotMargin()) : 0) - - (getChartInternal().getStyleManager().getLegendPosition() == LegendPosition.OutsideE && getChartInternal().getStyleManager().isLegendVisible() ? getChartInternal().getStyleManager() - .getChartPadding() : 0) + - (chart.getStyler().getLegendPosition() == LegendPosition.OutsideE && chart.getStyler().isLegendVisible() ? chart.getStyler().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.getStyler().getPlotMargin() - chart.getStyler().getChartPadding(); width = getYAxisWidthHint(height); // System.out.println("width after: " + width); @@ -209,7 +195,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.getStyler().isYAxisTitleVisible() ? axisTitle.getBounds().getWidth() : 0) + axisTick.getBounds().getWidth(); height = paintZone.getHeight(); bounds = new Rectangle2D.Double(xOffset, yOffset, width, height); @@ -219,42 +205,32 @@ 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.getStyler().isYAxisTicksVisible() ? chart.getStyler().getPlotMargin() : 0) + chart.getStyler().getChartPadding(); + double yOffset = chart.getYAxis().getBounds().getY() + chart.getYAxis().getBounds().getHeight() + chart.getStyler().getPlotMargin(); 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.getStyler().getLegendPosition() == LegendPosition.OutsideE ? chart.getLegend().getBounds().getWidth() : 0) - - 2 * getChartInternal().getStyleManager().getChartPadding() + - 2 * chart.getStyler().getChartPadding() - - (getChartInternal().getStyleManager().isYAxisTicksVisible() ? (getChartInternal().getStyleManager().getPlotPadding()) : 0) + - (chart.getStyler().isYAxisTicksVisible() ? (chart.getStyler().getPlotMargin()) : 0) - - (getChartInternal().getStyleManager().getLegendPosition() == LegendPosition.OutsideE && getChartInternal().getStyleManager().isLegendVisible() ? getChartInternal().getStyleManager() - .getChartPadding() : 0) + - (chart.getStyler().getLegendPosition() == LegendPosition.OutsideE && chart.getStyler().isLegendVisible() ? chart.getStyler().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.getStyler().getChartPadding() - chart.getStyler().getPlotMargin(); // System.out.println("height2: " + height2); Rectangle2D xAxisRectangle = new Rectangle2D.Double(xOffset, yOffset, width, height); @@ -276,6 +252,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 +261,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.getStyler().isXAxisTitleVisible()) { + TextLayout textLayout = new TextLayout(chart.getXAxisTitle(), chart.getStyler().getAxisTitleFont(), new FontRenderContext(null, true, false)); Rectangle2D rectangle = textLayout.getBounds(); - titleHeight = rectangle.getHeight() + getChartInternal().getStyleManager().getAxisTitlePadding(); + titleHeight = rectangle.getHeight() + chart.getStyler().getAxisTitlePadding(); } // Axis tick labels double axisTickLabelsHeight = 0.0; - if (getChartInternal().getStyleManager().isXAxisTicksVisible()) { + if (chart.getStyler().isXAxisTicksVisible()) { // get some real tick labels // System.out.println("XAxisHeightHint"); @@ -316,34 +289,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.getStyler().getAxisTickLabelsFont(), new FontRenderContext(null, true, false)); + AffineTransform rot = chart.getStyler().getXAxisLabelRotation() == 0 ? null : AffineTransform.getRotateInstance(-1 * Math.toRadians(chart.getStyler().getXAxisLabelRotation())); Shape shape = textLayout.getOutline(rot); Rectangle2D rectangle = shape.getBounds(); - axisTickLabelsHeight = rectangle.getHeight() + getChartInternal().getStyleManager().getAxisTickPadding() + getChartInternal().getStyleManager().getAxisTickMarkLength(); + axisTickLabelsHeight = rectangle.getHeight() + chart.getStyler().getAxisTickPadding() + chart.getStyler().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.getStyler().isYAxisTitleVisible()) { + TextLayout textLayout = new TextLayout(chart.getyYAxisTitle(), chart.getStyler().getAxisTitleFont(), new FontRenderContext(null, true, false)); Rectangle2D rectangle = textLayout.getBounds(); - titleHeight = rectangle.getHeight() + getChartInternal().getStyleManager().getAxisTitlePadding(); + titleHeight = rectangle.getHeight() + chart.getStyler().getAxisTitlePadding(); } // Axis tick labels double axisTickLabelsHeight = 0.0; - if (getChartInternal().getStyleManager().isYAxisTicksVisible()) { + if (chart.getStyler().isYAxisTicksVisible()) { // get some real tick labels // System.out.println("XAxisHeightHint"); @@ -359,38 +327,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.getStyler().getAxisTickLabelsFont(), new FontRenderContext(null, true, false)); Rectangle2D rectangle = textLayout.getBounds(); - axisTickLabelsHeight = rectangle.getWidth() + getChartInternal().getStyleManager().getAxisTickPadding() + getChartInternal().getStyleManager().getAxisTickMarkLength(); + axisTickLabelsHeight = rectangle.getWidth() + chart.getStyler().getAxisTickPadding() + chart.getStyler().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.getStyler() instanceof Styler_Category) { + + List<?> categories = (List<?>) chart.getSeriesMap().values().iterator().next().getXData(); + AxisDataType axisType = chart.getAxisPair().getXAxis().getAxisDataType(); + + return new AxisTickCalculator_Category(getDirection(), workingSpace, categories, axisType, chart.getStyler()); - 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.getStyler()); } - else if (getChartInternal().getStyleManager().isXAxisLogarithmic()) { + else if (chart.getStyler().isXAxisLogarithmic()) { - return new AxisTickCalculator_Logarithmic(getDirection(), workingSpace, min, max, getChartInternal().getStyleManager()); + return new AxisTickCalculator_Logarithmic(getDirection(), workingSpace, min, max, chart.getStyler()); } else { - return new AxisTickCalculator_Number(getDirection(), workingSpace, min, max, getChartInternal().getStyleManager()); + return new AxisTickCalculator_Number(getDirection(), workingSpace, min, max, chart.getStyler()); } } @@ -398,32 +365,31 @@ 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.getStyler().isYAxisLogarithmic() && getAxisDataType() != AxisDataType.Date) { - return new AxisTickCalculator_Logarithmic(getDirection(), workingSpace, min, max, getChartInternal().getStyleManager()); + return new AxisTickCalculator_Logarithmic(getDirection(), workingSpace, min, max, chart.getStyler()); } else { - return new AxisTickCalculator_Number(getDirection(), workingSpace, min, max, getChartInternal().getStyleManager()); + return new AxisTickCalculator_Number(getDirection(), workingSpace, min, max, chart.getStyler()); } } } - @Override - public ChartInternal getChartInternal() { + // Getters ///////////////////////////////////////////////// - return axisPair.getChartInternal(); - } + protected AxisDataType getAxisDataType() { - // Getters ///////////////////////////////////////////////// + return axisDataType; + } - public AxisType getAxisType() { + public void setAxisDataType(AxisDataType axisDataType) { - return axisType; + if (axisDataType != null && this.axisDataType != null && this.axisDataType != axisDataType) { + throw new IllegalArgumentException("Different Axes (e.g. Date, Number, String) cannot be mixed on the same chart!!"); + } + this.axisDataType = 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<Styler_AxesChart, Series_AxesChart> getAxisTick() { - return paintZone; + return axisTick; } - public AxisTitle getAxisTitle() { + protected Direction getDirection() { - return axisTitle; + return direction; } - protected void setAxisTitle(AxisTitle axisTitle) { + protected AxisTitle<Styler_AxesChart, 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..5c3d625cb5e9c54d151374f5714c0afcf6a3c95e 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,155 @@ package org.knowm.xchart.internal.chartpart; import java.awt.Graphics2D; import java.awt.geom.Rectangle2D; +import org.knowm.xchart.Series_Category.ChartCategorySeriesRenderStyle; +import org.knowm.xchart.Styler_Category; +import org.knowm.xchart.internal.Series; +import org.knowm.xchart.internal.Series_AxesChart; +import org.knowm.xchart.internal.style.Styler_AxesChart; + /** * @author timmolter */ -public class AxisPair implements ChartPart { +public class AxisPair<ST extends Styler_AxesChart, S extends Series> implements ChartPart { - /** parent */ - private final ChartInternal chartInternal; + private final Chart<Styler_AxesChart, Series_AxesChart> chart; - private Axis xAxis; - private Axis yAxis; + private final Axis<Styler_AxesChart, Series_AxesChart> xAxis; + private final Axis<Styler_AxesChart, Series_AxesChart> yAxis; /** * Constructor * - * @param the parent chartInternal + * @param chart */ - public AxisPair(ChartInternal chartInternal) { + public AxisPair(Chart<Styler_AxesChart, 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<Styler_AxesChart, Series_AxesChart>(chart, Axis.Direction.X); + yAxis = new Axis<Styler_AxesChart, 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() { + + // set the axis data types, making sure all are compatible + xAxis.setAxisDataType(null); + yAxis.setAxisDataType(null); + for (Series_AxesChart series : chart.getSeriesMap().values()) { + xAxis.setAxisDataType(series.getxAxisDataType()); + yAxis.setAxisDataType(series.getyAxisDataType()); + } + + // calculate axis min and max + xAxis.resetMinMax(); + yAxis.resetMinMax(); + + // if no series, we still want to plot an empty plot with axes. Since there are no min an max with no series added, we just fake it arbirarily. + if (chart.getSeriesMap() == null || chart.getSeriesMap().size() < 1) { + xAxis.addMinMax(-1, 1); + yAxis.addMinMax(-1, 1); + } + else { + 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.getStyler().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.getStyler().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.getStyler() instanceof Styler_Category) { + + Styler_Category stylerCategory = (Styler_Category) chart.getStyler(); + if (stylerCategory.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.getStyler().getXAxisMin() != null) + + { + overrideXAxisMinValue = chart.getStyler().getXAxisMin(); + } + if (chart.getStyler().getXAxisMax() != null) + + { + overrideXAxisMaxValue = chart.getStyler().getXAxisMax(); + } + if (chart.getStyler().getYAxisMin() != null) + + { + overrideYAxisMinValue = chart.getStyler().getYAxisMin(); + } + if (chart.getStyler().getYAxisMax() != null) + + { + overrideYAxisMaxValue = chart.getStyler().getYAxisMax(); + } + + xAxis.setMin(overrideXAxisMinValue); + xAxis.setMax(overrideXAxisMaxValue); + yAxis.setMin(overrideYAxisMinValue); + yAxis.setMax(overrideYAxisMaxValue); - return chartInternal; } - // Getters ///////////////////////////////////////////////// + // Getters & Setters ///////////////////////////////////////////////// - public Axis getXAxis() { + protected Axis<Styler_AxesChart, Series_AxesChart> getXAxis() { return xAxis; } - public Axis getYAxis() { + protected Axis<Styler_AxesChart, 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..acf8027b7ec40da381e96b47776d4d9afe28f6cb 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.internal.Series; +import org.knowm.xchart.internal.Series_AxesChart; +import org.knowm.xchart.internal.chartpart.Axis.Direction; +import org.knowm.xchart.internal.style.Styler_AxesChart; + /** * An axis tick */ -public class AxisTick implements ChartPart { +public class AxisTick<ST extends Styler_AxesChart, S extends Series> implements ChartPart { - /** parent */ - private Axis axis; + private final Chart<Styler_AxesChart, Series_AxesChart> chart; + private Rectangle2D bounds; + private final Direction direction; /** the axisticklabels */ - private AxisTickLabels axisTickLabels; + private AxisTickLabels<Styler_AxesChart, Series_AxesChart> axisTickLabels; /** the axistickmarks */ - private AxisTickMarks axisTickMarks; - - /** the bounds */ - private Rectangle2D bounds = new Rectangle2D.Double(); + private AxisTickMarks<Styler_AxesChart, Series_AxesChart> axisTickMarks; /** * Constructor * - * @param axis + * @param chart + * @param direction */ - protected AxisTick(Axis axis) { + protected AxisTick(Chart<Styler_AxesChart, 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<Styler_AxesChart, Series_AxesChart>(chart, direction); + axisTickMarks = new AxisTickMarks<Styler_AxesChart, 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.getStyler().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.getStyler().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.getStyler().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.getStyler().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<Styler_AxesChart, 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 83% 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..e06975dda2101854f814fe236b55235f631a102e 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.Styler_AxesChart; /** * @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 Styler_AxesChart styler; /** * Constructor @@ -55,15 +55,15 @@ public abstract class AxisTickCalculator { * @param workingSpace * @param minValue * @param maxValue - * @param styleManager + * @param styler */ - public AxisTickCalculator(Direction axisDirection, double workingSpace, double minValue, double maxValue, StyleManager styleManager) { + public AxisTickCalculator_(Direction axisDirection, double workingSpace, double minValue, double maxValue, Styler_AxesChart styler) { this.axisDirection = axisDirection; this.workingSpace = workingSpace; this.minValue = minValue; this.maxValue = maxValue; - this.styleManager = styleManager; + this.styler = styler; } /** @@ -113,8 +113,8 @@ public abstract class AxisTickCalculator { } // System.out.println("longestLabel: " + sampleLabel); - TextLayout textLayout = new TextLayout(sampleLabel, styleManager.getAxisTickLabelsFont(), new FontRenderContext(null, true, false)); - AffineTransform rot = styleManager.getXAxisLabelRotation() == 0 ? null : AffineTransform.getRotateInstance(-1 * Math.toRadians(styleManager.getXAxisLabelRotation())); + TextLayout textLayout = new TextLayout(sampleLabel, styler.getAxisTickLabelsFont(), new FontRenderContext(null, true, false)); + AffineTransform rot = styler.getXAxisLabelRotation() == 0 ? null : AffineTransform.getRotateInstance(-1 * Math.toRadians(styler.getXAxisLabelRotation())); Shape shape = textLayout.getOutline(rot); Rectangle2D rectangle = shape.getBounds(); double largestLabelWidth = rectangle.getWidth(); 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..bbee9ff158e4713f80417a1c83aab86c774b0760 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.Styler_AxesChart; /** * 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 @@ -40,19 +40,19 @@ public class AxisTickCalculator_Category extends AxisTickCalculator { * @param workingSpace * @param categories * @param axisType - * @param styleManager + * @param styler */ - public AxisTickCalculator_Category(Direction axisDirection, double workingSpace, List<?> categories, AxisType axisType, StyleManager styleManager) { + public AxisTickCalculator_Category(Direction axisDirection, double workingSpace, List<?> categories, AxisDataType axisType, Styler_AxesChart styler) { - super(axisDirection, workingSpace, Double.NaN, Double.NaN, styleManager); + super(axisDirection, workingSpace, Double.NaN, Double.NaN, styler); 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 + int tickSpace = (int) (styler.getPlotContentSize() * workingSpace); // in plot space // where the tick should begin in the working space in pixels double margin = Utils.getTickStartOffset(workingSpace, tickSpace); @@ -64,29 +64,29 @@ public class AxisTickCalculator_Category extends AxisTickCalculator { // set up String formatters that may be encountered NumberFormatter numberFormatter = null; SimpleDateFormat simpleDateformat = null; - if (axisType == AxisType.Number) { - numberFormatter = new NumberFormatter(styleManager); + if (axisType == AxisDataType.Number) { + numberFormatter = new NumberFormatter(styler); } - else if (axisType == AxisType.Date) { - if (styleManager.getDatePattern() == null) { + else if (axisType == AxisDataType.Date) { + if (styler.getDatePattern() == null) { throw new RuntimeException("You need to set the Date Formatting Pattern!!!"); } - simpleDateformat = new SimpleDateFormat(styleManager.getDatePattern(), styleManager.getLocale()); - simpleDateformat.setTimeZone(styleManager.getTimezone()); + simpleDateformat = new SimpleDateFormat(styler.getDatePattern(), styler.getLocale()); + simpleDateformat.setTimeZone(styler.getTimezone()); } 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..b526ededf5e935d937a2b0d3b090eeb580ed8724 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.Styler_AxesChart; /** * 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); @@ -106,11 +106,11 @@ public class AxisTickCalculator_Date extends AxisTickCalculator { * @param workingSpace * @param minValue * @param maxValue - * @param styleManager + * @param styler */ - public AxisTickCalculator_Date(Direction axisDirection, double workingSpace, double minValue, double maxValue, StyleManager styleManager) { + public AxisTickCalculator_Date(Direction axisDirection, double workingSpace, double minValue, double maxValue, Styler_AxesChart styler) { - super(axisDirection, workingSpace, minValue, maxValue, styleManager); + super(axisDirection, workingSpace, minValue, maxValue, styler); calculate(); } @@ -118,10 +118,10 @@ public class AxisTickCalculator_Date extends AxisTickCalculator { private void calculate() { // tick space - a percentage of the working space available for ticks - double tickSpace = styleManager.getAxisTickSpacePercentage() * workingSpace; // in plot space + double tickSpace = styler.getPlotContentSize() * workingSpace; // in plot space // this prevents an infinite loop when the plot gets sized really small. - if (tickSpace < styleManager.getXAxisTickMarkSpacingHint()) { + if (tickSpace < styler.getXAxisTickMarkSpacingHint()) { // System.out.println("Returning!"); return; } @@ -134,7 +134,7 @@ public class AxisTickCalculator_Date extends AxisTickCalculator { // System.out.println("span: " + span); // Generate the labels first, see if they "look" OK and reiterate with an increased tickSpacingHint - int tickSpacingHint = styleManager.getXAxisTickMarkSpacingHint(); + int tickSpacingHint = styler.getXAxisTickMarkSpacingHint(); int gridStepInChartSpace = 0; // System.out.println("calculating ticks..."); @@ -185,13 +185,13 @@ public class AxisTickCalculator_Date extends AxisTickCalculator { // Define Date Pattern // override pattern if one was explicitly given - if (styleManager.getDatePattern() != null) { - datePattern = styleManager.getDatePattern(); + if (styler.getDatePattern() != null) { + datePattern = styler.getDatePattern(); } // System.out.println("datePattern: " + datePattern); - SimpleDateFormat simpleDateformat = new SimpleDateFormat(datePattern, styleManager.getLocale()); - simpleDateformat.setTimeZone(styleManager.getTimezone()); + SimpleDateFormat simpleDateformat = new SimpleDateFormat(datePattern, styler.getLocale()); + simpleDateformat.setTimeZone(styler.getTimezone()); // return simpleDateformat.format(value); 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..a759e07e50da6df0831adee78eeec5c22617694d 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.Styler_AxesChart; /** * 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; @@ -38,12 +38,12 @@ public class AxisTickCalculator_Logarithmic extends AxisTickCalculator { * @param workingSpace * @param minValue * @param maxValue - * @param styleManager + * @param styler */ - public AxisTickCalculator_Logarithmic(Direction axisDirection, double workingSpace, double minValue, double maxValue, StyleManager styleManager) { + public AxisTickCalculator_Logarithmic(Direction axisDirection, double workingSpace, double minValue, double maxValue, Styler_AxesChart styler) { - super(axisDirection, workingSpace, minValue, maxValue, styleManager); - numberFormatter = new NumberFormatter(styleManager); + super(axisDirection, workingSpace, minValue, maxValue, styler); + numberFormatter = new NumberFormatter(styler); calculate(); } @@ -57,10 +57,10 @@ public class AxisTickCalculator_Logarithmic extends AxisTickCalculator { } // tick space - a percentage of the working space available for ticks - double tickSpace = styleManager.getAxisTickSpacePercentage() * workingSpace; // in plot space + double tickSpace = styler.getPlotContentSize() * workingSpace; // in plot space // this prevents an infinite loop when the plot gets sized really small. - if (tickSpace < styleManager.getXAxisTickMarkSpacingHint()) { + if (tickSpace < styler.getXAxisTickMarkSpacingHint()) { return; } @@ -74,17 +74,17 @@ public class AxisTickCalculator_Logarithmic extends AxisTickCalculator { // System.out.println("logMin: " + logMin); // System.out.println("logMax: " + logMax); - // if (axisDirection == Direction.Y && styleManager.getYAxisMin() != null) { - // logMin = (int) (Math.log10(styleManager.getYAxisMin())); // no floor + // if (axisDirection == Direction.Y && styler.getYAxisMin() != null) { + // logMin = (int) (Math.log10(styler.getYAxisMin())); // no floor // } - // if (axisDirection == Direction.Y && styleManager.getYAxisMax() != null) { - // logMax = (int) (Math.log10(styleManager.getYAxisMax())); // no floor + // if (axisDirection == Direction.Y && styler.getYAxisMax() != null) { + // logMax = (int) (Math.log10(styler.getYAxisMax())); // no floor // } - // if (axisDirection == Direction.X && styleManager.getXAxisMin() != null) { - // logMin = (int) (Math.log10(styleManager.getXAxisMin())); // no floor + // if (axisDirection == Direction.X && styler.getXAxisMin() != null) { + // logMin = (int) (Math.log10(styler.getXAxisMin())); // no floor // } - // if (axisDirection == Direction.X && styleManager.getXAxisMax() != null) { - // logMax = (int) (Math.log10(styleManager.getXAxisMax())); // no floor + // if (axisDirection == Direction.X && styler.getXAxisMax() != null) { + // logMax = (int) (Math.log10(styler.getXAxisMax())); // no floor // } double firstPosition = Utils.pow(10, logMin); 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..18e04ce5f1a421e92ba22f14f8e5aaada3d98b28 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.Styler_AxesChart; /** * 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; @@ -39,12 +39,12 @@ public class AxisTickCalculator_Number extends AxisTickCalculator { * @param workingSpace * @param minValue * @param maxValue - * @param styleManager + * @param styler */ - public AxisTickCalculator_Number(Direction axisDirection, double workingSpace, double minValue, double maxValue, StyleManager styleManager) { + public AxisTickCalculator_Number(Direction axisDirection, double workingSpace, double minValue, double maxValue, Styler_AxesChart styler) { - super(axisDirection, workingSpace, minValue, maxValue, styleManager); - numberFormatter = new NumberFormatter(styleManager); + super(axisDirection, workingSpace, minValue, maxValue, styler); + numberFormatter = new NumberFormatter(styler); calculate(); } @@ -58,21 +58,21 @@ public class AxisTickCalculator_Number extends AxisTickCalculator { } // tick space - a percentage of the working space available for ticks - double tickSpace = styleManager.getAxisTickSpacePercentage() * workingSpace; // in plot space + double tickSpace = styler.getPlotContentSize() * workingSpace; // in plot space // this prevents an infinite loop when the plot gets sized really small. - if (tickSpace < styleManager.getXAxisTickMarkSpacingHint()) { + if (tickSpace < styler.getXAxisTickMarkSpacingHint()) { return; } // where the tick should begin in the working space in pixels double margin = Utils.getTickStartOffset(workingSpace, tickSpace); // in plot space double gridStep = getGridStepForDecimal(tickSpace); // the span of the data - double span = Math.abs(maxValue - minValue); // in data space + double span = Math.abs(Math.min((maxValue - minValue), Double.MAX_VALUE - 1)); // in data space ////////////////////////// - int tickSpacingHint = (axisDirection == Direction.X ? styleManager.getXAxisTickMarkSpacingHint() : styleManager.getYAxisTickMarkSpacingHint()) - 5; + int tickSpacingHint = (axisDirection == Direction.X ? styler.getXAxisTickMarkSpacingHint() : styler.getYAxisTickMarkSpacingHint()) - 5; // for very short plots, squeeze some more ticks in than normal into the Y-Axis if (axisDirection == Direction.Y && tickSpace < 160) { 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..8e69be386ab68eb687345287b1114cbc4a3c4df4 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.internal.Series; +import org.knowm.xchart.internal.Series_AxesChart; +import org.knowm.xchart.internal.chartpart.Axis.Direction; +import org.knowm.xchart.internal.style.Styler_AxesChart; + /** * Axis tick labels */ -public class AxisTickLabels implements ChartPart { - - /** parent */ - private final AxisTick axisTick; +public class AxisTickLabels<ST extends Styler_AxesChart, S extends Series> implements ChartPart { - /** the bounds */ - private Rectangle2D bounds = new Rectangle2D.Double(); + private final Chart<Styler_AxesChart, Series_AxesChart> chart; + private Rectangle2D bounds; + private final Direction direction; /** * Constructor * - * @param axisTick + * @param chart + * @param direction */ - protected AxisTickLabels(AxisTick axisTick) { + protected AxisTickLabels(Chart<Styler_AxesChart, 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.getStyler().getAxisTickLabelsFont()); - g.setColor(getChartInternal().getStyleManager().getAxisTickLabelsColor()); + g.setColor(chart.getStyler().getAxisTickLabelsColor()); - if (axisTick.getAxis().getDirection() == Axis.Direction.Y && getChartInternal().getStyleManager().isYAxisTicksVisible()) { // Y-Axis + if (direction == Axis.Direction.Y && chart.getStyler().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.getStyler().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.getStyler().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.getStyler().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.getStyler().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.getStyler().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.getStyler().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.getStyler().getXAxisLabelRotation())); double shiftY = -1 * (tickLabelBounds.getY() + tickLabelBounds.getHeight()); // System.out.println(shiftX); // System.out.println("shiftY: " + shiftY); @@ -179,7 +178,7 @@ public class AxisTickLabels implements ChartPart { // // debug box // g.setColor(Color.MAGENTA); // g.draw(new Rectangle2D.Double(xPos, yOffset - tickLabelBounds.getHeight(), tickLabelBounds.getWidth(), tickLabelBounds.getHeight())); - // g.setColor(getChartPainter().getStyleManager().getAxisTickLabelsColor()); + // g.setColor(getChartPainter().getstyler().getAxisTickLabelsColor()); if (tickLabelBounds.getHeight() > maxTickLabelHeight) { maxTickLabelHeight = tickLabelBounds.getHeight(); @@ -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..3dee366837b046462b9938ea05926352113201ac 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.internal.Series; +import org.knowm.xchart.internal.Series_AxesChart; +import org.knowm.xchart.internal.chartpart.Axis.Direction; +import org.knowm.xchart.internal.style.Styler_AxesChart; + /** * 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<ST extends Styler_AxesChart, S extends Series> implements ChartPart { - /** the bounds */ - private Rectangle2D bounds = new Rectangle2D.Double(); + private final Chart<Styler_AxesChart, 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<Styler_AxesChart, 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.getStyler().getAxisTickMarksColor()); + g.setStroke(chart.getStyler().getAxisTickMarksStroke()); - if (axisTick.getAxis().getDirection() == Axis.Direction.Y && getChartInternal().getStyleManager().isYAxisTicksVisible()) { // Y-Axis + if (direction == Axis.Direction.Y && chart.getStyler().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.getStyler() + .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.getStyler().getAxisTickMarkLength(), chart.getYAxis().getPaintZone().getHeight()); // g.setColor(Color.yellow); // g.draw(bounds); // tick marks - if (getChartInternal().getStyleManager().isAxisTicksMarksVisible()) { + if (chart.getStyler().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.getStyler().getAxisTickMarkLength(), flippedTickLocation); g.draw(line); } } } // Line - if (getChartInternal().getStyleManager().isAxisTicksLineVisible()) { + if (chart.getStyler().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.getStyler().getAxisTickMarkLength(), yOffset, xOffset + chart.getStyler().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.getStyler().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.getStyler().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.getStyler().getAxisTickMarkLength(), chart.getXAxis().getPaintZone().getWidth(), chart.getStyler().getAxisTickMarkLength()); + // g.setColor(Color.yellow); + // g.draw(bounds); // tick marks - if (getChartInternal().getStyleManager().isAxisTicksMarksVisible()) { + if (chart.getStyler().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.getStyler().getAxisTickMarkLength()); g.draw(line); } } } // Line - if (getChartInternal().getStyleManager().isAxisTicksLineVisible()) { + if (chart.getStyler().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.getStyler().getAxisTickMarksStroke()); + g.drawLine((int) xOffset, (int) (yOffset - chart.getStyler().getAxisTickMarkLength()), (int) (xOffset + chart.getXAxis().getPaintZone().getWidth()), (int) (yOffset - chart + .getStyler().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..acd8f464bac615a2f2a1745cbdc147cbaf7dbdc4 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.internal.Series; +import org.knowm.xchart.internal.Series_AxesChart; +import org.knowm.xchart.internal.chartpart.Axis.Direction; +import org.knowm.xchart.internal.style.Styler_AxesChart; + /** * AxisTitle */ -public class AxisTitle implements ChartPart { - - /** parent */ - private final Axis axis; - - /** the title text */ - private String text = ""; // default to "" +public class AxisTitle<ST extends Styler_AxesChart, S extends Series> implements ChartPart { - /** the bounds */ + private final Chart<Styler_AxesChart, 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<Styler_AxesChart, 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.getStyler().getChartFontColor()); + g.setFont(chart.getStyler().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.getStyler().isYAxisTitleVisible()) { FontRenderContext frc = g.getFontRenderContext(); - TextLayout nonRotatedTextLayout = new TextLayout(text, getChartInternal().getStyleManager().getAxisTitleFont(), frc); + TextLayout nonRotatedTextLayout = new TextLayout(chart.getyYAxisTitle(), chart.getStyler().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.getStyler() .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.getStyler().isXAxisTitleVisible()) { FontRenderContext frc = g.getFontRenderContext(); - TextLayout textLayout = new TextLayout(text, getChartInternal().getStyleManager().getAxisTitleFont(), frc); + TextLayout textLayout = new TextLayout(chart.getXAxisTitle(), chart.getStyler().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.getStyler().getAxisTitlePadding(), rectangle.getWidth(), rectangle.getHeight() + chart.getStyler().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..34cd05c72945bdb1bf8aea76c09388a6f53ff87b --- /dev/null +++ b/xchart/src/main/java/org/knowm/xchart/internal/chartpart/Chart.java @@ -0,0 +1,220 @@ +/** + * 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 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.Styler; + +/** + * An XChart Chart + * + * @author timmolter + */ +public abstract class Chart<ST extends Styler, S extends Series> implements ChartPart { + + public abstract void paint(Graphics2D g, int width, int height); + + protected ST styler; + + /** Meta Data */ + private int width; + private int height; + private String title = ""; + private String xAxisTitle = ""; + private String yAxisTitle = ""; + + /** Chart Parts */ + protected ChartTitle chartTitle; + protected Legend_ legend; + protected Plot_ plot; + protected AxisPair axisPair; + + protected Map<String, S> seriesMap = new LinkedHashMap<String, S>(); + + /** + * Constructor + * + * @param width + * @param height + * @param styler + */ + public Chart(int width, int height, ST styler) { + + this.width = width; + this.height = height; + this.styler = styler; + + 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_ getLegend() { + + return legend; + } + + 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; + } + + public S removeSeries(String seriesName) { + + return seriesMap.remove(seriesName); + } + + /** + * Gets the Chart's styler, which can be used to customize the Chart's appearance + * + * @return the styler + */ + public ST getStyler() { + + return styler; + } + + @Override + public Rectangle2D getBounds() { + + return new Rectangle2D.Double(0, 0, width, height); + } +} 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..d443d55e8bc12f09373c79212b065728dda76077 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,121 +29,99 @@ 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.getStyler().getChartTitleFont()); + + if (!chart.getStyler().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.getStyler().getChartTitleFont(), frc); + Rectangle2D textBounds = textLayout.getBounds(); + + double xOffset = chart.getPlot().getBounds().getX(); // of plot left edge + double yOffset = chart.getStyler().getChartPadding(); + + // title box + if (chart.getStyler().isChartTitleBoxVisible()) { + + // paint the chart title box + double chartTitleBoxWidth = chart.getPlot().getBounds().getWidth(); + double chartTitleBoxHeight = textBounds.getHeight() + 2 * chart.getStyler().getChartTitlePadding(); + + g.setStroke(new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL)); + Shape rect = new Rectangle2D.Double(xOffset, yOffset, chartTitleBoxWidth, chartTitleBoxHeight); + g.setColor(chart.getStyler().getChartTitleBoxBackgroundColor()); + g.fill(rect); + g.setColor(chart.getStyler().getChartTitleBoxBorderColor()); + g.draw(rect); } - this.text = text; + + // paint title + xOffset = chart.getPlot().getBounds().getX() + (chart.getPlot().getBounds().getWidth() - textBounds.getWidth()) / 2.0; + yOffset = chart.getStyler().getChartPadding() + textBounds.getHeight() + chart.getStyler().getChartTitlePadding(); + + g.setColor(chart.getStyler().getChartFontColor()); + 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); + + double width = 2 * chart.getStyler().getChartTitlePadding() + textBounds.getWidth(); + double height = 2 * chart.getStyler().getChartTitlePadding() + textBounds.getHeight(); + bounds = new Rectangle2D.Double(xOffset - chart.getStyler().getChartTitlePadding(), yOffset - textBounds.getHeight() - chart.getStyler().getChartTitlePadding(), width, height); + // g.setColor(Color.green); + // g.draw(bounds); + } /** - * get the height of the chart title including the chart padding + * get the height of the chart title including the chart title padding * * @return */ - protected int getSizeHint() { + private Rectangle2D getBoundsHint() { - if (chartInternal.getStyleManager().isChartTitleVisible()) { + if (chart.getStyler().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.getStyler().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.getStyler().getChartTitlePadding() + rectangle.getWidth(); + double height = 2 * chart.getStyler().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(); + return new Rectangle2D.Double(); // Constructs a new Rectangle2D, initialized to location (0, 0) and size (0, 0). } } - @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); - } - - } - @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 deleted file mode 100644 index 80ef017a98c7c9668cd2ce65afee0c5671c41f62..0000000000000000000000000000000000000000 --- a/xchart/src/main/java/org/knowm/xchart/internal/chartpart/Legend.java +++ /dev/null @@ -1,344 +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.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; - -/** - * @author timmolter - */ -public class Legend implements ChartPart { - - private static final int LEGEND_MARGIN = 6; - private static final int BOX_SIZE = 20; - private static final int MULTI_LINE_SPACE = 3; - - private double legendBoxWidth = 0.0; - private double legendBoxHeight = 0.0; - - /** - * parent - */ - private final ChartInternal chartInternal; - - /** - * the bounds - */ - private Rectangle2D bounds; - - /** - * Constructor - * - * @param chartInternal - */ - public Legend(ChartInternal chartInternal) { - - this.chartInternal = chartInternal; - } - - /** - * determine the width and height of the chart legend - */ - 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()) { - - Map<String, Rectangle2D> seriesBounds = getSeriesTextBounds(series); - - 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()) { - return; - } - - // if the area to draw a chart on is so small, don't even bother - if (chartInternal.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; - } - - g.setStroke(new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 10.0f, new float[] { 3.0f, 0.0f }, 0.0f)); - - 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); - - // Draw legend content inside legend box - double startx = xOffset + getChartInternal().getStyleManager().getLegendPadding(); - double starty = yOffset + getChartInternal().getStyleManager().getLegendPadding(); - - for (Series series : chartInternal.getSeriesMap().values()) { - - Map<String, Rectangle2D> seriesTextBounds = getSeriesTextBounds(series); - - float blockHeight = 0; - double legendTextContentMaxWidth = 0; - for (Map.Entry<String, Rectangle2D> entry : seriesTextBounds.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()); - - 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) { - - double x = startx + getChartInternal().getStyleManager().getLegendSeriesLineLength() + getChartInternal().getStyleManager().getLegendPadding(); - for (Map.Entry<String, Rectangle2D> entry : seriesTextBounds.entrySet()) { - - 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(); - } - - } - - // bounds - bounds = new Rectangle2D.Double(xOffset, yOffset, legendBoxWidth, legendBoxHeight); - - // g.setColor(Color.blue); - // g.draw(bounds); - - } - - private Map<String, Rectangle2D> getSeriesTextBounds(Series series) { - - // FontMetrics fontMetrics = g.getFontMetrics(getChartPainter().getStyleManager().getLegendFont()); - // float fontDescent = fontMetrics.getDescent(); - - 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); - Rectangle2D bounds = shape.getBounds2D(); - // System.out.println(tl.getAscent()); - // System.out.println(tl.getDescent()); - // System.out.println(tl.getBounds()); - // seriesTextBounds.put(line, new Rectangle2D.Double(bounds.getX(), bounds.getY(), bounds.getWidth(), bounds.getHeight() - tl.getDescent())); - // seriesTextBounds.put(line, new Rectangle2D.Double(bounds.getX(), bounds.getY(), bounds.getWidth(), tl.getAscent())); - seriesTextBounds.put(line, bounds); - } - 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/Legend_.java b/xchart/src/main/java/org/knowm/xchart/internal/chartpart/Legend_.java new file mode 100644 index 0000000000000000000000000000000000000000..81acfa4c767f59da00520d1e88d7fc8bf61f130e --- /dev/null +++ b/xchart/src/main/java/org/knowm/xchart/internal/chartpart/Legend_.java @@ -0,0 +1,206 @@ +/** + * 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.Rectangle2D; +import java.util.LinkedHashMap; +import java.util.Map; + +import org.knowm.xchart.internal.Series; +import org.knowm.xchart.internal.chartpart.RenderableSeries.LegendRenderType; +import org.knowm.xchart.internal.style.Styler; + +/** + * @author timmolter + */ +public abstract class Legend_<ST extends Styler, S extends Series> implements ChartPart { + + public abstract double getSeriesLegendRenderGraphicHeight(Series series); + + protected static final int LEGEND_MARGIN = 6; + protected static final int BOX_SIZE = 20; + protected static final int MULTI_LINE_SPACE = 3; + + protected Chart<ST, S> chart; + protected Rectangle2D bounds = null; + + protected double xOffset = 0; + protected double yOffset = 0; + + /** + * Constructor + * + * @param chart + */ + public Legend_(Chart<ST, S> chart) { + + this.chart = chart; + + } + + @Override + public void paint(Graphics2D g) { + + if (chart.getSeriesMap().isEmpty()) { + return; + } + + // if the area to draw a chart on is so small, don't even bother + if (chart.getPlot().getBounds().getWidth() < 30) { + return; + } + + // 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 this bounds is the width and height. + } + + // legend draw position + + switch (chart.getStyler().getLegendPosition()) { + case OutsideE: + xOffset = chart.getWidth() - bounds.getWidth() - chart.getStyler().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; + } + + // draw legend box background and border + Shape rect = new Rectangle2D.Double(xOffset, yOffset, bounds.getWidth(), bounds.getHeight()); + g.setColor(chart.getStyler().getLegendBackgroundColor()); + g.fill(rect); + g.setStroke(new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 10.0f, new float[] { 3.0f, 0.0f }, 0.0f)); + g.setColor(chart.getStyler().getLegendBorderColor()); + g.draw(rect); + } + + /** + * determine the width and height of the chart legend + */ + public Rectangle2D getBoundsHint() { + + if (!chart.getStyler().isLegendVisible()) { + return new Rectangle2D.Double(); // Constructs a new Rectangle2D, initialized to location (0, 0) and size (0, 0). + } + + boolean containsBox = false; + + // determine legend text content max width + double legendTextContentMaxWidth = 0; + + // determine total legend content height + double legendContentHeight = 0; + + Map<String, S> map = chart.getSeriesMap(); + for (Series series : map.values()) { + + if (series.isShowInLegend()) { + continue; + } + + Map<String, Rectangle2D> seriesTextBounds = getSeriesTextBounds(series); + + double legendEntryHeight = 0; // could be multi-line + 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; // subtract away the bottom MULTI_LINE_SPACE + legendEntryHeight = Math.max(legendEntryHeight, (getSeriesLegendRenderGraphicHeight(series))); + + legendContentHeight += legendEntryHeight + chart.getStyler().getLegendPadding(); + + if (series.getLegendRenderType() == LegendRenderType.Box) { + containsBox = true; + } + } + + // determine legend content width + double legendContentWidth = 0; + if (!containsBox) { + legendContentWidth = chart.getStyler().getLegendSeriesLineLength() + chart.getStyler().getLegendPadding() + legendTextContentMaxWidth; + } + else { + legendContentWidth = BOX_SIZE + chart.getStyler().getLegendPadding() + legendTextContentMaxWidth; + } + + // Legend Box + double width = legendContentWidth + 2 * chart.getStyler().getLegendPadding(); + double height = legendContentHeight + 1 * chart.getStyler().getLegendPadding(); + + return new Rectangle2D.Double(Double.NaN, Double.NaN, width, height); // Double.NaN indicates not sure yet. + } + + // 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().getstyler().getLegendFont()); + // float fontDescent = fontMetrics.getDescent(); + + String lines[] = series.getName().split("\\n"); + Map<String, Rectangle2D> seriesTextBounds = new LinkedHashMap<String, Rectangle2D>(lines.length); + for (String line : lines) { + TextLayout textLayout = new TextLayout(line, chart.getStyler().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()); + // System.out.println(tl.getBounds()); + // seriesTextBounds.put(line, new Rectangle2D.Double(bounds.getX(), bounds.getY(), bounds.getWidth(), bounds.getHeight() - tl.getDescent())); + // seriesTextBounds.put(line, new Rectangle2D.Double(bounds.getX(), bounds.getY(), bounds.getWidth(), tl.getAscent())); + seriesTextBounds.put(line, bounds); + } + return seriesTextBounds; + } + +} diff --git a/xchart/src/main/java/org/knowm/xchart/internal/chartpart/Legend_AxesChart.java b/xchart/src/main/java/org/knowm/xchart/internal/chartpart/Legend_AxesChart.java new file mode 100644 index 0000000000000000000000000000000000000000..9f05f7b8266c6dde58115812f0fded6d882e24c6 --- /dev/null +++ b/xchart/src/main/java/org/knowm/xchart/internal/chartpart/Legend_AxesChart.java @@ -0,0 +1,218 @@ +/** + * 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_XY; +import org.knowm.xchart.internal.Series; +import org.knowm.xchart.internal.Series_AxesChart; +import org.knowm.xchart.internal.chartpart.RenderableSeries.LegendRenderType; +import org.knowm.xchart.internal.style.Styler_AxesChart; +import org.knowm.xchart.internal.style.lines.SeriesLines; + +/** + * @author timmolter + */ +public class Legend_AxesChart<ST extends Styler_AxesChart, S extends Series> extends Legend_ { + + Styler_AxesChart stylerAxesChart; + + /** + * Constructor + * + * @param chart + */ + public Legend_AxesChart(Chart<Styler_AxesChart, Series_XY> chart) { + + super(chart); + stylerAxesChart = chart.getStyler(); + } + + @Override + public void paint(Graphics2D g) { + + if (!chart.getStyler().isLegendVisible()) { + return; + } + + super.paint(g); + + g.setStroke(new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 10.0f, new float[] { 3.0f, 0.0f }, 0.0f)); + + // Draw legend content inside legend box + double startx = xOffset + chart.getStyler().getLegendPadding(); + double starty = yOffset + chart.getStyler().getLegendPadding(); + + Map<String, Series_AxesChart> map = chart.getSeriesMap(); + for (Series_AxesChart series : map.values()) { + + if (series.isShowInLegend()) { + continue; + } + + 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 : stylerAxesChart.getMarkerSize())); + + // ////// paint series render graphic ///////// + + // paint line and marker + if (series.getLegendRenderType() != LegendRenderType.Box) { + + // paint line + if (series.getLegendRenderType() == LegendRenderType.Line && series.getLineStyle() != SeriesLines.NONE) { + g.setColor(series.getLineColor()); + g.setStroke(series.getLineStyle()); + Shape line = new Line2D.Double(startx, starty + legendEntryHeight / 2.0, startx + chart.getStyler().getLegendSeriesLineLength(), starty + legendEntryHeight / 2.0); + g.draw(line); + } + + // // debug box + // Rectangle2D boundsTemp = new Rectangle2D.Double(startx, starty, styler.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.getStyler().getLegendSeriesLineLength() / 2.0, starty + legendEntryHeight / 2.0, stylerAxesChart.getMarkerSize()); + + } + } + else { // bar/pie type series + + // paint little box + Shape rectSmall = new Rectangle2D.Double(startx, starty, BOX_SIZE, BOX_SIZE); + if (stylerAxesChart.isBarFilled()) { + g.setColor(series.getFillColor()); + g.fill(rectSmall); + } + + g.setColor(series.getLineColor()); + g.draw(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.getStyler().getChartFontColor()); + + double multiLineOffset = 0.0; + + if (series.getLegendRenderType() != LegendRenderType.Box) { + + double x = startx + chart.getStyler().getLegendSeriesLineLength() + chart.getStyler().getLegendPadding(); + for (Map.Entry<String, Rectangle2D> entry : seriesTextBounds.entrySet()) { + + double height = entry.getValue().getHeight(); + double centerOffsetY = (Math.max(stylerAxesChart.getMarkerSize(), height) - height) / 2.0; + + FontRenderContext frc = g.getFontRenderContext(); + TextLayout tl = new TextLayout(entry.getKey(), chart.getStyler().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.getStyler().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.getStyler().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.getStyler().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 : stylerAxesChart.getMarkerSize(); + } +} diff --git a/xchart/src/main/java/org/knowm/xchart/internal/chartpart/Legend_Pie.java b/xchart/src/main/java/org/knowm/xchart/internal/chartpart/Legend_Pie.java new file mode 100644 index 0000000000000000000000000000000000000000..4197d6a91cf1703ce0ba206b14f46c4c308a0266 --- /dev/null +++ b/xchart/src/main/java/org/knowm/xchart/internal/chartpart/Legend_Pie.java @@ -0,0 +1,159 @@ +/** + * 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.Styler_Pie; +import org.knowm.xchart.internal.Series; +import org.knowm.xchart.internal.style.Styler_AxesChart; + +/** + * @author timmolter + */ +public class Legend_Pie<ST extends Styler_AxesChart, S extends Series> extends Legend_ { + + Styler_Pie stylerPie; + + /** + * Constructor + * + * @param chart + */ + public Legend_Pie(Chart<Styler_Pie, Series_Pie> chart) { + + super(chart); + stylerPie = chart.getStyler(); + } + + @Override + public void paint(Graphics2D g) { + + if (!chart.getStyler().isLegendVisible()) { + return; + } + + super.paint(g); + + g.setStroke(new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 10.0f, new float[] { 3.0f, 0.0f }, 0.0f)); + + // Draw legend content inside legend box + double startx = xOffset + chart.getStyler().getLegendPadding(); + double starty = yOffset + chart.getStyler().getLegendPadding(); + + Map<String, Series> map = chart.getSeriesMap(); + for (Series series : map.values()) { + + if (series.isShowInLegend()) { + continue; + } + + 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.getStyler().getChartFontColor()); + + double multiLineOffset = 0.0; + + // bar/pie type series + + final double x = startx + BOX_SIZE + chart.getStyler().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.getStyler().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.getStyler().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..6784fdf18bad0dec2477b05213d9833e3998679a 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,22 +20,22 @@ 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.Styler_AxesChart; /** * @author timmolter */ public class NumberFormatter { - private final StyleManager styleManager; + private final Styler_AxesChart styler; /** * Constructor */ - public NumberFormatter(StyleManager styleManager) { + public NumberFormatter(Styler_AxesChart styler) { - this.styleManager = styleManager; + this.styler = styler; } public String getFormatPattern(BigDecimal value, double min, double max) { @@ -121,20 +121,20 @@ public class NumberFormatter { */ public String formatNumber(BigDecimal value, double min, double max, Direction axisDirection) { - NumberFormat numberFormat = NumberFormat.getNumberInstance(styleManager.getLocale()); + NumberFormat numberFormat = NumberFormat.getNumberInstance(styler.getLocale()); String decimalPattern; - if (axisDirection == Direction.X && styleManager.getXAxisDecimalPattern() != null) { + if (axisDirection == Direction.X && styler.getXAxisDecimalPattern() != null) { - decimalPattern = styleManager.getXAxisDecimalPattern(); + decimalPattern = styler.getXAxisDecimalPattern(); } - else if (axisDirection == Direction.Y && styleManager.getYAxisDecimalPattern() != null) { - decimalPattern = styleManager.getYAxisDecimalPattern(); + else if (axisDirection == Direction.Y && styler.getYAxisDecimalPattern() != null) { + decimalPattern = styler.getYAxisDecimalPattern(); } - else if (styleManager.getDecimalPattern() != null) { + else if (styler.getDecimalPattern() != null) { - decimalPattern = styleManager.getDecimalPattern(); + decimalPattern = styler.getDecimalPattern(); } else { decimalPattern = getFormatPattern(value, min, max); @@ -155,20 +155,20 @@ public class NumberFormatter { */ public String formatLogNumber(double value, Direction axisDirection) { - NumberFormat numberFormat = NumberFormat.getNumberInstance(styleManager.getLocale()); + NumberFormat numberFormat = NumberFormat.getNumberInstance(styler.getLocale()); String decimalPattern; - if (axisDirection == Direction.X && styleManager.getXAxisDecimalPattern() != null) { + if (axisDirection == Direction.X && styler.getXAxisDecimalPattern() != null) { - decimalPattern = styleManager.getXAxisDecimalPattern(); + decimalPattern = styler.getXAxisDecimalPattern(); } - else if (axisDirection == Direction.Y && styleManager.getYAxisDecimalPattern() != null) { - decimalPattern = styleManager.getYAxisDecimalPattern(); + else if (axisDirection == Direction.Y && styler.getYAxisDecimalPattern() != null) { + decimalPattern = styler.getYAxisDecimalPattern(); } - else if (styleManager.getDecimalPattern() != null) { + else if (styler.getDecimalPattern() != null) { - decimalPattern = styleManager.getDecimalPattern(); + decimalPattern = styler.getDecimalPattern(); } else { if (Math.abs(value) > 1000.0 || Math.abs(value) < 0.001) { 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/PlotContentCategoricalChart_Pie.java b/xchart/src/main/java/org/knowm/xchart/internal/chartpart/PlotContentCategoricalChart_Pie.java deleted file mode 100644 index 5d694dc232f2b765408ebcb41a9e4984ae4aac2a..0000000000000000000000000000000000000000 --- a/xchart/src/main/java/org/knowm/xchart/internal/chartpart/PlotContentCategoricalChart_Pie.java +++ /dev/null @@ -1,129 +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.Arc2D; -import java.awt.geom.Rectangle2D; - -import org.knowm.xchart.Series; - -/** - * @author timmolter - */ -public class PlotContentCategoricalChart_Pie extends PlotContent { - - /** - * Constructor - * - * @param plot - */ - protected PlotContentCategoricalChart_Pie(Plot plot) { - - super(plot); - } - - @Override - public void paint(Graphics2D g) { - - // plot area bounds - Rectangle2D bounds = plot.getBounds(); - // g.setStroke(new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL)); - // g.setColor(Color.red); - // g.draw(bounds); - - // if the area to draw a chart on is so small, don't even bother - if (bounds.getWidth() < 30) { - return; - } - - // clip bounds TODO Do we need this? - Rectangle2D rectangle = new Rectangle2D.Double(0, 0, getChartInternal().getWidth(), getChartInternal().getHeight()); - // g.setStroke(new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL)); - // g.setColor(Color.green); - // g.draw(rectangle); - g.setClip(bounds.createIntersection(rectangle)); - - // pie bounds - double percentage = .70; - double halfBorderPercentage = (1 - percentage) / 2.0; - Rectangle2D pieBounds = new Rectangle2D.Double(bounds.getX() + bounds.getWidth() * halfBorderPercentage, bounds.getY() + bounds.getHeight() * halfBorderPercentage, bounds.getWidth() * percentage, - bounds.getHeight() * percentage); - // g.setStroke(new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL)); - // g.setColor(Color.black); - // g.draw(pieBounds); - - // 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(); - - total += y.doubleValue(); - } - - // draw pie slices - double curValue = 0.0; - double startAngle = 0; - for (Series series : getChartInternal().getSeriesMap().values()) { - - // String x = (String) series.getXData().iterator().next(); - Number y = series.getYData().iterator().next(); - - 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.draw(new Arc2D.Double(pieBounds.getX(), pieBounds.getY(), pieBounds.getWidth(), pieBounds.getHeight(), startAngle, arcAngle, Arc2D.PIE)); - curValue += y.doubleValue(); - } - - g.setClip(null); - - } - - // private double[] getPercentageVector(Collection<? extends Number> collection) { - // - // float total = 0.0f; - // - // double[] vectorCenters = new double[collection.size()]; - // Iterator<? extends Number> yItr = collection.iterator(); - // - // int counter = 0; - // while (yItr.hasNext()) { - // - // Number next = yItr.next(); - // - // double y = next.doubleValue(); - // System.out.println(y); - // vectorCenters[counter] = vectorCenters[counter] + y; - // - // total += vectorCenters[counter++]; - // } - // - // double[] vectorPercentages = new double[vectorCenters.length]; - // - // for (int i = 0; i < vectorPercentages.length; i++) { - // vectorPercentages[i] = vectorCenters[i] / total; - // } - // - // return vectorPercentages; - // } - -} 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..8a9dca34e3ac779506bbc646ba44853fe2b93992 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.Styler_AxesChart; /** * @author timmolter */ -public abstract class PlotContent implements ChartPart { +public abstract class PlotContent_<ST extends Styler_AxesChart, S extends Series> implements ChartPart { - /** parent */ - protected Plot plot; - - StyleManager styleManager; + protected final Chart<ST, 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<ST, 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 63% 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..2364f2fcc473cd5d00018fca4cef21bc8ee858b1 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,64 @@ 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.Styler_Category; +import org.knowm.xchart.internal.Series; import org.knowm.xchart.internal.Utils; +import org.knowm.xchart.internal.style.Styler; +import org.knowm.xchart.internal.style.lines.SeriesLines; /** * @author timmolter */ -public class PlotContentCategoricalChart_Bar extends PlotContent { +public class PlotContent_Category_Bar<ST extends Styler, S extends Series> extends PlotContent_ { + + Styler_Category stylerCategory; /** * Constructor * - * @param plot + * @param chart */ - protected PlotContentCategoricalChart_Bar(Plot plot) { + protected PlotContent_Category_Bar(Chart<Styler_Category, Series_Category> chart) { - super(plot); + super(chart); + this.stylerCategory = chart.getStyler(); } @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 = stylerCategory.getPlotContentSize() * bounds.getWidth(); double xLeftMargin = Utils.getTickStartOffset(bounds.getWidth(), xTickSpace); // Y-Axis - double yTickSpace = styleManager.getAxisTickSpacePercentage() * bounds.getHeight(); + double yTickSpace = stylerCategory.getPlotContentSize() * 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 +98,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,47 +169,80 @@ public class PlotContentCategoricalChart_Bar extends PlotContent { double xOffset; double barWidth; - if (getChartInternal().getStyleManager().isBarsOverlapped()) { - double barWidthPercentage = getChartInternal().getStyleManager().getBarWidthPercentage(); + if (stylerCategory.isBarsOverlapped()) { + double barWidthPercentage = stylerCategory.getBarWidthPercentage(); barWidth = gridStep * barWidthPercentage; double barMargin = gridStep * (1 - barWidthPercentage) / 2; - xOffset = bounds.getX() + xLeftMargin + gridStep * categoryCounter++ + barMargin; + if (ChartCategorySeriesRenderStyle.Stick.equals(series.getChartCategorySeriesRenderStyle())) { + xOffset = bounds.getX() + xLeftMargin + categoryCounter++ * gridStep + gridStep / 2; + } + else { + xOffset = bounds.getX() + xLeftMargin + gridStep * categoryCounter++ + barMargin; + } } else { - double barWidthPercentage = getChartInternal().getStyleManager().getBarWidthPercentage(); - barWidth = gridStep / getChartInternal().getSeriesMap().size() * barWidthPercentage; + double barWidthPercentage = stylerCategory.getBarWidthPercentage(); + barWidth = gridStep / chart.getSeriesMap().size() * barWidthPercentage; double barMargin = gridStep * (1 - barWidthPercentage) / 2; - xOffset = bounds.getX() + xLeftMargin + gridStep * categoryCounter++ + seriesCounter * barWidth + barMargin; + if (ChartCategorySeriesRenderStyle.Stick.equals(series.getChartCategorySeriesRenderStyle())) { + xOffset = bounds.getX() + xLeftMargin + categoryCounter++ * gridStep + seriesCounter * barMargin + gridStep / chart.getSeriesMap().size() / 2; + } + else { + 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()); + g.setColor(series.getLineColor()); Path2D.Double path = new Path2D.Double(); path.moveTo(xOffset, yOffset); path.lineTo(xOffset + barWidth, yOffset); path.lineTo(xOffset + barWidth, zeroOffset); path.lineTo(xOffset, zeroOffset); path.closePath(); - g.setStroke(series.getStroke()); - if (getChartInternal().getStyleManager().isBarFilled()) { + g.setStroke(series.getLineStyle()); + if (stylerCategory.isBarFilled()) { g.fill(path); } else { g.draw(path); } } + else if (ChartCategorySeriesRenderStyle.Stick.equals(series.getChartCategorySeriesRenderStyle())) { + + // paint line + if (series.getLineStyle() != SeriesLines.NONE) { + + g.setColor(series.getLineColor()); + g.setStroke(series.getLineStyle()); + Shape line = new Line2D.Double(xOffset, zeroOffset, xOffset, yOffset); + g.draw(line); + } + + // paint marker + if (series.getMarker() != null) { + g.setColor(series.getMarkerColor()); + + if (y <= 0) { + series.getMarker().paint(g, xOffset, zeroOffset, stylerCategory.getMarkerSize()); + } + else { + series.getMarker().paint(g, xOffset, yOffset, stylerCategory.getMarkerSize()); + } + } + } else { // paint line - if (Series.SeriesType.Line.equals(series.getSeriesType())) { + if (series.getChartCategorySeriesRenderStyle() == ChartCategorySeriesRenderStyle.Line) { - if (series.getStroke() != null) { + if (series.getLineStyle() != SeriesLines.NONE) { if (previousX != -Double.MAX_VALUE && previousY != -Double.MAX_VALUE) { - g.setColor(series.getStrokeColor()); - g.setStroke(series.getStroke()); + g.setColor(series.getLineColor()); + g.setStroke(series.getLineStyle()); Shape line = new Line2D.Double(previousX, previousY, xOffset + barWidth / 2, yOffset); g.draw(line); } @@ -223,7 +254,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, stylerCategory.getMarkerSize()); } } @@ -235,11 +266,11 @@ public class PlotContentCategoricalChart_Bar extends PlotContent { double eb = ebItr.next().doubleValue(); // set error bar style - if (getChartInternal().getStyleManager().isErrorBarsColorSeriesColor()) { - g.setColor(series.getStrokeColor()); + if (stylerCategory.isErrorBarsColorSeriesColor()) { + g.setColor(series.getLineColor()); } else { - g.setColor(getChartInternal().getStyleManager().getErrorBarsColor()); + g.setColor(stylerCategory.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 69% 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..c6fa001a45f58b1ec3bf41d7b854bae04b03f482 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,43 @@ 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.Styler_Category; +import org.knowm.xchart.internal.Series; import org.knowm.xchart.internal.Utils; +import org.knowm.xchart.internal.style.Styler; +import org.knowm.xchart.internal.style.lines.SeriesLines; /** * @author timmolter */ -public class PlotContentCategoricalChart_Line_Area_Scatter extends PlotContent { +public class PlotContent_Category_Line_Area_Scatter<ST extends Styler, S extends Series> extends PlotContent_ { + + Styler_Category stylerCategory; /** * Constructor * * @param plot */ - protected PlotContentCategoricalChart_Line_Area_Scatter(Plot plot) { + protected PlotContent_Category_Line_Area_Scatter(Chart<Styler_Category, Series_Category> chart) { - super(plot); + super(chart); + this.stylerCategory = chart.getStyler(); } @Override public void paint(Graphics2D g) { // logarithmic - // if (getChartInternal().getStyleManager().isYAxisLogarithmic()) { + // if (stylerCategory.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 +76,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 +85,36 @@ public class PlotContentCategoricalChart_Line_Area_Scatter extends PlotContent { // g.setClip(bounds.createIntersection(g.getClipBounds())); // X-Axis - double xTickSpace = styleManager.getAxisTickSpacePercentage() * bounds.getWidth(); + double xTickSpace = stylerCategory.getPlotContentSize() * bounds.getWidth(); double xLeftMargin = Utils.getTickStartOffset((int) bounds.getWidth(), xTickSpace); // Y-Axis - double yTickSpace = styleManager.getAxisTickSpacePercentage() * bounds.getHeight(); + double yTickSpace = stylerCategory.getPlotContentSize() * 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 (stylerCategory.isXAxisLogarithmic()) { xMin = Math.log10(xMin); xMax = Math.log10(xMax); } - if (getChartInternal().getStyleManager().isYAxisLogarithmic()) { + if (stylerCategory.isYAxisLogarithmic()) { yMin = Math.log10(yMin); yMax = Math.log10(yMax); } + // System.out.println("yMin = " + yMin); + // System.out.println("yMax = " + yMax); - int numCategories = getChartInternal().getSeriesMap().values().iterator().next().getXData().size(); - double gridStep = xTickSpace / numCategories; + Map<String, Series_Category> seriesMap = chart.getSeriesMap(); - for (Series series : getChartInternal().getSeriesMap().values()) { + int numCategories = seriesMap.values().iterator().next().getXData().size(); + double gridStep = xTickSpace / numCategories; - // sanity check - - 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 : seriesMap.values()) { // data points Collection<? extends Number> yData = series.getYData(); @@ -143,13 +150,13 @@ public class PlotContentCategoricalChart_Line_Area_Scatter extends PlotContent { double y = 0.0; // System.out.println(y); - if (getChartInternal().getStyleManager().isYAxisLogarithmic()) { + if (stylerCategory.isYAxisLogarithmic()) { y = Math.log10(yOrig); } else { y = yOrig; } - // System.out.println(y); + System.out.println(y); double yTransform = bounds.getHeight() - (yTopMargin + (y - yMin) / (yMax - yMin) * yTickSpace); @@ -160,20 +167,19 @@ public class PlotContentCategoricalChart_Line_Area_Scatter extends PlotContent { double xOffset = bounds.getX() + xLeftMargin + categoryCounter++ * gridStep + gridStep / 2; double yOffset = bounds.getY() + yTransform; - // System.out.println(xTransform); // System.out.println(xOffset); // System.out.println(yTransform); // System.out.println(yOffset); // System.out.println("---"); // paint line - if (Series.SeriesType.Line.equals(series.getSeriesType()) || Series.SeriesType.Area.equals(series.getSeriesType())) { + if (ChartCategorySeriesRenderStyle.Line.equals(series.getChartCategorySeriesRenderStyle()) || ChartCategorySeriesRenderStyle.Area.equals(series.getChartCategorySeriesRenderStyle())) { - if (series.getStroke() != null) { + if (series.getLineStyle() != SeriesLines.NONE) { if (previousX != -Double.MAX_VALUE && previousY != -Double.MAX_VALUE) { - g.setColor(series.getStrokeColor()); - g.setStroke(series.getStroke()); + g.setColor(series.getLineColor()); + g.setStroke(series.getLineStyle()); Shape line = new Line2D.Double(previousX, previousY, xOffset, yOffset); g.draw(line); } @@ -181,7 +187,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) { @@ -200,13 +206,28 @@ public class PlotContentCategoricalChart_Line_Area_Scatter extends PlotContent { } } + // paint stick + if (ChartCategorySeriesRenderStyle.Stick.equals(series.getChartCategorySeriesRenderStyle())) { + + if (series.getLineStyle() != SeriesLines.NONE) { + + double yBottomOfArea = bounds.getY() + bounds.getHeight() - yTopMargin; + + g.setColor(series.getLineColor()); + g.setStroke(series.getLineStyle()); + Shape line = new Line2D.Double(xOffset, yBottomOfArea, xOffset, yOffset); + g.draw(line); + } + + } + previousX = xOffset; previousY = yOffset; // 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, stylerCategory.getMarkerSize()); } // paint error bars @@ -215,17 +236,17 @@ public class PlotContentCategoricalChart_Line_Area_Scatter extends PlotContent { double eb = ebItr.next().doubleValue(); // set error bar style - if (getChartInternal().getStyleManager().isErrorBarsColorSeriesColor()) { - g.setColor(series.getStrokeColor()); + if (stylerCategory.isErrorBarsColorSeriesColor()) { + g.setColor(series.getLineColor()); } else { - g.setColor(getChartInternal().getStyleManager().getErrorBarsColor()); + g.setColor(stylerCategory.getErrorBarsColor()); } g.setStroke(errorBarStroke); // Top value double topValue = 0.0; - if (getChartInternal().getStyleManager().isYAxisLogarithmic()) { + if (stylerCategory.isYAxisLogarithmic()) { topValue = yOrig + eb; topValue = Math.log10(topValue); } @@ -237,7 +258,7 @@ public class PlotContentCategoricalChart_Line_Area_Scatter extends PlotContent { // Bottom value double bottomValue = 0.0; - if (getChartInternal().getStyleManager().isYAxisLogarithmic()) { + if (stylerCategory.isYAxisLogarithmic()) { bottomValue = yOrig - eb; // System.out.println(bottomValue); bottomValue = Math.log10(bottomValue); diff --git a/xchart/src/main/java/org/knowm/xchart/internal/chartpart/PlotContent_Pie.java b/xchart/src/main/java/org/knowm/xchart/internal/chartpart/PlotContent_Pie.java new file mode 100644 index 0000000000000000000000000000000000000000..168459fd149978bfe090d2bdccc464725bf458f2 --- /dev/null +++ b/xchart/src/main/java/org/knowm/xchart/internal/chartpart/PlotContent_Pie.java @@ -0,0 +1,244 @@ +/** + * 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.Arc2D; +import java.awt.geom.Line2D; +import java.awt.geom.Rectangle2D; +import java.text.DecimalFormat; +import java.util.Map; + +import org.knowm.xchart.Series_Pie; +import org.knowm.xchart.Styler_Pie; +import org.knowm.xchart.Styler_Pie.AnnotationType; +import org.knowm.xchart.internal.Series; +import org.knowm.xchart.internal.style.Styler; + +/** + * @author timmolter + */ +public class PlotContent_Pie<ST extends Styler, S extends Series> extends PlotContent_ { + + Styler_Pie stylerPie; + DecimalFormat df = new DecimalFormat("#.0"); + + /** + * Constructor + * + * @param plot + */ + protected PlotContent_Pie(Chart<Styler_Pie, Series_Pie> chart) { + + super(chart); + stylerPie = chart.getStyler(); + } + + @Override + public void paint(Graphics2D g) { + + // plot area bounds + Rectangle2D bounds = getBounds(); + // g.setStroke(new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL)); + // g.setColor(Color.red); + // g.draw(bounds); + + // if the area to draw a chart on is so small, don't even bother + if (bounds.getWidth() < 30) { + return; + } + + // 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); + g.setClip(bounds.createIntersection(rectangle)); + + // pie bounds + double pieFillPercentage = stylerPie.getPlotContentSize(); + + // if (stylerPie.isCircular()) { + // + // double pieDiameter = Math.min(bounds.getWidth(), bounds.getHeight()); + // } + + double halfBorderPercentage = (1 - pieFillPercentage) / 2.0; + double width = stylerPie.isCircular() ? Math.min(bounds.getWidth(), bounds.getHeight()) : bounds.getWidth(); + double height = stylerPie.isCircular() ? Math.min(bounds.getWidth(), bounds.getHeight()) : bounds.getHeight(); + + Rectangle2D pieBounds = new Rectangle2D.Double( + + bounds.getX() + bounds.getWidth() / 2 - width / 2 + halfBorderPercentage * width, + + bounds.getY() + bounds.getHeight() / 2 - height / 2 + halfBorderPercentage * height, + + width * pieFillPercentage, + + height * pieFillPercentage); + + // g.setStroke(new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL)); + // g.setColor(Color.black); + // g.draw(pieBounds); + + // get total + double total = 0.0; + + Map<String, Series_Pie> map = chart.getSeriesMap(); + for (Series_Pie series : map.values()) { + + total += series.getValue().doubleValue(); + } + + // draw pie slices + // double curValue = 0.0; + // double curValue = 0.0; + double startAngle = stylerPie.getStartAngleInDegrees() + 90; + + map = chart.getSeriesMap(); + for (Series_Pie series : map.values()) { + + Number y = series.getValue(); + + // draw slice + 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(stylerPie.getPlotBackgroundColor()); + g.draw(new Arc2D.Double(pieBounds.getX(), pieBounds.getY(), pieBounds.getWidth(), pieBounds.getHeight(), startAngle, arcAngle, Arc2D.PIE)); + // curValue += y.doubleValue(); + + // draw annotation + String annotation = ""; + if (stylerPie.getAnnotationType() == AnnotationType.Label) { + annotation = series.getName(); + } + else if (stylerPie.getAnnotationType() == AnnotationType.LabelAndPercentage) { + double percentage = y.doubleValue() / total * 100; + annotation = series.getName() + " (" + df.format(percentage) + "%)"; + } + else if (stylerPie.getAnnotationType() == AnnotationType.Percentage) { + double percentage = y.doubleValue() / total * 100; + annotation = df.format(percentage) + "%"; + } + + TextLayout textLayout = new TextLayout(annotation, stylerPie.getAnnotationFont(), new FontRenderContext(null, true, false)); + Rectangle2D percentageRectangle = textLayout.getBounds(); + + double xCenter = pieBounds.getX() + pieBounds.getWidth() / 2 - percentageRectangle.getWidth() / 2; + double yCenter = pieBounds.getY() + pieBounds.getHeight() / 2 + percentageRectangle.getHeight() / 2; + double angle = (arcAngle + startAngle) - arcAngle / 2; + double xOffset = xCenter + Math.cos(Math.toRadians(angle)) * (pieBounds.getWidth() / 2 * stylerPie.getAnnotationDistance()); + double yOffset = yCenter - Math.sin(Math.toRadians(angle)) * (pieBounds.getHeight() / 2 * stylerPie.getAnnotationDistance()); + + // get annotation width + Shape shape = textLayout.getOutline(null); + Rectangle2D annotationBounds = shape.getBounds2D(); + double annotationWidth = annotationBounds.getWidth(); + // System.out.println("annotationWidth= " + annotationWidth); + double annotationHeight = annotationBounds.getHeight(); + // System.out.println("annotationHeight= " + annotationHeight); + + // get slice area + double xOffset1 = xCenter + Math.cos(Math.toRadians(startAngle)) * (pieBounds.getWidth() / 2 * stylerPie.getAnnotationDistance()); + double yOffset1 = yCenter - Math.sin(Math.toRadians(startAngle)) * (pieBounds.getHeight() / 2 * stylerPie.getAnnotationDistance()); + double xOffset2 = xCenter + Math.cos(Math.toRadians((arcAngle + startAngle))) * (pieBounds.getWidth() / 2 * stylerPie.getAnnotationDistance()); + double yOffset2 = yCenter - Math.sin(Math.toRadians((arcAngle + startAngle))) * (pieBounds.getHeight() / 2 * stylerPie.getAnnotationDistance()); + // System.out.println("xOffset1= " + xOffset1); + // System.out.println("yOffset1= " + yOffset1); + // System.out.println("xOffset2= " + xOffset2); + // System.out.println("yOffset2= " + yOffset2); + double xDiff = Math.abs(xOffset1 - xOffset2); + double yDiff = Math.abs(yOffset1 - yOffset2); + // System.out.println("xDiff= " + xDiff); + // System.out.println("yDiff= " + yDiff); + // double max = Math.max(xDiff, yDiff); + // System.out.println(" ================== "); + boolean annotationWillFit = false; + if (xDiff >= yDiff) { // assume more vertically orientated slice + if (annotationWidth < xDiff) { + annotationWillFit = true; + } + } + else if (xDiff <= yDiff) { // assume more horizontally orientated slice + if (annotationHeight < yDiff) { + annotationWillFit = true; + } + } + + // draw annotation + if (annotationWillFit) { + + g.setColor(stylerPie.getChartFontColor()); + g.setFont(stylerPie.getChartTitleFont()); + AffineTransform orig = g.getTransform(); + AffineTransform at = new AffineTransform(); + + // inside + if (stylerPie.getAnnotationDistance() <= 1.0) { + at.translate(xOffset, yOffset); + } + + // outside + else { + + // Tick Mark + xCenter = pieBounds.getX() + pieBounds.getWidth() / 2; + yCenter = pieBounds.getY() + pieBounds.getHeight() / 2; + // double endPoint = Math.min((2.0 - (stylerPie.getAnnotationDistance() - 1)), 1.95); + double endPoint = (3.0 - stylerPie.getAnnotationDistance()); + double xOffsetStart = xCenter + Math.cos(Math.toRadians(angle)) * (pieBounds.getWidth() / 2.01); + double xOffsetEnd = xCenter + Math.cos(Math.toRadians(angle)) * (pieBounds.getWidth() / endPoint); + double yOffsetStart = yCenter - Math.sin(Math.toRadians(angle)) * (pieBounds.getHeight() / 2.01); + double yOffsetEnd = yCenter - Math.sin(Math.toRadians(angle)) * (pieBounds.getHeight() / endPoint); + + g.setStroke(new BasicStroke(2.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER)); + Shape line = new Line2D.Double(xOffsetStart, yOffsetStart, xOffsetEnd, yOffsetEnd); + g.draw(line); + + // annotation + at.translate(xOffset - Math.sin(Math.toRadians(angle - 90)) * annotationWidth / 2 + 3, yOffset); + + } + + g.transform(at); + g.fill(shape); + g.setTransform(orig); + + } + // else { + // System.out.println("Won't fit."); + // System.out.println("xDiff= " + xDiff); + // System.out.println("yDiff= " + yDiff); + // System.out.println("annotationWidth= " + annotationWidth); + // System.out.println("annotationHeight= " + annotationHeight); + // + // } + + startAngle += arcAngle; + } + + g.setClip(null); + + } + +} 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 74% 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..8b69e5eb0b8dedca39068026007da9545cfdae3e 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,39 @@ 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.Styler_XY; +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.Styler_AxesChart; +import org.knowm.xchart.internal.style.lines.SeriesLines; /** * @author timmolter */ -public class PlotContentNumericalChart extends PlotContent { +public class PlotContent_XY<ST extends Styler_AxesChart, S extends Series> extends PlotContent_ { + + Styler_XY stylerXY; /** * Constructor * - * @param plot + * @param chart */ - protected PlotContentNumericalChart(Plot plot) { + protected PlotContent_XY(Chart<Styler_XY, Series_XY> chart) { - super(plot); + super(chart); + stylerXY = chart.getStyler(); } @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 +73,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 +82,30 @@ public class PlotContentNumericalChart extends PlotContent { // g.setClip(bounds.createIntersection(g.getClipBounds())); // X-Axis - double xTickSpace = styleManager.getAxisTickSpacePercentage() * bounds.getWidth(); + double xTickSpace = stylerXY.getPlotContentSize() * bounds.getWidth(); double xLeftMargin = Utils.getTickStartOffset((int) bounds.getWidth(), xTickSpace); // Y-Axis - double yTickSpace = styleManager.getAxisTickSpacePercentage() * bounds.getHeight(); + double yTickSpace = stylerXY.getPlotContentSize() * 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 (stylerXY.isXAxisLogarithmic()) { xMin = Math.log10(xMin); xMax = Math.log10(xMax); } - if (getChartInternal().getStyleManager().isYAxisLogarithmic()) { + if (stylerXY.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!!!"); - } + 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 (stylerXY.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 (stylerXY.isYAxisLogarithmic()) { y = Math.log10(yOrig); } else { @@ -180,13 +185,15 @@ public class PlotContentNumericalChart extends PlotContent { // System.out.println("---"); // paint line - if (Series.SeriesType.Line.equals(series.getSeriesType()) || Series.SeriesType.Area.equals(series.getSeriesType())) { - if (series.getStroke() != null) { + boolean isSeriesLineOrArea = (ChartXYSeriesRenderStyle.Line == series.getChartXYSeriesRenderStyle()) || (ChartXYSeriesRenderStyle.Area == series.getChartXYSeriesRenderStyle()); + + if (isSeriesLineOrArea) { + if (series.getLineStyle() != SeriesLines.NONE) { if (previousX != -Double.MAX_VALUE && previousY != -Double.MAX_VALUE) { - g.setColor(series.getStrokeColor()); - g.setStroke(series.getStroke()); + g.setColor(series.getLineColor()); + g.setStroke(series.getLineStyle()); Shape line = new Line2D.Double(previousX, previousY, xOffset, yOffset); g.draw(line); } @@ -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, stylerXY.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()) { - g.setColor(series.getStrokeColor()); + if (stylerXY.isErrorBarsColorSeriesColor()) { + g.setColor(series.getLineColor()); } else { - g.setColor(getChartInternal().getStyleManager().getErrorBarsColor()); + g.setColor(stylerXY.getErrorBarsColor()); } g.setStroke(errorBarStroke); // Top value double topValue = 0.0; - if (getChartInternal().getStyleManager().isYAxisLogarithmic()) { + if (stylerXY.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 (stylerXY.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 deleted file mode 100644 index ad6f11f50d3546756ee6e27e1f204e164888e1f0..0000000000000000000000000000000000000000 --- a/xchart/src/main/java/org/knowm/xchart/internal/chartpart/PlotSurface.java +++ /dev/null @@ -1,153 +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.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; - -/** - * Draws the plot background, the plot border and the horizontal and vertical grid lines - * - * @author timmolter - */ -public class PlotSurface implements ChartPart { - - /** parent */ - private Plot plot; - - /** - * Constructor - * - * @param plot - */ - protected PlotSurface(Plot plot) { - - this.plot = plot; - } - - @Override - public Rectangle2D getBounds() { - - return plot.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/PlotSurface_.java b/xchart/src/main/java/org/knowm/xchart/internal/chartpart/PlotSurface_.java new file mode 100644 index 0000000000000000000000000000000000000000..56c1b2cd4b3886286e840852ef654a0dc41d81e0 --- /dev/null +++ b/xchart/src/main/java/org/knowm/xchart/internal/chartpart/PlotSurface_.java @@ -0,0 +1,46 @@ +/** + * 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.geom.Rectangle2D; + +import org.knowm.xchart.internal.Series; +import org.knowm.xchart.internal.style.Styler; + +/** + * @author timmolter + */ +public abstract class PlotSurface_<ST extends Styler, S extends Series> implements ChartPart { + + protected final Chart<ST, S> chart; + + /** + * Constructor + * + * @param chart + */ + protected PlotSurface_(Chart<ST, S> chart) { + + this.chart = chart; + } + + @Override + public Rectangle2D getBounds() { + + return chart.getPlot().getBounds(); + } +} diff --git a/xchart/src/main/java/org/knowm/xchart/internal/chartpart/PlotSurface_AxesChart.java b/xchart/src/main/java/org/knowm/xchart/internal/chartpart/PlotSurface_AxesChart.java new file mode 100644 index 0000000000000000000000000000000000000000..cdace49391cc73051721954970354aadd473ed69 --- /dev/null +++ b/xchart/src/main/java/org/knowm/xchart/internal/chartpart/PlotSurface_AxesChart.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.Styler; +import org.knowm.xchart.internal.style.Styler_AxesChart; + +/** + * Draws the plot background, the plot border and the horizontal and vertical grid lines + * + * @author timmolter + */ +public class PlotSurface_AxesChart<ST extends Styler, S extends Series> extends PlotSurface_ { + + private final Styler_AxesChart stylerAxesChart; + + /** + * Constructor + * + * @param chart + */ + protected PlotSurface_AxesChart(Chart<Styler_AxesChart, Series_XY> chart) { + + super(chart); + this.stylerAxesChart = chart.getStyler(); + } + + @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(stylerAxesChart.getPlotBackgroundColor()); + g.fill(rect); + + // paint plot border + if (stylerAxesChart.isPlotBorderVisible()) { + g.setColor(stylerAxesChart.getPlotBorderColor()); + // g.setStroke(getChartPainter().getstyler().getAxisTickMarksStroke()); + g.draw(rect); + } + + // paint grid lines and/or inner plot ticks + + // horizontal + if (stylerAxesChart.isPlotGridHorizontalLinesVisible() || stylerAxesChart.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 (stylerAxesChart.isPlotGridHorizontalLinesVisible()) { + + g.setColor(stylerAxesChart.getPlotGridLinesColor()); + g.setStroke(stylerAxesChart.getPlotGridLinesStroke()); + Shape line = new Line2D.Double(bounds.getX(), yOffset, bounds.getX() + bounds.getWidth(), yOffset); + g.draw(line); + } + + // tick marks + if (stylerAxesChart.isPlotTicksMarksVisible()) { + + g.setColor(stylerAxesChart.getAxisTickMarksColor()); + g.setStroke(stylerAxesChart.getAxisTickMarksStroke()); + Shape line = new Line2D.Double(bounds.getX(), yOffset, bounds.getX() + stylerAxesChart.getAxisTickMarkLength(), yOffset); + g.draw(line); + line = new Line2D.Double(bounds.getX() + bounds.getWidth(), yOffset, bounds.getX() + bounds.getWidth() - stylerAxesChart.getAxisTickMarkLength(), yOffset); + g.draw(line); + } + } + } + } + + // vertical + + if ((stylerAxesChart.isPlotGridVerticalLinesVisible() || stylerAxesChart.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 (stylerAxesChart.isPlotGridVerticalLinesVisible()) { + g.setColor(stylerAxesChart.getPlotGridLinesColor()); + g.setStroke(stylerAxesChart.getPlotGridLinesStroke()); + + Shape line = new Line2D.Double(xOffset, bounds.getY(), xOffset, bounds.getY() + bounds.getHeight()); + g.draw(line); + } + // tick marks + if (stylerAxesChart.isPlotTicksMarksVisible()) { + + g.setColor(stylerAxesChart.getAxisTickMarksColor()); + g.setStroke(stylerAxesChart.getAxisTickMarksStroke()); + + Shape line = new Line2D.Double(xOffset, bounds.getY(), xOffset, bounds.getY() + stylerAxesChart.getAxisTickMarkLength()); + g.draw(line); + line = new Line2D.Double(xOffset, bounds.getY() + bounds.getHeight(), xOffset, bounds.getY() + bounds.getHeight() - stylerAxesChart.getAxisTickMarkLength()); + g.draw(line); + } + } + } + } + } + +} diff --git a/xchart/src/main/java/org/knowm/xchart/internal/chartpart/PlotSurface_Pie.java b/xchart/src/main/java/org/knowm/xchart/internal/chartpart/PlotSurface_Pie.java new file mode 100644 index 0000000000000000000000000000000000000000..48fc244e314e15bdd525d96b3ae5f46d5dc5cff2 --- /dev/null +++ b/xchart/src/main/java/org/knowm/xchart/internal/chartpart/PlotSurface_Pie.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.Styler_Pie; +import org.knowm.xchart.internal.Series; +import org.knowm.xchart.internal.style.Styler; + +/** + * Draws the plot background and the plot border + * + * @author timmolter + */ +public class PlotSurface_Pie<ST extends Styler, S extends Series> extends PlotSurface_ { + + private final Styler_Pie stylerPie; + + /** + * Constructor + * + * @param chart + */ + protected PlotSurface_Pie(Chart<Styler_Pie, Series_Pie> chart) { + + super(chart); + this.stylerPie = chart.getStyler(); + } + + @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(stylerPie.getPlotBackgroundColor()); + g.fill(rect); + + // paint plot border + if (stylerPie.isPlotBorderVisible()) { + g.setColor(stylerPie.getPlotBorderColor()); + // g.setStroke(getChartPainter().getstyler().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..4ae95fd20c3eeb739e3c9d4c00ebb3ed237dc13f --- /dev/null +++ b/xchart/src/main/java/org/knowm/xchart/internal/chartpart/Plot_.java @@ -0,0 +1,65 @@ +/** + * 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.Styler; + +/** + * @author timmolter + */ +public class Plot_<ST extends Styler, S extends Series> implements ChartPart { + + protected final Chart<ST, S> chart; + protected Rectangle2D bounds; + + protected PlotSurface_ plotSurface; + protected PlotContent_ plotContent; + + /** + * Constructor + * + * @param chart + */ + public Plot_(Chart<ST, S> chart) { + + this.chart = chart; + } + + @Override + public void paint(Graphics2D g) { + + // g.setColor(Color.green); + // g.draw(bounds); + + plotSurface.paint(g); + if (chart.getSeriesMap().isEmpty()) { + return; + } + 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..00cf4b80d826ec84d2fc586923944e1f5f54ef9a --- /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.Styler; +import org.knowm.xchart.internal.style.Styler_AxesChart; + +/** + * @author timmolter + */ +public class Plot_AxesChart<ST extends Styler, S extends Series> extends Plot_ { + + Styler_AxesChart stylerAxesChart; + + /** + * Constructor + * + * @param chart + */ + public Plot_AxesChart(Chart<Styler_AxesChart, Series_XY> chart) { + + super(chart); + stylerAxesChart = chart.getStyler(); + this.plotSurface = new PlotSurface_AxesChart<Styler_AxesChart, Series_XY>(chart); + } + + @Override + public void paint(Graphics2D g) { + + // calculate bounds + double xOffset = chart.getYAxis().getBounds().getX() + chart.getYAxis().getBounds().getWidth() + + + (stylerAxesChart.isYAxisTicksVisible() ? stylerAxesChart.getPlotMargin() : 0); + + double yOffset = chart.getYAxis().getBounds().getY(); + double width = chart.getXAxis().getBounds().getWidth(); + double height = chart.getYAxis().getBounds().getHeight(); + this.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..e90da768b00942c7c36381918a9956875578e7a7 --- /dev/null +++ b/xchart/src/main/java/org/knowm/xchart/internal/chartpart/Plot_Category.java @@ -0,0 +1,60 @@ +/** + * 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 org.knowm.xchart.Series_Category; +import org.knowm.xchart.Series_Category.ChartCategorySeriesRenderStyle; +import org.knowm.xchart.Styler_Category; +import org.knowm.xchart.internal.Series; +import org.knowm.xchart.internal.style.Styler_AxesChart; + +/** + * @author timmolter + */ +public class Plot_Category<ST extends Styler_AxesChart, S extends Series> extends Plot_AxesChart { + + Styler_Category stylerCategory; + + /** + * Constructor + * + * @param chart + */ + public Plot_Category(Chart<Styler_Category, Series_Category> chart) { + + super(chart); + stylerCategory = chart.getStyler(); + } + + @Override + public void paint(Graphics2D g) { + + if (ChartCategorySeriesRenderStyle.Bar.equals(stylerCategory.getChartCategorySeriesRenderStyle()) || ChartCategorySeriesRenderStyle.Stick.equals(stylerCategory + .getChartCategorySeriesRenderStyle())) { + + this.plotContent = new PlotContent_Category_Bar<Styler_Category, Series_Category>(chart); + } + else { + this.plotContent = new PlotContent_Category_Line_Area_Scatter<Styler_Category, Series_Category>(chart); + } + + super.paint(g); + } + +} 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..5e78f15ab65f9fab87bc27f9b5dd894eda3c14a1 --- /dev/null +++ b/xchart/src/main/java/org/knowm/xchart/internal/chartpart/Plot_Pie.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.chartpart; + +import java.awt.Graphics2D; +import java.awt.geom.Rectangle2D; + +import org.knowm.xchart.Series_Pie; +import org.knowm.xchart.Styler_Pie; +import org.knowm.xchart.internal.Series; +import org.knowm.xchart.internal.style.Styler; +import org.knowm.xchart.internal.style.Styler.LegendPosition; + +/** + * @author timmolter + */ +public class Plot_Pie<ST extends Styler, S extends Series> extends Plot_ { + + /** + * Constructor + * + * @param chart + */ + public Plot_Pie(Chart<Styler_Pie, Series_Pie> chart) { + + super(chart); + this.plotContent = new PlotContent_Pie<Styler_Pie, Series_Pie>(chart); + this.plotSurface = new PlotSurface_Pie<Styler_Pie, Series_Pie>(chart); + } + + @Override + public void paint(Graphics2D g) { + + // calculate bounds + double xOffset = chart.getStyler().getChartPadding(); + + // double yOffset = chart.getChartTitle().getBounds().getHeight() + 2 * chart.getStyler().getChartPadding(); + double yOffset = chart.getChartTitle().getBounds().getHeight() + chart.getStyler().getChartPadding(); + + double width = + + chart.getWidth() + + - (chart.getStyler().getLegendPosition() == LegendPosition.OutsideE ? chart.getLegend().getBounds().getWidth() : 0) + + - 2 * chart.getStyler().getChartPadding() + + - (chart.getStyler().getLegendPosition() == LegendPosition.OutsideE && chart.getStyler().isLegendVisible() ? chart.getStyler().getChartPadding() : 0); + + double height = chart.getHeight() - chart.getChartTitle().getBounds().getHeight() - 2 * chart.getStyler().getChartPadding(); + + this.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..f4cf136595417870e4dd53aac77972cc6220006a --- /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.Styler_XY; +import org.knowm.xchart.internal.Series; +import org.knowm.xchart.internal.style.Styler_AxesChart; + +/** + * @author timmolter + */ +public class Plot_XY<ST extends Styler_AxesChart, S extends Series> extends Plot_AxesChart { + + /** + * Constructor + * + * @param chart + */ + public Plot_XY(Chart<Styler_XY, Series_XY> chart) { + + super(chart); + this.plotContent = new PlotContent_XY<Styler_XY, 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/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..7800a6feb1743e8ece92328a7ca8fc8ba59d6482 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,11 +16,10 @@ */ package org.knowm.xchart.internal.style; -import java.util.List; +import java.awt.BasicStroke; +import java.awt.Color; -import org.knowm.xchart.SeriesColor; -import org.knowm.xchart.SeriesLineStyle; -import org.knowm.xchart.SeriesMarker; +import org.knowm.xchart.internal.style.markers.Marker; /** * Cycles through the different colors, markers, and strokes in a predetermined way @@ -29,22 +28,16 @@ import org.knowm.xchart.SeriesMarker; * * @author timmolter */ -public abstract class SeriesColorMarkerLineStyleCycler { +public class SeriesColorMarkerLineStyleCycler { - public abstract List<SeriesColor> getSeriesColorList(); - - 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 Color[] seriesColorList; /** a map holding the SeriesMarkers */ - private final List<SeriesMarker> seriesMarkerList; + private final Marker[] seriesMarkerList; /** a map holding the SeriesLineStyles */ - private final List<SeriesLineStyle> seriesLineStyleList; + private final BasicStroke[] seriesLineStyleList; /** an internal counter */ private int colorCounter = 0; @@ -54,39 +47,39 @@ public abstract class SeriesColorMarkerLineStyleCycler { /** * Constructor */ - public SeriesColorMarkerLineStyleCycler() { + public SeriesColorMarkerLineStyleCycler(Color[] seriesColorList, Marker[] seriesMarkerList, BasicStroke[] seriesLineStyleList) { - seriesColorList = getSeriesColorList(); - seriesMarkerList = getSeriesMarkerList(); - seriesLineStyleList = getLineStyleList(); + this.seriesColorList = seriesColorList; + this.seriesMarkerList = seriesMarkerList; + this.seriesLineStyleList = seriesLineStyleList; } /** - * Get the next SeriesColorMarkerLineStyle + * Get the next ColorMarkerLineStyle * - * @return the next SeriesColorMarkerLineStyle + * @return the next ColorMarkerLineStyle */ public SeriesColorMarkerLineStyle getNextSeriesColorMarkerLineStyle() { // 1. Color - cycle through colors one by one - if (colorCounter >= seriesColorList.size()) { + if (colorCounter >= seriesColorList.length) { colorCounter = 0; strokeCounter++; } - SeriesColor seriesColor = seriesColorList.get(colorCounter++); + Color seriesColor = seriesColorList[colorCounter++]; // 2. Stroke - cycle through strokes one by one but only after a color cycle - if (strokeCounter >= seriesLineStyleList.size()) { + if (strokeCounter >= seriesLineStyleList.length) { strokeCounter = 0; } - SeriesLineStyle seriesLineStyle = seriesLineStyleList.get(strokeCounter); + BasicStroke seriesLineStyle = seriesLineStyleList[strokeCounter]; // 3. Marker - cycle through markers one by one - if (markerCounter >= seriesMarkerList.size()) { + if (markerCounter >= seriesMarkerList.length) { markerCounter = 0; } - SeriesMarker marker = seriesMarkerList.get(markerCounter++); + Marker marker = seriesMarkerList[markerCounter++]; - return new SeriesColorMarkerLineStyle(seriesColor.getColor(), marker.getMarker(), seriesLineStyle.getBasicStroke()); + return new SeriesColorMarkerLineStyle(seriesColor, marker, seriesLineStyle); } } diff --git a/xchart/src/main/java/org/knowm/xchart/internal/style/Styler.java b/xchart/src/main/java/org/knowm/xchart/internal/style/Styler.java new file mode 100644 index 0000000000000000000000000000000000000000..2b2a2e72461b07d7832add9e5842d129f06b4356 --- /dev/null +++ b/xchart/src/main/java/org/knowm/xchart/internal/style/Styler.java @@ -0,0 +1,477 @@ +/** + * 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.BasicStroke; +import java.awt.Color; +import java.awt.Font; + +import org.knowm.xchart.internal.style.markers.Marker; + +/** + * The styler is used to manage all things related to styling of the vast number of Chart components + * + * @author timmolter + */ +public abstract class Styler { + + 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 Theme_GGPlot2(); + + case Matlab: + return new Theme_Matlab(); + + case XChart: + default: + return new Theme_XChart(); + } + } + } + + public enum TextAlignment { + + Left, Centre, Right; + } + + /** the default Theme */ + protected Theme_ theme = new Theme_XChart(); + + // Chart Style /////////////////////////////// + private Color chartBackgroundColor; + private Color chartFontColor; + private int chartPadding; + private Color[] seriesColors; + private BasicStroke[] seriesLines; + private Marker[] seriesMarkers; + + // 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; + private double plotContentSize = .92; + + protected void setAllStyles() { + + // Chart Style /////////////////////////////// + chartBackgroundColor = theme.getChartBackgroundColor(); + chartFontColor = theme.getChartFontColor(); + chartPadding = theme.getChartPadding(); + seriesColors = theme.getSeriesColors(); + seriesLines = theme.getSeriesLines(); + seriesMarkers = theme.getSeriesMarkers(); + + // 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(); + plotContentSize = theme.getPlotContentSize(); + } + + // 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; + } + + // Chart Title /////////////////////////////// + + public Color[] getSeriesColors() { + + return seriesColors; + } + + public void setSeriesColors(Color[] seriesColors) { + + this.seriesColors = seriesColors; + } + + public BasicStroke[] getSeriesLines() { + + return seriesLines; + } + + public void setSeriesLines(BasicStroke[] seriesLines) { + + this.seriesLines = seriesLines; + } + + public Marker[] getSeriesMarkers() { + + return seriesMarkers; + } + + public void setSeriesMarkers(Marker[] seriesMarkers) { + + this.seriesMarkers = seriesMarkers; + } + + /** + * 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; + } + + public double getPlotContentSize() { + + return plotContentSize; + } + + /** + * Sets the content size of the plot inside the plot area of the chart. To fill the area 100%, use a value of 1.0. + * + * @param plotContentSize - Valid range is between 0 and 1. + */ + public void setPlotContentSize(double plotContentSize) { + + if (plotContentSize < 0 || plotContentSize > 1) { + throw new IllegalArgumentException("Plot content size must be tween 0 and 1!!!"); + } + + this.plotContentSize = plotContentSize; + } + +} diff --git a/xchart/src/main/java/org/knowm/xchart/StyleManager.java b/xchart/src/main/java/org/knowm/xchart/internal/style/Styler_AxesChart.java similarity index 63% rename from xchart/src/main/java/org/knowm/xchart/StyleManager.java rename to xchart/src/main/java/org/knowm/xchart/internal/style/Styler_AxesChart.java index b7c0acfbf2bee32930fde289f17e04d8ec9fe327..a08458e92ff2095770aced9cf61ef3c53723c9c9 100644 --- a/xchart/src/main/java/org/knowm/xchart/StyleManager.java +++ b/xchart/src/main/java/org/knowm/xchart/internal/style/Styler_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"); @@ -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 Styler_AxesChart extends Styler { // Chart Axes /////////////////////////////// private boolean xAxisTitleVisible; @@ -110,7 +41,7 @@ public class StyleManager { private Color axisTickLabelsColor; private boolean isAxisTicksLineVisible; private boolean isAxisTicksMarksVisible; - private int plotPadding; + private int plotMargin; private int axisTitlePadding; private int xAxisTickMarkSpacingHint; private int yAxisTickMarkSpacingHint; @@ -120,7 +51,6 @@ public class StyleManager { private Double xAxisMax; private Double yAxisMin; private Double yAxisMax; - private double axisTickSpacePercentage; private TextAlignment xAxisLabelAlignment = TextAlignment.Centre; private TextAlignment yAxisLabelAlignment = TextAlignment.Left; private int xAxisLabelRotation = 0; @@ -128,9 +58,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 +82,10 @@ public class StyleManager { private String xAxisDecimalPattern; private String yAxisDecimalPattern; - /** - * Constructor - */ - public StyleManager() { - - setAllStyles(); - } - - private void setAllStyles() { + @Override + protected void setAllStyles() { - // Chart Style /////////////////////////////// - chartType = ChartType.Line; - 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(); + super.setAllStyles(); // axes xAxisTitleVisible = theme.isXAxisTitleVisible(); @@ -203,7 +101,7 @@ public class StyleManager { axisTickLabelsColor = theme.getAxisTickLabelsColor(); isAxisTicksLineVisible = theme.isAxisTicksLineVisible(); isAxisTicksMarksVisible = theme.isAxisTicksMarksVisible(); - plotPadding = theme.getPlotPadding(); + plotMargin = theme.getPlotMargin(); axisTitlePadding = theme.getAxisTitlePadding(); xAxisTickMarkSpacingHint = theme.getXAxisTickMarkSpacingHint(); yAxisTickMarkSpacingHint = theme.getYAxisTickMarkSpacingHint(); @@ -213,14 +111,10 @@ public class StyleManager { xAxisMax = null; yAxisMin = null; yAxisMax = null; - axisTickSpacePercentage = .95; // 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 +125,6 @@ public class StyleManager { isBarFilled = theme.isBarFilled(); // Line, Scatter, Area Charts /////////////////////////////// - markerSize = theme.getMarkerSize(); // Error Bars /////////////////////////////// @@ -247,298 +140,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 +162,7 @@ public class StyleManager { * * @param isVisible */ + public void setYAxisTitleVisible(boolean yAxisTitleVisible) { this.yAxisTitleVisible = yAxisTitleVisible; @@ -576,6 +178,7 @@ public class StyleManager { * * @param isVisible */ + public void setAxisTitlesVisible(boolean isVisible) { this.xAxisTitleVisible = isVisible; @@ -587,6 +190,7 @@ public class StyleManager { * * @param axisTitleFont */ + public void setAxisTitleFont(Font axisTitleFont) { this.axisTitleFont = axisTitleFont; @@ -634,6 +238,7 @@ public class StyleManager { * * @param isVisible */ + public void setAxisTicksVisible(boolean isVisible) { this.xAxisTicksVisible = isVisible; @@ -645,6 +250,7 @@ public class StyleManager { * * @param foxAxisTicksFontnt */ + public void setAxisTickLabelsFont(Font axisTicksFont) { this.axisTickLabelsFont = axisTicksFont; @@ -660,6 +266,7 @@ public class StyleManager { * * @param axisTickMarkLength */ + public void setAxisTickMarkLength(int axisTickMarkLength) { this.axisTickMarkLength = axisTickMarkLength; @@ -690,6 +297,7 @@ public class StyleManager { * * @param axisTickColor */ + public void setAxisTickMarksColor(Color axisTickColor) { this.axisTickMarksColor = axisTickColor; @@ -705,6 +313,7 @@ public class StyleManager { * * @param axisTickMarksStroke */ + public void setAxisTickMarksStroke(Stroke axisTickMarksStroke) { this.axisTickMarksStroke = axisTickMarksStroke; @@ -720,6 +329,7 @@ public class StyleManager { * * @param axisTickLabelsColor */ + public void setAxisTickLabelsColor(Color axisTickLabelsColor) { this.axisTickLabelsColor = axisTickLabelsColor; @@ -735,6 +345,7 @@ public class StyleManager { * * @param isAxisTicksLineVisible */ + public void setAxisTicksLineVisible(boolean isAxisTicksLineVisible) { this.isAxisTicksLineVisible = isAxisTicksLineVisible; @@ -750,6 +361,7 @@ public class StyleManager { * * @param isAxisTicksMarksVisible */ + public void setAxisTicksMarksVisible(boolean isAxisTicksMarksVisible) { this.isAxisTicksMarksVisible = isAxisTicksMarksVisible; @@ -761,18 +373,19 @@ public class StyleManager { } /** - * sets the padding between the tick marks and the plot area + * sets the margin around the plot area * - * @param plotPadding + * @param plotMargin */ - public void setPlotPadding(int plotPadding) { - this.plotPadding = plotPadding; + public void setPlotMargin(int plotMargin) { + + this.plotMargin = plotMargin; } - public int getPlotPadding() { + public int getPlotMargin() { - return plotPadding; + return plotMargin; } /** @@ -780,6 +393,7 @@ public class StyleManager { * * @param axisTitlePadding */ + public void setAxisTitlePadding(int axisTitlePadding) { this.axisTitlePadding = axisTitlePadding; @@ -795,6 +409,7 @@ public class StyleManager { * * @param xAxisTickMarkSpacingHint */ + public void setXAxisTickMarkSpacingHint(int xAxisTickMarkSpacingHint) { this.xAxisTickMarkSpacingHint = xAxisTickMarkSpacingHint; @@ -810,6 +425,7 @@ public class StyleManager { * * @param xAxisTickMarkSpacingHint */ + public void setYAxisTickMarkSpacingHint(int yAxisTickMarkSpacingHint) { this.yAxisTickMarkSpacingHint = yAxisTickMarkSpacingHint; @@ -825,6 +441,7 @@ public class StyleManager { * * @param isxAxisLogarithmic */ + public void setXAxisLogarithmic(boolean isXAxisLogarithmic) { this.isXAxisLogarithmic = isXAxisLogarithmic; @@ -840,6 +457,7 @@ public class StyleManager { * * @param isyAxisLogarithmic */ + public void setYAxisLogarithmic(boolean isYAxisLogarithmic) { this.isYAxisLogarithmic = isYAxisLogarithmic; @@ -890,16 +508,6 @@ public class StyleManager { return yAxisMax; } - public void setAxisTickSpacePercentage(double axisTickSpacePercentage) { - - this.axisTickSpacePercentage = axisTickSpacePercentage; - } - - public double getAxisTickSpacePercentage() { - - return axisTickSpacePercentage; - } - public TextAlignment getXAxisLabelAlignment() { return xAxisLabelAlignment; @@ -937,6 +545,7 @@ public class StyleManager { * * @param isPlotGridLinesVisible */ + public void setPlotGridLinesVisible(boolean isPlotGridLinesVisible) { this.isPlotGridHorizontalLinesVisible = isPlotGridLinesVisible; @@ -953,6 +562,7 @@ public class StyleManager { * * @param isPlotGridLinesVisible */ + public void setPlotGridHorizontalLinesVisible(boolean isPlotGridHorizontalLinesVisible) { this.isPlotGridHorizontalLinesVisible = isPlotGridHorizontalLinesVisible; @@ -968,6 +578,7 @@ public class StyleManager { * * @param isPlotGridLinesVisible */ + public void setPlotGridVerticalLinesVisible(boolean isPlotGridVerticalLinesVisible) { this.isPlotGridVerticalLinesVisible = isPlotGridVerticalLinesVisible; @@ -978,56 +589,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 +610,7 @@ public class StyleManager { * * @param plotGridLinesColor */ + public void setPlotGridLinesColor(Color plotGridLinesColor) { this.plotGridLinesColor = plotGridLinesColor; @@ -1058,6 +626,7 @@ public class StyleManager { * * @param plotGridLinesStroke */ + public void setPlotGridLinesStroke(Stroke plotGridLinesStroke) { this.plotGridLinesStroke = plotGridLinesStroke; @@ -1075,6 +644,7 @@ public class StyleManager { * * @param barWidthPercentage */ + public void setBarWidthPercentage(double barWidthPercentage) { this.barWidthPercentage = barWidthPercentage; @@ -1090,6 +660,7 @@ public class StyleManager { * * @param isBarsOverlapped */ + public void setBarsOverlapped(boolean isBarsOverlapped) { this.isBarsOverlapped = isBarsOverlapped; @@ -1105,6 +676,7 @@ public class StyleManager { * * @param isBarFilled */ + public void setBarFilled(boolean isBarFilled) { this.isBarFilled = isBarFilled; @@ -1122,6 +694,7 @@ public class StyleManager { * * @param markerSize */ + public void setMarkerSize(int markerSize) { this.markerSize = markerSize; @@ -1139,6 +712,7 @@ public class StyleManager { * * @param errorBarsColor */ + public void setErrorBarsColor(Color errorBarsColor) { this.errorBarsColor = errorBarsColor; @@ -1154,6 +728,7 @@ public class StyleManager { * * @return */ + public void setErrorBarsColorSeriesColor(boolean isErrorBarsColorSeriesColor) { this.isErrorBarsColorSeriesColor = isErrorBarsColorSeriesColor; @@ -1171,6 +746,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 +762,7 @@ public class StyleManager { * * @param timezone the timezone to use when formatting date data */ + public void setTimezone(TimeZone timezone) { this.timezone = timezone; @@ -1201,6 +778,7 @@ public class StyleManager { * * @param pattern - the pattern describing the date and time format */ + public void setDatePattern(String datePattern) { this.datePattern = datePattern; @@ -1216,6 +794,7 @@ public class StyleManager { * * @param pattern - the pattern describing the decimal format */ + public void setDecimalPattern(String decimalPattern) { this.decimalPattern = decimalPattern; @@ -1236,6 +815,7 @@ public class StyleManager { * * @param xAxisDecimalPattern */ + public void setXAxisDecimalPattern(String xAxisDecimalPattern) { this.xAxisDecimalPattern = xAxisDecimalPattern; @@ -1251,6 +831,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 similarity index 80% rename from xchart/src/main/java/org/knowm/xchart/internal/style/Theme.java rename to xchart/src/main/java/org/knowm/xchart/internal/style/Theme_.java index 84dfdff38f40fd9df292ed8d9378f1f9e9df1cc0..58b59af7a40104f2e36f9a39bafa09e748ab3563 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,12 +20,16 @@ import java.awt.Color; import java.awt.Font; import java.awt.Stroke; -import org.knowm.xchart.StyleManager.LegendPosition; +import org.knowm.xchart.Styler_Pie.AnnotationType; +import org.knowm.xchart.internal.style.Styler.LegendPosition; +import org.knowm.xchart.internal.style.colors.SeriesColors; +import org.knowm.xchart.internal.style.lines.SeriesLines; +import org.knowm.xchart.internal.style.markers.SeriesMarkers; /** * @author timmolter */ -public interface Theme { +public interface Theme_ extends SeriesMarkers, SeriesLines, SeriesColors { // Chart Style /////////////////////////////// @@ -35,8 +39,6 @@ public interface Theme { public int getChartPadding(); - public SeriesColorMarkerLineStyleCycler getSeriesColorMarkerLineStyleCycler(); - // Chart Title /////////////////////////////// public Font getChartTitleFont(); @@ -97,8 +99,6 @@ public interface Theme { public int getAxisTitlePadding(); - public int getPlotPadding(); - public int getXAxisTickMarkSpacingHint(); public int getYAxisTickMarkSpacingHint(); @@ -123,6 +123,10 @@ public interface Theme { public boolean isPlotTicksMarksVisible(); + public double getPlotContentSize(); + + public int getPlotMargin(); + // Bar Charts /////////////////////////////// public double getBarWidthPercentage(); @@ -131,6 +135,18 @@ public interface Theme { public boolean isBarFilled(); + // Pie Charts /////////////////////////////// + + public boolean isCircular(); + + public double getStartAngleInDegrees(); + + public Font getPieFont(); + + public double getAnnotationDistance(); + + AnnotationType getAnnotationType(); + // Line, Scatter, Area Charts /////////////////////////////// public int getMarkerSize(); diff --git a/xchart/src/main/java/org/knowm/xchart/internal/style/GGPlot2Theme.java b/xchart/src/main/java/org/knowm/xchart/internal/style/Theme_GGPlot2.java similarity index 64% rename from xchart/src/main/java/org/knowm/xchart/internal/style/GGPlot2Theme.java rename to xchart/src/main/java/org/knowm/xchart/internal/style/Theme_GGPlot2.java index ac9a333526090be89bef6f9e5decd8c5ac780299..9e3dd262d006afd6c1c4d8f87edc7ca8d06bcdf9 100644 --- a/xchart/src/main/java/org/knowm/xchart/internal/style/GGPlot2Theme.java +++ b/xchart/src/main/java/org/knowm/xchart/internal/style/Theme_GGPlot2.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,35 +20,19 @@ import java.awt.BasicStroke; import java.awt.Color; import java.awt.Font; import java.awt.Stroke; -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.Styler_Pie.AnnotationType; +import org.knowm.xchart.internal.style.Styler.LegendPosition; +import org.knowm.xchart.internal.style.colors.ChartColor; +import org.knowm.xchart.internal.style.colors.GGPlot2SeriesColors; +import org.knowm.xchart.internal.style.lines.GGPlot2SeriesLines; +import org.knowm.xchart.internal.style.markers.GGPlot2SeriesMarkers; +import org.knowm.xchart.internal.style.markers.Marker; /** * @author timmolter */ -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 class Theme_GGPlot2 implements Theme_ { // Chart Style /////////////////////////////// @@ -71,11 +55,23 @@ public class GGPlot2Theme implements Theme { } @Override - public SeriesColorMarkerLineStyleCycler getSeriesColorMarkerLineStyleCycler() { + public Marker[] getSeriesMarkers() { + + return new GGPlot2SeriesMarkers().getSeriesMarkers(); - return new XChartSeriesColorMarkerLineStyleCycler(); } + @Override + public BasicStroke[] getSeriesLines() { + + return new GGPlot2SeriesLines().getSeriesLines(); + } + + @Override + public Color[] getSeriesColors() { + + return new GGPlot2SeriesColors().getSeriesColors(); + } // Chart Title /////////////////////////////// @Override @@ -87,7 +83,7 @@ public class GGPlot2Theme implements Theme { @Override public boolean isChartTitleVisible() { - return false; + return true; } @Override @@ -209,21 +205,21 @@ public class GGPlot2Theme implements Theme { } @Override - public boolean isAxisTicksLineVisible() { + public int getPlotMargin() { - return false; + return 0; } @Override - public boolean isAxisTicksMarksVisible() { + public boolean isAxisTicksLineVisible() { - return true; + return false; } @Override - public int getPlotPadding() { + public boolean isAxisTicksMarksVisible() { - return 0; + return true; } @Override @@ -319,6 +315,12 @@ public class GGPlot2Theme implements Theme { return new BasicStroke(1.5f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 10.0f, new float[] { 3.0f, 0.0f }, 0.0f); } + @Override + public double getPlotContentSize() { + + return .92; + } + // Bar Charts /////////////////////////////// @Override @@ -339,75 +341,58 @@ public class GGPlot2Theme implements Theme { return true; } - // Line, Scatter, Area Charts /////////////////////////////// + // Pie Charts /////////////////////////////// @Override - public int getMarkerSize() { + public boolean isCircular() { - return 8; + return true; } - // Error Bars /////////////////////////////// - @Override - public Color getErrorBarsColor() { + public double getStartAngleInDegrees() { - return ChartColor.getAWTColor(ChartColor.DARK_GREY); + return 0; } @Override - public boolean isErrorBarsColorSeriesColor() { + public Font getPieFont() { - return false; + return new Font(Font.SANS_SERIF, Font.PLAIN, 15); } - public class XChartSeriesColorMarkerLineStyleCycler extends SeriesColorMarkerLineStyleCycler { + @Override + public double getAnnotationDistance() { - @Override - public List<SeriesColor> getSeriesColorList() { + return .67; + } - // 1. Color - List<SeriesColor> seriesColorMap = new ArrayList<SeriesColor>(); + @Override + public AnnotationType getAnnotationType() { - // The color blind friendly palette - // seriesColorMap.add(BLACK); - // seriesColorMap.add(ORANGE); - // seriesColorMap.add(SKY_BLUE); - // seriesColorMap.add(BLUISH_GREEN); - // seriesColorMap.add(YELLOW); - // seriesColorMap.add(BLUE); - // seriesColorMap.add(VERMILLION); - // seriesColorMap.add(REDDISH_PURPLE); + return AnnotationType.LabelAndPercentage; + } - seriesColorMap.add(RED); - seriesColorMap.add(YELLOW_GREEN); - seriesColorMap.add(GREEN); - seriesColorMap.add(BLUE); - seriesColorMap.add(PURPLE); + // Line, Scatter, Area Charts /////////////////////////////// - return seriesColorMap; - } + @Override + public int getMarkerSize() { - @Override - public List<SeriesMarker> getSeriesMarkerList() { + return 8; + } - // 2. Marker - List<SeriesMarker> seriesMarkerList = new ArrayList<SeriesMarker>(); - seriesMarkerList.add(SeriesMarker.CIRCLE); - seriesMarkerList.add(SeriesMarker.DIAMOND); - return seriesMarkerList; - } + // Error Bars /////////////////////////////// - @Override - public List<SeriesLineStyle> getLineStyleList() { + @Override + public Color getErrorBarsColor() { - // 3. Stroke - List<SeriesLineStyle> seriesLineStyleList = new ArrayList<SeriesLineStyle>(); - seriesLineStyleList.add(SeriesLineStyle.SOLID); - seriesLineStyleList.add(SeriesLineStyle.DOT_DOT); - seriesLineStyleList.add(SeriesLineStyle.DASH_DASH); - return seriesLineStyleList; - } + return ChartColor.getAWTColor(ChartColor.DARK_GREY); + } + + @Override + public boolean isErrorBarsColorSeriesColor() { + return false; } + } diff --git a/xchart/src/main/java/org/knowm/xchart/internal/style/MatlabTheme.java b/xchart/src/main/java/org/knowm/xchart/internal/style/Theme_Matlab.java similarity index 71% rename from xchart/src/main/java/org/knowm/xchart/internal/style/MatlabTheme.java rename to xchart/src/main/java/org/knowm/xchart/internal/style/Theme_Matlab.java index 8996dde5939b078e418665ef002f3fce255cd57e..221bdf84455937f77bb8bf0b4a036df8000f555d 100644 --- a/xchart/src/main/java/org/knowm/xchart/internal/style/MatlabTheme.java +++ b/xchart/src/main/java/org/knowm/xchart/internal/style/Theme_Matlab.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,27 +20,19 @@ import java.awt.BasicStroke; import java.awt.Color; import java.awt.Font; import java.awt.Stroke; -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.Styler_Pie.AnnotationType; +import org.knowm.xchart.internal.style.Styler.LegendPosition; +import org.knowm.xchart.internal.style.colors.ChartColor; +import org.knowm.xchart.internal.style.colors.MatlabSeriesColors; +import org.knowm.xchart.internal.style.lines.MatlabSeriesLines; +import org.knowm.xchart.internal.style.markers.Marker; +import org.knowm.xchart.internal.style.markers.MatlabSeriesMarkers; /** * @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 class Theme_Matlab implements Theme_ { // Chart Style /////////////////////////////// @@ -63,9 +55,24 @@ public class MatlabTheme implements Theme { } @Override - public SeriesColorMarkerLineStyleCycler getSeriesColorMarkerLineStyleCycler() { + public Marker[] getSeriesMarkers() { + + return new MatlabSeriesMarkers().getSeriesMarkers(); + + } + + @Override + public BasicStroke[] getSeriesLines() { + + return new MatlabSeriesLines().getSeriesLines(); + + } + + @Override + public Color[] getSeriesColors() { + + return new MatlabSeriesColors().getSeriesColors(); - return new MatlabSeriesColorMarkerLineStyleCycler(); } // Chart Title /////////////////////////////// @@ -79,7 +86,7 @@ public class MatlabTheme implements Theme { @Override public boolean isChartTitleVisible() { - return false; + return true; } @Override @@ -201,6 +208,12 @@ public class MatlabTheme implements Theme { return 4; } + @Override + public int getPlotMargin() { + + return 3; + } + @Override public Color getAxisTickMarksColor() { @@ -231,12 +244,6 @@ public class MatlabTheme implements Theme { return false; } - @Override - public int getPlotPadding() { - - return 3; - } - @Override public int getAxisTitlePadding() { @@ -312,6 +319,12 @@ public class MatlabTheme implements Theme { } + @Override + public double getPlotContentSize() { + + return .92; + } + // Bar Charts /////////////////////////////// @Override @@ -332,64 +345,58 @@ public class MatlabTheme implements Theme { return true; } - // Line, Scatter, Area Charts /////////////////////////////// + // Pie Charts /////////////////////////////// @Override - public int getMarkerSize() { + public boolean isCircular() { - return 8; + return true; } - // Error Bars /////////////////////////////// + @Override + public double getStartAngleInDegrees() { + + return 0; + } @Override - public Color getErrorBarsColor() { + public Font getPieFont() { - return ChartColor.getAWTColor(ChartColor.BLACK); + return new Font(Font.SANS_SERIF, Font.PLAIN, 15); } @Override - public boolean isErrorBarsColorSeriesColor() { + public double getAnnotationDistance() { - return false; + return .67; } - public class MatlabSeriesColorMarkerLineStyleCycler extends SeriesColorMarkerLineStyleCycler { + @Override + public AnnotationType getAnnotationType() { - @Override - public List<SeriesColor> getSeriesColorList() { + return AnnotationType.Label; + } - // 1. Color - List<SeriesColor> seriesColorMap = new ArrayList<SeriesColor>(); - seriesColorMap.add(BLUE); - seriesColorMap.add(GREEN); - seriesColorMap.add(RED); - seriesColorMap.add(TURQUOISE); - seriesColorMap.add(MAGENTA); - seriesColorMap.add(YELLOW); - seriesColorMap.add(DARK_GREY); - return seriesColorMap; - } + // Line, Scatter, Area Charts /////////////////////////////// - @Override - public List<SeriesMarker> getSeriesMarkerList() { + @Override + public int getMarkerSize() { + + return 8; + } - // 2. Marker - List<SeriesMarker> seriesMarkerList = new ArrayList<SeriesMarker>(); - seriesMarkerList.add(SeriesMarker.NONE); - return seriesMarkerList; - } + // Error Bars /////////////////////////////// + + @Override + public Color getErrorBarsColor() { - @Override - public List<SeriesLineStyle> getLineStyleList() { + return ChartColor.getAWTColor(ChartColor.BLACK); + } - // 3. Stroke - List<SeriesLineStyle> seriesLineStyleList = new ArrayList<SeriesLineStyle>(); - seriesLineStyleList.add(SeriesLineStyle.SOLID); - seriesLineStyleList.add(SeriesLineStyle.DASH_DASH); - seriesLineStyleList.add(SeriesLineStyle.DOT_DOT); - return seriesLineStyleList; - } + @Override + public boolean isErrorBarsColorSeriesColor() { + return false; } + } diff --git a/xchart/src/main/java/org/knowm/xchart/internal/style/XChartTheme.java b/xchart/src/main/java/org/knowm/xchart/internal/style/Theme_XChart.java similarity index 58% rename from xchart/src/main/java/org/knowm/xchart/internal/style/XChartTheme.java rename to xchart/src/main/java/org/knowm/xchart/internal/style/Theme_XChart.java index ff561f759a671b1501bc76cc22e7fdff35f04baf..7d2711be58fabbf44b1b420bfd77a4651685e958 100644 --- a/xchart/src/main/java/org/knowm/xchart/internal/style/XChartTheme.java +++ b/xchart/src/main/java/org/knowm/xchart/internal/style/Theme_XChart.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,44 +20,19 @@ import java.awt.BasicStroke; import java.awt.Color; import java.awt.Font; import java.awt.Stroke; -import java.util.ArrayList; -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.Styler_Pie.AnnotationType; +import org.knowm.xchart.internal.style.Styler.LegendPosition; +import org.knowm.xchart.internal.style.colors.ChartColor; +import org.knowm.xchart.internal.style.colors.XChartSeriesColors; +import org.knowm.xchart.internal.style.lines.XChartSeriesLines; +import org.knowm.xchart.internal.style.markers.Marker; +import org.knowm.xchart.internal.style.markers.XChartSeriesMarkers; /** * @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); +public class Theme_XChart implements Theme_ { // Chart Style /////////////////////////////// @@ -80,9 +55,21 @@ public class XChartTheme implements Theme { } @Override - public SeriesColorMarkerLineStyleCycler getSeriesColorMarkerLineStyleCycler() { + public Color[] getSeriesColors() { - return new XChartSeriesColorMarkerLineStyleCycler(); + return new XChartSeriesColors().getSeriesColors(); + } + + @Override + public Marker[] getSeriesMarkers() { + + return new XChartSeriesMarkers().getSeriesMarkers(); + } + + @Override + public BasicStroke[] getSeriesLines() { + + return new XChartSeriesLines().getSeriesLines(); } // Chart Title /////////////////////////////// @@ -96,7 +83,7 @@ public class XChartTheme implements Theme { @Override public boolean isChartTitleVisible() { - return false; + return true; } @Override @@ -218,6 +205,12 @@ public class XChartTheme implements Theme { return 4; } + @Override + public int getPlotMargin() { + + return 4; + } + @Override public Color getAxisTickMarksColor() { @@ -248,12 +241,6 @@ public class XChartTheme implements Theme { return true; } - @Override - public int getPlotPadding() { - - return 4; - } - @Override public int getAxisTitlePadding() { @@ -328,6 +315,12 @@ public class XChartTheme implements Theme { return new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 10.0f, new float[] { 3.0f, 3.0f }, 0.0f); } + @Override + public double getPlotContentSize() { + + return .92; + } + // Bar Charts /////////////////////////////// @Override @@ -348,6 +341,38 @@ public class XChartTheme implements Theme { return true; } + // Pie Charts /////////////////////////////// + + @Override + public boolean isCircular() { + + return true; + } + + @Override + public double getStartAngleInDegrees() { + + return 0; + } + + @Override + public Font getPieFont() { + + return new Font(Font.SANS_SERIF, Font.PLAIN, 15); + } + + @Override + public double getAnnotationDistance() { + + return .67; + } + + @Override + public AnnotationType getAnnotationType() { + + return AnnotationType.Percentage; + } + // Line, Scatter, Area Charts /////////////////////////////// @Override @@ -370,64 +395,4 @@ public class XChartTheme implements Theme { return false; } - public class XChartSeriesColorMarkerLineStyleCycler 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; - } - - @Override - public List<SeriesMarker> getSeriesMarkerList() { - - // 2. Marker - List<SeriesMarker> seriesMarkerList = new ArrayList<SeriesMarker>(); - for (SeriesMarker seriesMarker : EnumSet.allOf(SeriesMarker.class)) { - if (seriesMarker.getIndex() >= 0) { // skip SeriesMarker.NONE - seriesMarkerList.add(seriesMarker); - } - } - return seriesMarkerList; - } - - @Override - public List<SeriesLineStyle> getLineStyleList() { - - // 3. Stroke - List<SeriesLineStyle> seriesLineStyleList = new ArrayList<SeriesLineStyle>(); - for (SeriesLineStyle seriesLineStyle : EnumSet.allOf(SeriesLineStyle.class)) { - if (seriesLineStyle.getIndex() >= 0) { // skip SeriesLineStyle.NONE - seriesLineStyleList.add(seriesLineStyle); - } - } - return seriesLineStyleList; - } - - } - } diff --git a/xchart/src/main/java/org/knowm/xchart/ChartColor.java b/xchart/src/main/java/org/knowm/xchart/internal/style/colors/ChartColor.java similarity index 92% rename from xchart/src/main/java/org/knowm/xchart/ChartColor.java rename to xchart/src/main/java/org/knowm/xchart/internal/style/colors/ChartColor.java index 1b4edc2b7c9cd22184bec3096af0691e58e5a775..c883935700f61899873ee4f95dbc95e2c2f04b93 100644 --- a/xchart/src/main/java/org/knowm/xchart/ChartColor.java +++ b/xchart/src/main/java/org/knowm/xchart/internal/style/colors/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"); @@ -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.colors; import java.awt.Color; diff --git a/xchart/src/main/java/org/knowm/xchart/internal/style/colors/ColorBlindFriendlySeriesColors.java b/xchart/src/main/java/org/knowm/xchart/internal/style/colors/ColorBlindFriendlySeriesColors.java new file mode 100644 index 0000000000000000000000000000000000000000..2e5eb22b79b6cae0cc915998be5586bf9652a171 --- /dev/null +++ b/xchart/src/main/java/org/knowm/xchart/internal/style/colors/ColorBlindFriendlySeriesColors.java @@ -0,0 +1,51 @@ +/** + * 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; + +/** + * @author timmolter + */ +public class ColorBlindFriendlySeriesColors implements SeriesColors { + + // The color blind friendly palette + 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); + + private final Color[] seriesColors; + + /** + * Constructor + */ + public ColorBlindFriendlySeriesColors() { + + seriesColors = new Color[] { BLACK, ORANGE, SKY_BLUE, BLUISH_GREEN, YELLOW, BLUE, VERMILLION, REDDISH_PURPLE }; + } + + @Override + public Color[] getSeriesColors() { + + return seriesColors; + } +} diff --git a/xchart/src/main/java/org/knowm/xchart/internal/style/colors/GGPlot2SeriesColors.java b/xchart/src/main/java/org/knowm/xchart/internal/style/colors/GGPlot2SeriesColors.java new file mode 100644 index 0000000000000000000000000000000000000000..19b400d1a09fee31f96f7983f274d419a11bc5c5 --- /dev/null +++ b/xchart/src/main/java/org/knowm/xchart/internal/style/colors/GGPlot2SeriesColors.java @@ -0,0 +1,47 @@ +/** + * 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; + +/** + * @author timmolter + */ +public class GGPlot2SeriesColors implements SeriesColors { + + 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); + + private final Color[] seriesColors; + + /** + * Constructor + */ + public GGPlot2SeriesColors() { + + seriesColors = new Color[] { RED, YELLOW_GREEN, GREEN, BLUE, PURPLE }; + } + + @Override + public Color[] getSeriesColors() { + + return seriesColors; + } +} diff --git a/xchart/src/main/java/org/knowm/xchart/internal/style/colors/MatlabSeriesColors.java b/xchart/src/main/java/org/knowm/xchart/internal/style/colors/MatlabSeriesColors.java new file mode 100644 index 0000000000000000000000000000000000000000..4d0ddca85283a21e31b833e864a0790d3a9cb1a6 --- /dev/null +++ b/xchart/src/main/java/org/knowm/xchart/internal/style/colors/MatlabSeriesColors.java @@ -0,0 +1,49 @@ +/** + * 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; + +/** + * @author timmolter + */ +public class MatlabSeriesColors implements SeriesColors { + + 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); + + private final Color[] seriesColors; + + /** + * Constructor + */ + public MatlabSeriesColors() { + + seriesColors = new Color[] { BLUE, GREEN, RED, TURQUOISE, MAGENTA, YELLOW, DARK_GREY }; + } + + @Override + public Color[] getSeriesColors() { + + return seriesColors; + } +} 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..2373f62be2a61109213edeb0fc402e4fd6d061ce --- /dev/null +++ b/xchart/src/main/java/org/knowm/xchart/internal/style/colors/PrinterFriendlySeriesColors.java @@ -0,0 +1,51 @@ +/** + * 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; + +/** + * @author timmolter + */ +public class PrinterFriendlySeriesColors implements SeriesColors { + + // 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); + + private final Color[] seriesColors; + + /** + * Constructor + */ + public PrinterFriendlySeriesColors() { + + seriesColors = new Color[] { RED, GREEN, BLUE, PURPLE, ORANGE }; + } + + @Override + public Color[] getSeriesColors() { + + return seriesColors; + } +} diff --git a/xchart/src/main/java/org/knowm/xchart/internal/style/colors/SeriesColors.java b/xchart/src/main/java/org/knowm/xchart/internal/style/colors/SeriesColors.java new file mode 100644 index 0000000000000000000000000000000000000000..a45d4cc6e33aa82e6730c87c6392292a285001dd --- /dev/null +++ b/xchart/src/main/java/org/knowm/xchart/internal/style/colors/SeriesColors.java @@ -0,0 +1,28 @@ +/** + * 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; + +/** + * @author timmolter + */ +public interface SeriesColors { + + public Color[] getSeriesColors(); + +} 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..2384dceac2da2fdaa88887176bed0e497ef2f6a1 --- /dev/null +++ b/xchart/src/main/java/org/knowm/xchart/internal/style/colors/XChartSeriesColors.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.internal.style.colors; + +import java.awt.Color; + +/** + * @author timmolter + */ +public class XChartSeriesColors implements SeriesColors { + + // 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); + + private final Color[] seriesColors; + + /** + * Constructor + */ + public XChartSeriesColors() { + + seriesColors = new Color[] { BLUE, ORANGE, PURPLE, GREEN, RED, YELLOW, MAGENTA, PINK, LIGHT_GREY, CYAN, BROWN, BLACK }; + } + + @Override + public Color[] getSeriesColors() { + + return seriesColors; + } +} diff --git a/xchart/src/main/java/org/knowm/xchart/internal/style/lines/GGPlot2SeriesLines.java b/xchart/src/main/java/org/knowm/xchart/internal/style/lines/GGPlot2SeriesLines.java new file mode 100644 index 0000000000000000000000000000000000000000..f96a5cb2039aff83242fa4560e941f091d06f717 --- /dev/null +++ b/xchart/src/main/java/org/knowm/xchart/internal/style/lines/GGPlot2SeriesLines.java @@ -0,0 +1,41 @@ +/** + * 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.lines; + +import java.awt.BasicStroke; + +/** + * @author timmolter + */ +public class GGPlot2SeriesLines implements SeriesLines { + + private final BasicStroke[] seriesLines; + + /** + * Constructor + */ + public GGPlot2SeriesLines() { + + seriesLines = new BasicStroke[] { SOLID, DOT_DOT, DASH_DASH }; + } + + @Override + public BasicStroke[] getSeriesLines() { + + return seriesLines; + } +} diff --git a/xchart/src/main/java/org/knowm/xchart/internal/style/lines/MatlabSeriesLines.java b/xchart/src/main/java/org/knowm/xchart/internal/style/lines/MatlabSeriesLines.java new file mode 100644 index 0000000000000000000000000000000000000000..864a88621a175866f60513c4c754f0aa0b29d4dc --- /dev/null +++ b/xchart/src/main/java/org/knowm/xchart/internal/style/lines/MatlabSeriesLines.java @@ -0,0 +1,41 @@ +/** + * 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.lines; + +import java.awt.BasicStroke; + +/** + * @author timmolter + */ +public class MatlabSeriesLines implements SeriesLines { + + private final BasicStroke[] seriesLines; + + /** + * Constructor + */ + public MatlabSeriesLines() { + + seriesLines = new BasicStroke[] { SOLID, DASH_DASH, DOT_DOT }; + } + + @Override + public BasicStroke[] getSeriesLines() { + + return seriesLines; + } +} diff --git a/xchart/src/main/java/org/knowm/xchart/internal/style/lines/NoneStroke.java b/xchart/src/main/java/org/knowm/xchart/internal/style/lines/NoneStroke.java new file mode 100644 index 0000000000000000000000000000000000000000..80f3a9a3d354f875105110a0a9a4515291a78dba --- /dev/null +++ b/xchart/src/main/java/org/knowm/xchart/internal/style/lines/NoneStroke.java @@ -0,0 +1,26 @@ +/** + * 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.lines; + +import java.awt.BasicStroke; + +/** + * @author timmolter + */ +public class NoneStroke extends BasicStroke { + +} diff --git a/xchart/src/main/java/org/knowm/xchart/internal/style/lines/SeriesLines.java b/xchart/src/main/java/org/knowm/xchart/internal/style/lines/SeriesLines.java new file mode 100644 index 0000000000000000000000000000000000000000..2dbff2f59112ea587e558de6245fcf8f45192480 --- /dev/null +++ b/xchart/src/main/java/org/knowm/xchart/internal/style/lines/SeriesLines.java @@ -0,0 +1,36 @@ +/** + * 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.lines; + +import java.awt.BasicStroke; + +/** + * Pre-defined Line Styles used for Series Lines + * + * @author timmolter + */ +public interface SeriesLines { + + public BasicStroke[] getSeriesLines(); + + public static BasicStroke NONE = new NoneStroke(); + public static BasicStroke SOLID = new BasicStroke(2.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER); + public static BasicStroke DASH_DOT = new BasicStroke(2.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10.0f, new float[] { 3.0f, 1.0f }, 0.0f); + public static BasicStroke DASH_DASH = new BasicStroke(2.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10.0f, new float[] { 3.0f, 3.0f }, 0.0f); + public static BasicStroke DOT_DOT = new BasicStroke(2.0f, BasicStroke.CAP_BUTT, BasicStroke.CAP_ROUND, 10.0f, new float[] { 2.0f }, 0.0f); + +} diff --git a/xchart/src/main/java/org/knowm/xchart/internal/style/lines/XChartSeriesLines.java b/xchart/src/main/java/org/knowm/xchart/internal/style/lines/XChartSeriesLines.java new file mode 100644 index 0000000000000000000000000000000000000000..5d9014da3dffb252bab180c3e959bce38c24b5f4 --- /dev/null +++ b/xchart/src/main/java/org/knowm/xchart/internal/style/lines/XChartSeriesLines.java @@ -0,0 +1,41 @@ +/** + * 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.lines; + +import java.awt.BasicStroke; + +/** + * @author timmolter + */ +public class XChartSeriesLines implements SeriesLines { + + private final BasicStroke[] seriesLines; + + /** + * Constructor + */ + public XChartSeriesLines() { + + seriesLines = new BasicStroke[] { SOLID, DASH_DOT, DASH_DASH, DOT_DOT }; + } + + @Override + public BasicStroke[] getSeriesLines() { + + return seriesLines; + } +} 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/style/markers/GGPlot2SeriesMarkers.java b/xchart/src/main/java/org/knowm/xchart/internal/style/markers/GGPlot2SeriesMarkers.java new file mode 100644 index 0000000000000000000000000000000000000000..66fe08bb6110205527de5208e8c8c786d0f9f8c2 --- /dev/null +++ b/xchart/src/main/java/org/knowm/xchart/internal/style/markers/GGPlot2SeriesMarkers.java @@ -0,0 +1,39 @@ +/** + * 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.markers; + +/** + * @author timmolter + */ +public class GGPlot2SeriesMarkers implements SeriesMarkers { + + private final Marker[] seriesMarkers; + + /** + * Constructor + */ + public GGPlot2SeriesMarkers() { + + seriesMarkers = new Marker[] { CIRCLE, DIAMOND }; + } + + @Override + public Marker[] getSeriesMarkers() { + + return seriesMarkers; + } +} 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/style/markers/MatlabSeriesMarkers.java b/xchart/src/main/java/org/knowm/xchart/internal/style/markers/MatlabSeriesMarkers.java new file mode 100644 index 0000000000000000000000000000000000000000..51995e5884719360f69df7f21b895341323fa680 --- /dev/null +++ b/xchart/src/main/java/org/knowm/xchart/internal/style/markers/MatlabSeriesMarkers.java @@ -0,0 +1,39 @@ +/** + * 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.markers; + +/** + * @author timmolter + */ +public class MatlabSeriesMarkers implements SeriesMarkers { + + private final Marker[] seriesMarkers; + + /** + * Constructor + */ + public MatlabSeriesMarkers() { + + seriesMarkers = new Marker[] { NONE }; + } + + @Override + public Marker[] getSeriesMarkers() { + + return seriesMarkers; + } +} diff --git a/xchart/src/main/java/org/knowm/xchart/internal/style/markers/None.java b/xchart/src/main/java/org/knowm/xchart/internal/style/markers/None.java new file mode 100644 index 0000000000000000000000000000000000000000..c9e4ae962aaa37852086082a22ddd1168c19c9ea --- /dev/null +++ b/xchart/src/main/java/org/knowm/xchart/internal/style/markers/None.java @@ -0,0 +1,33 @@ +/** + * 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.markers; + +import java.awt.Graphics2D; + +/** + * @author timmolter + */ +public class None extends Marker { + + @Override + public void paint(Graphics2D g, double xOffset, double yOffset, int markerSize) { + + // do nothing! + + } + +} diff --git a/xchart/src/main/java/org/knowm/xchart/internal/style/markers/SeriesMarkers.java b/xchart/src/main/java/org/knowm/xchart/internal/style/markers/SeriesMarkers.java new file mode 100644 index 0000000000000000000000000000000000000000..780e333593248f4760f04591225a808f7ea8218a --- /dev/null +++ b/xchart/src/main/java/org/knowm/xchart/internal/style/markers/SeriesMarkers.java @@ -0,0 +1,33 @@ +/** + * 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.markers; + +/** + * @author timmolter + */ +public interface SeriesMarkers { + + public static Marker NONE = new None(); + public static Marker CIRCLE = new Circle(); + public static Marker DIAMOND = new Diamond(); + public static Marker SQUARE = new Square(); + public static Marker TRIANGLE_DOWN = new TriangleDown(); + public static Marker TRIANGLE_UP = new TriangleUp(); + + public Marker[] getSeriesMarkers(); + +} 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/main/java/org/knowm/xchart/internal/style/markers/XChartSeriesMarkers.java b/xchart/src/main/java/org/knowm/xchart/internal/style/markers/XChartSeriesMarkers.java new file mode 100644 index 0000000000000000000000000000000000000000..548d6b167a1f970b6c767243fc3c9f0386538fce --- /dev/null +++ b/xchart/src/main/java/org/knowm/xchart/internal/style/markers/XChartSeriesMarkers.java @@ -0,0 +1,39 @@ +/** + * 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.markers; + +/** + * @author timmolter + */ +public class XChartSeriesMarkers implements SeriesMarkers { + + private final Marker[] seriesMarkers; + + /** + * Constructor + */ + public XChartSeriesMarkers() { + + seriesMarkers = new Marker[] { CIRCLE, DIAMOND, SQUARE, TRIANGLE_DOWN, TRIANGLE_UP }; + } + + @Override + public Marker[] getSeriesMarkers() { + + return seriesMarkers; + } +} 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(); - } - -}