Skip to content
Snippets Groups Projects
Commit 73b86475 authored by Anthony Quiros's avatar Anthony Quiros
Browse files

Remove vertical or horizontal lines in PlotSurface

adding  a option to disable or unable displaying of vertical or
horizontal lines in PlotSurface.
parent 3ed8ed9f
Branches
No related tags found
No related merge requests found
Showing
with 362 additions and 8 deletions
/**
* 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;
}
}
/**
* 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;
}
}
/**
* 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;
}
}
......@@ -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;
}
/**
......
......@@ -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());
......
......@@ -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() {
......
......@@ -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() {
......
......@@ -104,6 +104,10 @@ public interface Theme {
// Chart Plot Area ///////////////////////////////
public boolean isPlotGridLinesVisible();
public boolean isPlotGridVerticalLinesVisible();
public boolean isPlotGridHorizontalLinesVisible();
public Color getPlotBackgroundColor();
......
......@@ -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() {
......
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();
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment