From 3240a66728be202558f456d84d72644c80f57604 Mon Sep 17 00:00:00 2001 From: Tim Molter <tim.molter@gmail.com> Date: Sun, 10 Feb 2013 23:04:34 +0100 Subject: [PATCH] implemented ggplot2 theme --- .../xchart/demo/charts/line/ExampleChart.java | 1 - .../xchart/demo/charts/line/LineChart02.java | 2 - .../xchart/demo/charts/line/LineChart03.java | 2 - .../xchart/demo/charts/line/LineChart04.java | 2 - .../xchart/demo/charts/line/LineChart05.java | 17 +- .../xchart/demo/charts/line/LineChart06.java | 2 - .../xchart/demo/charts/line/LineChart07.java | 2 - .../xchart/demo/charts/line/LineChart08.java | 2 - .../xchart/demo/charts/line/LineChart09.java | 7 +- .../xchart/demo/charts/line/LineChart10.java | 2 - .../xchart/demo/charts/line/LineChart11.java | 2 - .../src/main/java/com/xeiam/xchart/Chart.java | 4 +- .../xeiam/xchart/internal/chartpart/Axis.java | 4 +- .../internal/chartpart/AxisTickLabels.java | 8 +- .../internal/chartpart/AxisTickMarks.java | 16 +- .../xchart/internal/chartpart/ChartTitle.java | 41 ++- .../xchart/internal/chartpart/Legend.java | 4 +- .../internal/chartpart/PlotSurface.java | 18 +- .../com/xeiam/xchart/style/ChartColor.java | 6 +- .../com/xeiam/xchart/style/StyleManager.java | 206 ++++++++++++-- .../xchart/style/theme/GGPlot2Theme.java | 253 ++++++++++++++++++ .../com/xeiam/xchart/style/theme/Theme.java | 25 +- .../xeiam/xchart/style/theme/XChartTheme.java | 75 +++++- .../com/xeiam/xchart/chart}/Example0.java | 2 +- .../com/xeiam/xchart/chart}/Example1.java | 2 +- .../com/xeiam/xchart/chart}/Example2.java | 2 +- .../com/xeiam/xchart/chart/LineChart05.java | 44 +++ .../com/xeiam/xchart/chart/LineChart06.java | 44 +++ .../java/com/xeiam/xchart/chart/NoBug.java | 69 +++++ .../xchart/{ => unit}/ValueFormatterTest.java | 2 +- 30 files changed, 761 insertions(+), 105 deletions(-) create mode 100644 xchart/src/main/java/com/xeiam/xchart/style/theme/GGPlot2Theme.java rename {xchart-demo/src/main/java/com/xeiam/xchart/example => xchart/src/test/java/com/xeiam/xchart/chart}/Example0.java (97%) rename {xchart-demo/src/main/java/com/xeiam/xchart/example => xchart/src/test/java/com/xeiam/xchart/chart}/Example1.java (97%) rename {xchart-demo/src/main/java/com/xeiam/xchart/example => xchart/src/test/java/com/xeiam/xchart/chart}/Example2.java (98%) create mode 100644 xchart/src/test/java/com/xeiam/xchart/chart/LineChart05.java create mode 100644 xchart/src/test/java/com/xeiam/xchart/chart/LineChart06.java create mode 100644 xchart/src/test/java/com/xeiam/xchart/chart/NoBug.java rename xchart/src/test/java/com/xeiam/xchart/{ => unit}/ValueFormatterTest.java (99%) diff --git a/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/line/ExampleChart.java b/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/line/ExampleChart.java index 51815b69..cfe44b64 100644 --- a/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/line/ExampleChart.java +++ b/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/line/ExampleChart.java @@ -24,7 +24,6 @@ package com.xeiam.xchart.demo.charts.line; import com.xeiam.xchart.Chart; /** - * @author timmolter */ public interface ExampleChart { diff --git a/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/line/LineChart02.java b/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/line/LineChart02.java index c84f1b9a..72c3b9ce 100644 --- a/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/line/LineChart02.java +++ b/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/line/LineChart02.java @@ -33,8 +33,6 @@ import com.xeiam.xchart.style.SeriesMarker; * <ul> * <li>Customizing the series style properties</li> * </ul> - * - * @author timmolter */ public class LineChart02 implements ExampleChart { diff --git a/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/line/LineChart03.java b/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/line/LineChart03.java index a76c69df..70b27629 100644 --- a/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/line/LineChart03.java +++ b/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/line/LineChart03.java @@ -24,8 +24,6 @@ import com.xeiam.xchart.SwingWrapper; /** * Multiple curves on one Chart - * - * @author timmolter */ public class LineChart03 implements ExampleChart { diff --git a/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/line/LineChart04.java b/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/line/LineChart04.java index efc9b7b3..6b76afb1 100644 --- a/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/line/LineChart04.java +++ b/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/line/LineChart04.java @@ -30,8 +30,6 @@ import com.xeiam.xchart.style.Series; /** * Date Axis - * - * @author timmolter */ public class LineChart04 implements ExampleChart { diff --git a/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/line/LineChart05.java b/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/line/LineChart05.java index ff22f9c4..433eb26a 100644 --- a/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/line/LineChart05.java +++ b/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/line/LineChart05.java @@ -16,13 +16,18 @@ package com.xeiam.xchart.demo.charts.line; import com.xeiam.xchart.Chart; -import com.xeiam.xchart.LineChart; +import com.xeiam.xchart.ChartBuilder; import com.xeiam.xchart.SwingWrapper; +import com.xeiam.xchart.style.theme.GGPlot2Theme; /** - * Vertical and horizontal lines - * - * @author timmolter + * GGPlot2 Theme + * <p> + * Demonstrates the following: + * <ul> + * <li>Building a Chart with ChartBuilder</li> + * <li>Applying the GGPlot2 Theme to the Chart</li> + * </ul> */ public class LineChart05 implements ExampleChart { @@ -37,7 +42,9 @@ public class LineChart05 implements ExampleChart { public Chart getChart() { // Create Chart - Chart chart = new LineChart(800, 600); + Chart chart = new ChartBuilder().width(800).height(600).theme(new GGPlot2Theme()).build(); + + // new LineChart(800, 600); // Customize Chart chart.setChartTitle("Example5"); diff --git a/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/line/LineChart06.java b/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/line/LineChart06.java index ab0f61dd..8e741ab7 100644 --- a/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/line/LineChart06.java +++ b/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/line/LineChart06.java @@ -21,8 +21,6 @@ import com.xeiam.xchart.SwingWrapper; /** * Single point - * - * @author timmolter */ public class LineChart06 implements ExampleChart { diff --git a/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/line/LineChart07.java b/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/line/LineChart07.java index 2506a99d..4516337b 100644 --- a/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/line/LineChart07.java +++ b/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/line/LineChart07.java @@ -24,8 +24,6 @@ import com.xeiam.xchart.SwingWrapper; /** * Longs as X-Axis data - * - * @author timmolter */ public class LineChart07 implements ExampleChart { diff --git a/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/line/LineChart08.java b/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/line/LineChart08.java index d7926a1d..7c1ea138 100644 --- a/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/line/LineChart08.java +++ b/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/line/LineChart08.java @@ -28,8 +28,6 @@ import com.xeiam.xchart.style.SeriesMarker; /** * Error bars - * - * @author timmolter */ public class LineChart08 implements ExampleChart { diff --git a/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/line/LineChart09.java b/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/line/LineChart09.java index 7be60a66..46a619c3 100644 --- a/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/line/LineChart09.java +++ b/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/line/LineChart09.java @@ -36,8 +36,6 @@ import com.xeiam.xchart.style.SeriesMarker; /** * Extensive chart customization - * - * @author timmolter */ public class LineChart09 implements ExampleChart { @@ -72,19 +70,18 @@ public class LineChart09 implements ExampleChart { } // Customize Chart - chart.setChartTitle("Sample Chart Extensive Cusomization"); + chart.setChartTitle("Sample Chart With Customization"); chart.setXAxisTitle("X"); chart.setYAxisTitle("Y"); chart.getStyleManager().setPlotBackgroundColor(ChartColor.getAWTColor(ChartColor.GREY)); chart.getStyleManager().setPlotGridLinesColor(new Color(255, 255, 255)); chart.getStyleManager().setChartBackgroundColor(Color.WHITE); chart.getStyleManager().setLegendBackgroundColor(Color.PINK); - chart.getStyleManager().setChartBordersColor(Color.GREEN); chart.getStyleManager().setChartFontColor(Color.MAGENTA); chart.getStyleManager().setChartTitleFont(new Font(Font.MONOSPACED, Font.BOLD, 24)); chart.getStyleManager().setLegendFont(new Font(Font.SERIF, Font.PLAIN, 18)); chart.getStyleManager().setAxisTitleFont(new Font(Font.SANS_SERIF, Font.ITALIC, 18)); - chart.getStyleManager().setAxisTicksFont(new Font(Font.SERIF, Font.PLAIN, 11)); + chart.getStyleManager().setAxisTickLabelsFont(new Font(Font.SERIF, Font.PLAIN, 11)); chart.getValueFormatter().setDatePattern("dd-MMM"); chart.getValueFormatter().setNormalDecimalPattern("#.000"); chart.getValueFormatter().setLocale(Locale.GERMAN); diff --git a/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/line/LineChart10.java b/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/line/LineChart10.java index 4dfd9c35..929eee30 100644 --- a/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/line/LineChart10.java +++ b/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/line/LineChart10.java @@ -25,8 +25,6 @@ import com.xeiam.xchart.style.SeriesMarker; /** * Plots Hundreds of Series on One Plot - * - * @author timmolter */ public class LineChart10 implements ExampleChart { diff --git a/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/line/LineChart11.java b/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/line/LineChart11.java index 690ce8f3..6c809dc5 100644 --- a/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/line/LineChart11.java +++ b/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/line/LineChart11.java @@ -21,8 +21,6 @@ import com.xeiam.xchart.SwingWrapper; /** * Using ChartBuilder to Make a Chart - * - * @author timmolter */ public class LineChart11 implements ExampleChart { diff --git a/xchart/src/main/java/com/xeiam/xchart/Chart.java b/xchart/src/main/java/com/xeiam/xchart/Chart.java index c720a405..4d8c2a6d 100644 --- a/xchart/src/main/java/com/xeiam/xchart/Chart.java +++ b/xchart/src/main/java/com/xeiam/xchart/Chart.java @@ -44,10 +44,10 @@ public abstract class Chart { private ValueFormatter valueFormatter = new ValueFormatter(); // Chart Parts - private ChartTitle chartTitle = new ChartTitle(this); private Legend chartLegend = new Legend(this); private AxisPair axisPair = new AxisPair(this); private Plot plot = new Plot(this); + private ChartTitle chartTitle = new ChartTitle(this); /** * Constructor @@ -103,10 +103,10 @@ public abstract class Chart { g.setColor(styleManager.getChartBackgroundColor()); g.fillRect(0, 0, width, height); - chartTitle.paint(g); chartLegend.paint(g); axisPair.paint(g); plot.paint(g); + chartTitle.paint(g); g.dispose(); } diff --git a/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/Axis.java b/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/Axis.java index 5a73a66e..68c60199 100644 --- a/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/Axis.java +++ b/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/Axis.java @@ -139,7 +139,7 @@ public class Axis implements ChartPart { // Axis tick labels double axisTickLabelsHeight = 0.0; if (getChart().getStyleManager().isxAxisTicksVisible()) { - TextLayout textLayout = new TextLayout("0", getChart().getStyleManager().getAxisTicksFont(), new FontRenderContext(null, true, false)); + TextLayout textLayout = new TextLayout("0", getChart().getStyleManager().getAxisTickLabelsFont(), new FontRenderContext(null, true, false)); Rectangle rectangle = textLayout.getPixelBounds(null, 0, 0); axisTickLabelsHeight = rectangle.getHeight() + getChart().getStyleManager().getAxisTickPadding() + getChart().getStyleManager().getAxisTickMarkLength() + getChart().getStyleManager().getPlotPadding(); @@ -167,7 +167,7 @@ public class Axis implements ChartPart { // | // ---- int xOffset = getChart().getStyleManager().getChartPadding(); - int yOffset = (int) (getChart().getChartTitle().getBounds().getY() + getChart().getChartTitle().getBounds().getHeight() + getChart().getStyleManager().getChartPadding()); + int yOffset = getChart().getChartTitle().getSizeHint(); int width = 80; // arbitrary, final width depends on Axis tick labels int height = getChart().getHeight() - yOffset - axisPair.getxAxis().getSizeHint() - getChart().getStyleManager().getChartPadding(); Rectangle yAxisRectangle = new Rectangle(xOffset, yOffset, width, height); diff --git a/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/AxisTickLabels.java b/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/AxisTickLabels.java index 90a87199..2cbabd21 100644 --- a/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/AxisTickLabels.java +++ b/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/AxisTickLabels.java @@ -53,9 +53,9 @@ public class AxisTickLabels implements ChartPart { public void paint(Graphics2D g) { bounds = new Rectangle(); - g.setFont(getChart().getStyleManager().getAxisTicksFont()); + g.setFont(getChart().getStyleManager().getAxisTickLabelsFont()); - g.setColor(getChart().getStyleManager().getChartFontColor()); + g.setColor(getChart().getStyleManager().getAxisTickLabelsColor()); if (axisTick.getAxis().getDirection() == Axis.Direction.Y) { // Y-Axis @@ -70,7 +70,7 @@ public class AxisTickLabels implements ChartPart { FontRenderContext frc = g.getFontRenderContext(); // TextLayout layout = new TextLayout(tickLabel, font, new FontRenderContext(null, true, false)); - TextLayout layout = new TextLayout(tickLabel, getChart().getStyleManager().getAxisTicksFont(), frc); + TextLayout layout = new TextLayout(tickLabel, getChart().getStyleManager().getAxisTickLabelsFont(), frc); Rectangle tickLabelBounds = layout.getPixelBounds(null, 0, 0); layout.draw(g, xOffset, (int) (yOffset + axisTick.getAxis().getPaintZone().getHeight() - tickLocation + tickLabelBounds.getHeight() / 2.0)); @@ -95,7 +95,7 @@ public class AxisTickLabels implements ChartPart { int tickLocation = axisTick.getTickLocations().get(i); FontRenderContext frc = g.getFontRenderContext(); - TextLayout layout = new TextLayout(tickLabel, getChart().getStyleManager().getAxisTicksFont(), frc); + TextLayout layout = new TextLayout(tickLabel, getChart().getStyleManager().getAxisTickLabelsFont(), frc); Rectangle tickLabelBounds = layout.getPixelBounds(null, 0, 0); layout.draw(g, (int) (xOffset + tickLocation - tickLabelBounds.getWidth() / 2.0), yOffset); 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 4e23f890..d86526cb 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 @@ -15,10 +15,8 @@ */ package com.xeiam.xchart.internal.chartpart; -import java.awt.BasicStroke; import java.awt.Graphics2D; import java.awt.Rectangle; -import java.awt.Stroke; import com.xeiam.xchart.Chart; @@ -30,9 +28,6 @@ public class AxisTickMarks implements ChartPart { /** parent */ private AxisTick axisTick; - /** the line style */ - private final Stroke stroke = new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL); - /** the bounds */ private Rectangle bounds; @@ -57,7 +52,8 @@ public class AxisTickMarks implements ChartPart { bounds = new Rectangle(); - g.setColor(getChart().getStyleManager().getChartBordersColor()); + g.setColor(getChart().getStyleManager().getAxisTickMarksColor()); + g.setStroke(getChart().getStyleManager().getAxisTickMarksStroke()); if (axisTick.getAxis().getDirection() == Axis.Direction.Y) { // Y-Axis @@ -69,8 +65,8 @@ public class AxisTickMarks implements ChartPart { int tickLocation = axisTick.getTickLocations().get(i); - g.setColor(getChart().getStyleManager().getChartBordersColor()); - g.setStroke(stroke); + // g.setColor(getChart().getStyleManager().getChartBordersColor()); + // g.setStroke(stroke); g.drawLine(xOffset, yOffset + (int) (axisTick.getAxis().getPaintZone().getHeight() - tickLocation), xOffset + getChart().getStyleManager().getAxisTickMarkLength(), yOffset + (int) (axisTick.getAxis().getPaintZone().getHeight() - tickLocation)); @@ -98,8 +94,8 @@ public class AxisTickMarks implements ChartPart { int tickLocation = axisTick.getTickLocations().get(i); - g.setColor(getChart().getStyleManager().getChartBordersColor()); - g.setStroke(stroke); + // g.setColor(getChart().getStyleManager().getChartBordersColor()); + // g.setStroke(stroke); g.drawLine(xOffset + tickLocation, yOffset, xOffset + tickLocation, yOffset - getChart().getStyleManager().getAxisTickMarkLength()); } diff --git a/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/ChartTitle.java b/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/ChartTitle.java index 22e3c75b..5ac128bb 100644 --- a/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/ChartTitle.java +++ b/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/ChartTitle.java @@ -61,6 +61,24 @@ public class ChartTitle implements ChartPart { this.text = text; } + /** + * get the height of the chart title including the chart padding + * + * @return + */ + protected int getSizeHint() { + + if (chart.getStyleManager().isChartTitleVisible()) { + + TextLayout textLayout = new TextLayout(text, chart.getStyleManager().getChartTitleFont(), new FontRenderContext(null, true, false)); + Rectangle rectangle = textLayout.getPixelBounds(null, 0, 0); + int titleHeight = (int) ((chart.getStyleManager().isChartTitleVisible() ? rectangle.getHeight() : 0)); + return chart.getStyleManager().getChartPadding() + 2 * chart.getStyleManager().getChartTitlePadding() + titleHeight; + } else { + return chart.getStyleManager().getChartPadding(); + } + } + @Override public void paint(Graphics2D g) { @@ -69,14 +87,27 @@ public class ChartTitle implements ChartPart { if (chart.getStyleManager().isChartTitleVisible()) { + // create rectangle first for sizing FontRenderContext frc = g.getFontRenderContext(); TextLayout textLayout = new TextLayout(text, chart.getStyleManager().getChartTitleFont(), frc); Rectangle rectangle = textLayout.getPixelBounds(null, 0, 0); - int xOffset = (int) ((chart.getWidth() - rectangle.getWidth()) / 2.0); - int yOffset = (int) ((chart.getStyleManager().isChartTitleVisible() ? (chart.getStyleManager().getChartPadding() - rectangle.getY()) : 0)); - bounds = new Rectangle(xOffset, yOffset + (chart.getStyleManager().isChartTitleVisible() ? (int) rectangle.getY() : 0), (int) rectangle.getWidth(), (int) (chart.getStyleManager() - .isChartTitleVisible() ? rectangle.getHeight() : 0)); + // paint the chart title box + int chartTitleBoxWidth = (int) chart.getPlot().getBounds().getWidth(); + int chartTitleBoxHeight = (int) (rectangle.getHeight() + 2 * chart.getStyleManager().getChartTitlePadding()); + int xOffset = (int) chart.getPlot().getBounds().getX(); + int yOffset = chart.getStyleManager().getChartPadding(); + + g.setColor(chart.getStyleManager().getChartTitleBorderColor()); + g.drawRect(xOffset - 1, yOffset, chartTitleBoxWidth - 1, chartTitleBoxHeight - 1); + g.setColor(chart.getStyleManager().getChartTitleBackgroundColor()); + g.fillRect(xOffset - 1, yOffset + 1, chartTitleBoxWidth, chartTitleBoxHeight - 1); + + // paint title + xOffset = (int) (chart.getPlot().getBounds().getX() + (chart.getPlot().getBounds().getWidth() - rectangle.getWidth()) / 2.0); + yOffset = (int) (chart.getStyleManager().getChartPadding() - rectangle.getY() + chart.getStyleManager().getChartTitlePadding()); + + bounds = new Rectangle(xOffset, yOffset + ((int) rectangle.getY()), (int) rectangle.getWidth(), (int) (rectangle.getHeight())); // g.setColor(Color.green); // g.draw(bounds); @@ -89,7 +120,7 @@ public class ChartTitle implements ChartPart { @Override public Rectangle getBounds() { - return bounds; + return null; // this should never be needed } @Override diff --git a/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/Legend.java b/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/Legend.java index b3ac07c1..c423c034 100644 --- a/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/Legend.java +++ b/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/Legend.java @@ -85,9 +85,9 @@ public class Legend implements ChartPart { int legendBoxWidth = legendContentWidth + 2 * chart.getStyleManager().getLegendPadding(); int legendBoxHeight = legendContentHeight + 2 * chart.getStyleManager().getLegendPadding(); int xOffset = chart.getWidth() - legendBoxWidth - chart.getStyleManager().getChartPadding(); - int yOffset = (int) ((chart.getHeight() - legendBoxHeight) / 2.0 + chart.getChartTitle().getBounds().getY() + chart.getChartTitle().getBounds().getHeight()); + int yOffset = (int) ((chart.getHeight() - legendBoxHeight) / 2.0 + chart.getChartTitle().getSizeHint()); - g.setColor(chart.getStyleManager().getChartBordersColor()); + g.setColor(chart.getStyleManager().getLegendBorderColor()); g.drawRect(xOffset, yOffset, legendBoxWidth, legendBoxHeight); g.setColor(chart.getStyleManager().getLegendBackgroundColor()); g.fillRect(xOffset + 1, yOffset + 1, legendBoxWidth - 1, legendBoxHeight - 1); 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 ea5d9831..5080ecc9 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 @@ -15,7 +15,6 @@ */ package com.xeiam.xchart.internal.chartpart; -import java.awt.BasicStroke; import java.awt.Graphics2D; import java.awt.Rectangle; import java.awt.Stroke; @@ -31,9 +30,6 @@ public class PlotSurface implements ChartPart { /** parent */ private Plot plot; - /** the line style */ - private final Stroke stroke = new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 10.0f, new float[] { 3.0f, 3.0f }, 0.0f); - /** * Constructor * @@ -59,9 +55,15 @@ public class PlotSurface implements ChartPart { Rectangle backgroundRectangle = new Rectangle((int) bounds.getX() - 1, (int) bounds.getY(), (int) (bounds.getWidth()), (int) bounds.getHeight()); g.setColor(getChart().getStyleManager().getPlotBackgroundColor()); g.fill(backgroundRectangle); - Rectangle borderRectangle = new Rectangle((int) bounds.getX() - 1, (int) bounds.getY(), (int) (bounds.getWidth()), (int) bounds.getHeight()); - g.setColor(getChart().getStyleManager().getChartBordersColor()); - g.draw(borderRectangle); + + // paint plot border + if (getChart().getStyleManager().isPlotBorderVisible()) { + Rectangle borderRectangle = new Rectangle((int) bounds.getX() - 1, (int) bounds.getY(), (int) (bounds.getWidth()), (int) bounds.getHeight()); + g.setColor(getChart().getStyleManager().getPlotBorderColor()); + g.draw(borderRectangle); + } + + Stroke stroke = getChart().getStyleManager().getPlotGridLinesStroke(); // paint grid lines if (getChart().getStyleManager().isPlotGridLinesVisible()) { @@ -88,7 +90,7 @@ public class PlotSurface implements ChartPart { g.setColor(getChart().getStyleManager().getPlotGridLinesColor()); g.setStroke(stroke); - g.drawLine((int) (bounds.getX() + tickLocation - 1), (int) (bounds.getY() + 1), (int) (bounds.getX() + tickLocation - 1), (int) (bounds.getY() + bounds.getHeight() - 1)); + 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/style/ChartColor.java b/xchart/src/main/java/com/xeiam/xchart/style/ChartColor.java index 6dab696f..bce06330 100644 --- a/xchart/src/main/java/com/xeiam/xchart/style/ChartColor.java +++ b/xchart/src/main/java/com/xeiam/xchart/style/ChartColor.java @@ -28,13 +28,13 @@ public enum ChartColor { BLACK(new Color(0, 0, 0)), /** DARK_GREY */ - DARK_GREY(new Color(22, 22, 22)), + DARK_GREY(new Color(130, 130, 130)), /** GREY */ - GREY(new Color(200, 200, 200)), + GREY(new Color(210, 210, 210)), /** LIGHT_GREY */ - LIGHT_GREY(new Color(252, 252, 252)), + LIGHT_GREY(new Color(230, 230, 230)), /** WHITE */ WHITE(new Color(255, 255, 255)); diff --git a/xchart/src/main/java/com/xeiam/xchart/style/StyleManager.java b/xchart/src/main/java/com/xeiam/xchart/style/StyleManager.java index cccfe424..def9dc9f 100644 --- a/xchart/src/main/java/com/xeiam/xchart/style/StyleManager.java +++ b/xchart/src/main/java/com/xeiam/xchart/style/StyleManager.java @@ -23,6 +23,7 @@ package com.xeiam.xchart.style; import java.awt.Color; import java.awt.Font; +import java.awt.Stroke; import com.xeiam.xchart.style.theme.Theme; import com.xeiam.xchart.style.theme.XChartTheme; @@ -37,17 +38,20 @@ public class StyleManager { // Chart Style /////////////////////////////// private Color chartBackgroundColor; - public Color chartBordersColor; public Color chartFontColor; private int chartPadding; // Chart Title /////////////////////////////// private Font chartTitleFont; private boolean isChartTitleVisible; + private Color chartTitleBackgroundColor; + private Color chartTitleBorderColor; + private int chartTitlePadding; // Chart Legend /////////////////////////////// private boolean isLegendVisible; private Color legendBackgroundColor; + private Color legendBorderColor; private Font legendFont; private int legendPadding; @@ -57,9 +61,12 @@ public class StyleManager { private Font axisTitleFont; private boolean xAxisTicksVisible; private boolean yAxisTicksVisible; - private Font axisTicksFont; + private Font axisTickLabelsFont; private int axisTickMarkLength; private int axisTickPadding; + private Color axisTickMarksColor; + private Stroke axisTickMarksStroke; + private Color axisTickLabelsColor; private boolean isAxisTicksLineVisible; private int plotPadding; private int axisTitlePadding; @@ -67,7 +74,10 @@ public class StyleManager { // Chart Plot Area /////////////////////////////// private boolean isPlotGridLinesVisible; private Color plotBackgroundColor; + private Color plotBorderColor; + private boolean isPlotBorderVisible; private Color plotGridLinesColor; + private Stroke plotGridLinesStroke; // Error Bars /////////////////////////////// private Color errorBarsColor; @@ -84,17 +94,20 @@ public class StyleManager { // Chart Style /////////////////////////////// chartBackgroundColor = theme.getChartBackgroundColor(); - chartBordersColor = theme.getChartBordersColor(); chartFontColor = theme.getChartFontColor(); chartPadding = theme.getChartPadding(); // Chart Title /////////////////////////////// chartTitleFont = theme.getChartTitleFont(); isChartTitleVisible = theme.isChartTitleVisible(); + chartTitleBackgroundColor = theme.getChartTitleBackgroundColor(); + chartTitleBorderColor = theme.getChartTitleBorderColor(); + chartTitlePadding = theme.getChartTitlePadding(); // legend isLegendVisible = theme.isLegendVisible(); legendBackgroundColor = theme.getLegendBackgroundColor(); + legendBorderColor = theme.getLegendBorderColor(); legendFont = theme.getLegendFont(); legendPadding = theme.getLegendPadding(); @@ -104,9 +117,12 @@ public class StyleManager { axisTitleFont = theme.getAxisTitleFont(); xAxisTicksVisible = theme.isXAxisTicksVisible(); yAxisTicksVisible = theme.isYAxisTicksVisible(); - axisTicksFont = theme.getAxisTicksFont(); + axisTickLabelsFont = theme.getAxisTickLabelsFont(); axisTickMarkLength = theme.getAxisTickMarkLength(); axisTickPadding = theme.getAxisTickPadding(); + axisTickMarksColor = theme.getAxisTickMarksColor(); + axisTickMarksStroke = theme.getAxisTickMarksStroke(); + axisTickLabelsColor = theme.getAxisTickLabelsColor(); isAxisTicksLineVisible = theme.isAxisTicksLineVisible(); plotPadding = theme.getPlotPadding(); axisTitlePadding = theme.getAxisTitlePadding(); @@ -114,7 +130,10 @@ public class StyleManager { // Chart Plot Area /////////////////////////////// isPlotGridLinesVisible = theme.isPlotGridLinesVisible(); plotBackgroundColor = theme.getPlotBackgroundColor(); + plotBorderColor = theme.getPlotBorderColor(); + isPlotBorderVisible = theme.isPlotBorderVisible(); plotGridLinesColor = theme.getPlotGridLinesColor(); + plotGridLinesStroke = theme.getPlotGridLinesStroke(); // Error Bars /////////////////////////////// errorBarsColor = theme.getErrorBarsColor(); @@ -149,22 +168,7 @@ public class StyleManager { } /** - * Sets the color of the plot border, legend border, tick marks, and error bars - * - * @param color - */ - public void setChartBordersColor(Color color) { - - this.chartBordersColor = color; - } - - public Color getChartBordersColor() { - - return chartBordersColor; - } - - /** - * Set the chart font color + * Set the chart font color. includes: Chart title, axes label, legend * * @param color */ @@ -225,10 +229,55 @@ public class StyleManager { return isChartTitleVisible; } + /** + * set the chart title background color + * + * @param chartTitleBackgroundColor + */ + public void setChartTitleBackgroundColor(Color chartTitleBackgroundColor) { + + this.chartTitleBackgroundColor = chartTitleBackgroundColor; + } + + public Color getChartTitleBackgroundColor() { + + return chartTitleBackgroundColor; + } + + /** + * set the chart title border color + * + * @param chartTitleBorderColor + */ + public void setChartTitleBorderColor(Color chartTitleBorderColor) { + + this.chartTitleBorderColor = chartTitleBorderColor; + } + + public Color getChartTitleBorderColor() { + + return chartTitleBorderColor; + } + + /** + * set the chart title padding; the space between the chart title and the plot area + * + * @param chartTitlePadding + */ + public void setChartTitlePadding(int chartTitlePadding) { + + this.chartTitlePadding = chartTitlePadding; + } + + public int getChartTitlePadding() { + + return chartTitlePadding; + } + // Chart Legend /////////////////////////////// /** - * Set the chart legend color + * Set the chart legend background color * * @param color */ @@ -242,6 +291,21 @@ public class StyleManager { return legendBackgroundColor; } + /** + * Set the chart legend border color + * + * @return + */ + public Color getLegendBorderColor() { + + return legendBorderColor; + } + + public void setLegendBorderColor(Color legendBorderColor) { + + this.legendBorderColor = legendBorderColor; + } + /** * Set the chart legend font * @@ -395,14 +459,14 @@ public class StyleManager { * * @param foxAxisTicksFontnt */ - public void setAxisTicksFont(Font axisTicksFont) { + public void setAxisTickLabelsFont(Font axisTicksFont) { - this.axisTicksFont = axisTicksFont; + this.axisTickLabelsFont = axisTicksFont; } - public Font getAxisTicksFont() { + public Font getAxisTickLabelsFont() { - return axisTicksFont; + return axisTickLabelsFont; } /** @@ -421,7 +485,7 @@ public class StyleManager { } /** - * the padding between the tick labels and the tick marks + * sets the padding between the tick labels and the tick marks * * @param axisTickPadding */ @@ -435,6 +499,51 @@ public class StyleManager { return axisTickPadding; } + /** + * sets the axis tick mark color + * + * @param axisTickColor + */ + public void setAxisTickMarksColor(Color axisTickColor) { + + this.axisTickMarksColor = axisTickColor; + } + + public Color getAxisTickMarksColor() { + + return axisTickMarksColor; + } + + /** + * sets the axis tick marks Stroke + * + * @param axisTickMarksStroke + */ + public void setAxisTickMarksStroke(Stroke axisTickMarksStroke) { + + this.axisTickMarksStroke = axisTickMarksStroke; + } + + public Stroke getAxisTickMarksStroke() { + + return axisTickMarksStroke; + } + + /** + * sets the axis tick label color + * + * @param axisTickLabelsColor + */ + public void setAxisTickLabelsColor(Color axisTickLabelsColor) { + + this.axisTickLabelsColor = axisTickLabelsColor; + } + + public Color getAxisTickLabelsColor() { + + return axisTickLabelsColor; + } + /** * sets the visibility of the line parallel to the plot edges that go along with the tick marks * @@ -512,6 +621,36 @@ public class StyleManager { return plotBackgroundColor; } + /** + * set the plot area's border color + * + * @param plotBorderColor + */ + public void setPlotBorderColor(Color plotBorderColor) { + + this.plotBorderColor = plotBorderColor; + } + + public Color getPlotBorderColor() { + + return plotBorderColor; + } + + /** + * sets the visibility of the border around the plot area + * + * @param isPlotBorderVisible + */ + public void setPlotBorderVisible(boolean isPlotBorderVisible) { + + this.isPlotBorderVisible = isPlotBorderVisible; + } + + public boolean isPlotBorderVisible() { + + return isPlotBorderVisible; + } + /** * set the plot area's grid lines color * @@ -527,6 +666,21 @@ public class StyleManager { return plotGridLinesColor; } + /** + * set the plot area's grid lines Stroke + * + * @param plotGridLinesStroke + */ + public void setPlotGridLinesStroke(Stroke plotGridLinesStroke) { + + this.plotGridLinesStroke = plotGridLinesStroke; + } + + public Stroke getPlotGridLinesStroke() { + + return plotGridLinesStroke; + } + // Error Bars /////////////////////////////// /** diff --git a/xchart/src/main/java/com/xeiam/xchart/style/theme/GGPlot2Theme.java b/xchart/src/main/java/com/xeiam/xchart/style/theme/GGPlot2Theme.java new file mode 100644 index 00000000..05144636 --- /dev/null +++ b/xchart/src/main/java/com/xeiam/xchart/style/theme/GGPlot2Theme.java @@ -0,0 +1,253 @@ +/** + * 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.style.theme; + +import java.awt.BasicStroke; +import java.awt.Color; +import java.awt.Font; +import java.awt.Stroke; + +import com.xeiam.xchart.style.ChartColor; + +/** + * @author timmolter + */ +public class GGPlot2Theme 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.PLAIN, 14); + } + + @Override + public boolean isChartTitleVisible() { + + return false; + } + + @Override + public Color getChartTitleBackgroundColor() { + + return ChartColor.getAWTColor(ChartColor.GREY); + } + + @Override + public Color getChartTitleBorderColor() { + + return ChartColor.getAWTColor(ChartColor.GREY); + } + + @Override + public int getChartTitlePadding() { + + return 5; + } + + // Chart Legend /////////////////////////////// + + @Override + public Font getLegendFont() { + + return new Font(Font.SANS_SERIF, Font.PLAIN, 14); + } + + @Override + public boolean isLegendVisible() { + + return true; + } + + @Override + public Color getLegendBackgroundColor() { + + return ChartColor.getAWTColor(ChartColor.WHITE); + } + + @Override + public Color getLegendBorderColor() { + + return ChartColor.getAWTColor(ChartColor.WHITE); + } + + @Override + public int getLegendPadding() { + + return 10; + } + + // Chart Axes /////////////////////////////// + + @Override + public boolean isXAxisTitleVisible() { + + return false; + } + + @Override + public boolean isYAxisTitleVisible() { + + return false; + } + + @Override + public Font getAxisTitleFont() { + + return new Font(Font.SANS_SERIF, Font.PLAIN, 14); + } + + @Override + public boolean isXAxisTicksVisible() { + + return true; + } + + @Override + public boolean isYAxisTicksVisible() { + + return true; + } + + @Override + public Font getAxisTickLabelsFont() { + + return new Font(Font.SANS_SERIF, Font.BOLD, 13); + } + + @Override + public int getAxisTickMarkLength() { + + return 8; + } + + @Override + public int getAxisTickPadding() { + + return 5; + } + + @Override + public boolean isAxisTicksLineVisible() { + + return false; + } + + @Override + public int getPlotPadding() { + + return 0; + } + + @Override + public Color getAxisTickMarksColor() { + + return ChartColor.getAWTColor(ChartColor.DARK_GREY); + + } + + @Override + public Stroke getAxisTickMarksStroke() { + + return new BasicStroke(1.5f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL); + } + + @Override + public Color getAxisTickLabelsColor() { + + return ChartColor.getAWTColor(ChartColor.DARK_GREY); + } + + @Override + public int getAxisTitlePadding() { + + return 10; + } + + // Chart Plot Area /////////////////////////////// + + @Override + public boolean isPlotGridLinesVisible() { + + return true; + } + + @Override + public Color getPlotBackgroundColor() { + + return ChartColor.getAWTColor(ChartColor.LIGHT_GREY); + } + + @Override + public Color getPlotBorderColor() { + + return ChartColor.getAWTColor(ChartColor.WHITE); + } + + @Override + public boolean isPlotBorderVisible() { + + return false; + } + + @Override + public Color getPlotGridLinesColor() { + + return ChartColor.getAWTColor(ChartColor.WHITE); + } + + @Override + public Stroke getPlotGridLinesStroke() { + + return new BasicStroke(1.5f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL); + } + + // Error Bars /////////////////////////////// + + @Override + public Color getErrorBarsColor() { + + return ChartColor.getAWTColor(ChartColor.DARK_GREY); + } + +} diff --git a/xchart/src/main/java/com/xeiam/xchart/style/theme/Theme.java b/xchart/src/main/java/com/xeiam/xchart/style/theme/Theme.java index 0cac20f3..dd039e86 100644 --- a/xchart/src/main/java/com/xeiam/xchart/style/theme/Theme.java +++ b/xchart/src/main/java/com/xeiam/xchart/style/theme/Theme.java @@ -23,6 +23,7 @@ package com.xeiam.xchart.style.theme; import java.awt.Color; import java.awt.Font; +import java.awt.Stroke; /** * @author timmolter @@ -33,8 +34,6 @@ public interface Theme { public Color getChartBackgroundColor(); - public Color getChartBordersColor(); - public Color getChartFontColor(); public int getChartPadding(); @@ -45,6 +44,12 @@ public interface Theme { public boolean isChartTitleVisible(); + public Color getChartTitleBackgroundColor(); + + public Color getChartTitleBorderColor(); + + public int getChartTitlePadding(); + // Chart Legend /////////////////////////////// public Font getLegendFont(); @@ -53,6 +58,8 @@ public interface Theme { public Color getLegendBackgroundColor(); + public Color getLegendBorderColor(); + public int getLegendPadding(); // Chart Axes /////////////////////////////// @@ -67,12 +74,18 @@ public interface Theme { public boolean isYAxisTicksVisible(); - public Font getAxisTicksFont(); + public Font getAxisTickLabelsFont(); public int getAxisTickMarkLength(); public int getAxisTickPadding(); + public Color getAxisTickMarksColor(); + + public Stroke getAxisTickMarksStroke(); + + public Color getAxisTickLabelsColor(); + public boolean isAxisTicksLineVisible(); public int getAxisTitlePadding(); @@ -85,8 +98,14 @@ public interface Theme { public Color getPlotBackgroundColor(); + public Color getPlotBorderColor(); + + public boolean isPlotBorderVisible(); + public Color getPlotGridLinesColor(); + public Stroke getPlotGridLinesStroke(); + // Error Bars /////////////////////////////// public Color getErrorBarsColor(); diff --git a/xchart/src/main/java/com/xeiam/xchart/style/theme/XChartTheme.java b/xchart/src/main/java/com/xeiam/xchart/style/theme/XChartTheme.java index c8694e8b..03351c0d 100644 --- a/xchart/src/main/java/com/xeiam/xchart/style/theme/XChartTheme.java +++ b/xchart/src/main/java/com/xeiam/xchart/style/theme/XChartTheme.java @@ -21,8 +21,10 @@ */ package com.xeiam.xchart.style.theme; +import java.awt.BasicStroke; import java.awt.Color; import java.awt.Font; +import java.awt.Stroke; import com.xeiam.xchart.style.ChartColor; @@ -39,12 +41,6 @@ public class XChartTheme implements Theme { return ChartColor.getAWTColor(ChartColor.GREY); } - @Override - public Color getChartBordersColor() { - - return ChartColor.getAWTColor(ChartColor.DARK_GREY); - } - @Override public Color getChartFontColor() { @@ -71,6 +67,24 @@ public class XChartTheme implements Theme { return false; } + @Override + public Color getChartTitleBackgroundColor() { + + return ChartColor.getAWTColor(ChartColor.GREY); + } + + @Override + public Color getChartTitleBorderColor() { + + return ChartColor.getAWTColor(ChartColor.GREY); + } + + @Override + public int getChartTitlePadding() { + + return 5; + } + // Chart Legend /////////////////////////////// @Override @@ -88,7 +102,14 @@ public class XChartTheme implements Theme { @Override public Color getLegendBackgroundColor() { - return ChartColor.getAWTColor(ChartColor.LIGHT_GREY); + return ChartColor.getAWTColor(ChartColor.WHITE); + + } + + @Override + public Color getLegendBorderColor() { + + return ChartColor.getAWTColor(ChartColor.DARK_GREY); } @Override @@ -130,7 +151,7 @@ public class XChartTheme implements Theme { } @Override - public Font getAxisTicksFont() { + public Font getAxisTickLabelsFont() { return new Font(Font.SANS_SERIF, Font.BOLD, 12); } @@ -147,6 +168,24 @@ public class XChartTheme implements Theme { return 4; } + @Override + public Color getAxisTickMarksColor() { + + return ChartColor.getAWTColor(ChartColor.DARK_GREY); + } + + @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() { @@ -176,7 +215,19 @@ public class XChartTheme implements Theme { @Override public Color getPlotBackgroundColor() { - return ChartColor.getAWTColor(ChartColor.LIGHT_GREY); + return ChartColor.getAWTColor(ChartColor.WHITE); + } + + @Override + public Color getPlotBorderColor() { + + return ChartColor.getAWTColor(ChartColor.DARK_GREY); + } + + @Override + public boolean isPlotBorderVisible() { + + return true; } @Override @@ -185,6 +236,12 @@ public class XChartTheme implements Theme { return ChartColor.getAWTColor(ChartColor.GREY); } + @Override + public Stroke getPlotGridLinesStroke() { + + return new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 10.0f, new float[] { 3.0f, 3.0f }, 0.0f); + } + // Error Bars /////////////////////////////// @Override diff --git a/xchart-demo/src/main/java/com/xeiam/xchart/example/Example0.java b/xchart/src/test/java/com/xeiam/xchart/chart/Example0.java similarity index 97% rename from xchart-demo/src/main/java/com/xeiam/xchart/example/Example0.java rename to xchart/src/test/java/com/xeiam/xchart/chart/Example0.java index 142f568d..3708c8d0 100644 --- a/xchart-demo/src/main/java/com/xeiam/xchart/example/Example0.java +++ b/xchart/src/test/java/com/xeiam/xchart/chart/Example0.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.xeiam.xchart.example; +package com.xeiam.xchart.chart; import com.xeiam.xchart.BitmapEncoder; import com.xeiam.xchart.Chart; diff --git a/xchart-demo/src/main/java/com/xeiam/xchart/example/Example1.java b/xchart/src/test/java/com/xeiam/xchart/chart/Example1.java similarity index 97% rename from xchart-demo/src/main/java/com/xeiam/xchart/example/Example1.java rename to xchart/src/test/java/com/xeiam/xchart/chart/Example1.java index e47de08f..1e8f7128 100644 --- a/xchart-demo/src/main/java/com/xeiam/xchart/example/Example1.java +++ b/xchart/src/test/java/com/xeiam/xchart/chart/Example1.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.xeiam.xchart.example; +package com.xeiam.xchart.chart; import com.xeiam.xchart.BitmapEncoder; import com.xeiam.xchart.Chart; diff --git a/xchart-demo/src/main/java/com/xeiam/xchart/example/Example2.java b/xchart/src/test/java/com/xeiam/xchart/chart/Example2.java similarity index 98% rename from xchart-demo/src/main/java/com/xeiam/xchart/example/Example2.java rename to xchart/src/test/java/com/xeiam/xchart/chart/Example2.java index 4006d587..2a8f4b25 100644 --- a/xchart-demo/src/main/java/com/xeiam/xchart/example/Example2.java +++ b/xchart/src/test/java/com/xeiam/xchart/chart/Example2.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.xeiam.xchart.example; +package com.xeiam.xchart.chart; import java.util.ArrayList; import java.util.List; diff --git a/xchart/src/test/java/com/xeiam/xchart/chart/LineChart05.java b/xchart/src/test/java/com/xeiam/xchart/chart/LineChart05.java new file mode 100644 index 00000000..5981ceb1 --- /dev/null +++ b/xchart/src/test/java/com/xeiam/xchart/chart/LineChart05.java @@ -0,0 +1,44 @@ +/** + * 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.chart; + +import com.xeiam.xchart.Chart; +import com.xeiam.xchart.LineChart; +import com.xeiam.xchart.SwingWrapper; + +/** + * Vertical and horizontal lines + * + * @author timmolter + */ +public class LineChart05 { + + public static void main(String[] args) { + + // Create Chart + Chart chart = new LineChart(800, 600); + + // Customize Chart + chart.setChartTitle("LineChart05"); + chart.setXAxisTitle("X"); + chart.setYAxisTitle("Y"); + + chart.addSeries("vertical", new double[] { 1, 1 }, new double[] { -10, 10 }); + chart.addSeries("horizontal", new double[] { -10, 10 }, new double[] { 0, 0 }); + new SwingWrapper(chart).displayChart(); + } + +} diff --git a/xchart/src/test/java/com/xeiam/xchart/chart/LineChart06.java b/xchart/src/test/java/com/xeiam/xchart/chart/LineChart06.java new file mode 100644 index 00000000..7d1deabd --- /dev/null +++ b/xchart/src/test/java/com/xeiam/xchart/chart/LineChart06.java @@ -0,0 +1,44 @@ +/** + * 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.chart; + +import com.xeiam.xchart.Chart; +import com.xeiam.xchart.LineChart; +import com.xeiam.xchart.SwingWrapper; + +/** + * Single point + * + * @author timmolter + */ +public class LineChart06 { + + public static void main(String[] args) { + + // Create Chart + Chart chart = new LineChart(800, 600); + + // Customize Chart + chart.setChartTitle("LineChart06"); + chart.setXAxisTitle("X"); + chart.setYAxisTitle("Y"); + + chart.addSeries("single point (1,1)", new double[] { 1 }, new double[] { 1 }); + + new SwingWrapper(chart).displayChart(); + } + +} diff --git a/xchart/src/test/java/com/xeiam/xchart/chart/NoBug.java b/xchart/src/test/java/com/xeiam/xchart/chart/NoBug.java new file mode 100644 index 00000000..0fae2dd0 --- /dev/null +++ b/xchart/src/test/java/com/xeiam/xchart/chart/NoBug.java @@ -0,0 +1,69 @@ +/** + * 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.chart; + +import java.util.ArrayList; +import java.util.List; + +import com.xeiam.xchart.Chart; +import com.xeiam.xchart.LineChart; +import com.xeiam.xchart.SwingWrapper; +import com.xeiam.xchart.style.Series; + +/** + * @author timmolter + */ +public class NoBug { + + static void plot(Chart chart, int n) { + + chart.setChartTitle("title"); + chart.setXAxisTitle("X"); + chart.setYAxisTitle("Y"); + List<Number> x = new ArrayList<Number>(); + List<Number> y = new ArrayList<Number>(); + String seriesName = addOneSeries(chart, n, x, y); + } + + private static String addOneSeries(Chart chart, int n, List<Number> x, List<Number> y) { + + for (int i = 0; i <= 10; i++) { + x.add(i / 10.); + y.add(i * n / 10.); + } + String seriesName = "series " + n; + Series series = chart.addSeries(seriesName, x, y); + chart.setxAxisMinMax(0, 1); + chart.setyAxisMinMax(-5, 5); + return seriesName; + } + + public static void main(String[] args) { + + for (int i = 0; i < 4; i++) { + Chart chart = new LineChart(700, 500); + plot(chart, i); + new SwingWrapper(chart).displayChart(); + } + } + +} diff --git a/xchart/src/test/java/com/xeiam/xchart/ValueFormatterTest.java b/xchart/src/test/java/com/xeiam/xchart/unit/ValueFormatterTest.java similarity index 99% rename from xchart/src/test/java/com/xeiam/xchart/ValueFormatterTest.java rename to xchart/src/test/java/com/xeiam/xchart/unit/ValueFormatterTest.java index 3c266f11..3c501749 100644 --- a/xchart/src/test/java/com/xeiam/xchart/ValueFormatterTest.java +++ b/xchart/src/test/java/com/xeiam/xchart/unit/ValueFormatterTest.java @@ -19,7 +19,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package com.xeiam.xchart; +package com.xeiam.xchart.unit; import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.MatcherAssert.assertThat; -- GitLab