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 51815b690c5e6ff365cc4e22c47901db1acac552..cfe44b64d3c39d146d1924813ecb953b57a0f632 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 c84f1b9aa4b393ae13621b7a43e29c23f95fbc85..72c3b9ce22916a2dfc662988832f594a8f7f1291 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 a76c69dfc6f8526f1b28c950911f5816b70f103d..70b276295577efc79db46bcfc8e2397c022d479e 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 efc9b7b386b29a70e78dc136af6bc7f2512d1fbe..6b76afb1b8765e587da6c6a7a03518abd88c57f7 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 ff22f9c4368e85afcd18ef661cd3c6bc9d0a6976..433eb26a74c1d1d456efa2a659ceda746fbf8d9c 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 ab0f61dd782615c9ad9d505eb159e3ddd199ba53..8e741ab718fd0cf11287087c30124678f9920335 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 2506a99d77bb5c421c1c644cb2fe6f96257f699e..4516337b8e1cd999c169aa0745cc27b820d05b25 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 d7926a1ddeb84f81ca8970cb6ad9ff27be5e4d74..7c1ea138799e232158483f6a2f584057f31d7714 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 7be60a669aecf0fcfa79dc1b70e3ed2c35b49460..46a619c359646410695967487984a6434d85fa6c 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 4dfd9c351fe457ae8a12622934f111fc9595bda0..929eee301bd9602b6ce1e2084d6d8acb4c4e0806 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 690ce8f318523b91061dee4f7758297f6ba6b127..6c809dc5f72ee296f10b28032e0d545ae54ae525 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 c720a405a82792c35445d24cf2a4275c75f8a41f..4d8c2a6db755ea96f7779e4020d7bd60012b9076 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 5a73a66edd82f9ef198c5813c25271f358413ebf..68c60199b026cba11bc8a9841dd57dcd36e476fd 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 90a8719922eaf23e0a8518bdebbaaeb49497a0b1..2cbabd21c5129574478ddd9cd9fe51a2e1d1e045 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 4e23f8905e8d1393ef1febe8adbb1be86a024852..d86526cb4b1908de5903156ea3bfb0e252bf9c9c 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 22e3c75b379bc635278f09c99c7a1556761d1ee8..5ac128bbeea8791e1f2e97fca46be0729b6d3be4 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 b3ac07c1fd61897e5c002b4b12c7113989e317e3..c423c03491f5dc760216abf9f6355b880d85a984 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 ea5d9831d7d2db4ec72a0ba8fb2d6d73bb3bfc25..5080ecc92a873da97c9d365f968f8ef165f8e18c 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 6dab696f395f422869662ac03367cb5462778642..bce06330460f8c30279c72bb3b35987ae146395e 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 cccfe42482d4875f45f4c311f4e81cc6ac974d99..def9dc9f4be314630d1badac4589441fc6164420 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 0000000000000000000000000000000000000000..05144636fe4a5910a235c6657389f5b66bbd76df --- /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 0cac20f37ef42b4c27590bb3bfb67b52a49ca193..dd039e861cc6f274555a5f0bd3ef7633dba7d9ee 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 c8694e8b28c839bed9b57b1bb59f88e3b2408914..03351c0d479ea60586c7f80cd054dc6dfb470472 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 142f568d987b98570fba5863b0adf8571a4195e3..3708c8d0c4adbbe29dbeecb954af4664c1679952 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 e47de08fb811475ef5fe7684f3f14ad0e970569e..1e8f7128d85d225d1523c0086027804ef3a6a302 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 4006d587bbcde7e6197d72c78e936941beb95df6..2a8f4b2598d061fc856275062ae33ed4ed5a7865 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 0000000000000000000000000000000000000000..5981ceb13d9de17ef4331d4af2d5848e84c8af0c --- /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 0000000000000000000000000000000000000000..7d1deabdc2fd2340c5c2ea4a7431fb37cd190cbe --- /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 0000000000000000000000000000000000000000..0fae2dd04c9fb9cdc59ba44d8ee9ec6fd73508ac --- /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 3c266f11e344905fd8f9c4c8b3aab6b96c422594..3c501749fe4e0d6c2eaa4b05b0ff5230380944b8 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;