diff --git a/.travis.yml b/.travis.yml index 9eb3ee2119c4377d83967a80b81e78bffb0d0981..4b322dd4517fce5df6c688ce89d540ae7b7854de 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,4 +1,6 @@ language: java +sudo: false + before_install: "git clone -b travis `git config --get remote.origin.url` target/travis" script: " if [ ${TRAVIS_PULL_REQUEST} = 'false' ]; @@ -8,6 +10,9 @@ else mvn clean verify --settings target/travis/settings.xml; fi" +jdk: + - openjdk6 + # whitelist branches: only: diff --git a/README.md b/README.md index 031c4a73ca125199a69c55a04378bc3bc3bc080d..445adb656fff357452e5c5e0b23bced19db8cc7b 100644 --- a/README.md +++ b/README.md @@ -93,7 +93,7 @@ Add the XChart library as a dependency to your pom.xml file: <dependency> <groupId>org.knowm.xchart</groupId> <artifactId>xchart</artifactId> - <version>2.6.0</version> + <version>2.6.1</version> </dependency> ``` @@ -109,7 +109,7 @@ For snapshots, add the following to your pom.xml file: <dependency> <groupId>org.knowm.xchart</groupId> <artifactId>xchart</artifactId> - <version>2.6.1-SNAPSHOT</version> + <version>2.6.2-SNAPSHOT</version> </dependency> ``` diff --git a/pom.xml b/pom.xml index 19646777086787e2f445eac08a048fd3aa492010..bc3b120704c13dce159f2862a61dc50e648e7026 100644 --- a/pom.xml +++ b/pom.xml @@ -3,10 +3,10 @@ <modelVersion>4.0.0</modelVersion> <groupId>org.knowm.xchart</groupId> <artifactId>xchart-parent</artifactId> - <version>2.6.1-SNAPSHOT</version> + <version>2.6.2-SNAPSHOT</version> <packaging>pom</packaging> <name>XChart Parent</name> - <description>Basic Charts for Java Applications</description> + <description>XChart is a light weight Java library for plotting data.</description> <url>http://knowm.org/open-source/xchart</url> <inceptionYear>2011</inceptionYear> @@ -65,19 +65,12 @@ <downloadUrl>https://oss.sonatype.org/content/groups/public/org/knowm/xchart</downloadUrl> </distributionManagement> - <repositories> - <repository> - <id>erichseifert.de</id> - <url>http://mvn.erichseifert.de/maven2</url> - </repository> - </repositories> - <dependencyManagement> <dependencies> <dependency> <groupId>de.erichseifert.vectorgraphics2d</groupId> <artifactId>VectorGraphics2D</artifactId> - <version>0.9.2</version> + <version>0.9.3</version> <optional>true</optional> </dependency> </dependencies> diff --git a/xchart-demo/pom.xml b/xchart-demo/pom.xml index 802290b84e0b86479c559ed0f919cbb3b216198c..01d843b22330634dc7d6897796a246527118cd0a 100644 --- a/xchart-demo/pom.xml +++ b/xchart-demo/pom.xml @@ -5,7 +5,7 @@ <parent> <groupId>org.knowm.xchart</groupId> <artifactId>xchart-parent</artifactId> - <version>2.6.1-SNAPSHOT</version> + <version>2.6.2-SNAPSHOT</version> </parent> <artifactId>xchart-demo</artifactId> @@ -17,7 +17,7 @@ <dependency> <groupId>org.knowm.xchart</groupId> <artifactId>xchart</artifactId> - <version>2.6.1-SNAPSHOT</version> + <version>2.6.2-SNAPSHOT</version> </dependency> </dependencies> diff --git a/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/plot/lines/Example0WithoutHorizontalLines.java b/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/plot/lines/Example0WithoutHorizontalLines.java new file mode 100644 index 0000000000000000000000000000000000000000..e88229ef8a6f865987fe45e7bf7b3106086d385a --- /dev/null +++ b/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/plot/lines/Example0WithoutHorizontalLines.java @@ -0,0 +1,71 @@ +/** + * Copyright 2015 Knowm Inc. (http://knowm.org) and contributors. + * Copyright 2011-2015 Xeiam LLC (http://xeiam.com) and contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.knowm.xchart.demo.charts.plot.lines; + +import java.util.ArrayList; +import java.util.List; + +import org.knowm.xchart.BitmapEncoder; +import org.knowm.xchart.BitmapEncoder.BitmapFormat; +import org.knowm.xchart.Chart; +import org.knowm.xchart.ChartBuilder; +import org.knowm.xchart.Series; +import org.knowm.xchart.SeriesMarker; +import org.knowm.xchart.SwingWrapper; +import org.knowm.xchart.VectorGraphicsEncoder; +import org.knowm.xchart.VectorGraphicsEncoder.VectorGraphicsFormat; + +/** + * Creates a simple Chart and saves it as a PNG and JPEG image file. + */ +public class Example0WithoutHorizontalLines { + + public static void main(String[] args) { + + int numCharts = 4; + + List<Chart> charts = new ArrayList<Chart>(); + + for (int i = 0; i < numCharts; i++) { + Chart chart = new ChartBuilder().xAxisTitle("X").yAxisTitle("Y").width(600).height(400).build(); + chart.getStyleManager().setYAxisMin(-10); + chart.getStyleManager().setYAxisMax(10); + chart.getStyleManager().setPlotGridHorizontalLinesVisible(false); + Series series = chart.addSeries("" + i, null, getRandomWalk(200)); + series.setMarker(SeriesMarker.NONE); + charts.add(chart); + } + new SwingWrapper(charts).displayChartMatrix(); + } + + /** + * Generates a set of random walk data + * + * @param numPoints + * @return + */ + private static double[] getRandomWalk(int numPoints) { + + double[] y = new double[numPoints]; + y[0] = 0; + for (int i = 1; i < y.length; i++) { + y[i] = y[i - 1] + Math.random() - .5; + } + return y; + } + +} diff --git a/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/plot/lines/Example0WithoutVerticalAndHorizontalLines.java b/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/plot/lines/Example0WithoutVerticalAndHorizontalLines.java new file mode 100644 index 0000000000000000000000000000000000000000..c2342e8562decc5afd2eac88ee190424e4410a76 --- /dev/null +++ b/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/plot/lines/Example0WithoutVerticalAndHorizontalLines.java @@ -0,0 +1,70 @@ +/** + * Copyright 2015 Knowm Inc. (http://knowm.org) and contributors. + * Copyright 2011-2015 Xeiam LLC (http://xeiam.com) and contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.knowm.xchart.demo.charts.plot.lines; + +import java.util.ArrayList; +import java.util.List; + +import org.knowm.xchart.Chart; +import org.knowm.xchart.ChartBuilder; +import org.knowm.xchart.Series; +import org.knowm.xchart.SeriesMarker; +import org.knowm.xchart.SwingWrapper; + +/** + * Create a Chart matrix + * + * @author timmolter + */ +public class Example0WithoutVerticalAndHorizontalLines { + + public static void main(String[] args) { + + int numCharts = 4; + + List<Chart> charts = new ArrayList<Chart>(); + + for (int i = 0; i < numCharts; i++) { + Chart chart = new ChartBuilder().xAxisTitle("X").yAxisTitle("Y").width(600).height(400).build(); + chart.getStyleManager().setYAxisMin(-10); + chart.getStyleManager().setYAxisMax(10); + chart.getStyleManager().setPlotGridVerticalLinesVisible(false); + chart.getStyleManager().setPlotGridHorizontalLinesVisible(false); + Series series = chart.addSeries("" + i, null, getRandomWalk(200)); + series.setMarker(SeriesMarker.NONE); + charts.add(chart); + } + new SwingWrapper(charts).displayChartMatrix(); + } + + /** + * Generates a set of random walk data + * + * @param numPoints + * @return + */ + private static double[] getRandomWalk(int numPoints) { + + double[] y = new double[numPoints]; + y[0] = 0; + for (int i = 1; i < y.length; i++) { + y[i] = y[i - 1] + Math.random() - .5; + } + return y; + } + +} diff --git a/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/plot/lines/Example0WithoutVerticalLines.java b/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/plot/lines/Example0WithoutVerticalLines.java new file mode 100644 index 0000000000000000000000000000000000000000..645cb6da8b9ba7b367bf3d3342342306e93c8c5d --- /dev/null +++ b/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/plot/lines/Example0WithoutVerticalLines.java @@ -0,0 +1,67 @@ +/** + * Copyright 2015 Knowm Inc. (http://knowm.org) and contributors. + * Copyright 2011-2015 Xeiam LLC (http://xeiam.com) and contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.knowm.xchart.demo.charts.plot.lines; + +import java.util.ArrayList; +import java.util.List; + +import org.knowm.xchart.Chart; +import org.knowm.xchart.ChartBuilder; +import org.knowm.xchart.Series; +import org.knowm.xchart.SeriesMarker; +import org.knowm.xchart.SwingWrapper; + +/** + * Creates a simple Chart using QuickChart + */ +public class Example0WithoutVerticalLines { + + public static void main(String[] args) { + + int numCharts = 4; + + List<Chart> charts = new ArrayList<Chart>(); + + for (int i = 0; i < numCharts; i++) { + Chart chart = new ChartBuilder().xAxisTitle("X").yAxisTitle("Y").width(600).height(400).build(); + chart.getStyleManager().setYAxisMin(-10); + chart.getStyleManager().setYAxisMax(10); + chart.getStyleManager().setPlotGridVerticalLinesVisible(false); + Series series = chart.addSeries("" + i, null, getRandomWalk(200)); + series.setMarker(SeriesMarker.NONE); + charts.add(chart); + } + new SwingWrapper(charts).displayChartMatrix(); + } + + /** + * Generates a set of random walk data + * + * @param numPoints + * @return + */ + private static double[] getRandomWalk(int numPoints) { + + double[] y = new double[numPoints]; + y[0] = 0; + for (int i = 1; i < y.length; i++) { + y[i] = y[i - 1] + Math.random() - .5; + } + return y; + } + +} diff --git a/xchart/pom.xml b/xchart/pom.xml index 589035806cc50643276cb12d35e5549738bfc3b0..cbfa725badc4f4323869adc0c3fcf5234a8e610b 100644 --- a/xchart/pom.xml +++ b/xchart/pom.xml @@ -5,7 +5,7 @@ <parent> <groupId>org.knowm.xchart</groupId> <artifactId>xchart-parent</artifactId> - <version>2.6.1-SNAPSHOT</version> + <version>2.6.2-SNAPSHOT</version> </parent> <artifactId>xchart</artifactId> diff --git a/xchart/src/main/java/org/knowm/xchart/StyleManager.java b/xchart/src/main/java/org/knowm/xchart/StyleManager.java index ad084568bbefe93829379dcf7674d9431e790948..a2f4f3ef8ec2495e707419e25d1a815e4b9b3478 100644 --- a/xchart/src/main/java/org/knowm/xchart/StyleManager.java +++ b/xchart/src/main/java/org/knowm/xchart/StyleManager.java @@ -127,7 +127,8 @@ public class StyleManager { private int xAxisLabelRotation = 0; // Chart Plot Area /////////////////////////////// - private boolean isPlotGridLinesVisible; + private boolean isPlotGridHorizontalLinesVisible; + private boolean isPlotGridVerticalLinesVisible; private Color plotBackgroundColor; private Color plotBorderColor; private boolean isPlotBorderVisible; @@ -215,7 +216,8 @@ public class StyleManager { axisTickSpacePercentage = .95; // Chart Plot Area /////////////////////////////// - isPlotGridLinesVisible = theme.isPlotGridLinesVisible(); + isPlotGridVerticalLinesVisible = theme.isPlotGridVerticalLinesVisible(); + isPlotGridHorizontalLinesVisible = theme.isPlotGridHorizontalLinesVisible(); plotBackgroundColor = theme.getPlotBackgroundColor(); plotBorderColor = theme.getPlotBorderColor(); isPlotBorderVisible = theme.isPlotBorderVisible(); @@ -927,12 +929,44 @@ public class StyleManager { */ public void setPlotGridLinesVisible(boolean isPlotGridLinesVisible) { - this.isPlotGridLinesVisible = isPlotGridLinesVisible; + this.isPlotGridHorizontalLinesVisible = isPlotGridLinesVisible; + this.isPlotGridVerticalLinesVisible = isPlotGridLinesVisible; } + @Deprecated public boolean isPlotGridLinesVisible() { - return isPlotGridLinesVisible; + return isPlotGridHorizontalLinesVisible && isPlotGridVerticalLinesVisible; + } + + /** + * sets the visibility of the horizontal gridlines on the plot area + * + * @param isPlotGridLinesVisible + */ + public void setPlotGridHorizontalLinesVisible(boolean isPlotGridHorizontalLinesVisible) { + + this.isPlotGridHorizontalLinesVisible = isPlotGridHorizontalLinesVisible; + } + + public boolean isPlotGridHorizontalLinesVisible() { + + return isPlotGridHorizontalLinesVisible; + } + + /** + * sets the visibility of the vertical gridlines on the plot area + * + * @param isPlotGridLinesVisible + */ + public void setPlotGridVerticalLinesVisible(boolean isPlotGridVerticalLinesVisible) { + + this.isPlotGridVerticalLinesVisible = isPlotGridVerticalLinesVisible; + } + + public boolean isPlotGridVerticalLinesVisible() { + + return isPlotGridVerticalLinesVisible; } /** diff --git a/xchart/src/main/java/org/knowm/xchart/internal/chartpart/PlotSurface.java b/xchart/src/main/java/org/knowm/xchart/internal/chartpart/PlotSurface.java index 3c04fcd176268bdfbee4e04a0ae3fdc998d8562b..b21d3226ca797d0bb6c80e31c907681c7995b1f3 100644 --- a/xchart/src/main/java/org/knowm/xchart/internal/chartpart/PlotSurface.java +++ b/xchart/src/main/java/org/knowm/xchart/internal/chartpart/PlotSurface.java @@ -68,7 +68,10 @@ public class PlotSurface implements ChartPart { } // paint grid lines and/or inner plot ticks - if (getChartPainter().getStyleManager().isPlotGridLinesVisible() || getChartPainter().getStyleManager().isPlotTicksMarksVisible()) { + if (getChartPainter().getStyleManager().isPlotGridHorizontalLinesVisible() + || getChartPainter().getStyleManager().isPlotGridVerticalLinesVisible() + || getChartPainter().getStyleManager().isPlotTicksMarksVisible() + ) { // horizontal List<Double> yAxisTickLocations = getChartPainter().getAxisPair().getYAxis().getAxisTickCalculator().getTickLocations(); @@ -79,7 +82,7 @@ public class PlotSurface implements ChartPart { if (yOffset > bounds.getY() && yOffset < bounds.getY() + bounds.getHeight()) { // draw lines - if (getChartPainter().getStyleManager().isPlotGridLinesVisible()) { + if (getChartPainter().getStyleManager().isPlotGridHorizontalLinesVisible()) { g.setColor(getChartPainter().getStyleManager().getPlotGridLinesColor()); g.setStroke(getChartPainter().getStyleManager().getPlotGridLinesStroke()); @@ -103,7 +106,7 @@ public class PlotSurface implements ChartPart { // vertical if (getChartPainter().getStyleManager().getChartType() != ChartType.Bar - && (getChartPainter().getStyleManager().isPlotGridLinesVisible() + && (getChartPainter().getStyleManager().isPlotGridVerticalLinesVisible() || getChartPainter().getStyleManager().isPlotTicksMarksVisible()) @@ -118,7 +121,7 @@ public class PlotSurface implements ChartPart { if (xOffset > bounds.getX() && xOffset < bounds.getX() + bounds.getWidth()) { // draw lines - if (getChartPainter().getStyleManager().isPlotGridLinesVisible()) { + if (getChartPainter().getStyleManager().isPlotGridVerticalLinesVisible()) { g.setColor(getChartPainter().getStyleManager().getPlotGridLinesColor()); g.setStroke(getChartPainter().getStyleManager().getPlotGridLinesStroke()); 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 e0461c2068d0fa79474d10736cbf01ab08a1ac16..24a6337bbb573091586b7f1add5e4adba5761349 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 @@ -244,6 +244,20 @@ public class GGPlot2Theme implements Theme { return true; } + + @Override + public boolean isPlotGridVerticalLinesVisible() { + + return true; + } + + + @Override + public boolean isPlotGridHorizontalLinesVisible() { + + return true; + } + @Override public Color getPlotBackgroundColor() { 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 cdb2776a69871c46d584dc5f8e249af541c9a313..f0b3f780766798f436ff2fc848d10f1cf105dbd4 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 @@ -244,6 +244,18 @@ public class MatlabTheme implements Theme { return true; } + @Override + public boolean isPlotGridVerticalLinesVisible() { + + return true; + } + + @Override + public boolean isPlotGridHorizontalLinesVisible() { + + return true; + } + @Override public Color getPlotBackgroundColor() { 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 c2a4132aa2b4261d4d3d87144c30e786c7e36390..c593bf92c572d4cf3ed58e3888368589188f4d6b 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 @@ -104,6 +104,10 @@ public interface Theme { // Chart Plot Area /////////////////////////////// public boolean isPlotGridLinesVisible(); + + public boolean isPlotGridVerticalLinesVisible(); + + public boolean isPlotGridHorizontalLinesVisible(); public Color getPlotBackgroundColor(); 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 56ba4b9388e3df3134ef472c40898b2914e7b3d5..fb69b0610c7d0d68927edb152a646bdc353c9a3e 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 @@ -244,6 +244,18 @@ public class XChartTheme implements Theme { return true; } + @Override + public boolean isPlotGridVerticalLinesVisible() { + + return true; + } + + @Override + public boolean isPlotGridHorizontalLinesVisible() { + + return true; + } + @Override public Color getPlotBackgroundColor() { diff --git a/xchart/src/test/java/org/knowm/xchart/StyleManagerTest.java b/xchart/src/test/java/org/knowm/xchart/StyleManagerTest.java new file mode 100644 index 0000000000000000000000000000000000000000..bcaaf767f201cec201050a369af478c3506646d6 --- /dev/null +++ b/xchart/src/test/java/org/knowm/xchart/StyleManagerTest.java @@ -0,0 +1,67 @@ +package org.knowm.xchart; + +import org.junit.Before; +import org.junit.Test; + +import static org.fest.assertions.api.Assertions.assertThat; + +public class StyleManagerTest { + + private StyleManager styleManager; + + @Before + public void setUp() { + styleManager = new StyleManager(); + } + + @SuppressWarnings("deprecation") + @Test + public void setPlotGridLinesVisibleTestWithFalse(){ + styleManager.setPlotGridLinesVisible(false); + assertThat(styleManager.isPlotGridLinesVisible()).isFalse(); + assertThat(styleManager.isPlotGridHorizontalLinesVisible()).isFalse(); + assertThat(styleManager.isPlotGridVerticalLinesVisible()).isFalse(); + } + + @SuppressWarnings("deprecation") + @Test + public void setPlotGridLinesVisibleTestWithTrue(){ + styleManager.setPlotGridHorizontalLinesVisible(true); + assertThat(styleManager.isPlotGridLinesVisible()).isTrue(); + assertThat(styleManager.isPlotGridHorizontalLinesVisible()).isTrue(); + assertThat(styleManager.isPlotGridVerticalLinesVisible()).isTrue(); + } + + @SuppressWarnings("deprecation") + @Test + public void setPlotGridHorizontalLinesVisibleTestWithFalse(){ + styleManager.setPlotGridHorizontalLinesVisible(false); + assertThat(styleManager.isPlotGridHorizontalLinesVisible()).isFalse(); + assertThat(styleManager.isPlotGridLinesVisible()).isFalse(); + } + + @SuppressWarnings("deprecation") + @Test + public void setPlotGridHorizontalLinesVisibleTestWithTrue(){ + styleManager.setPlotGridLinesVisible(true); + assertThat(styleManager.isPlotGridHorizontalLinesVisible()).isTrue(); + assertThat(styleManager.isPlotGridLinesVisible()).isTrue(); + } + + @SuppressWarnings("deprecation") + @Test + public void setPlotGridVerticalLinesVisibleTestWithFalse(){ + styleManager.setPlotGridVerticalLinesVisible(false); + assertThat(styleManager.isPlotGridVerticalLinesVisible()).isFalse(); + assertThat(styleManager.isPlotGridLinesVisible()).isFalse(); + } + + @SuppressWarnings("deprecation") + @Test + public void setPlotGridVerticalLinesVisibleTestWithTrue(){ + styleManager.setPlotGridVerticalLinesVisible(true); + assertThat(styleManager.isPlotGridVerticalLinesVisible()).isTrue(); + assertThat(styleManager.isPlotGridLinesVisible()).isTrue(); + } + +}