From 79720cfc9fbea9db96e92c080dc73dccb4a30128 Mon Sep 17 00:00:00 2001 From: Tim Molter <tim@knowm.org> Date: Sun, 10 Jan 2016 20:05:21 +0100 Subject: [PATCH] Added ability to customize series colors, markers, and line styles individually at the theme level --- .../demo/charts/area/AreaLineChart03.java | 10 +- .../xchart/demo/charts/bar/BarChart02.java | 4 +- .../xchart/demo/charts/date/DateChart01.java | 4 +- .../xchart/demo/charts/line/LineChart02.java | 8 +- .../xchart/demo/charts/line/LineChart03.java | 10 +- .../xchart/demo/charts/line/LineChart04.java | 8 +- .../xchart/demo/charts/line/LineChart05.java | 12 +-- .../xchart/demo/charts/line/LineChart06.java | 8 +- .../xchart/demo/charts/line/LineChart07.java | 4 +- .../xchart/demo/charts/pie/PieChart01.java | 3 +- .../xchart/demo/charts/pie/PieChart02.java | 61 ++++++++++++ .../demo/charts/scatter/ScatterChart04.java | 4 +- .../xchart/standalone/ErrorBarLogTest.java | 16 ++-- .../knowm/xchart/standalone/ErrorBarTest.java | 16 ++-- .../Example0WithoutHorizontalLines.java | 4 +- ...ple0WithoutVerticalAndHorizontalLines.java | 4 +- .../Example0WithoutVerticalLines.java | 4 +- .../org/knowm/xchart/standalone/Example1.java | 4 +- .../org/knowm/xchart/standalone/Example2.java | 4 +- .../xchart/standalone/TestForIssue83.java | 4 +- .../java/org/knowm/xchart/Chart_Category.java | 41 +++++++-- .../main/java/org/knowm/xchart/Chart_Pie.java | 26 +++++- .../main/java/org/knowm/xchart/Chart_XY.java | 42 ++++++++- .../java/org/knowm/xchart/QuickChart.java | 5 +- .../org/knowm/xchart/SeriesLineStyle.java | 92 ------------------- .../java/org/knowm/xchart/SeriesMarker.java | 89 ------------------ .../org/knowm/xchart/Series_AxesChart.java | 29 ++---- .../org/knowm/xchart/Series_Category.java | 6 +- .../java/org/knowm/xchart/Series_Pie.java | 6 +- .../main/java/org/knowm/xchart/Series_XY.java | 6 +- .../org/knowm/xchart/internal/Series.java | 5 +- .../xchart/internal/chartpart/Chart.java | 11 ++- .../internal/chartpart/LegendAxesChart.java | 16 ++-- .../chartpart/PlotContent_Category_Bar.java | 13 +-- ...lotContent_Category_Line_Area_Scatter.java | 9 +- .../internal/chartpart/PlotContent_XY.java | 9 +- .../xchart/internal/style/GGPlot2Theme.java | 91 ++++-------------- .../xchart/internal/style/MatlabTheme.java | 75 +++++---------- .../SeriesColorMarkerLineStyleCycler.java | 41 ++++----- .../xchart/internal/style/StyleManager.java | 41 +++++++-- .../knowm/xchart/internal/style/Theme.java | 9 +- .../xchart/internal/style/XChartTheme.java | 62 ++++--------- .../style/colors}/ChartColor.java | 2 +- .../ColorBlindFriendlySeriesColors.java | 51 ++++++++++ .../style/colors/GGPlot2SeriesColors.java | 47 ++++++++++ .../style/colors/MatlabSeriesColors.java | 49 ++++++++++ .../colors/PrinterFriendlySeriesColors.java | 16 +--- .../internal/style/colors/SeriesColors.java | 27 ++++++ .../style/colors/XChartSeriesColors.java | 23 +---- .../style/lines/GGPlot2SeriesLines.java | 41 +++++++++ .../style/lines/MatlabSeriesLines.java | 41 +++++++++ .../internal/style/lines/NoneStroke.java | 25 +++++ .../internal/style/lines/SeriesLines.java | 36 ++++++++ .../style/lines/XChartSeriesLines.java | 41 +++++++++ .../style/markers/GGPlot2SeriesMarkers.java | 39 ++++++++ .../style/markers/MatlabSeriesMarkers.java | 39 ++++++++ .../xchart/internal/style/markers/None.java | 33 +++++++ .../internal/style/markers/SeriesMarkers.java | 32 +++++++ .../style/markers/XChartSeriesMarkers.java | 39 ++++++++ 59 files changed, 938 insertions(+), 559 deletions(-) create mode 100644 xchart-demo/src/main/java/org/knowm/xchart/demo/charts/pie/PieChart02.java delete mode 100644 xchart/src/main/java/org/knowm/xchart/SeriesLineStyle.java delete mode 100644 xchart/src/main/java/org/knowm/xchart/SeriesMarker.java rename xchart/src/main/java/org/knowm/xchart/{ => internal/style/colors}/ChartColor.java (96%) create mode 100644 xchart/src/main/java/org/knowm/xchart/internal/style/colors/ColorBlindFriendlySeriesColors.java create mode 100644 xchart/src/main/java/org/knowm/xchart/internal/style/colors/GGPlot2SeriesColors.java create mode 100644 xchart/src/main/java/org/knowm/xchart/internal/style/colors/MatlabSeriesColors.java create mode 100644 xchart/src/main/java/org/knowm/xchart/internal/style/colors/SeriesColors.java create mode 100644 xchart/src/main/java/org/knowm/xchart/internal/style/lines/GGPlot2SeriesLines.java create mode 100644 xchart/src/main/java/org/knowm/xchart/internal/style/lines/MatlabSeriesLines.java create mode 100644 xchart/src/main/java/org/knowm/xchart/internal/style/lines/NoneStroke.java create mode 100644 xchart/src/main/java/org/knowm/xchart/internal/style/lines/SeriesLines.java create mode 100644 xchart/src/main/java/org/knowm/xchart/internal/style/lines/XChartSeriesLines.java create mode 100644 xchart/src/main/java/org/knowm/xchart/internal/style/markers/GGPlot2SeriesMarkers.java create mode 100644 xchart/src/main/java/org/knowm/xchart/internal/style/markers/MatlabSeriesMarkers.java create mode 100644 xchart/src/main/java/org/knowm/xchart/internal/style/markers/None.java create mode 100644 xchart/src/main/java/org/knowm/xchart/internal/style/markers/SeriesMarkers.java create mode 100644 xchart/src/main/java/org/knowm/xchart/internal/style/markers/XChartSeriesMarkers.java 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 1a683a2a..be67a8d4 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 @@ -17,7 +17,6 @@ package org.knowm.xchart.demo.charts.area; import org.knowm.xchart.Chart_XY; -import org.knowm.xchart.SeriesMarker; import org.knowm.xchart.Series_XY; import org.knowm.xchart.Series_XY.ChartXYSeriesRenderStyle; import org.knowm.xchart.SwingWrapper; @@ -25,6 +24,7 @@ import org.knowm.xchart.demo.charts.ExampleChart; import org.knowm.xchart.internal.chartpart.Chart; import org.knowm.xchart.internal.style.StyleManager; import org.knowm.xchart.internal.style.StyleManager.LegendPosition; +import org.knowm.xchart.internal.style.markers.SeriesMarkers; /** * Combination Line & Area Chart @@ -79,17 +79,17 @@ public class AreaLineChart03 implements ExampleChart { // @formatter:on Series_XY seriesLiability = chart.addSeries("Liability", xAges, yLiability); - seriesLiability.setMarker(SeriesMarker.NONE); + seriesLiability.setMarker(SeriesMarkers.NONE); seriesLiability.setChartXYSeriesRenderStyle(Series_XY.ChartXYSeriesRenderStyle.Area); Series_XY seriesPercentile75th = chart.addSeries("75th Percentile", xAges, yPercentile75th); - seriesPercentile75th.setMarker(SeriesMarker.NONE); + seriesPercentile75th.setMarker(SeriesMarkers.NONE); Series_XY seriesPercentile50th = chart.addSeries("50th Percentile", xAges, yPercentile50th); - seriesPercentile50th.setMarker(SeriesMarker.NONE); + seriesPercentile50th.setMarker(SeriesMarkers.NONE); Series_XY seriesPercentile25th = chart.addSeries("25th Percentile", xAges, yPercentile25th); - seriesPercentile25th.setMarker(SeriesMarker.NONE); + seriesPercentile25th.setMarker(SeriesMarkers.NONE); chart.getStyleManager().setYAxisLabelAlignment(StyleManager.TextAlignment.Right); chart.getStyleManager().setYAxisDecimalPattern("$ #,###.##"); 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 0693fb85..f68cbbfa 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 @@ -30,8 +30,8 @@ import org.knowm.xchart.Series_Category; import org.knowm.xchart.SwingWrapper; import org.knowm.xchart.demo.charts.ExampleChart; import org.knowm.xchart.internal.chartpart.Chart; -import org.knowm.xchart.internal.style.MatlabTheme; import org.knowm.xchart.internal.style.StyleManager.ChartTheme; +import org.knowm.xchart.internal.style.colors.MatlabSeriesColors; /** * Date Categories @@ -76,7 +76,7 @@ public class BarChart02 implements ExampleChart { yData.add(-1 * 0.00000001 * ((random.nextInt(i) + 1))); } Series_Category series = chart.addSeries("Model 77", xData, yData); - series.setLineColor(MatlabTheme.RED); + series.setLineColor(MatlabSeriesColors.RED); chart.getStyleManager().setPlotGridLinesVisible(false); chart.getStyleManager().setBarFilled(false); chart.getStyleManager().setDatePattern("YYYY"); 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 c710df9f..11252122 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 @@ -26,11 +26,11 @@ import java.util.Random; import org.knowm.xchart.ChartBuilderXY; import org.knowm.xchart.Chart_XY; -import org.knowm.xchart.SeriesMarker; import org.knowm.xchart.Series_XY; import org.knowm.xchart.SwingWrapper; import org.knowm.xchart.demo.charts.ExampleChart; import org.knowm.xchart.internal.chartpart.Chart; +import org.knowm.xchart.internal.style.markers.SeriesMarkers; /** * Millisecond Scale @@ -78,7 +78,7 @@ public class DateChart01 implements ExampleChart { } Series_XY series = chart.addSeries("blah", xData, yData); - series.setMarker(SeriesMarker.NONE); + series.setMarker(SeriesMarkers.NONE); return chart; 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 435e344c..6343531e 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 @@ -20,13 +20,13 @@ import java.util.ArrayList; import java.util.List; import org.knowm.xchart.Chart_XY; -import org.knowm.xchart.SeriesLineStyle; -import org.knowm.xchart.SeriesMarker; import org.knowm.xchart.Series_XY; import org.knowm.xchart.SwingWrapper; import org.knowm.xchart.demo.charts.ExampleChart; import org.knowm.xchart.internal.chartpart.Chart; 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 @@ -67,9 +67,9 @@ public class LineChart02 implements ExampleChart { // Series 1 Series_XY series1 = chart.addSeries("y=sin(x)", xData, yData); series1.setLineColor(XChartSeriesColors.PURPLE); - series1.setLineStyle(SeriesLineStyle.DASH_DASH); + series1.setLineStyle(SeriesLines.DASH_DASH); series1.setMarkerColor(XChartSeriesColors.GREEN); - series1.setMarker(SeriesMarker.SQUARE); + 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 edd28b75..e2f77d7a 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 @@ -26,16 +26,16 @@ import java.util.Date; import java.util.List; import java.util.Locale; -import org.knowm.xchart.ChartColor; import org.knowm.xchart.Chart_XY; -import org.knowm.xchart.SeriesLineStyle; -import org.knowm.xchart.SeriesMarker; import org.knowm.xchart.Series_XY; import org.knowm.xchart.SwingWrapper; import org.knowm.xchart.demo.charts.ExampleChart; import org.knowm.xchart.internal.chartpart.Chart; import org.knowm.xchart.internal.style.StyleManager.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 @@ -105,8 +105,8 @@ public class LineChart03 implements ExampleChart { 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 0712ee83..c92d5e42 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 @@ -17,13 +17,13 @@ package org.knowm.xchart.demo.charts.line; import org.knowm.xchart.Chart_XY; -import org.knowm.xchart.SeriesLineStyle; -import org.knowm.xchart.SeriesMarker; import org.knowm.xchart.Series_XY; import org.knowm.xchart.SwingWrapper; import org.knowm.xchart.demo.charts.ExampleChart; import org.knowm.xchart.internal.chartpart.Chart; 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 @@ -52,8 +52,8 @@ public class LineChart04 implements ExampleChart { for (int i = 0; i < 200; i++) { Series_XY series = chart.addSeries("A" + i, new double[] { Math.random() / 1000, Math.random() / 1000 }, new double[] { Math.random() / -1000, Math.random() / -1000 }); series.setLineColor(XChartSeriesColors.BLUE); - series.setLineStyle(SeriesLineStyle.SOLID); - series.setMarker(SeriesMarker.CIRCLE); + series.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 dab6163b..39d3666a 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 @@ -19,13 +19,13 @@ package org.knowm.xchart.demo.charts.line; import java.awt.Color; import org.knowm.xchart.Chart_XY; -import org.knowm.xchart.SeriesLineStyle; -import org.knowm.xchart.SeriesMarker; import org.knowm.xchart.Series_XY; import org.knowm.xchart.SwingWrapper; import org.knowm.xchart.demo.charts.ExampleChart; import org.knowm.xchart.internal.chartpart.Chart; import org.knowm.xchart.internal.style.StyleManager.LegendPosition; +import org.knowm.xchart.internal.style.lines.SeriesLines; +import org.knowm.xchart.internal.style.markers.SeriesMarkers; /** * Scatter and Line @@ -63,13 +63,13 @@ public class LineChart05 implements ExampleChart { double[] yData2 = new double[] { 102, 49, 23.6, 11.3, 5.4, 2.6, 1.25 }; Series_XY series = chart.addSeries("A", xData, yData); - series.setLineStyle(SeriesLineStyle.NONE); - series.setMarker(SeriesMarker.DIAMOND); + series.setLineStyle(SeriesLines.NONE); + series.setMarker(SeriesMarkers.DIAMOND); series.setMarkerColor(Color.BLACK); Series_XY series2 = chart.addSeries("B", xData, yData2); - series2.setMarker(SeriesMarker.NONE); - series2.setLineStyle(SeriesLineStyle.DASH_DASH); + series2.setMarker(SeriesMarkers.NONE); + series2.setLineStyle(SeriesLines.DASH_DASH); series2.setLineColor(Color.BLACK); chart.getStyleManager().setYAxisLogarithmic(true); 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 72f8db5c..9f02c457 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 @@ -19,12 +19,12 @@ package org.knowm.xchart.demo.charts.line; import java.awt.Color; import org.knowm.xchart.Chart_XY; -import org.knowm.xchart.SeriesLineStyle; -import org.knowm.xchart.SeriesMarker; import org.knowm.xchart.Series_XY; import org.knowm.xchart.SwingWrapper; import org.knowm.xchart.demo.charts.ExampleChart; import org.knowm.xchart.internal.chartpart.Chart; +import org.knowm.xchart.internal.style.lines.SeriesLines; +import org.knowm.xchart.internal.style.markers.SeriesMarkers; /** * Logarithmic Y-Axis with Error Bars @@ -66,9 +66,9 @@ public class LineChart06 implements ExampleChart { 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.GREEN); 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 edd78b03..c54cc7b2 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 @@ -20,7 +20,6 @@ import java.util.Arrays; import java.util.List; import org.knowm.xchart.Chart_Category; -import org.knowm.xchart.SeriesMarker; import org.knowm.xchart.Series_Category; import org.knowm.xchart.Series_Category.ChartCategorySeriesRenderStyle; import org.knowm.xchart.SwingWrapper; @@ -28,6 +27,7 @@ import org.knowm.xchart.demo.charts.ExampleChart; import org.knowm.xchart.internal.chartpart.Chart; import org.knowm.xchart.internal.style.StyleManager.ChartTheme; import org.knowm.xchart.internal.style.StyleManager.LegendPosition; +import org.knowm.xchart.internal.style.markers.SeriesMarkers; /** * Line chart with multiple Category Series @@ -96,7 +96,7 @@ public class LineChart07 implements ExampleChart { // Add data series to chart for (int i = 0; i < seriesNames.length; i++) { Series_Category series = chart.addSeries(seriesNames[i], xAxisKeys, Arrays.asList(dataPerSeries[i])); - series.setMarker(SeriesMarker.NONE); + series.setMarker(SeriesMarkers.NONE); // series.setChartCategorySeriesRenderStyle(ChartCategorySeriesRenderStyle.Line); } chart.getStyleManager().setYAxisLogarithmic(true); diff --git a/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/pie/PieChart01.java b/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/pie/PieChart01.java index 37779bfb..3ab59549 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 @@ -27,7 +27,7 @@ import org.knowm.xchart.demo.charts.ExampleChart; * Demonstrates the following: * <ul> * <li>Pie Chart - * <li>ChartBuilder + * <li>ChartBuilderPie */ public class PieChart01 implements ExampleChart<Chart_Pie> { @@ -42,7 +42,6 @@ public class PieChart01 implements ExampleChart<Chart_Pie> { public Chart_Pie getChart() { // Create Chart - // TODO remove chartType(ChartType.Pie) Chart_Pie chart = new ChartBuilderPie().width(800).height(600).title(getClass().getSimpleName()).build(); chart.addSeries("Pennies", 387); chart.addSeries("Nickels", 234); 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 00000000..9b4af002 --- /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.ChartBuilderPie; +import org.knowm.xchart.Chart_Pie; +import org.knowm.xchart.SwingWrapper; +import org.knowm.xchart.demo.charts.ExampleChart; + +/** + * Pie Chart with 4 Slices + * <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 ChartBuilderPie().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.getStyleManager().setSeriesColors(sliceColors); + + return chart; + } + +} 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 be387c48..a20078bb 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 @@ -22,11 +22,11 @@ import java.util.List; import org.knowm.xchart.ChartBuilderXY; import org.knowm.xchart.Chart_XY; -import org.knowm.xchart.SeriesMarker; import org.knowm.xchart.Series_XY; import org.knowm.xchart.SwingWrapper; import org.knowm.xchart.demo.charts.ExampleChart; import org.knowm.xchart.internal.chartpart.Chart; +import org.knowm.xchart.internal.style.markers.SeriesMarkers; /** * Error Bars @@ -74,7 +74,7 @@ public class ScatterChart04 implements ExampleChart { // Series 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/standalone/ErrorBarLogTest.java b/xchart-demo/src/main/java/org/knowm/xchart/standalone/ErrorBarLogTest.java index b692b80b..5fb51619 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 @@ -19,11 +19,11 @@ package org.knowm.xchart.standalone; import java.awt.Color; import org.knowm.xchart.Chart_XY; -import org.knowm.xchart.SeriesLineStyle; -import org.knowm.xchart.SeriesMarker; import org.knowm.xchart.Series_XY; import org.knowm.xchart.SwingWrapper; import org.knowm.xchart.internal.style.colors.XChartSeriesColors; +import org.knowm.xchart.internal.style.lines.SeriesLines; +import org.knowm.xchart.internal.style.markers.SeriesMarkers; /** * @author timmolter @@ -60,21 +60,21 @@ public class ErrorBarLogTest { 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(XChartSeriesColors.RED); - series3.setLineStyle(SeriesLineStyle.DASH_DASH); + series3.setLineStyle(SeriesLines.DASH_DASH); - series3.setMarker(SeriesMarker.NONE); + series3.setMarker(SeriesMarkers.NONE); series3.setLineColor(XChartSeriesColors.RED); 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 fc79eea9..5f4c2db3 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 @@ -19,11 +19,11 @@ package org.knowm.xchart.standalone; import java.awt.Color; import org.knowm.xchart.Chart_XY; -import org.knowm.xchart.SeriesLineStyle; -import org.knowm.xchart.SeriesMarker; import org.knowm.xchart.Series_XY; import org.knowm.xchart.SwingWrapper; import org.knowm.xchart.internal.style.colors.XChartSeriesColors; +import org.knowm.xchart.internal.style.lines.SeriesLines; +import org.knowm.xchart.internal.style.markers.SeriesMarkers; /** * @author timmolter @@ -46,14 +46,14 @@ public class ErrorBarTest { Series_XY series1 = mychart.addSeries("Error bar test data", xData, yData1, errdata); Series_XY series2 = mychart.addSeries("Y+error", xData, yData2); Series_XY series3 = mychart.addSeries("Y-error", xData, yData3); - series1.setLineStyle(SeriesLineStyle.SOLID); - series1.setMarker(SeriesMarker.DIAMOND); + series1.setLineStyle(SeriesLines.SOLID); + series1.setMarker(SeriesMarkers.DIAMOND); series1.setMarkerColor(Color.MAGENTA); - series2.setLineStyle(SeriesLineStyle.DASH_DASH); - series2.setMarker(SeriesMarker.NONE); + series2.setLineStyle(SeriesLines.DASH_DASH); + series2.setMarker(SeriesMarkers.NONE); series2.setLineColor(XChartSeriesColors.RED); - series3.setLineStyle(SeriesLineStyle.DASH_DASH); - series3.setMarker(SeriesMarker.NONE); + 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/Example0WithoutHorizontalLines.java b/xchart-demo/src/main/java/org/knowm/xchart/standalone/Example0WithoutHorizontalLines.java index aa303a6f..10a2bc5d 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 @@ -21,10 +21,10 @@ import java.util.List; import org.knowm.xchart.ChartBuilderXY; import org.knowm.xchart.Chart_XY; -import org.knowm.xchart.SeriesMarker; import org.knowm.xchart.Series_XY; import org.knowm.xchart.SwingWrapper; import org.knowm.xchart.internal.chartpart.Chart; +import org.knowm.xchart.internal.style.markers.SeriesMarkers; /** * Creates a simple Chart and saves it as a PNG and JPEG image file. @@ -43,7 +43,7 @@ public class Example0WithoutHorizontalLines { chart.getStyleManager().setYAxisMax(10); chart.getStyleManager().setPlotGridHorizontalLinesVisible(false); Series_XY series = chart.addSeries("" + i, null, getRandomWalk(200)); - series.setMarker(SeriesMarker.NONE); + series.setMarker(SeriesMarkers.NONE); charts.add(chart); } new SwingWrapper(charts).displayChartMatrix(); 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 afc8d0b4..435629cc 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 @@ -21,10 +21,10 @@ import java.util.List; import org.knowm.xchart.ChartBuilderXY; import org.knowm.xchart.Chart_XY; -import org.knowm.xchart.SeriesMarker; import org.knowm.xchart.Series_XY; import org.knowm.xchart.SwingWrapper; import org.knowm.xchart.internal.chartpart.Chart; +import org.knowm.xchart.internal.style.markers.SeriesMarkers; /** * Create a Chart matrix @@ -46,7 +46,7 @@ public class Example0WithoutVerticalAndHorizontalLines { chart.getStyleManager().setPlotGridVerticalLinesVisible(false); chart.getStyleManager().setPlotGridHorizontalLinesVisible(false); Series_XY series = chart.addSeries("" + i, null, getRandomWalk(200)); - series.setMarker(SeriesMarker.NONE); + series.setMarker(SeriesMarkers.NONE); charts.add(chart); } new SwingWrapper(charts).displayChartMatrix(); 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 6708ce6a..2f6f02dc 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 @@ -21,10 +21,10 @@ import java.util.List; import org.knowm.xchart.ChartBuilderXY; import org.knowm.xchart.Chart_XY; -import org.knowm.xchart.SeriesMarker; import org.knowm.xchart.Series_XY; import org.knowm.xchart.SwingWrapper; import org.knowm.xchart.internal.chartpart.Chart; +import org.knowm.xchart.internal.style.markers.SeriesMarkers; /** * Creates a simple Chart using QuickChart @@ -43,7 +43,7 @@ public class Example0WithoutVerticalLines { chart.getStyleManager().setYAxisMax(10); chart.getStyleManager().setPlotGridVerticalLinesVisible(false); Series_XY series = chart.addSeries("" + i, null, getRandomWalk(200)); - series.setMarker(SeriesMarker.NONE); + series.setMarker(SeriesMarkers.NONE); charts.add(chart); } new SwingWrapper(charts).displayChartMatrix(); 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 651a0fd4..3d6bbd68 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 @@ -19,10 +19,10 @@ package org.knowm.xchart.standalone; import org.knowm.xchart.BitmapEncoder; import org.knowm.xchart.BitmapEncoder.BitmapFormat; import org.knowm.xchart.Chart_XY; -import org.knowm.xchart.SeriesMarker; import org.knowm.xchart.Series_XY; import org.knowm.xchart.VectorGraphicsEncoder; import org.knowm.xchart.VectorGraphicsEncoder.VectorGraphicsFormat; +import org.knowm.xchart.internal.style.markers.SeriesMarkers; /** * Creates a simple Chart and saves it as a PNG and JPEG image file. @@ -39,7 +39,7 @@ public class Example1 { chart.setXAxisTitle("X"); chart.setXAxisTitle("Y"); Series_XY series = chart.addSeries("y(x)", null, yData); - series.setMarker(SeriesMarker.CIRCLE); + 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 960e5189..6accffad 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 @@ -21,10 +21,10 @@ import java.util.List; import org.knowm.xchart.ChartBuilderXY; import org.knowm.xchart.Chart_XY; -import org.knowm.xchart.SeriesMarker; import org.knowm.xchart.Series_XY; import org.knowm.xchart.SwingWrapper; import org.knowm.xchart.internal.chartpart.Chart; +import org.knowm.xchart.internal.style.markers.SeriesMarkers; /** * Create a Chart matrix @@ -44,7 +44,7 @@ public class Example2 { chart.getStyleManager().setYAxisMin(-10); chart.getStyleManager().setYAxisMax(10); Series_XY series = chart.addSeries("" + i, null, getRandomWalk(200)); - series.setMarker(SeriesMarker.NONE); + series.setMarker(SeriesMarkers.NONE); charts.add(chart); } new SwingWrapper(charts).displayChartMatrix(); 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 f2797e91..862d3528 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 @@ -19,10 +19,10 @@ package org.knowm.xchart.standalone; import java.io.IOException; import org.knowm.xchart.Chart_XY; -import org.knowm.xchart.SeriesLineStyle; import org.knowm.xchart.SwingWrapper; import org.knowm.xchart.internal.style.StyleManager; import org.knowm.xchart.internal.style.StyleManager.LegendPosition; +import org.knowm.xchart.internal.style.lines.SeriesLines; /** * @author timmolter @@ -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/src/main/java/org/knowm/xchart/Chart_Category.java b/xchart/src/main/java/org/knowm/xchart/Chart_Category.java index c35580e7..19a60564 100644 --- a/xchart/src/main/java/org/knowm/xchart/Chart_Category.java +++ b/xchart/src/main/java/org/knowm/xchart/Chart_Category.java @@ -27,8 +27,10 @@ import org.knowm.xchart.internal.chartpart.AxisPair; import org.knowm.xchart.internal.chartpart.Chart; import org.knowm.xchart.internal.chartpart.LegendAxesChart; import org.knowm.xchart.internal.chartpart.Plot_Category; -import org.knowm.xchart.internal.style.Theme; +import org.knowm.xchart.internal.style.SeriesColorMarkerLineStyle; +import org.knowm.xchart.internal.style.SeriesColorMarkerLineStyleCycler; import org.knowm.xchart.internal.style.StyleManager.ChartTheme; +import org.knowm.xchart.internal.style.Theme; /** * @author timmolter @@ -178,10 +180,10 @@ public class Chart_Category extends Chart<StyleManagerCategory, Series_Category> // inspect the series to see what kind of data it contains (Number, Date) - series = new Series_Category(seriesName, xData, yData, errorBars, styleManager.getSeriesColorMarkerLineStyleCycler().getNextSeriesColorMarkerLineStyle()); + series = new Series_Category(seriesName, xData, yData, errorBars); } else { // generate xData - series = new Series_Category(seriesName, getGeneratedData(yData.size()), yData, errorBars, styleManager.getSeriesColorMarkerLineStyleCycler().getNextSeriesColorMarkerLineStyle()); + series = new Series_Category(seriesName, getGeneratedData(yData.size()), yData, errorBars); } seriesMap.put(seriesName, series); @@ -238,9 +240,7 @@ public class Chart_Category extends Chart<StyleManagerCategory, Series_Category> seriesCategory.setChartCategorySeriesRenderStyle(getStyleManager().getChartCategorySeriesRenderStyle()); } } - - // override min/max value for bar charts' Y-Axis - // getyAxis().setMin(0); + setSeriesStyles(); // paint chart main background g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); // global rendering hint @@ -256,4 +256,33 @@ public class Chart_Category extends Chart<StyleManagerCategory, Series_Category> g.dispose(); } + /** + * set the series color, marker and line style based on theme + */ + public void setSeriesStyles() { + + SeriesColorMarkerLineStyleCycler seriesColorMarkerLineStyleCycler = new SeriesColorMarkerLineStyleCycler(getStyleManager().getSeriesColors(), getStyleManager().getSeriesMarkers(), + getStyleManager().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 index 1538d832..e6452a4c 100644 --- a/xchart/src/main/java/org/knowm/xchart/Chart_Pie.java +++ b/xchart/src/main/java/org/knowm/xchart/Chart_Pie.java @@ -25,8 +25,10 @@ import org.knowm.xchart.internal.Series; import org.knowm.xchart.internal.chartpart.Chart; import org.knowm.xchart.internal.chartpart.LegendPie; import org.knowm.xchart.internal.chartpart.Plot_Pie; -import org.knowm.xchart.internal.style.Theme; +import org.knowm.xchart.internal.style.SeriesColorMarkerLineStyle; +import org.knowm.xchart.internal.style.SeriesColorMarkerLineStyleCycler; import org.knowm.xchart.internal.style.StyleManager.ChartTheme; +import org.knowm.xchart.internal.style.Theme; /** * @author timmolter @@ -91,7 +93,7 @@ public class Chart_Pie extends Chart<StyleManagerPie, Series_Pie> { */ public Series addSeries(String seriesName, Number value) { - Series_Pie series = new Series_Pie(seriesName, value, styleManager.getSeriesColorMarkerLineStyleCycler().getNextSeriesColorMarkerLineStyle()); + 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!!!"); @@ -125,6 +127,8 @@ public class Chart_Pie extends Chart<StyleManagerPie, Series_Pie> { } } + setSeriesStyles(); + // paint chart main background g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); // global rendering hint g.setColor(styleManager.getChartBackgroundColor()); @@ -137,4 +141,22 @@ public class Chart_Pie extends Chart<StyleManagerPie, Series_Pie> { g.dispose(); } + + /** + * set the series color based on theme + */ + public void setSeriesStyles() { + + SeriesColorMarkerLineStyleCycler seriesColorMarkerLineStyleCycler = new SeriesColorMarkerLineStyleCycler(getStyleManager().getSeriesColors(), getStyleManager().getSeriesMarkers(), + getStyleManager().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 index 4a0a0537..6c5e3f0f 100644 --- a/xchart/src/main/java/org/knowm/xchart/Chart_XY.java +++ b/xchart/src/main/java/org/knowm/xchart/Chart_XY.java @@ -27,8 +27,10 @@ import org.knowm.xchart.internal.chartpart.AxisPair; import org.knowm.xchart.internal.chartpart.Chart; import org.knowm.xchart.internal.chartpart.LegendAxesChart; import org.knowm.xchart.internal.chartpart.Plot_XY; -import org.knowm.xchart.internal.style.Theme; +import org.knowm.xchart.internal.style.SeriesColorMarkerLineStyle; +import org.knowm.xchart.internal.style.SeriesColorMarkerLineStyleCycler; import org.knowm.xchart.internal.style.StyleManager.ChartTheme; +import org.knowm.xchart.internal.style.Theme; /** * @author timmolter @@ -178,10 +180,10 @@ public class Chart_XY extends Chart<StyleManagerXY, Series_XY> { // inspect the series to see what kind of data it contains (Number, Date) - series = new Series_XY(seriesName, xData, yData, errorBars, styleManager.getSeriesColorMarkerLineStyleCycler().getNextSeriesColorMarkerLineStyle()); + series = new Series_XY(seriesName, xData, yData, errorBars); } else { // generate xData - series = new Series_XY(seriesName, getGeneratedData(yData.size()), yData, errorBars, styleManager.getSeriesColorMarkerLineStyleCycler().getNextSeriesColorMarkerLineStyle()); + series = new Series_XY(seriesName, getGeneratedData(yData.size()), yData, errorBars); } seriesMap.put(seriesName, series); @@ -233,11 +235,12 @@ public class Chart_XY extends Chart<StyleManagerXY, Series_XY> { // set the series render styles if they are not set. Legend and Plot need it. for (Series_XY seriesXY : getSeriesMap().values()) { - Series_XY.ChartXYSeriesRenderStyle seriesType = seriesXY.getChartXYSeriesRenderStyle(); // would be directly set - if (seriesType == null) { // wasn't overridden, use default from Style Manager + Series_XY.ChartXYSeriesRenderStyle chartXYSeriesRenderStyle = seriesXY.getChartXYSeriesRenderStyle(); // would be directly set + if (chartXYSeriesRenderStyle == null) { // wasn't overridden, use default from Style Manager seriesXY.setChartXYSeriesRenderStyle(getStyleManager().getChartXYSeriesRenderStyle()); } } + setSeriesStyles(); // paint chart main background g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); // global rendering hint @@ -253,4 +256,33 @@ public class Chart_XY extends Chart<StyleManagerXY, Series_XY> { g.dispose(); } + /** + * set the series color, marker and line style based on theme + */ + public void setSeriesStyles() { + + SeriesColorMarkerLineStyleCycler seriesColorMarkerLineStyleCycler = new SeriesColorMarkerLineStyleCycler(getStyleManager().getSeriesColors(), getStyleManager().getSeriesMarkers(), + getStyleManager().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/QuickChart.java b/xchart/src/main/java/org/knowm/xchart/QuickChart.java index e338a9c2..7ce6f042 100644 --- a/xchart/src/main/java/org/knowm/xchart/QuickChart.java +++ b/xchart/src/main/java/org/knowm/xchart/QuickChart.java @@ -19,6 +19,7 @@ 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 @@ -90,7 +91,7 @@ public final class QuickChart { chart.getStyleManager().setLegendVisible(false); series = chart.addSeries(" " + i, xData, yData[i]); } - series.setMarker(SeriesMarker.NONE); + series.setMarker(SeriesMarkers.NONE); } return chart; @@ -118,7 +119,7 @@ public final class QuickChart { chart.setYAxisTitle(yTitle); Series_XY series = chart.addSeries(seriesName, xData, yData); - series.setMarker(SeriesMarker.NONE); + series.setMarker(SeriesMarkers.NONE); return chart; 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 c5fa248b..00000000 --- a/xchart/src/main/java/org/knowm/xchart/SeriesLineStyle.java +++ /dev/null @@ -1,92 +0,0 @@ -/** - * Copyright 2015-2016 Knowm Inc. (http://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 9be4d83e..00000000 --- a/xchart/src/main/java/org/knowm/xchart/SeriesMarker.java +++ /dev/null @@ -1,89 +0,0 @@ -/** - * Copyright 2015-2016 Knowm Inc. (http://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.style.markers.Circle; -import org.knowm.xchart.internal.style.markers.Diamond; -import org.knowm.xchart.internal.style.markers.Marker; -import org.knowm.xchart.internal.style.markers.Square; -import org.knowm.xchart.internal.style.markers.TriangleDown; -import org.knowm.xchart.internal.style.markers.TriangleUp; - -/** - * Pre-defined Markers used for Series Lines - * - * @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_AxesChart.java b/xchart/src/main/java/org/knowm/xchart/Series_AxesChart.java index c4418a97..b39e967e 100644 --- a/xchart/src/main/java/org/knowm/xchart/Series_AxesChart.java +++ b/xchart/src/main/java/org/knowm/xchart/Series_AxesChart.java @@ -25,7 +25,6 @@ import java.util.List; import org.knowm.xchart.internal.Series; import org.knowm.xchart.internal.chartpart.Axis.AxisDataType; -import org.knowm.xchart.internal.style.SeriesColorMarkerLineStyle; import org.knowm.xchart.internal.style.markers.Marker; /** @@ -78,21 +77,16 @@ public abstract class Series_AxesChart extends Series { * @param yData * @param yAxisType * @param errorBars - * @param seriesColorMarkerLineStyle */ - public Series_AxesChart(String name, List<?> xData, List<? extends Number> yData, List<? extends Number> errorBars, SeriesColorMarkerLineStyle seriesColorMarkerLineStyle) { + public Series_AxesChart(String name, List<?> xData, List<? extends Number> yData, List<? extends Number> errorBars) { - super(name, seriesColorMarkerLineStyle); + super(name); this.xData = xData; this.xAxisType = getAxesType(xData); this.yData = yData; this.yAxisType = AxisDataType.Number; this.errorBars = errorBars; - strokeColor = seriesColorMarkerLineStyle.getColor(); - markerColor = seriesColorMarkerLineStyle.getColor(); - marker = seriesColorMarkerLineStyle.getMarker(); - stroke = seriesColorMarkerLineStyle.getStroke(); calculateMinMax(); } @@ -202,17 +196,6 @@ public abstract class Series_AxesChart extends 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 * @@ -240,9 +223,9 @@ public abstract class Series_AxesChart extends Series { * * @param seriesMarker */ - public Series setMarker(SeriesMarker seriesMarker) { + public Series setMarker(Marker seriesMarker) { - this.marker = seriesMarker.getMarker(); + this.marker = seriesMarker; return this; } @@ -302,7 +285,7 @@ public abstract class Series_AxesChart extends Series { return yMax; } - public BasicStroke getStroke() { + public BasicStroke getLineStyle() { return stroke; } @@ -312,7 +295,7 @@ public abstract class Series_AxesChart extends Series { return marker; } - public Color getStrokeColor() { + public Color getLineColor() { return strokeColor; } diff --git a/xchart/src/main/java/org/knowm/xchart/Series_Category.java b/xchart/src/main/java/org/knowm/xchart/Series_Category.java index aaefc7b7..116b30a3 100644 --- a/xchart/src/main/java/org/knowm/xchart/Series_Category.java +++ b/xchart/src/main/java/org/knowm/xchart/Series_Category.java @@ -23,7 +23,6 @@ import java.util.List; import org.knowm.xchart.internal.chartpart.Axis.AxisDataType; import org.knowm.xchart.internal.chartpart.RenderableSeries; import org.knowm.xchart.internal.chartpart.RenderableSeries.LegendRenderType; -import org.knowm.xchart.internal.style.SeriesColorMarkerLineStyle; /** * A Series containing X and Y data to be plotted on a Chart @@ -58,11 +57,10 @@ public class Series_Category extends Series_AxesChart { * @param xData * @param yData * @param errorBars - * @param seriesColorMarkerLineStyle */ - public Series_Category(String name, List<?> xData, List<? extends Number> yData, List<? extends Number> errorBars, SeriesColorMarkerLineStyle seriesColorMarkerLineStyle) { + public Series_Category(String name, List<?> xData, List<? extends Number> yData, List<? extends Number> errorBars) { - super(name, xData, yData, errorBars, seriesColorMarkerLineStyle); + super(name, xData, yData, errorBars); } diff --git a/xchart/src/main/java/org/knowm/xchart/Series_Pie.java b/xchart/src/main/java/org/knowm/xchart/Series_Pie.java index 129d491d..85f94f17 100644 --- a/xchart/src/main/java/org/knowm/xchart/Series_Pie.java +++ b/xchart/src/main/java/org/knowm/xchart/Series_Pie.java @@ -19,7 +19,6 @@ package org.knowm.xchart; import org.knowm.xchart.internal.Series; import org.knowm.xchart.internal.chartpart.RenderableSeries; import org.knowm.xchart.internal.chartpart.RenderableSeries.LegendRenderType; -import org.knowm.xchart.internal.style.SeriesColorMarkerLineStyle; /** * A Series containing Pie data to be plotted on a Chart @@ -54,11 +53,10 @@ public class Series_Pie extends Series { * * @param name * @param value - * @param seriesColorMarkerLineStyle */ - public Series_Pie(String name, Number value, SeriesColorMarkerLineStyle seriesColorMarkerLineStyle) { + public Series_Pie(String name, Number value) { - super(name, seriesColorMarkerLineStyle); + super(name); 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 index ab961a8c..ff3a7cb4 100644 --- a/xchart/src/main/java/org/knowm/xchart/Series_XY.java +++ b/xchart/src/main/java/org/knowm/xchart/Series_XY.java @@ -23,7 +23,6 @@ import java.util.List; import org.knowm.xchart.internal.chartpart.Axis.AxisDataType; import org.knowm.xchart.internal.chartpart.RenderableSeries; import org.knowm.xchart.internal.chartpart.RenderableSeries.LegendRenderType; -import org.knowm.xchart.internal.style.SeriesColorMarkerLineStyle; /** * A Series containing X and Y data to be plotted on a Chart @@ -58,11 +57,10 @@ public class Series_XY extends Series_AxesChart { * @param xData * @param yData * @param errorBars - * @param seriesColorMarkerLineStyle */ - public Series_XY(String name, List<?> xData, List<? extends Number> yData, List<? extends Number> errorBars, SeriesColorMarkerLineStyle seriesColorMarkerLineStyle) { + public Series_XY(String name, List<?> xData, List<? extends Number> yData, List<? extends Number> errorBars) { - super(name, xData, yData, errorBars, seriesColorMarkerLineStyle); + super(name, xData, yData, errorBars); } public ChartXYSeriesRenderStyle getChartXYSeriesRenderStyle() { diff --git a/xchart/src/main/java/org/knowm/xchart/internal/Series.java b/xchart/src/main/java/org/knowm/xchart/internal/Series.java index 4c29e2c8..ae4c6a81 100644 --- a/xchart/src/main/java/org/knowm/xchart/internal/Series.java +++ b/xchart/src/main/java/org/knowm/xchart/internal/Series.java @@ -19,7 +19,6 @@ package org.knowm.xchart.internal; import java.awt.Color; import org.knowm.xchart.internal.chartpart.RenderableSeries.LegendRenderType; -import org.knowm.xchart.internal.style.SeriesColorMarkerLineStyle; /** * A Series containing X and Y data to be plotted on a Chart @@ -41,15 +40,13 @@ public abstract class Series { * @param name * @param seriesColorMarkerLineStyle */ - public Series(String name, SeriesColorMarkerLineStyle 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; - fillColor = seriesColorMarkerLineStyle.getColor(); - } public Color getFillColor() { 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 index 0736256d..f522bde9 100644 --- a/xchart/src/main/java/org/knowm/xchart/internal/chartpart/Chart.java +++ b/xchart/src/main/java/org/knowm/xchart/internal/chartpart/Chart.java @@ -17,6 +17,7 @@ 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; @@ -30,9 +31,7 @@ import org.knowm.xchart.internal.style.StyleManager; * * @author timmolter */ -public abstract class Chart<SM extends StyleManager, S extends Series> { - - public abstract void paint(Graphics2D g); // TODO 3.0.0 combine with ChartPart? +public abstract class Chart<SM extends StyleManager, S extends Series> implements ChartPart { public abstract void paint(Graphics2D g, int width, int height); @@ -207,4 +206,10 @@ public abstract class Chart<SM extends StyleManager, S extends Series> { return styleManager; } + + @Override + public Rectangle2D getBounds() { + + return new Rectangle2D.Double(0, 0, width, height); + } } diff --git a/xchart/src/main/java/org/knowm/xchart/internal/chartpart/LegendAxesChart.java b/xchart/src/main/java/org/knowm/xchart/internal/chartpart/LegendAxesChart.java index 2ef9fae3..ffb4f89d 100644 --- a/xchart/src/main/java/org/knowm/xchart/internal/chartpart/LegendAxesChart.java +++ b/xchart/src/main/java/org/knowm/xchart/internal/chartpart/LegendAxesChart.java @@ -31,6 +31,7 @@ import org.knowm.xchart.Series_XY; import org.knowm.xchart.internal.Series; import org.knowm.xchart.internal.chartpart.RenderableSeries.LegendRenderType; import org.knowm.xchart.internal.style.StyleManagerAxesChart; +import org.knowm.xchart.internal.style.lines.SeriesLines; /** * @author timmolter @@ -124,9 +125,9 @@ public class LegendAxesChart<SM extends StyleManagerAxesChart, S extends Series> if (series.getLegendRenderType() != LegendRenderType.Box) { // paint line - if (series.getLegendRenderType() == LegendRenderType.Line && series.getStroke() != null) { - g.setColor(series.getStrokeColor()); - g.setStroke(series.getStroke()); + 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.getStyleManager().getLegendSeriesLineLength(), starty + legendEntryHeight / 2.0); g.draw(line); } @@ -147,11 +148,14 @@ public class LegendAxesChart<SM extends StyleManagerAxesChart, S extends Series> 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); + Shape rectSmall = new Rectangle2D.Double(startx, starty, BOX_SIZE, BOX_SIZE); + if (styleManagerAxesChart.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)); diff --git a/xchart/src/main/java/org/knowm/xchart/internal/chartpart/PlotContent_Category_Bar.java b/xchart/src/main/java/org/knowm/xchart/internal/chartpart/PlotContent_Category_Bar.java index 965272d7..006dfff9 100644 --- a/xchart/src/main/java/org/knowm/xchart/internal/chartpart/PlotContent_Category_Bar.java +++ b/xchart/src/main/java/org/knowm/xchart/internal/chartpart/PlotContent_Category_Bar.java @@ -31,6 +31,7 @@ import org.knowm.xchart.StyleManagerCategory; import org.knowm.xchart.internal.Series; import org.knowm.xchart.internal.Utils; import org.knowm.xchart.internal.style.StyleManager; +import org.knowm.xchart.internal.style.lines.SeriesLines; /** * @author timmolter @@ -184,14 +185,14 @@ public class PlotContent_Category_Bar<SM extends StyleManager, S extends Series> // paint series 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()); + g.setStroke(series.getLineStyle()); if (styleManagerCategory.isBarFilled()) { g.fill(path); } @@ -204,11 +205,11 @@ public class PlotContent_Category_Bar<SM extends StyleManager, S extends Series> // paint line 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); } @@ -233,7 +234,7 @@ public class PlotContent_Category_Bar<SM extends StyleManager, S extends Series> // set error bar style if (styleManagerCategory.isErrorBarsColorSeriesColor()) { - g.setColor(series.getStrokeColor()); + g.setColor(series.getLineColor()); } else { g.setColor(styleManagerCategory.getErrorBarsColor()); diff --git a/xchart/src/main/java/org/knowm/xchart/internal/chartpart/PlotContent_Category_Line_Area_Scatter.java b/xchart/src/main/java/org/knowm/xchart/internal/chartpart/PlotContent_Category_Line_Area_Scatter.java index 34e739cd..2aaa9cc0 100644 --- a/xchart/src/main/java/org/knowm/xchart/internal/chartpart/PlotContent_Category_Line_Area_Scatter.java +++ b/xchart/src/main/java/org/knowm/xchart/internal/chartpart/PlotContent_Category_Line_Area_Scatter.java @@ -31,6 +31,7 @@ import org.knowm.xchart.StyleManagerCategory; import org.knowm.xchart.internal.Series; import org.knowm.xchart.internal.Utils; import org.knowm.xchart.internal.style.StyleManager; +import org.knowm.xchart.internal.style.lines.SeriesLines; /** * @author timmolter @@ -173,11 +174,11 @@ public class PlotContent_Category_Line_Area_Scatter<SM extends StyleManager, S e // paint line 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); } @@ -220,7 +221,7 @@ public class PlotContent_Category_Line_Area_Scatter<SM extends StyleManager, S e // set error bar style if (styleManagerCategory.isErrorBarsColorSeriesColor()) { - g.setColor(series.getStrokeColor()); + g.setColor(series.getLineColor()); } else { g.setColor(styleManagerCategory.getErrorBarsColor()); diff --git a/xchart/src/main/java/org/knowm/xchart/internal/chartpart/PlotContent_XY.java b/xchart/src/main/java/org/knowm/xchart/internal/chartpart/PlotContent_XY.java index dd5664ef..29534e05 100644 --- a/xchart/src/main/java/org/knowm/xchart/internal/chartpart/PlotContent_XY.java +++ b/xchart/src/main/java/org/knowm/xchart/internal/chartpart/PlotContent_XY.java @@ -33,6 +33,7 @@ import org.knowm.xchart.internal.Series; import org.knowm.xchart.internal.Utils; import org.knowm.xchart.internal.chartpart.Axis.AxisDataType; import org.knowm.xchart.internal.style.StyleManagerAxesChart; +import org.knowm.xchart.internal.style.lines.SeriesLines; /** * @author timmolter @@ -189,11 +190,11 @@ public class PlotContent_XY<SM extends StyleManagerAxesChart, S extends Series> boolean isSeriesLineOrArea = (ChartXYSeriesRenderStyle.Line == series.getChartXYSeriesRenderStyle()) || (ChartXYSeriesRenderStyle.Area == series.getChartXYSeriesRenderStyle()); if (isSeriesLineOrArea) { - 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); } @@ -236,7 +237,7 @@ public class PlotContent_XY<SM extends StyleManagerAxesChart, S extends Series> // set error bar style if (styleManagerXY.isErrorBarsColorSeriesColor()) { - g.setColor(series.getStrokeColor()); + g.setColor(series.getLineColor()); } else { g.setColor(styleManagerXY.getErrorBarsColor()); diff --git a/xchart/src/main/java/org/knowm/xchart/internal/style/GGPlot2Theme.java b/xchart/src/main/java/org/knowm/xchart/internal/style/GGPlot2Theme.java index aa23de61..5909d99d 100644 --- a/xchart/src/main/java/org/knowm/xchart/internal/style/GGPlot2Theme.java +++ b/xchart/src/main/java/org/knowm/xchart/internal/style/GGPlot2Theme.java @@ -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.SeriesLineStyle; -import org.knowm.xchart.SeriesMarker; import org.knowm.xchart.internal.style.StyleManager.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 Color BLACK = new Color(0, 0, 0, 255); - // public static Color ORANGE = new Color(230, 159, 0, 255); - // public static Color SKY_BLUE = new Color(86, 180, 233, 255); - // public static Color BLUISH_GREEN = new Color(0, 158, 115, 255); - // public static Color YELLOW = new Color(240, 228, 66, 255); - // public static Color BLUE = new Color(0, 114, 178, 255); - // public static Color VERMILLION = new Color(213, 94, 0, 255); - // public static Color REDDISH_PURPLE = new Color(204, 121, 167, 255); - - public static Color RED = new Color(248, 118, 109, 255); - public static Color YELLOW_GREEN = new Color(163, 165, 0, 255); - public static Color GREEN = new Color(0, 191, 125, 255); - public static Color BLUE = new Color(0, 176, 246, 255); - public static Color PURPLE = new Color(231, 107, 243, 255); - // Chart Style /////////////////////////////// @Override @@ -70,11 +54,23 @@ public class GGPlot2Theme implements Theme { } @Override - public SeriesColorMarkerLineStyleCycler getSeriesColorMarkerLineStyleCycler() { + public Marker[] getSeriesMarkers() { + + return new GGPlot2SeriesMarkers().getSeriesMarkers(); + + } + + @Override + public BasicStroke[] getSeriesLines() { - return new XChartColorMarkerLineStyleCycler(); + return new GGPlot2SeriesLines().getSeriesLines(); } + @Override + public Color[] getSeriesColors() { + + return new GGPlot2SeriesColors().getSeriesColors(); + } // Chart Title /////////////////////////////// @Override @@ -360,53 +356,4 @@ public class GGPlot2Theme implements Theme { return false; } - public class XChartColorMarkerLineStyleCycler extends SeriesColorMarkerLineStyleCycler { - - @Override - public List<Color> getColorList() { - - // 1. Color - List<Color> seriesColorMap = new ArrayList<Color>(); - - // 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); - - seriesColorMap.add(RED); - seriesColorMap.add(YELLOW_GREEN); - seriesColorMap.add(GREEN); - seriesColorMap.add(BLUE); - seriesColorMap.add(PURPLE); - - return seriesColorMap; - } - - @Override - public List<SeriesMarker> getSeriesMarkerList() { - - // 2. Marker - List<SeriesMarker> seriesMarkerList = new ArrayList<SeriesMarker>(); - seriesMarkerList.add(SeriesMarker.CIRCLE); - seriesMarkerList.add(SeriesMarker.DIAMOND); - return seriesMarkerList; - } - - @Override - public List<SeriesLineStyle> getLineStyleList() { - - // 3. Stroke - List<SeriesLineStyle> seriesLineStyleList = new ArrayList<SeriesLineStyle>(); - seriesLineStyleList.add(SeriesLineStyle.SOLID); - seriesLineStyleList.add(SeriesLineStyle.DOT_DOT); - seriesLineStyleList.add(SeriesLineStyle.DASH_DASH); - return seriesLineStyleList; - } - - } } diff --git a/xchart/src/main/java/org/knowm/xchart/internal/style/MatlabTheme.java b/xchart/src/main/java/org/knowm/xchart/internal/style/MatlabTheme.java index dfacbea5..1749f61c 100644 --- a/xchart/src/main/java/org/knowm/xchart/internal/style/MatlabTheme.java +++ b/xchart/src/main/java/org/knowm/xchart/internal/style/MatlabTheme.java @@ -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.SeriesLineStyle; -import org.knowm.xchart.SeriesMarker; import org.knowm.xchart.internal.style.StyleManager.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 Color BLUE = new Color(0, 0, 255, 255); - public static Color GREEN = new Color(0, 128, 0, 255); - public static Color RED = new Color(255, 0, 0, 255); - public static Color TURQUOISE = new Color(0, 191, 191, 255); - public static Color MAGENTA = new Color(191, 0, 191, 255); - public static Color YELLOW = new Color(191, 191, 0, 255); - public static Color DARK_GREY = new Color(64, 64, 64, 255); - // Chart Style /////////////////////////////// @Override @@ -62,9 +54,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 MatlabColorMarkerLineStyleCycler(); } // Chart Title /////////////////////////////// @@ -353,42 +360,4 @@ public class MatlabTheme implements Theme { return false; } - public class MatlabColorMarkerLineStyleCycler extends SeriesColorMarkerLineStyleCycler { - - @Override - public List<Color> getColorList() { - - // 1. Color - List<Color> seriesColorMap = new ArrayList<Color>(); - seriesColorMap.add(BLUE); - seriesColorMap.add(GREEN); - seriesColorMap.add(RED); - seriesColorMap.add(TURQUOISE); - seriesColorMap.add(MAGENTA); - seriesColorMap.add(YELLOW); - seriesColorMap.add(DARK_GREY); - return seriesColorMap; - } - - @Override - public List<SeriesMarker> getSeriesMarkerList() { - - // 2. Marker - List<SeriesMarker> seriesMarkerList = new ArrayList<SeriesMarker>(); - seriesMarkerList.add(SeriesMarker.NONE); - return seriesMarkerList; - } - - @Override - public List<SeriesLineStyle> getLineStyleList() { - - // 3. Stroke - List<SeriesLineStyle> seriesLineStyleList = new ArrayList<SeriesLineStyle>(); - seriesLineStyleList.add(SeriesLineStyle.SOLID); - seriesLineStyleList.add(SeriesLineStyle.DASH_DASH); - seriesLineStyleList.add(SeriesLineStyle.DOT_DOT); - return seriesLineStyleList; - } - - } } 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 f2c56b06..7800a6fe 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 @@ -16,11 +16,10 @@ */ package org.knowm.xchart.internal.style; +import java.awt.BasicStroke; import java.awt.Color; -import java.util.List; -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 abstract List<Color> getColorList(); - - public abstract List<SeriesMarker> getSeriesMarkerList(); - - public abstract List<SeriesLineStyle> getLineStyleList(); +public class SeriesColorMarkerLineStyleCycler { /** a List holding the Colors */ - private final List<Color> seriesColorList; + 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,11 +47,11 @@ public abstract class SeriesColorMarkerLineStyleCycler { /** * Constructor */ - public SeriesColorMarkerLineStyleCycler() { + public SeriesColorMarkerLineStyleCycler(Color[] seriesColorList, Marker[] seriesMarkerList, BasicStroke[] seriesLineStyleList) { - seriesColorList = getColorList(); - seriesMarkerList = getSeriesMarkerList(); - seriesLineStyleList = getLineStyleList(); + this.seriesColorList = seriesColorList; + this.seriesMarkerList = seriesMarkerList; + this.seriesLineStyleList = seriesLineStyleList; } /** @@ -69,24 +62,24 @@ public abstract class SeriesColorMarkerLineStyleCycler { public SeriesColorMarkerLineStyle getNextSeriesColorMarkerLineStyle() { // 1. Color - cycle through colors one by one - if (colorCounter >= seriesColorList.size()) { + if (colorCounter >= seriesColorList.length) { colorCounter = 0; strokeCounter++; } - Color 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, marker.getMarker(), seriesLineStyle.getBasicStroke()); + return new SeriesColorMarkerLineStyle(seriesColor, marker, seriesLineStyle); } } diff --git a/xchart/src/main/java/org/knowm/xchart/internal/style/StyleManager.java b/xchart/src/main/java/org/knowm/xchart/internal/style/StyleManager.java index 2aa2689e..9adf1c3e 100644 --- a/xchart/src/main/java/org/knowm/xchart/internal/style/StyleManager.java +++ b/xchart/src/main/java/org/knowm/xchart/internal/style/StyleManager.java @@ -16,9 +16,12 @@ */ 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 StyleManager is used to manage all things related to styling of the vast number of Chart components * @@ -63,7 +66,9 @@ public abstract class StyleManager { private Color chartBackgroundColor; private Color chartFontColor; private int chartPadding; - private SeriesColorMarkerLineStyleCycler seriesColorMarkerLineStyleCycler; + private Color[] seriesColors; + private BasicStroke[] seriesLines; + private Marker[] seriesMarkers; // Chart Title /////////////////////////////// private Font chartTitleFont; @@ -93,7 +98,9 @@ public abstract class StyleManager { chartBackgroundColor = theme.getChartBackgroundColor(); chartFontColor = theme.getChartFontColor(); chartPadding = theme.getChartPadding(); - seriesColorMarkerLineStyleCycler = theme.getSeriesColorMarkerLineStyleCycler(); + seriesColors = theme.getSeriesColors(); + seriesLines = theme.getSeriesLines(); + seriesMarkers = theme.getSeriesMarkers(); // Chart Title /////////////////////////////// chartTitleFont = theme.getChartTitleFont(); @@ -165,17 +172,37 @@ public abstract class StyleManager { return chartPadding; } - public SeriesColorMarkerLineStyleCycler getSeriesColorMarkerLineStyleCycler() { + // Chart Title /////////////////////////////// + + public Color[] getSeriesColors() { - return seriesColorMarkerLineStyleCycler; + return seriesColors; } - public void setSeriesColorMarkerLineStyleCycler(SeriesColorMarkerLineStyleCycler seriesColorMarkerLineStyleCycler) { + public void setSeriesColors(Color[] seriesColors) { - this.seriesColorMarkerLineStyleCycler = seriesColorMarkerLineStyleCycler; + this.seriesColors = seriesColors; } - // Chart Title /////////////////////////////// + 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 diff --git a/xchart/src/main/java/org/knowm/xchart/internal/style/Theme.java b/xchart/src/main/java/org/knowm/xchart/internal/style/Theme.java index 3b0f6981..eb8e8388 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 @@ -21,11 +21,14 @@ import java.awt.Font; import java.awt.Stroke; import org.knowm.xchart.internal.style.StyleManager.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,10 +38,6 @@ public interface Theme { public int getChartPadding(); - public SeriesColorMarkerLineStyleCycler getSeriesColorMarkerLineStyleCycler(); - - // public List<Color> getSeriesColors(); - // Chart Title /////////////////////////////// public Font getChartTitleFont(); diff --git a/xchart/src/main/java/org/knowm/xchart/internal/style/XChartTheme.java b/xchart/src/main/java/org/knowm/xchart/internal/style/XChartTheme.java index 0c1bcba6..888cd960 100644 --- a/xchart/src/main/java/org/knowm/xchart/internal/style/XChartTheme.java +++ b/xchart/src/main/java/org/knowm/xchart/internal/style/XChartTheme.java @@ -20,15 +20,13 @@ 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.SeriesLineStyle; -import org.knowm.xchart.SeriesMarker; import org.knowm.xchart.internal.style.StyleManager.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 @@ -56,9 +54,21 @@ public class XChartTheme implements Theme { } @Override - public SeriesColorMarkerLineStyleCycler getSeriesColorMarkerLineStyleCycler() { + public Color[] getSeriesColors() { - return new XChartColorMarkerLineStyleCycler(); + return new XChartSeriesColors().getSeriesColors(); + } + + @Override + public Marker[] getSeriesMarkers() { + + return new XChartSeriesMarkers().getSeriesMarkers(); + } + + @Override + public BasicStroke[] getSeriesLines() { + + return new XChartSeriesLines().getSeriesLines(); } // Chart Title /////////////////////////////// @@ -346,40 +356,4 @@ public class XChartTheme implements Theme { return false; } - public class XChartColorMarkerLineStyleCycler extends SeriesColorMarkerLineStyleCycler { - - @Override - public List<Color> getColorList() { - - return new XChartSeriesColors().getSeriesColors(); - } - - @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 96% 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 0d9fe8ca..c8839357 100644 --- a/xchart/src/main/java/org/knowm/xchart/ChartColor.java +++ b/xchart/src/main/java/org/knowm/xchart/internal/style/colors/ChartColor.java @@ -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 00000000..2e5eb22b --- /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 00000000..19b400d1 --- /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 00000000..4d0ddca8 --- /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 index fd3ad067..2373f62b 100644 --- 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 @@ -17,13 +17,11 @@ package org.knowm.xchart.internal.style.colors; import java.awt.Color; -import java.util.ArrayList; -import java.util.List; /** * @author timmolter */ -public class PrinterFriendlySeriesColors { +public class PrinterFriendlySeriesColors implements SeriesColors { // printer-friendly colors from http://colorbrewer2.org/ public static Color RED = new Color(228, 26, 28, 180); @@ -35,22 +33,18 @@ public class PrinterFriendlySeriesColors { // public static Color BROWN = new Color(166, 86, 40, 180); // public static Color PINK = new Color(247, 129, 191, 180); - List<Color> seriesColors = new ArrayList<Color>(); + private final Color[] seriesColors; /** * Constructor */ public PrinterFriendlySeriesColors() { - seriesColors.add(RED); - seriesColors.add(GREEN); - seriesColors.add(BLUE); - seriesColors.add(PURPLE); - seriesColors.add(ORANGE); - + seriesColors = new Color[] { RED, GREEN, BLUE, PURPLE, ORANGE }; } - public List<Color> getSeriesColors() { + @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 00000000..3b1671bb --- /dev/null +++ b/xchart/src/main/java/org/knowm/xchart/internal/style/colors/SeriesColors.java @@ -0,0 +1,27 @@ +/** + * 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.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 index 7adf13a0..2384dcea 100644 --- 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 @@ -17,13 +17,11 @@ package org.knowm.xchart.internal.style.colors; import java.awt.Color; -import java.util.ArrayList; -import java.util.List; /** * @author timmolter */ -public class XChartSeriesColors { +public class XChartSeriesColors implements SeriesColors { // original XChart colors public static Color BLUE = new Color(0, 55, 255, 180); @@ -39,29 +37,18 @@ public class XChartSeriesColors { public static Color BROWN = new Color(102, 56, 10, 180); public static Color BLACK = new Color(0, 0, 0, 180); - List<Color> seriesColors = new ArrayList<Color>(); + private final Color[] seriesColors; /** * Constructor */ public XChartSeriesColors() { - seriesColors.add(BLUE); - seriesColors.add(ORANGE); - seriesColors.add(PURPLE); - seriesColors.add(GREEN); - seriesColors.add(RED); - seriesColors.add(YELLOW); - seriesColors.add(MAGENTA); - seriesColors.add(PINK); - seriesColors.add(LIGHT_GREY); - seriesColors.add(CYAN); - seriesColors.add(BROWN); - seriesColors.add(BLACK); - + seriesColors = new Color[] { BLUE, ORANGE, PURPLE, GREEN, RED, YELLOW, MAGENTA, PINK, LIGHT_GREY, CYAN, BROWN, BLACK }; } - public List<Color> getSeriesColors() { + @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 00000000..f96a5cb2 --- /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 00000000..864a8862 --- /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 00000000..c34ca10d --- /dev/null +++ b/xchart/src/main/java/org/knowm/xchart/internal/style/lines/NoneStroke.java @@ -0,0 +1,25 @@ +/** + * 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.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 00000000..2dbff2f5 --- /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 00000000..5d9014da --- /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/style/markers/GGPlot2SeriesMarkers.java b/xchart/src/main/java/org/knowm/xchart/internal/style/markers/GGPlot2SeriesMarkers.java new file mode 100644 index 00000000..66fe08bb --- /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/style/markers/MatlabSeriesMarkers.java b/xchart/src/main/java/org/knowm/xchart/internal/style/markers/MatlabSeriesMarkers.java new file mode 100644 index 00000000..51995e58 --- /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 00000000..c9e4ae96 --- /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 00000000..eef1a17d --- /dev/null +++ b/xchart/src/main/java/org/knowm/xchart/internal/style/markers/SeriesMarkers.java @@ -0,0 +1,32 @@ +/** + * 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.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/style/markers/XChartSeriesMarkers.java b/xchart/src/main/java/org/knowm/xchart/internal/style/markers/XChartSeriesMarkers.java new file mode 100644 index 00000000..548d6b16 --- /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; + } +} -- GitLab