diff --git a/xchart-demo/src/main/java/com/xeiam/xchart/demo/XChartDemo.java b/xchart-demo/src/main/java/com/xeiam/xchart/demo/XChartDemo.java index d6ba7804780c2c828e0920768b67b42913b7841e..6916afd19a1d29c9e80ea02798b359a9eb57489f 100644 --- a/xchart-demo/src/main/java/com/xeiam/xchart/demo/XChartDemo.java +++ b/xchart-demo/src/main/java/com/xeiam/xchart/demo/XChartDemo.java @@ -53,6 +53,7 @@ import com.xeiam.xchart.demo.charts.scatter.ScatterChart03; import com.xeiam.xchart.demo.charts.scatter.ScatterChart04; import com.xeiam.xchart.demo.charts.theme.ThemeChart01; import com.xeiam.xchart.demo.charts.theme.ThemeChart02; +import com.xeiam.xchart.demo.charts.theme.ThemeChart03; /** * Class containing all XChart example charts @@ -206,7 +207,10 @@ public class XChartDemo extends JPanel implements TreeSelectionListener { chart = new DefaultMutableTreeNode(new ChartInfo("ThemeChart01 - Default XChart Theme", new ThemeChart01().getChart())); category.add(chart); - chart = new DefaultMutableTreeNode(new ChartInfo("ThemeChart01 - GGPlot2 Theme", new ThemeChart02().getChart())); + chart = new DefaultMutableTreeNode(new ChartInfo("ThemeChart02 - GGPlot2 Theme", new ThemeChart02().getChart())); + category.add(chart); + + chart = new DefaultMutableTreeNode(new ChartInfo("ThemeChart03 - Matlab Theme", new ThemeChart03().getChart())); category.add(chart); // Date category diff --git a/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/theme/ThemeChart01.java b/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/theme/ThemeChart01.java index 22dd73a48005712be69bc64798f80d0768194995..b364baef3f9645b8d6e0e80edc618582d329ae76 100644 --- a/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/theme/ThemeChart01.java +++ b/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/theme/ThemeChart01.java @@ -52,7 +52,7 @@ public class ThemeChart01 implements ExampleChart { } // Customize Chart - chart.setChartTitle("XChartTheme"); + chart.setChartTitle("XChart Theme"); chart.setXAxisTitle("X"); chart.setYAxisTitle("Y"); diff --git a/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/theme/ThemeChart02.java b/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/theme/ThemeChart02.java index b9505f9f3acbd8458bcefdf3e4ae0bd24ffda24e..7c399ce5da0128701d338bbf4193588362a4f3ee 100644 --- a/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/theme/ThemeChart02.java +++ b/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/theme/ThemeChart02.java @@ -17,8 +17,8 @@ package com.xeiam.xchart.demo.charts.theme; import com.xeiam.xchart.Chart; import com.xeiam.xchart.ChartBuilder; -import com.xeiam.xchart.SwingWrapper; import com.xeiam.xchart.StyleManager.ChartTheme; +import com.xeiam.xchart.SwingWrapper; import com.xeiam.xchart.demo.charts.ExampleChart; /** @@ -43,7 +43,7 @@ public class ThemeChart02 implements ExampleChart { public Chart getChart() { // Create Chart - Chart chart = new ChartBuilder().width(800).height(600).theme(ChartTheme.GGPlot2).title("GGPlot2Theme").xAxisTitle("X").yAxisTitle("Y").build(); + Chart chart = new ChartBuilder().width(800).height(600).theme(ChartTheme.GGPlot2).title("GGPlot2 Theme").xAxisTitle("X").yAxisTitle("Y").build(); chart.addSeries("vertical", new double[] { 1, 1 }, new double[] { -10, 10 }); chart.addSeries("horizontal", new double[] { -10, 10 }, new double[] { 0, 0 }); diff --git a/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/theme/ThemeChart03.java b/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/theme/ThemeChart03.java new file mode 100644 index 0000000000000000000000000000000000000000..af06ffe0d9dadb9b83ba3a10d3acd9f205417ac6 --- /dev/null +++ b/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/theme/ThemeChart03.java @@ -0,0 +1,113 @@ +/** + * Copyright 2011-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 com.xeiam.xchart.demo.charts.theme; + +import java.text.DateFormat; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Date; + +import com.xeiam.xchart.Chart; +import com.xeiam.xchart.ChartBuilder; +import com.xeiam.xchart.Series; +import com.xeiam.xchart.SeriesLineStyle; +import com.xeiam.xchart.StyleManager.ChartTheme; +import com.xeiam.xchart.SwingWrapper; +import com.xeiam.xchart.demo.charts.ExampleChart; + +/** + * Matlab Theme + * <p> + * Demonstrates the following: + * <ul> + * <li>Building a Chart with ChartBuilder + * <li>Applying the Matlab Theme to the Chart + * <li>Vertical and Horizontal Lines + */ +public class ThemeChart03 implements ExampleChart { + + public static void main(String[] args) { + + ExampleChart exampleChart = new ThemeChart03(); + Chart chart = exampleChart.getChart(); + new SwingWrapper(chart).displayChart(); + } + + @Override + public Chart getChart() { + + // Create Chart + Chart chart = new ChartBuilder().width(800).height(600).theme(ChartTheme.Matlab).title("Matlab Theme").xAxisTitle("X").yAxisTitle("Y").build(); + chart.getStyleManager().setPlotGridLinesVisible(false); + + // generate data + Collection<Date> xData = new ArrayList<Date>(); + Collection<Number> y1Data = new ArrayList<Number>(); + Collection<Number> y2Data = new ArrayList<Number>(); + + DateFormat sdf = new SimpleDateFormat("yyyy-MM"); + + Date date; + try { + date = sdf.parse("2012-08"); + xData.add(date); + y1Data.add(120); + y2Data.add(15); + + date = sdf.parse("2012-11"); + xData.add(date); + y1Data.add(165); + y2Data.add(15); + + date = sdf.parse("2013-01"); + xData.add(date); + y1Data.add(210); + y2Data.add(20); + + date = sdf.parse("2013-02"); + xData.add(date); + y1Data.add(400); + y2Data.add(30); + + date = sdf.parse("2013-03"); + xData.add(date); + y1Data.add(800); + y2Data.add(100); + + date = sdf.parse("2013-04"); + xData.add(date); + y1Data.add(2000); + y2Data.add(120); + + date = sdf.parse("2013-05"); + xData.add(date); + y1Data.add(3000); + y2Data.add(150); + + } catch (ParseException e) { + e.printStackTrace(); + } + + Series series1 = chart.addDateSeries("downloads", xData, y1Data); + series1.setLineStyle(SeriesLineStyle.DOT_DOT); + chart.addDateSeries("price", xData, y2Data); + + return chart; + } + +} diff --git a/xchart-demo/src/main/java/com/xeiam/xchart/standalone/ErrorBarTest.java b/xchart-demo/src/main/java/com/xeiam/xchart/standalone/ErrorBarTest.java index ed27b6636d03a4bf06905319d20d6a0fd65dad39..6d094d707951febc1d20f7c3fbce3facff6d544d 100644 --- a/xchart-demo/src/main/java/com/xeiam/xchart/standalone/ErrorBarTest.java +++ b/xchart-demo/src/main/java/com/xeiam/xchart/standalone/ErrorBarTest.java @@ -37,7 +37,6 @@ public class ErrorBarTest { public static void main(String[] args) throws Exception { - // Test code for plotting double[] xData = new double[] { 0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 }; double[] yData1 = new double[] { 100, 100, 100, 50, 50, 50, 50 }; double[] errdata = new double[] { 50, 20, 10, 50, 40, 20, 10 }; @@ -46,7 +45,7 @@ public class ErrorBarTest { double[] yData3 = new double[] { 150, 120, 110, 100, 90, 70, 60 }; Chart mychart = new Chart(900, 700); - mychart.getStyleManager().setYAxisLogarithmic(false); // set log or linear Y axis + // mychart.getStyleManager().setYAxisLogarithmic(true); // set log or linear Y axis mychart.getStyleManager().setYAxisMin(0); mychart.getStyleManager().setYAxisMax(150); mychart.getStyleManager().setErrorBarsColor(Color.black); diff --git a/xchart-demo/src/main/java/com/xeiam/xchart/standalone/ErrorBarText2.java b/xchart-demo/src/main/java/com/xeiam/xchart/standalone/ErrorBarText2.java new file mode 100644 index 0000000000000000000000000000000000000000..c97f1729af6f9f7332e9e01bc1858e5969d1201b --- /dev/null +++ b/xchart-demo/src/main/java/com/xeiam/xchart/standalone/ErrorBarText2.java @@ -0,0 +1,92 @@ +/** + * Copyright (C) 2013 Xeiam LLC http://xeiam.com + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies + * of the Software, and to permit persons to whom the Software is furnished to do + * so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package com.xeiam.xchart.standalone; + +import java.awt.Color; + +import com.xeiam.xchart.Chart; +import com.xeiam.xchart.Series; +import com.xeiam.xchart.SeriesColor; +import com.xeiam.xchart.SeriesLineStyle; +import com.xeiam.xchart.SeriesMarker; +import com.xeiam.xchart.SwingWrapper; + +/** + * @author timmolter + */ +public class ErrorBarText2 { + + public static void main(String[] args) throws Exception { + + double[] xData = new double[] { 0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 }; + + double[] yData1 = new double[] { 100, 100, 100, 10, 10, 10, 10 }; + + double[] yData2 = new double[] { 50, 80, 90, 1, 5, 8, 9 }; + + double[] yData3 = new double[] { 150, 120, 110, 19, 15, 12, 11 }; + + double[] errdata = new double[] { 1, .699, .301, 2, 1, .699, 0.301 }; + + Chart mychart = new Chart(1200, 800); + + mychart.getStyleManager().setYAxisLogarithmic(true); // set log or linear Y axis + + mychart.getStyleManager().setYAxisMin(.099); + + mychart.getStyleManager().setYAxisMax(1000); + + mychart.getStyleManager().setXAxisMin(0); + + mychart.getStyleManager().setXAxisMax(10); + + mychart.getStyleManager().setErrorBarsColor(Color.black); + + Series series1 = mychart.addSeries("Error bar test data", xData, yData1, errdata); + + Series series2 = mychart.addSeries("Y+error", xData, yData2); + + Series series3 = mychart.addSeries("Y-error", xData, yData3); + + series1.setLineStyle(SeriesLineStyle.SOLID); + + series1.setMarker(SeriesMarker.DIAMOND); + + series1.setMarkerColor(Color.MAGENTA); + + series2.setLineStyle(SeriesLineStyle.DASH_DASH); + + series2.setMarker(SeriesMarker.NONE); + + series2.setLineColor(SeriesColor.RED); + + series3.setLineStyle(SeriesLineStyle.DASH_DASH); + + series3.setMarker(SeriesMarker.NONE); + + series3.setLineColor(SeriesColor.RED); + + new SwingWrapper(mychart).displayChart(); + + } + +} diff --git a/xchart/src/main/java/com/xeiam/xchart/SeriesLineStyle.java b/xchart/src/main/java/com/xeiam/xchart/SeriesLineStyle.java index 7573a64596050ec6523f301cad0f1da7f7a46f1d..02dec6d6334b8d11227b38c43a144e91ea18d015 100644 --- a/xchart/src/main/java/com/xeiam/xchart/SeriesLineStyle.java +++ b/xchart/src/main/java/com/xeiam/xchart/SeriesLineStyle.java @@ -37,7 +37,7 @@ public enum SeriesLineStyle { 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.JOIN_MITER, 10.0f, new float[] { 1.0f, 1.0f }, 0.0f)); + 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; diff --git a/xchart/src/main/java/com/xeiam/xchart/StyleManager.java b/xchart/src/main/java/com/xeiam/xchart/StyleManager.java index 03f6c8d33a886b346c1b7fc27687b255a718b86e..e4a763b966141898c3061ed9f722390d7fc3c4f6 100644 --- a/xchart/src/main/java/com/xeiam/xchart/StyleManager.java +++ b/xchart/src/main/java/com/xeiam/xchart/StyleManager.java @@ -28,6 +28,7 @@ import java.util.Locale; import java.util.TimeZone; import com.xeiam.xchart.internal.style.GGPlot2Theme; +import com.xeiam.xchart.internal.style.MatlabTheme; import com.xeiam.xchart.internal.style.Theme; import com.xeiam.xchart.internal.style.XChartTheme; @@ -50,7 +51,7 @@ public class StyleManager { public enum ChartTheme { - XChart, GGPlot2 + XChart, GGPlot2, Matlab } /** the default Theme */ @@ -91,6 +92,7 @@ public class StyleManager { private Stroke axisTickMarksStroke; private Color axisTickLabelsColor; private boolean isAxisTicksLineVisible; + private boolean isAxisTicksMarksVisible; private int plotPadding; private int axisTitlePadding; private boolean isXAxisLogarithmic; @@ -105,6 +107,7 @@ public class StyleManager { private Color plotBackgroundColor; private Color plotBorderColor; private boolean isPlotBorderVisible; + private boolean isPlotTicksMarksVisible; private Color plotGridLinesColor; private Stroke plotGridLinesStroke; @@ -163,6 +166,7 @@ public class StyleManager { axisTickMarksStroke = theme.getAxisTickMarksStroke(); axisTickLabelsColor = theme.getAxisTickLabelsColor(); isAxisTicksLineVisible = theme.isAxisTicksLineVisible(); + isAxisTicksMarksVisible = theme.isAxisTicksMarksVisible(); plotPadding = theme.getPlotPadding(); axisTitlePadding = theme.getAxisTitlePadding(); isXAxisLogarithmic = false; @@ -177,6 +181,7 @@ public class StyleManager { plotBackgroundColor = theme.getPlotBackgroundColor(); plotBorderColor = theme.getPlotBorderColor(); isPlotBorderVisible = theme.isPlotBorderVisible(); + isPlotTicksMarksVisible = theme.isPlotTicksMarksVisible(); plotGridLinesColor = theme.getPlotGridLinesColor(); plotGridLinesStroke = theme.getPlotGridLinesStroke(); @@ -213,6 +218,8 @@ public class StyleManager { setTheme(new XChartTheme()); } else if (chartTheme == ChartTheme.GGPlot2) { setTheme(new GGPlot2Theme()); + } else if (chartTheme == ChartTheme.Matlab) { + setTheme(new MatlabTheme()); } } @@ -675,7 +682,22 @@ public class StyleManager { } /** - * sets the pading between the tick marks and the plot area + * sets the visibility of the tick marks + * + * @param isAxisTicksMarksVisible + */ + public void setAxisTicksMarksVisible(boolean isAxisTicksMarksVisible) { + + this.isAxisTicksMarksVisible = isAxisTicksMarksVisible; + } + + public boolean isAxisTicksMarksVisible() { + + return isAxisTicksMarksVisible; + } + + /** + * sets the padding between the tick marks and the plot area * * @param plotPadding */ @@ -836,6 +858,21 @@ public class StyleManager { return isPlotBorderVisible; } + /** + * sets the visibility of the ticks marks inside the plot area + * + * @param isPlotTicksMarksVisible + */ + public void setPlotTicksMarksVisible(boolean isPlotTicksMarksVisible) { + + this.isPlotTicksMarksVisible = isPlotTicksMarksVisible; + } + + public boolean isPlotTicksMarksVisible() { + + return isPlotTicksMarksVisible; + } + /** * set the plot area's grid lines color * diff --git a/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/AxisTickMarks.java b/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/AxisTickMarks.java index 9741344ebcbbbd9f62704915b39f57acb76c5240..488c6316a0a182d83340676006a3092581ff2c49 100644 --- a/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/AxisTickMarks.java +++ b/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/AxisTickMarks.java @@ -57,18 +57,20 @@ public class AxisTickMarks implements ChartPart { int yOffset = (int) (axisTick.getAxis().getPaintZone().getY()); // tick marks - for (int i = 0; i < axisTick.getTickLabels().size(); i++) { + if (getChartPainter().getStyleManager().isAxisTicksMarksVisible()) { - int tickLocation = axisTick.getTickLocations().get(i); + for (int i = 0; i < axisTick.getTickLabels().size(); i++) { - // g.setColor(getChart().getStyleManager().getChartBordersColor()); - // g.setStroke(stroke); + int tickLocation = axisTick.getTickLocations().get(i); - g.drawLine(xOffset, yOffset + (int) (axisTick.getAxis().getPaintZone().getHeight() - tickLocation), xOffset + getChartPainter().getStyleManager().getAxisTickMarkLength(), yOffset - + (int) (axisTick.getAxis().getPaintZone().getHeight() - tickLocation)); + // g.setColor(getChart().getStyleManager().getChartBordersColor()); + // g.setStroke(stroke); - } + g.drawLine(xOffset, yOffset + (int) (axisTick.getAxis().getPaintZone().getHeight() - tickLocation), xOffset + getChartPainter().getStyleManager().getAxisTickMarkLength(), yOffset + + (int) (axisTick.getAxis().getPaintZone().getHeight() - tickLocation)); + } + } // Line if (getChartPainter().getStyleManager().isAxisTicksLineVisible()) { g.drawLine(xOffset + getChartPainter().getStyleManager().getAxisTickMarkLength(), yOffset, xOffset + getChartPainter().getStyleManager().getAxisTickMarkLength(), yOffset @@ -87,16 +89,18 @@ public class AxisTickMarks implements ChartPart { int yOffset = (int) (axisTick.getAxisTickLabels().getBounds().getY() - getChartPainter().getStyleManager().getAxisTickPadding()); // tick marks - for (int i = 0; i < axisTick.getTickLabels().size(); i++) { + if (getChartPainter().getStyleManager().isAxisTicksMarksVisible()) { - int tickLocation = axisTick.getTickLocations().get(i); + for (int i = 0; i < axisTick.getTickLabels().size(); i++) { - // g.setColor(getChart().getStyleManager().getChartBordersColor()); - // g.setStroke(stroke); + int tickLocation = axisTick.getTickLocations().get(i); - g.drawLine(xOffset + tickLocation, yOffset, xOffset + tickLocation, yOffset - getChartPainter().getStyleManager().getAxisTickMarkLength()); - } + // g.setColor(getChart().getStyleManager().getChartBordersColor()); + // g.setStroke(stroke); + g.drawLine(xOffset + tickLocation, yOffset, xOffset + tickLocation, yOffset - getChartPainter().getStyleManager().getAxisTickMarkLength()); + } + } // Line if (getChartPainter().getStyleManager().isAxisTicksLineVisible()) { diff --git a/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/PlotSurface.java b/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/PlotSurface.java index 9123c72cb9f415e0470d9939b84a7e4f989ee07c..7db92af558468a231e2a9e3587da41352d7374cb 100644 --- a/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/PlotSurface.java +++ b/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/PlotSurface.java @@ -17,7 +17,6 @@ package com.xeiam.xchart.internal.chartpart; import java.awt.Graphics2D; import java.awt.Rectangle; -import java.awt.Stroke; import java.util.List; import com.xeiam.xchart.StyleManager.ChartType; @@ -63,36 +62,63 @@ public class PlotSurface implements ChartPart { g.draw(borderRectangle); } - Stroke stroke = getChartPainter().getStyleManager().getPlotGridLinesStroke(); - - // paint grid lines - if (getChartPainter().getStyleManager().isPlotGridLinesVisible()) { + // paint grid lines and or inner plot tics + if (getChartPainter().getStyleManager().isPlotGridLinesVisible() || getChartPainter().getStyleManager().isPlotTicksMarksVisible()) { // horizontal List<Integer> yAxisTickLocations = getChartPainter().getAxisPair().getyAxis().getAxisTick().getTickLocations(); for (int i = 0; i < yAxisTickLocations.size(); i++) { int tickLocation = yAxisTickLocations.get(i); + int yOffset = (int) (bounds.getY() + bounds.getHeight() - tickLocation); + + // draw lines + if (getChartPainter().getStyleManager().isPlotGridLinesVisible()) { + + g.setColor(getChartPainter().getStyleManager().getPlotGridLinesColor()); + g.setStroke(getChartPainter().getStyleManager().getPlotGridLinesStroke()); + // System.out.println("bounds.getY()= " + bounds.getY()); + g.drawLine((int) bounds.getX(), yOffset, (int) (bounds.getX() + bounds.getWidth() - 2), yOffset); + } + // tick marks + if (getChartPainter().getStyleManager().isPlotTicksMarksVisible()) { + + g.setColor(getChartPainter().getStyleManager().getAxisTickMarksColor()); + g.setStroke(getChartPainter().getStyleManager().getAxisTickMarksStroke()); - g.setColor(getChartPainter().getStyleManager().getPlotGridLinesColor()); - g.setStroke(stroke); - // System.out.println("bounds.getY()= " + bounds.getY()); - g.drawLine((int) bounds.getX(), (int) (bounds.getY() + bounds.getHeight() - tickLocation), (int) (bounds.getX() + bounds.getWidth() - 2), - (int) (bounds.getY() + bounds.getHeight() - tickLocation)); + g.drawLine((int) bounds.getX(), yOffset, (int) bounds.getX() + getChartPainter().getStyleManager().getAxisTickMarkLength(), yOffset); + g.drawLine((int) (bounds.getX() + bounds.getWidth() - 2), yOffset, (int) (bounds.getX() + bounds.getWidth() - 2) - getChartPainter().getStyleManager().getAxisTickMarkLength(), yOffset); + + } } // vertical - if (getChartPainter().getStyleManager().getChartType() != ChartType.Bar) { + if (getChartPainter().getStyleManager().getChartType() != ChartType.Bar + && (getChartPainter().getStyleManager().isPlotGridLinesVisible() || getChartPainter().getStyleManager().isPlotTicksMarksVisible())) { List<Integer> xAxisTickLocations = getChartPainter().getAxisPair().getxAxis().getAxisTick().getTickLocations(); for (int i = 0; i < xAxisTickLocations.size(); i++) { int tickLocation = xAxisTickLocations.get(i); + int xOffset = (int) (bounds.getX() + tickLocation - 1); - g.setColor(getChartPainter().getStyleManager().getPlotGridLinesColor()); - g.setStroke(stroke); + // draw lines + if (getChartPainter().getStyleManager().isPlotGridLinesVisible()) { + g.setColor(getChartPainter().getStyleManager().getPlotGridLinesColor()); + g.setStroke(getChartPainter().getStyleManager().getPlotGridLinesStroke()); + + g.drawLine(xOffset, (int) (bounds.getY()), xOffset, (int) (bounds.getY() + bounds.getHeight() - 1)); + } + // tick marks + if (getChartPainter().getStyleManager().isPlotTicksMarksVisible()) { + + g.setColor(getChartPainter().getStyleManager().getAxisTickMarksColor()); + g.setStroke(getChartPainter().getStyleManager().getAxisTickMarksStroke()); + + g.drawLine(xOffset, (int) (bounds.getY()), xOffset, (int) (bounds.getY()) + getChartPainter().getStyleManager().getAxisTickMarkLength()); + g.drawLine(xOffset, (int) (bounds.getY() + bounds.getHeight() - 1), xOffset, (int) (bounds.getY() + bounds.getHeight() - 1) - getChartPainter().getStyleManager().getAxisTickMarkLength()); - g.drawLine((int) (bounds.getX() + tickLocation - 1), (int) (bounds.getY()), (int) (bounds.getX() + tickLocation - 1), (int) (bounds.getY() + bounds.getHeight() - 1)); + } } } } diff --git a/xchart/src/main/java/com/xeiam/xchart/internal/style/GGPlot2Theme.java b/xchart/src/main/java/com/xeiam/xchart/internal/style/GGPlot2Theme.java index a817902a9eb8aaf1df1c2b32e44143d37b6344db..9b2433e3cac8b7a1aaee748ca8e1d9d89e3281f5 100644 --- a/xchart/src/main/java/com/xeiam/xchart/internal/style/GGPlot2Theme.java +++ b/xchart/src/main/java/com/xeiam/xchart/internal/style/GGPlot2Theme.java @@ -186,6 +186,12 @@ public class GGPlot2Theme implements Theme { return false; } + @Override + public boolean isAxisTicksMarksVisible() { + + return true; + } + @Override public int getPlotPadding() { @@ -243,6 +249,12 @@ public class GGPlot2Theme implements Theme { return false; } + @Override + public boolean isPlotTicksMarksVisible() { + + return false; + } + @Override public Color getPlotGridLinesColor() { diff --git a/xchart/src/main/java/com/xeiam/xchart/internal/style/MatlabTheme.java b/xchart/src/main/java/com/xeiam/xchart/internal/style/MatlabTheme.java new file mode 100644 index 0000000000000000000000000000000000000000..63fefbb823420fa8e40a06872ef279abc5bb866f --- /dev/null +++ b/xchart/src/main/java/com/xeiam/xchart/internal/style/MatlabTheme.java @@ -0,0 +1,279 @@ +/** + * Copyright (C) 2013 Xeiam LLC http://xeiam.com + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies + * of the Software, and to permit persons to whom the Software is furnished to do + * so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package com.xeiam.xchart.internal.style; + +import java.awt.BasicStroke; +import java.awt.Color; +import java.awt.Font; +import java.awt.Stroke; + +import com.xeiam.xchart.ChartColor; +import com.xeiam.xchart.StyleManager.LegendPosition; + +/** + * @author timmolter + */ +public class MatlabTheme implements Theme { + + // Chart Style /////////////////////////////// + + @Override + public Color getChartBackgroundColor() { + + return ChartColor.getAWTColor(ChartColor.WHITE); + } + + @Override + public Color getChartFontColor() { + + return ChartColor.getAWTColor(ChartColor.BLACK); + } + + @Override + public int getChartPadding() { + + return 10; + } + + // Chart Title /////////////////////////////// + + @Override + public Font getChartTitleFont() { + + return new Font(Font.SANS_SERIF, Font.BOLD, 14); + } + + @Override + public boolean isChartTitleVisible() { + + return false; + } + + @Override + public boolean isChartTitleBoxVisible() { + + return false; + } + + @Override + public Color getChartTitleBoxBackgroundColor() { + + return ChartColor.getAWTColor(ChartColor.WHITE); + } + + @Override + public Color getChartTitleBoxBorderColor() { + + return ChartColor.getAWTColor(ChartColor.WHITE); + } + + @Override + public int getChartTitlePadding() { + + return 5; + } + + // Chart Legend /////////////////////////////// + + @Override + public Font getLegendFont() { + + return new Font(Font.SANS_SERIF, Font.PLAIN, 11); + } + + @Override + public boolean isLegendVisible() { + + return true; + } + + @Override + public Color getLegendBackgroundColor() { + + return ChartColor.getAWTColor(ChartColor.WHITE); + + } + + @Override + public Color getLegendBorderColor() { + + return ChartColor.getAWTColor(ChartColor.BLACK); + } + + @Override + public int getLegendPadding() { + + return 10; + } + + @Override + public LegendPosition getLegendPosition() { + + return LegendPosition.OutsideE; + } + + // Chart Axes /////////////////////////////// + + @Override + public boolean isXAxisTitleVisible() { + + return true; + } + + @Override + public boolean isYAxisTitleVisible() { + + return true; + } + + @Override + public Font getAxisTitleFont() { + + return new Font(Font.SANS_SERIF, Font.PLAIN, 12); + } + + @Override + public boolean isXAxisTicksVisible() { + + return true; + } + + @Override + public boolean isYAxisTicksVisible() { + + return true; + } + + @Override + public Font getAxisTickLabelsFont() { + + return new Font(Font.SANS_SERIF, Font.PLAIN, 12); + } + + @Override + public int getAxisTickMarkLength() { + + return 5; + } + + @Override + public int getAxisTickPadding() { + + return 4; + } + + @Override + public Color getAxisTickMarksColor() { + + return ChartColor.getAWTColor(ChartColor.BLACK); + } + + @Override + public Stroke getAxisTickMarksStroke() { + + return new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL); + } + + @Override + public Color getAxisTickLabelsColor() { + + return ChartColor.getAWTColor(ChartColor.BLACK); + } + + @Override + public boolean isAxisTicksLineVisible() { + + return false; + } + + @Override + public boolean isAxisTicksMarksVisible() { + + return false; + } + + @Override + public int getPlotPadding() { + + return 3; + } + + @Override + public int getAxisTitlePadding() { + + return 10; + } + + // Chart Plot Area /////////////////////////////// + + @Override + public boolean isPlotGridLinesVisible() { + + return true; + } + + @Override + public Color getPlotBackgroundColor() { + + return ChartColor.getAWTColor(ChartColor.WHITE); + } + + @Override + public Color getPlotBorderColor() { + + return ChartColor.getAWTColor(ChartColor.BLACK); + } + + @Override + public boolean isPlotBorderVisible() { + + return true; + } + + @Override + public boolean isPlotTicksMarksVisible() { + + return true; + } + + @Override + public Color getPlotGridLinesColor() { + + return ChartColor.getAWTColor(ChartColor.BLACK); + } + + @Override + public Stroke getPlotGridLinesStroke() { + + return new BasicStroke(1.0f, BasicStroke.CAP_BUTT, BasicStroke.CAP_ROUND, 10.0f, new float[] { 1.0f, 2.0f }, 0.0f); + + } + + // Error Bars /////////////////////////////// + + @Override + public Color getErrorBarsColor() { + + return ChartColor.getAWTColor(ChartColor.BLACK); + } + +} diff --git a/xchart/src/main/java/com/xeiam/xchart/internal/style/Theme.java b/xchart/src/main/java/com/xeiam/xchart/internal/style/Theme.java index c6fdc4f0732b61f516b4fbc8d021002655fc7375..849620269750365ad3d48e251055e7545b5b594c 100644 --- a/xchart/src/main/java/com/xeiam/xchart/internal/style/Theme.java +++ b/xchart/src/main/java/com/xeiam/xchart/internal/style/Theme.java @@ -94,6 +94,8 @@ public interface Theme { public boolean isAxisTicksLineVisible(); + public boolean isAxisTicksMarksVisible(); + public int getAxisTitlePadding(); public int getPlotPadding(); @@ -112,6 +114,8 @@ public interface Theme { public Stroke getPlotGridLinesStroke(); + public boolean isPlotTicksMarksVisible(); + // Error Bars /////////////////////////////// public Color getErrorBarsColor(); diff --git a/xchart/src/main/java/com/xeiam/xchart/internal/style/XChartTheme.java b/xchart/src/main/java/com/xeiam/xchart/internal/style/XChartTheme.java index c727d38fa38e1619b398991a40e93576c55aeafb..c42e4caf4146fbe980afa6604d59cebbe9939f4e 100644 --- a/xchart/src/main/java/com/xeiam/xchart/internal/style/XChartTheme.java +++ b/xchart/src/main/java/com/xeiam/xchart/internal/style/XChartTheme.java @@ -205,6 +205,12 @@ public class XChartTheme implements Theme { return true; } + @Override + public boolean isAxisTicksMarksVisible() { + + return true; + } + @Override public int getPlotPadding() { @@ -243,6 +249,12 @@ public class XChartTheme implements Theme { return true; } + @Override + public boolean isPlotTicksMarksVisible() { + + return false; + } + @Override public Color getPlotGridLinesColor() {