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 1a683a2a585668f0c0491cd04d49da18b72e81b5..be67a8d48023fb895ec79b53aa43593074ce9a84 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 0693fb8586f6a69eea86c34162e53c013bd4d299..f68cbbfaadb63ee8aa690d7f34ef09d1b0f540fb 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 c710df9f1509013de3e80d60fe97775a028fc751..112521227f9bfcab021ee59e8c60c95b9cb7ffd1 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 435e344c67b441f598ce946908073f55265f70ee..6343531eec437116bfc09db4c01eb9c871d23d6d 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 edd28b755430f36b97c0237ba7c99185f46042ca..e2f77d7a8bdd016269a6c3eea0d4bde4bcea4426 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 0712ee83c695de8e5557e9ec0adf984b6a7cb332..c92d5e421a2e811d2bddeba7644e4f374822a6de 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 dab6163b3e7346b630b145c1c42391c5e1a051ff..39d3666ae5093b5f7e73d348a7b6a4f0671fba9b 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 72f8db5c2024299e0f57b3424f093b6b278c3c5f..9f02c45762de565f1352cdd897654529593e3fde 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 edd78b03de51b38c1895b6a6d2caafec66e6aba8..c54cc7b244299a2b6bb66e6ed0e5da8c10710fe1 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 37779bfbd9ea59b606b25772f22db5d314e87f9a..3ab595495aadb5726f4b14d71979e070b717dccb 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 0000000000000000000000000000000000000000..9b4af0025fad87817224a2372f82a1b8c205f763 --- /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 be387c486e52b5db795fb20d3b2e0696c6492bc6..a20078bbb8c6b5c1389d779f9eb52a24bf7a8819 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 b692b80b0ce505c2f08a3811a464e4e527658777..5fb51619ad9fe804bc794672b6dc6e2b2fb0b27d 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 fc79eea9b58b2426dd05bfd20b54c3bb1e2c84c9..5f4c2db347180c6db3f06dda4897c4dd37ae48a0 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 aa303a6f4191166e6e5abe9e56dab20c0e38a9cb..10a2bc5d5cc79fafb9a9f79021f49815b5f97d8b 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 afc8d0b406d2e8eaec0edca1d69633d4d3ae0fb6..435629ccbbe8f3f82bbc18e979efaac8103cc011 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 6708ce6afccad7e383174dcccb2c19c98e95d94d..2f6f02dc6117e8e46ae8db678f52fdccde0b2362 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 651a0fd4063cff71855c73e902465c0a968299e9..3d6bbd685231b6b8c62163455bcbe9deacea3597 100644 --- a/xchart-demo/src/main/java/org/knowm/xchart/standalone/Example1.java +++ b/xchart-demo/src/main/java/org/knowm/xchart/standalone/Example1.java @@ -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 960e51894be78954b44cb3e4e947434cf75e90f2..6accffad4b9237a8ef44a26c35d1ec06175fa543 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 f2797e91875eddeda366b91438630f5a8f8aac3f..862d35289b25cb40d716410843b71e8af9afe67d 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 c35580e73d9902daa5234952692f38d56e98b9b8..19a6056413d83957db5c71935af56fa6975838e9 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 1538d83237e88af9ca9739ec5623f49c6467fb7a..e6452a4ce1b4e2d2f87c4bdf4a23adfc2119ced7 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 4a0a053707a153040cca928a8b8f4674b33bbb78..6c5e3f0f7ca61b2efd5a7fca0641d1e098a63650 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 e338a9c24d51ccbb847bc3aa0d817c83b1971b13..7ce6f04266d1994ed7290b0d4706a518b6421049 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 c5fa248b86171062e0bdd869045e403325804da7..0000000000000000000000000000000000000000 --- 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 9be4d83e1eec8f1412978a40d8e749c420112185..0000000000000000000000000000000000000000 --- 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 c4418a977adbffe73352fc7be3dbafa8ad6d853e..b39e967e1993f3dae0c0eb62761423ecbf448259 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 aaefc7b7d5c1565ebdc5495690b62466f3bdeab3..116b30a30c25c34e28a0fc186587d574901d30ed 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 129d491d5c6fdc091429d12903c445aae1240b1a..85f94f1716f472c8aea861919734da6a71072948 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 ab961a8c61f140fec9eb4c7f5dea8aef1fd52f9e..ff3a7cb438626d0c91108e1bfe94e8f3413e4325 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 4c29e2c87fb4c8a02f32b2be446456cdd9dd2c03..ae4c6a815cc9786b4627e5736e643d67711d5dd8 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 0736256dba44938ab9f04f2842103bd59f01cf06..f522bde982878693cf93661c60fcd6318bcbbff7 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 2ef9fae3bf78b0c747e219a5eff7a14724555fb2..ffb4f89d0cfe285b96d9c59fe4628659c6981e62 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 965272d79638c3b6d873292da902cd6349cea734..006dfff9bd58c205485c6c549f1764c3203fe43f 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 34e739cd1eea081023adf6ced2836b92604514c3..2aaa9cc0bb5912e598183ff7203143216a83d1e1 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 dd5664ef2237114a45c42743b75a74e897d54957..29534e056fa270a7336a1d65652a7e62fd668549 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 aa23de61a5b6717bfc8acc36cb62e3d7e14becc8..5909d99d6256b7f78443b05833564b518f978812 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 dfacbea5a90095b41bea635e4b9dee1b9bc1772b..1749f61cd0f811ba47f357fd526183fc54d4044f 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 f2c56b067d27167af8677451b5e00468296237bf..7800a6feb1743e8ece92328a7ca8fc8ba59d6482 100644 --- a/xchart/src/main/java/org/knowm/xchart/internal/style/SeriesColorMarkerLineStyleCycler.java +++ b/xchart/src/main/java/org/knowm/xchart/internal/style/SeriesColorMarkerLineStyleCycler.java @@ -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 2aa2689e91dbd6266fd8dff998943f8e2db573ff..9adf1c3ebfafc3ef324e6a4fe3cc94fc4809b3ca 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 3b0f6981e940a82d3bc340aacaf511d253f0c5c2..eb8e8388d179d40847fcdd99cb72dc628727f556 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 0c1bcba638fb799a5d56eefc84b90a72ad07707f..888cd960cf07ec6850940e4cc9bc92b0f04832ae 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 0d9fe8caf48861621a7622ea1c96ce330890c206..c883935700f61899873ee4f95dbc95e2c2f04b93 100644 --- a/xchart/src/main/java/org/knowm/xchart/ChartColor.java +++ b/xchart/src/main/java/org/knowm/xchart/internal/style/colors/ChartColor.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.knowm.xchart; +package org.knowm.xchart.internal.style.colors; import java.awt.Color; diff --git a/xchart/src/main/java/org/knowm/xchart/internal/style/colors/ColorBlindFriendlySeriesColors.java b/xchart/src/main/java/org/knowm/xchart/internal/style/colors/ColorBlindFriendlySeriesColors.java new file mode 100644 index 0000000000000000000000000000000000000000..2e5eb22b79b6cae0cc915998be5586bf9652a171 --- /dev/null +++ b/xchart/src/main/java/org/knowm/xchart/internal/style/colors/ColorBlindFriendlySeriesColors.java @@ -0,0 +1,51 @@ +/** + * Copyright 2015-2016 Knowm Inc. (http://knowm.org) and contributors. + * Copyright 2011-2015 Xeiam LLC (http://xeiam.com) and contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.knowm.xchart.internal.style.colors; + +import java.awt.Color; + +/** + * @author timmolter + */ +public class ColorBlindFriendlySeriesColors implements SeriesColors { + + // The color blind friendly palette + public static Color BLACK = new Color(0, 0, 0, 255); + public static Color ORANGE = new Color(230, 159, 0, 255); + public static Color SKY_BLUE = new Color(86, 180, 233, 255); + public static Color BLUISH_GREEN = new Color(0, 158, 115, 255); + public static Color YELLOW = new Color(240, 228, 66, 255); + public static Color BLUE = new Color(0, 114, 178, 255); + public static Color VERMILLION = new Color(213, 94, 0, 255); + public static Color REDDISH_PURPLE = new Color(204, 121, 167, 255); + + private final Color[] seriesColors; + + /** + * Constructor + */ + public ColorBlindFriendlySeriesColors() { + + seriesColors = new Color[] { BLACK, ORANGE, SKY_BLUE, BLUISH_GREEN, YELLOW, BLUE, VERMILLION, REDDISH_PURPLE }; + } + + @Override + public Color[] getSeriesColors() { + + return seriesColors; + } +} diff --git a/xchart/src/main/java/org/knowm/xchart/internal/style/colors/GGPlot2SeriesColors.java b/xchart/src/main/java/org/knowm/xchart/internal/style/colors/GGPlot2SeriesColors.java new file mode 100644 index 0000000000000000000000000000000000000000..19b400d1a09fee31f96f7983f274d419a11bc5c5 --- /dev/null +++ b/xchart/src/main/java/org/knowm/xchart/internal/style/colors/GGPlot2SeriesColors.java @@ -0,0 +1,47 @@ +/** + * Copyright 2015-2016 Knowm Inc. (http://knowm.org) and contributors. + * Copyright 2011-2015 Xeiam LLC (http://xeiam.com) and contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.knowm.xchart.internal.style.colors; + +import java.awt.Color; + +/** + * @author timmolter + */ +public class GGPlot2SeriesColors implements SeriesColors { + + public static Color RED = new Color(248, 118, 109, 255); + public static Color YELLOW_GREEN = new Color(163, 165, 0, 255); + public static Color GREEN = new Color(0, 191, 125, 255); + public static Color BLUE = new Color(0, 176, 246, 255); + public static Color PURPLE = new Color(231, 107, 243, 255); + + private final Color[] seriesColors; + + /** + * Constructor + */ + public GGPlot2SeriesColors() { + + seriesColors = new Color[] { RED, YELLOW_GREEN, GREEN, BLUE, PURPLE }; + } + + @Override + public Color[] getSeriesColors() { + + return seriesColors; + } +} diff --git a/xchart/src/main/java/org/knowm/xchart/internal/style/colors/MatlabSeriesColors.java b/xchart/src/main/java/org/knowm/xchart/internal/style/colors/MatlabSeriesColors.java new file mode 100644 index 0000000000000000000000000000000000000000..4d0ddca85283a21e31b833e864a0790d3a9cb1a6 --- /dev/null +++ b/xchart/src/main/java/org/knowm/xchart/internal/style/colors/MatlabSeriesColors.java @@ -0,0 +1,49 @@ +/** + * Copyright 2015-2016 Knowm Inc. (http://knowm.org) and contributors. + * Copyright 2011-2015 Xeiam LLC (http://xeiam.com) and contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.knowm.xchart.internal.style.colors; + +import java.awt.Color; + +/** + * @author timmolter + */ +public class MatlabSeriesColors implements SeriesColors { + + public static Color BLUE = new Color(0, 0, 255, 255); + public static Color GREEN = new Color(0, 128, 0, 255); + public static Color RED = new Color(255, 0, 0, 255); + public static Color TURQUOISE = new Color(0, 191, 191, 255); + public static Color MAGENTA = new Color(191, 0, 191, 255); + public static Color YELLOW = new Color(191, 191, 0, 255); + public static Color DARK_GREY = new Color(64, 64, 64, 255); + + private final Color[] seriesColors; + + /** + * Constructor + */ + public MatlabSeriesColors() { + + seriesColors = new Color[] { BLUE, GREEN, RED, TURQUOISE, MAGENTA, YELLOW, DARK_GREY }; + } + + @Override + public Color[] getSeriesColors() { + + return seriesColors; + } +} diff --git a/xchart/src/main/java/org/knowm/xchart/internal/style/colors/PrinterFriendlySeriesColors.java b/xchart/src/main/java/org/knowm/xchart/internal/style/colors/PrinterFriendlySeriesColors.java index fd3ad0674e0dcfa32d6f4b7ae057dd42ab4ca766..2373f62be2a61109213edeb0fc402e4fd6d061ce 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 0000000000000000000000000000000000000000..3b1671bb569702a878bb20f3766cb1f97ae0d604 --- /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 7adf13a01796e7d7566120c4b212e9775563b510..2384dceac2da2fdaa88887176bed0e497ef2f6a1 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 0000000000000000000000000000000000000000..f96a5cb2039aff83242fa4560e941f091d06f717 --- /dev/null +++ b/xchart/src/main/java/org/knowm/xchart/internal/style/lines/GGPlot2SeriesLines.java @@ -0,0 +1,41 @@ +/** + * Copyright 2015-2016 Knowm Inc. (http://knowm.org) and contributors. + * Copyright 2011-2015 Xeiam LLC (http://xeiam.com) and contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.knowm.xchart.internal.style.lines; + +import java.awt.BasicStroke; + +/** + * @author timmolter + */ +public class GGPlot2SeriesLines implements SeriesLines { + + private final BasicStroke[] seriesLines; + + /** + * Constructor + */ + public GGPlot2SeriesLines() { + + seriesLines = new BasicStroke[] { SOLID, DOT_DOT, DASH_DASH }; + } + + @Override + public BasicStroke[] getSeriesLines() { + + return seriesLines; + } +} diff --git a/xchart/src/main/java/org/knowm/xchart/internal/style/lines/MatlabSeriesLines.java b/xchart/src/main/java/org/knowm/xchart/internal/style/lines/MatlabSeriesLines.java new file mode 100644 index 0000000000000000000000000000000000000000..864a88621a175866f60513c4c754f0aa0b29d4dc --- /dev/null +++ b/xchart/src/main/java/org/knowm/xchart/internal/style/lines/MatlabSeriesLines.java @@ -0,0 +1,41 @@ +/** + * Copyright 2015-2016 Knowm Inc. (http://knowm.org) and contributors. + * Copyright 2011-2015 Xeiam LLC (http://xeiam.com) and contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.knowm.xchart.internal.style.lines; + +import java.awt.BasicStroke; + +/** + * @author timmolter + */ +public class MatlabSeriesLines implements SeriesLines { + + private final BasicStroke[] seriesLines; + + /** + * Constructor + */ + public MatlabSeriesLines() { + + seriesLines = new BasicStroke[] { SOLID, DASH_DASH, DOT_DOT }; + } + + @Override + public BasicStroke[] getSeriesLines() { + + return seriesLines; + } +} diff --git a/xchart/src/main/java/org/knowm/xchart/internal/style/lines/NoneStroke.java b/xchart/src/main/java/org/knowm/xchart/internal/style/lines/NoneStroke.java new file mode 100644 index 0000000000000000000000000000000000000000..c34ca10d5fe55b8259fa6a62021dccc7211b568b --- /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 0000000000000000000000000000000000000000..2dbff2f59112ea587e558de6245fcf8f45192480 --- /dev/null +++ b/xchart/src/main/java/org/knowm/xchart/internal/style/lines/SeriesLines.java @@ -0,0 +1,36 @@ +/** + * Copyright 2015-2016 Knowm Inc. (http://knowm.org) and contributors. + * Copyright 2011-2015 Xeiam LLC (http://xeiam.com) and contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.knowm.xchart.internal.style.lines; + +import java.awt.BasicStroke; + +/** + * Pre-defined Line Styles used for Series Lines + * + * @author timmolter + */ +public interface SeriesLines { + + public BasicStroke[] getSeriesLines(); + + public static BasicStroke NONE = new NoneStroke(); + public static BasicStroke SOLID = new BasicStroke(2.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER); + public static BasicStroke DASH_DOT = new BasicStroke(2.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10.0f, new float[] { 3.0f, 1.0f }, 0.0f); + public static BasicStroke DASH_DASH = new BasicStroke(2.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10.0f, new float[] { 3.0f, 3.0f }, 0.0f); + public static BasicStroke DOT_DOT = new BasicStroke(2.0f, BasicStroke.CAP_BUTT, BasicStroke.CAP_ROUND, 10.0f, new float[] { 2.0f }, 0.0f); + +} diff --git a/xchart/src/main/java/org/knowm/xchart/internal/style/lines/XChartSeriesLines.java b/xchart/src/main/java/org/knowm/xchart/internal/style/lines/XChartSeriesLines.java new file mode 100644 index 0000000000000000000000000000000000000000..5d9014da3dffb252bab180c3e959bce38c24b5f4 --- /dev/null +++ b/xchart/src/main/java/org/knowm/xchart/internal/style/lines/XChartSeriesLines.java @@ -0,0 +1,41 @@ +/** + * Copyright 2015-2016 Knowm Inc. (http://knowm.org) and contributors. + * Copyright 2011-2015 Xeiam LLC (http://xeiam.com) and contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.knowm.xchart.internal.style.lines; + +import java.awt.BasicStroke; + +/** + * @author timmolter + */ +public class XChartSeriesLines implements SeriesLines { + + private final BasicStroke[] seriesLines; + + /** + * Constructor + */ + public XChartSeriesLines() { + + seriesLines = new BasicStroke[] { SOLID, DASH_DOT, DASH_DASH, DOT_DOT }; + } + + @Override + public BasicStroke[] getSeriesLines() { + + return seriesLines; + } +} diff --git a/xchart/src/main/java/org/knowm/xchart/internal/style/markers/GGPlot2SeriesMarkers.java b/xchart/src/main/java/org/knowm/xchart/internal/style/markers/GGPlot2SeriesMarkers.java new file mode 100644 index 0000000000000000000000000000000000000000..66fe08bb6110205527de5208e8c8c786d0f9f8c2 --- /dev/null +++ b/xchart/src/main/java/org/knowm/xchart/internal/style/markers/GGPlot2SeriesMarkers.java @@ -0,0 +1,39 @@ +/** + * Copyright 2015-2016 Knowm Inc. (http://knowm.org) and contributors. + * Copyright 2011-2015 Xeiam LLC (http://xeiam.com) and contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.knowm.xchart.internal.style.markers; + +/** + * @author timmolter + */ +public class GGPlot2SeriesMarkers implements SeriesMarkers { + + private final Marker[] seriesMarkers; + + /** + * Constructor + */ + public GGPlot2SeriesMarkers() { + + seriesMarkers = new Marker[] { CIRCLE, DIAMOND }; + } + + @Override + public Marker[] getSeriesMarkers() { + + return seriesMarkers; + } +} diff --git a/xchart/src/main/java/org/knowm/xchart/internal/style/markers/MatlabSeriesMarkers.java b/xchart/src/main/java/org/knowm/xchart/internal/style/markers/MatlabSeriesMarkers.java new file mode 100644 index 0000000000000000000000000000000000000000..51995e5884719360f69df7f21b895341323fa680 --- /dev/null +++ b/xchart/src/main/java/org/knowm/xchart/internal/style/markers/MatlabSeriesMarkers.java @@ -0,0 +1,39 @@ +/** + * Copyright 2015-2016 Knowm Inc. (http://knowm.org) and contributors. + * Copyright 2011-2015 Xeiam LLC (http://xeiam.com) and contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.knowm.xchart.internal.style.markers; + +/** + * @author timmolter + */ +public class MatlabSeriesMarkers implements SeriesMarkers { + + private final Marker[] seriesMarkers; + + /** + * Constructor + */ + public MatlabSeriesMarkers() { + + seriesMarkers = new Marker[] { NONE }; + } + + @Override + public Marker[] getSeriesMarkers() { + + return seriesMarkers; + } +} diff --git a/xchart/src/main/java/org/knowm/xchart/internal/style/markers/None.java b/xchart/src/main/java/org/knowm/xchart/internal/style/markers/None.java new file mode 100644 index 0000000000000000000000000000000000000000..c9e4ae962aaa37852086082a22ddd1168c19c9ea --- /dev/null +++ b/xchart/src/main/java/org/knowm/xchart/internal/style/markers/None.java @@ -0,0 +1,33 @@ +/** + * Copyright 2015-2016 Knowm Inc. (http://knowm.org) and contributors. + * Copyright 2011-2015 Xeiam LLC (http://xeiam.com) and contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.knowm.xchart.internal.style.markers; + +import java.awt.Graphics2D; + +/** + * @author timmolter + */ +public class None extends Marker { + + @Override + public void paint(Graphics2D g, double xOffset, double yOffset, int markerSize) { + + // do nothing! + + } + +} diff --git a/xchart/src/main/java/org/knowm/xchart/internal/style/markers/SeriesMarkers.java b/xchart/src/main/java/org/knowm/xchart/internal/style/markers/SeriesMarkers.java new file mode 100644 index 0000000000000000000000000000000000000000..eef1a17d1bb5f15978c32cd80bec5dc9f9f605b5 --- /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 0000000000000000000000000000000000000000..548d6b167a1f970b6c767243fc3c9f0386538fce --- /dev/null +++ b/xchart/src/main/java/org/knowm/xchart/internal/style/markers/XChartSeriesMarkers.java @@ -0,0 +1,39 @@ +/** + * Copyright 2015-2016 Knowm Inc. (http://knowm.org) and contributors. + * Copyright 2011-2015 Xeiam LLC (http://xeiam.com) and contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.knowm.xchart.internal.style.markers; + +/** + * @author timmolter + */ +public class XChartSeriesMarkers implements SeriesMarkers { + + private final Marker[] seriesMarkers; + + /** + * Constructor + */ + public XChartSeriesMarkers() { + + seriesMarkers = new Marker[] { CIRCLE, DIAMOND, SQUARE, TRIANGLE_DOWN, TRIANGLE_UP }; + } + + @Override + public Marker[] getSeriesMarkers() { + + return seriesMarkers; + } +}