From 61a1278c403c1c7cca6df417036d6ba381b34d15 Mon Sep 17 00:00:00 2001 From: Tim Molter <tim.molter@gmail.com> Date: Sun, 10 Feb 2013 18:25:54 +0100 Subject: [PATCH] cleaned up Series --- .../xchart/internal/chartpart/AxisPair.java | 8 +- .../xchart/internal/chartpart/Legend.java | 16 ++-- .../internal/chartpart/PlotContent.java | 18 ++-- .../java/com/xeiam/xchart/style/Series.java | 83 ++++++++++++++++--- 4 files changed, 92 insertions(+), 33 deletions(-) diff --git a/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/AxisPair.java b/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/AxisPair.java index b01b0322..132373e8 100644 --- a/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/AxisPair.java +++ b/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/AxisPair.java @@ -105,17 +105,17 @@ public class AxisPair implements ChartPart { // Sanity check if (xData != null && xData.size() != yData.size()) { - throw new IllegalArgumentException("X and Y-Axis sizes are not the same!!! "); + throw new IllegalArgumentException("X and Y-Axis sizes are not the same!!!"); } if (errorBars != null && errorBars.size() != yData.size()) { - throw new IllegalArgumentException("errorbars and Y-Axis sizes are not the same!!! "); + throw new IllegalArgumentException("errorbars and Y-Axis sizes are not the same!!!"); } seriesMap.put(seriesCount++, series); // add min/max to axis - xAxis.addMinMax(series.xMin, series.xMax); - yAxis.addMinMax(series.yMin, series.yMax); + xAxis.addMinMax(series.getxMin(), series.getxMax()); + yAxis.addMinMax(series.getyMin(), series.getyMax()); return series; } 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 72bedb43..24d8739f 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 @@ -62,7 +62,7 @@ public class Legend implements ChartPart { for (Integer seriesId : seriesMap.keySet()) { Series series = seriesMap.get(seriesId); - TextLayout textLayout = new TextLayout(series.name, chart.getStyleManager().getLegendFont(), new FontRenderContext(null, true, false)); + TextLayout textLayout = new TextLayout(series.getName(), chart.getStyleManager().getLegendFont(), new FontRenderContext(null, true, false)); Rectangle rectangle = textLayout.getPixelBounds(null, 0, 0); // System.out.println(rectangle); if (rectangle.getWidth() > legendTextContentMaxWidth) { @@ -98,20 +98,20 @@ public class Legend implements ChartPart { for (Integer seriesId : seriesMap.keySet()) { Series series = seriesMap.get(seriesId); // paint line - if (series.stroke != null) { - g.setColor(series.strokeColor); - g.setStroke(series.stroke); + if (series.getStroke() != null) { + g.setColor(series.getStrokeColor()); + g.setStroke(series.getStroke()); g.drawLine(startx, starty - Marker.Y_OFFSET, (int) (startx + Marker.SIZE * 3.0), starty - Marker.Y_OFFSET); } // paint marker - if (series.marker != null) { - g.setColor(series.markerColor); - series.marker.paint(g, (int) (startx + (Marker.SIZE * 1.5)), starty - Marker.Y_OFFSET); + if (series.getMarker() != null) { + g.setColor(series.getMarkerColor()); + series.getMarker().paint(g, (int) (startx + (Marker.SIZE * 1.5)), starty - Marker.Y_OFFSET); } // paint series name g.setColor(chart.getStyleManager().getChartFontColor()); - TextLayout layout = new TextLayout(series.name, chart.getStyleManager().getLegendFont(), new FontRenderContext(null, true, false)); + TextLayout layout = new TextLayout(series.getName(), chart.getStyleManager().getLegendFont(), new FontRenderContext(null, true, false)); layout.draw(g, (float) (startx + Marker.SIZE + (Marker.SIZE * 1.5) + chart.getStyleManager().getLegendPadding()), (starty + Marker.SIZE)); starty = starty + legendTextContentMaxHeight + chart.getStyleManager().getLegendPadding(); } diff --git a/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/PlotContent.java b/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/PlotContent.java index c9951921..c70b31f3 100644 --- a/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/PlotContent.java +++ b/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/PlotContent.java @@ -77,13 +77,13 @@ public class PlotContent implements ChartPart { int yTopMargin = AxisPair.getTickStartOffset((int) bounds.getHeight(), yTickSpace); // data points - Collection<?> xData = series.xData; + Collection<?> xData = series.getxData(); BigDecimal xMin = getChart().getAxisPair().getxAxis().getMin(); BigDecimal xMax = getChart().getAxisPair().getxAxis().getMax(); - Collection<Number> yData = series.yData; + Collection<Number> yData = series.getyData(); BigDecimal yMin = getChart().getAxisPair().getyAxis().getMin(); BigDecimal yMax = getChart().getAxisPair().getyAxis().getMax(); - Collection<Number> errorBars = series.errorBars; + Collection<Number> errorBars = series.getErrorBars(); int previousX = Integer.MIN_VALUE; int previousY = Integer.MIN_VALUE; @@ -133,10 +133,10 @@ public class PlotContent implements ChartPart { // System.out.println(yTransform); // paint line - if (series.stroke != null && !isScatterChart) { + if (series.getStroke() != null && !isScatterChart) { if (previousX != Integer.MIN_VALUE && previousY != Integer.MIN_VALUE) { - g.setColor(series.strokeColor); - g.setStroke(series.stroke); + g.setColor(series.getStrokeColor()); + g.setStroke(series.getStroke()); g.drawLine(previousX, previousY, xOffset, yOffset); } previousX = xOffset; @@ -144,9 +144,9 @@ public class PlotContent implements ChartPart { } // paint marker - if (series.marker != null) { - g.setColor(series.markerColor); - series.marker.paint(g, xOffset, yOffset); + if (series.getMarker() != null) { + g.setColor(series.getMarkerColor()); + series.getMarker().paint(g, xOffset, yOffset); } // paint errorbar diff --git a/xchart/src/main/java/com/xeiam/xchart/style/Series.java b/xchart/src/main/java/com/xeiam/xchart/style/Series.java index 030f099a..a8a86408 100644 --- a/xchart/src/main/java/com/xeiam/xchart/style/Series.java +++ b/xchart/src/main/java/com/xeiam/xchart/style/Series.java @@ -32,37 +32,37 @@ import com.xeiam.xchart.internal.markers.Marker; */ public class Series { - public String name = ""; + private String name = ""; - public Collection<?> xData; + private Collection<?> xData; - public Collection<Number> yData; + private Collection<Number> yData; - public Collection<Number> errorBars; + private Collection<Number> errorBars; /** the minimum value of axis range */ - public BigDecimal xMin; + private BigDecimal xMin; /** the maximum value of axis range */ - public BigDecimal xMax; + private BigDecimal xMax; /** the minimum value of axis range */ - public BigDecimal yMin; + private BigDecimal yMin; /** the maximum value of axis range */ - public BigDecimal yMax; + private BigDecimal yMax; /** Line Style */ - public BasicStroke stroke; + private BasicStroke stroke; /** Line Color */ - public Color strokeColor; + private Color strokeColor; /** Marker Style */ - public Marker marker; + private Marker marker; /** Marker Color */ - public Color markerColor; + private Color markerColor; /** * Constructor @@ -234,4 +234,63 @@ public class Series { this.markerColor = color; } + public Collection<?> getxData() { + + return xData; + } + + public Collection<Number> getyData() { + + return yData; + } + + public Collection<Number> getErrorBars() { + + return errorBars; + } + + public BigDecimal getxMin() { + + return xMin; + } + + public BigDecimal getxMax() { + + return xMax; + } + + public BigDecimal getyMin() { + + return yMin; + } + + public BigDecimal getyMax() { + + return yMax; + } + + public BasicStroke getStroke() { + + return stroke; + } + + public Marker getMarker() { + + return marker; + } + + public Color getStrokeColor() { + + return strokeColor; + } + + public Color getMarkerColor() { + + return markerColor; + } + + public String getName() { + + return name; + } } -- GitLab