Mercurial > dive4elements > river
changeset 9182:77eb4553245b
Fixed: waterlevels could not show a band any more
Correctly implemented 'showarea' on area themes now
author | gernotbelger |
---|---|
date | Tue, 26 Jun 2018 20:19:16 +0200 |
parents | 5dacb6ea75a1 |
children | 65543c75bfbb |
files | artifacts/src/main/java/org/dive4elements/river/jfree/StableXYDifferenceRenderer.java artifacts/src/main/java/org/dive4elements/river/jfree/StyledAreaSeriesCollection.java |
diffstat | 2 files changed, 652 insertions(+), 863 deletions(-) [+] |
line wrap: on
line diff
--- a/artifacts/src/main/java/org/dive4elements/river/jfree/StableXYDifferenceRenderer.java Tue Jun 26 20:18:18 2018 +0200 +++ b/artifacts/src/main/java/org/dive4elements/river/jfree/StableXYDifferenceRenderer.java Tue Jun 26 20:19:16 2018 +0200 @@ -87,23 +87,26 @@ import java.awt.BasicStroke; import java.awt.Color; -import java.awt.Graphics2D; import java.awt.Font; +import java.awt.Graphics2D; import java.awt.Paint; -import java.awt.geom.Point2D; import java.awt.Shape; import java.awt.Stroke; import java.awt.geom.GeneralPath; import java.awt.geom.Line2D; +import java.awt.geom.Point2D; import java.awt.geom.Rectangle2D; import java.io.IOException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; +import java.text.NumberFormat; import java.util.ArrayList; import java.util.Collections; import java.util.LinkedList; import java.util.List; +import org.apache.log4j.Logger; +import org.dive4elements.river.artifacts.math.Linear; import org.jfree.chart.LegendItem; import org.jfree.chart.axis.ValueAxis; import org.jfree.chart.entity.EntityCollection; @@ -114,50 +117,42 @@ import org.jfree.chart.plot.PlotOrientation; import org.jfree.chart.plot.PlotRenderingInfo; import org.jfree.chart.plot.XYPlot; +import org.jfree.chart.renderer.xy.AbstractXYItemRenderer; +import org.jfree.chart.renderer.xy.XYItemRendererState; import org.jfree.chart.urls.XYURLGenerator; +import org.jfree.data.xy.DefaultXYDataset; import org.jfree.data.xy.XYDataset; -import org.jfree.data.xy.DefaultXYDataset; import org.jfree.io.SerialUtilities; import org.jfree.ui.RectangleEdge; import org.jfree.util.PaintUtilities; import org.jfree.util.PublicCloneable; import org.jfree.util.ShapeUtilities; -import org.jfree.chart.renderer.xy.AbstractXYItemRenderer; -import org.jfree.chart.renderer.xy.XYItemRenderer; -import org.jfree.chart.renderer.xy.XYItemRendererState; - import gnu.trove.TDoubleArrayList; -import org.dive4elements.river.artifacts.math.Linear; - -import java.text.NumberFormat; - -import org.apache.log4j.Logger; - /** * A renderer for an {@link XYPlot} that highlights the differences between two - * series. The example shown here is generated by the + * series. The example shown here is generated by the * <code>DifferenceChartDemo1.java</code> program included in the JFreeChart * demo collection: - * <br><br> + * <br> + * <br> * <img src="../../../../../images/StableXYDifferenceRendererSample.png" * alt="StableXYDifferenceRendererSample.png" /> */ -public class StableXYDifferenceRenderer extends AbstractXYItemRenderer - implements XYItemRenderer, PublicCloneable { +public class StableXYDifferenceRenderer extends AbstractXYItemRenderer implements PublicCloneable { - private static Logger log = Logger.getLogger( - StableXYDifferenceRenderer.class); + private static Logger log = Logger.getLogger(StableXYDifferenceRenderer.class); public static final int CALCULATE_POSITIVE_AREA = 1; public static final int CALCULATE_NEGATIVE_AREA = 2; - public static final int CALCULATE_ALL_AREA = - CALCULATE_POSITIVE_AREA | CALCULATE_NEGATIVE_AREA; + public static final int CALCULATE_ALL_AREA = CALCULATE_POSITIVE_AREA | CALCULATE_NEGATIVE_AREA; /** For serialization. */ private static final long serialVersionUID = -8447915602375584857L; + private boolean drawArea = true; + /** The paint used to highlight positive differences (y(0) > y(1)). */ private transient Paint positivePaint; @@ -168,225 +163,160 @@ private boolean shapesVisible; /** Display shapes at each point? */ - protected boolean drawOutline; + private boolean drawOutline; /** Which stroke to draw outline with? */ - protected Stroke outlineStroke; + private Stroke outlineStroke; /** Which paint to draw outline with? */ - protected Paint outlinePaint; + private Paint outlinePaint; /** The shape to display in the legend item. */ private transient Shape legendShape; - protected boolean drawOriginalSeries; + private final boolean drawOriginalSeries; /** The color of the label showing the calculated area. */ - protected Color labelColor; + private Color labelColor; /** The background color of the label showing the calculated area. */ - protected Color labelBGColor; + private Color labelBGColor; /** Font to draw label of calculated area with. */ - protected Font labelFont; + private Font labelFont; /** Template to create i18ned label for area. */ - protected String areaLabelTamplate; + private String areaLabelTamplate; /** NumberFormat to use for area. */ - protected NumberFormat areaLabelNumberFormat; + private NumberFormat areaLabelNumberFormat; - protected int areaCalculationMode; + private int areaCalculationMode; - protected double positiveArea; - protected double negativeArea; + private double positiveArea; + + private double negativeArea; /** Whether or not to draw a label in the area. */ - protected boolean labelArea = true; - + private boolean labelArea = true; /** Arithmetic centroid of drawn polygons. */ - protected Point2D.Double centroid; - + private Point2D.Double centroid; /** Number of points that contributed to the centroid. */ - protected int centroidNPoints = 0; - + private int centroidNPoints = 0; /** * This flag controls whether or not the x-coordinates (in Java2D space) - * are rounded to integers. When set to true, this can avoid the vertical - * striping that anti-aliasing can generate. However, the rounding may not + * are rounded to integers. When set to true, this can avoid the vertical + * striping that anti-aliasing can generate. However, the rounding may not * be appropriate for output in high resolution formats (for example, * vector graphics formats such as SVG and PDF). * * @since 1.0.4 */ - private boolean roundXCoordinates; + private final boolean roundXCoordinates; /** * Creates a new renderer with default attributes. */ public StableXYDifferenceRenderer() { - this(Color.green, Color.red, false /*, null */); - } - - public StableXYDifferenceRenderer(Paint positivePaint, Paint negativePaint, - boolean shapes) { - this(positivePaint, negativePaint, shapes, CALCULATE_ALL_AREA); + this(Color.green, Color.red, false, CALCULATE_ALL_AREA); } /** * Creates a new renderer. * - * @param positivePaint the highlight color for positive differences - * (<code>null</code> not permitted). - * @param negativePaint the highlight color for negative differences - * (<code>null</code> not permitted). - * @param shapes draw shapes? + * @param positivePaint + * the highlight color for positive differences + * (<code>null</code> not permitted). + * @param negativePaint + * the highlight color for negative differences + * (<code>null</code> not permitted). + * @param shapes + * draw shapes? */ - public StableXYDifferenceRenderer(Paint positivePaint, Paint negativePaint, - boolean shapes, int areaCalculationMode) { + private StableXYDifferenceRenderer(final Paint positivePaint, final Paint negativePaint, final boolean shapes, final int areaCalculationMode) { if (positivePaint == null) { - throw new IllegalArgumentException( - "Null 'positivePaint' argument."); + throw new IllegalArgumentException("Null 'positivePaint' argument."); } if (negativePaint == null) { - throw new IllegalArgumentException( - "Null 'negativePaint' argument."); + throw new IllegalArgumentException("Null 'negativePaint' argument."); } this.positivePaint = positivePaint; this.negativePaint = negativePaint; this.shapesVisible = shapes; - this.legendShape = new Rectangle2D.Double(-3.0, -3.0, 10.0, 10.0); + this.legendShape = new Rectangle2D.Double(-3.0, -3.0, 10.0, 10.0); this.roundXCoordinates = false; - this.drawOutline = true; + this.drawOutline = true; this.outlineStroke = new BasicStroke(1); - this.outlinePaint = Color.black; + this.outlinePaint = Color.black; this.drawOriginalSeries = false; this.areaCalculationMode = areaCalculationMode; - this.labelBGColor = null; - this.centroid = new Point2D.Double(0,0); + this.labelBGColor = null; + this.centroid = new Point2D.Double(0, 0); } - public int getAreaCalculationMode() { - return areaCalculationMode; - } - - public void setAreaCalculationMode(int areaCalculationMode) { + public void setAreaCalculationMode(final int areaCalculationMode) { this.areaCalculationMode = areaCalculationMode; } - /** Set template to use to create area label (e.g. 'Area=%dm2'). */ - public void setAreaLabelTemplate(String areaTemplate) { + public void setAreaLabelTemplate(final String areaTemplate) { this.areaLabelTamplate = areaTemplate; } - - public void setAreaLabelNumberFormat(NumberFormat nf) { + public void setAreaLabelNumberFormat(final NumberFormat nf) { this.areaLabelNumberFormat = nf; } - - public boolean isLabelArea() { - return this.labelArea; - } - - public void setLabelArea(boolean label) { + public void setLabelArea(final boolean label) { this.labelArea = label; } - /** Set font to paint label with. */ - public void setLabelFont(Font font) { + public void setLabelFont(final Font font) { this.labelFont = font; } - - /** Get font with which label is painted. */ - public Font getLabelFont() { - return this.labelFont; - } - - /** Set color with which to paint label. */ - public void setLabelColor(Color color) { + public void setLabelColor(final Color color) { this.labelColor = color; } - - /** Get color with which label is painted. */ - public Color getLabelColor() { - return this.labelColor; - } - - /** Set color with which to paint label bg. */ - public void setLabelBGColor(Color color) { + public void setLabelBGColor(final Color color) { this.labelBGColor = color; } - - /** Get color with which label is painted. */ - public Color getLabelBGColor() { - return this.labelBGColor; - } - - - public double getCalculatedArea() { - return positiveArea + negativeArea; - } - /** * Sets color that is used if drawOutline is true. */ - public void setOutlinePaint(Paint outlinePaint) { + @Override + public void setOutlinePaint(final Paint outlinePaint) { this.outlinePaint = outlinePaint; } - - /** - * Gets color which is used if drawOutline is true. - */ - public Paint getOutlinePaint() { - return this.outlinePaint; - } - - /** * Sets Stroke that is used if drawOutline is true. */ - public void setOutlineStroke(Stroke stroke) { + @Override + public void setOutlineStroke(final Stroke stroke) { this.outlineStroke = stroke; } - - /** - * Returns Stroke that is used if drawOutline is true. - */ - public Stroke getOutlineStroke() { - return this.outlineStroke; - } - - /** * Whether or not to draw the 'Shape' of the area (in contrast to * shapes at data items). */ - public void setDrawOutline(boolean doDrawOutline) { + public void setDrawOutline(final boolean doDrawOutline) { this.drawOutline = doDrawOutline; } - - /** - * Returns whether or not to draw the shape of the outline. - */ - public boolean getDrawOutline() { - return this.drawOutline; + public void setDrawArea(final boolean doDrawArea) { + this.drawArea = doDrawArea; } - /** * Returns the paint used to highlight positive differences. * @@ -394,7 +324,7 @@ * * @see #setPositivePaint(Paint) */ - public Paint getPositivePaint() { + private Paint getPositivePaint() { return this.positivePaint; } @@ -402,11 +332,12 @@ * Sets the paint used to highlight positive differences and sends a * {@link RendererChangeEvent} to all registered listeners. * - * @param paint the paint (<code>null</code> not permitted). + * @param paint + * the paint (<code>null</code> not permitted). * * @see #getPositivePaint() */ - public void setPositivePaint(Paint paint) { + public void setPositivePaint(final Paint paint) { this.positivePaint = paint; fireChangeEvent(); } @@ -418,18 +349,19 @@ * * @see #setNegativePaint(Paint) */ - public Paint getNegativePaint() { + private Paint getNegativePaint() { return this.negativePaint; } /** * Sets the paint used to highlight negative differences. * - * @param paint the paint (<code>null</code> not permitted). + * @param paint + * the paint (<code>null</code> not permitted). * * @see #getNegativePaint() */ - public void setNegativePaint(Paint paint) { + public void setNegativePaint(final Paint paint) { this.negativePaint = paint; notifyListeners(new RendererChangeEvent(this)); } @@ -442,7 +374,7 @@ * * @see #setShapesVisible(boolean) */ - public boolean getShapesVisible() { + private boolean getShapesVisible() { return this.shapesVisible; } @@ -451,11 +383,12 @@ * data value, and sends a {@link RendererChangeEvent} to all registered * listeners. * - * @param flag the flag. + * @param flag + * the flag. * * @see #getShapesVisible() */ - public void setShapesVisible(boolean flag) { + public void setShapesVisible(final boolean flag) { this.shapesVisible = flag; fireChangeEvent(); } @@ -467,80 +400,36 @@ * * @see #setLegendLine(Shape) */ - public Shape getLegendLine() { + private Shape getLegendLine() { return this.legendShape; } /** - * Sets the shape used as a line in each legend item and sends a - * {@link RendererChangeEvent} to all registered listeners. - * - * @param line the line (<code>null</code> not permitted). - * - * @see #getLegendLine() - */ - public void setLegendLine(Shape line) { - if (line == null) { - throw new IllegalArgumentException("Null 'line' argument."); - } - this.legendShape = line; - fireChangeEvent(); - } - - /** - * Returns the flag that controls whether or not the x-coordinates (in - * Java2D space) are rounded to integer values. - * - * @return The flag. - * - * @since 1.0.4 - * - * @see #setRoundXCoordinates(boolean) - */ - public boolean getRoundXCoordinates() { - return this.roundXCoordinates; - } - - /** - * Sets the flag that controls whether or not the x-coordinates (in - * Java2D space) are rounded to integer values, and sends a - * {@link RendererChangeEvent} to all registered listeners. - * - * @param round the new flag value. - * - * @since 1.0.4 - * - * @see #getRoundXCoordinates() - */ - public void setRoundXCoordinates(boolean round) { - this.roundXCoordinates = round; - fireChangeEvent(); - } - - /** - * Initialises the renderer and returns a state object that should be - * passed to subsequent calls to the drawItem() method. This method will + * Initializes the renderer and returns a state object that should be + * passed to subsequent calls to the drawItem() method. This method will * be called before the first item is rendered, giving the renderer an - * opportunity to initialise any state information it wants to maintain. + * opportunity to initialize any state information it wants to maintain. * The renderer can do nothing if it chooses. * - * @param g2 the graphics device. - * @param dataArea the (visible) area inside the axes. - * @param plot the plot. - * @param data the data. - * @param info an optional info collection object to return data back to - * the caller. + * @param g2 + * the graphics device. + * @param dataArea + * the (visible) area inside the axes. + * @param plot + * the plot. + * @param data + * the data. + * @param info + * an optional info collection object to return data back to + * the caller. * * @return A state object. */ - public XYItemRendererState initialise(Graphics2D g2, - Rectangle2D dataArea, - XYPlot plot, - XYDataset data, - PlotRenderingInfo info) { + @Override + public XYItemRendererState initialise(final Graphics2D g2, final Rectangle2D dataArea, final XYPlot plot, final XYDataset data, + final PlotRenderingInfo info) { - XYItemRendererState state = super.initialise(g2, dataArea, plot, data, - info); + final XYItemRendererState state = super.initialise(g2, dataArea, plot, data, info); state.setProcessVisibleItemsOnly(false); return state; } @@ -551,55 +440,42 @@ * * @return The number of passes required by the renderer. */ + @Override public int getPassCount() { return 2; } - /** * Adds x/y data to series. */ - private static final void addSeries( - DefaultXYDataset ds, - Comparable key, - TDoubleArrayList xs, - TDoubleArrayList ys - ) { - ds.addSeries( - key, - new double [][] { - xs.toNativeArray(), - ys.toNativeArray() - }); + private static final void addSeries(final DefaultXYDataset ds, final Comparable key, final TDoubleArrayList xs, final TDoubleArrayList ys) { + ds.addSeries(key, new double[][] { xs.toNativeArray(), ys.toNativeArray() }); } - protected static List<XYDataset> splitByNaNsOneSeries( - XYDataset dataset - ) { - List<XYDataset> datasets = new ArrayList<XYDataset>(); + private static List<XYDataset> splitByNaNsOneSeries(final XYDataset dataset) { + final List<XYDataset> datasets = new ArrayList<>(); - int N = dataset.getItemCount(0); - TDoubleArrayList xs = new TDoubleArrayList(N); - TDoubleArrayList ys = new TDoubleArrayList(N); + final int N = dataset.getItemCount(0); + final TDoubleArrayList xs = new TDoubleArrayList(N); + final TDoubleArrayList ys = new TDoubleArrayList(N); for (int i = 0; i < N; ++i) { - double x = dataset.getXValue(0, i); - double y = dataset.getYValue(0, i); + final double x = dataset.getXValue(0, i); + final double y = dataset.getYValue(0, i); if (Double.isNaN(x) || Double.isNaN(y)) { if (!xs.isEmpty()) { - DefaultXYDataset ds = new DefaultXYDataset(); + final DefaultXYDataset ds = new DefaultXYDataset(); addSeries(ds, dataset.getSeriesKey(0), xs, ys); datasets.add(ds); xs.resetQuick(); ys.resetQuick(); } - } - else { + } else { xs.add(x); ys.add(y); } } if (!xs.isEmpty()) { - DefaultXYDataset ds = new DefaultXYDataset(); + final DefaultXYDataset ds = new DefaultXYDataset(); addSeries(ds, dataset.getSeriesKey(0), xs, ys); datasets.add(ds); } @@ -607,30 +483,30 @@ return datasets; } - private static final boolean add(TDoubleArrayList xs, double x) { - int N = xs.size(); - if (N == 0 || xs.getQuick(N-1) < x) { + private static final boolean add(final TDoubleArrayList xs, final double x) { + final int N = xs.size(); + if (N == 0 || xs.getQuick(N - 1) < x) { xs.add(x); return true; } return false; } - protected static boolean hasNaN(XYDataset dataset) { - int N = dataset.getItemCount(0); - int M = dataset.getItemCount(1); + private static boolean hasNaN(final XYDataset dataset) { + final int N = dataset.getItemCount(0); + final int M = dataset.getItemCount(1); for (int i = 0; i < N; ++i) { - double x = dataset.getXValue(0, i); - double y = dataset.getYValue(0, i); + final double x = dataset.getXValue(0, i); + final double y = dataset.getYValue(0, i); if (Double.isNaN(x) || Double.isNaN(y)) { return true; } } for (int j = 0; j < M; ++j) { - double x = dataset.getXValue(1, j); - double y = dataset.getYValue(1, j); + final double x = dataset.getXValue(1, j); + final double y = dataset.getYValue(1, j); if (Double.isNaN(x) || Double.isNaN(y)) { return true; } @@ -638,76 +514,73 @@ return false; } + private static List<XYDataset> splitByNaNsTwoSeries(final XYDataset dataset) { + final boolean debug = log.isDebugEnabled(); - protected static List<XYDataset> splitByNaNsTwoSeries( - XYDataset dataset - ) { - boolean debug = log.isDebugEnabled(); - - List<XYDataset> datasets = new ArrayList<XYDataset>(); + final List<XYDataset> datasets = new ArrayList<>(); if (!hasNaN(dataset)) { datasets.add(dataset); return datasets; } - int N = dataset.getItemCount(0); - int M = dataset.getItemCount(1); + final int N = dataset.getItemCount(0); + final int M = dataset.getItemCount(1); int i = 0, j = 0; // ignore leading NaNs for (; i < N; ++i) { - double x = dataset.getXValue(0, i); - double y = dataset.getYValue(0, i); + final double x = dataset.getXValue(0, i); + final double y = dataset.getYValue(0, i); if (!Double.isNaN(x) && !Double.isNaN(y)) { break; } } for (; j < M; ++j) { - double x = dataset.getXValue(1, j); - double y = dataset.getYValue(1, j); + final double x = dataset.getXValue(1, j); + final double y = dataset.getYValue(1, j); if (!Double.isNaN(x) && !Double.isNaN(y)) { break; } } - TDoubleArrayList six = new TDoubleArrayList(); - TDoubleArrayList siy = new TDoubleArrayList(); - TDoubleArrayList sjx = new TDoubleArrayList(); - TDoubleArrayList sjy = new TDoubleArrayList(); + final TDoubleArrayList six = new TDoubleArrayList(); + final TDoubleArrayList siy = new TDoubleArrayList(); + final TDoubleArrayList sjx = new TDoubleArrayList(); + final TDoubleArrayList sjy = new TDoubleArrayList(); while (i < N && j < M) { - int ni = i+1; - for (; ni < N && !Double.isNaN(dataset.getXValue(0, ni)); ++ni); - for (; ni < N && Double.isNaN(dataset.getXValue(0, ni)); ++ni); + int ni = i + 1; + for (; ni < N && !Double.isNaN(dataset.getXValue(0, ni)); ++ni) + ; + for (; ni < N && Double.isNaN(dataset.getXValue(0, ni)); ++ni) + ; - int nj = j+1; - for (; nj < M && !Double.isNaN(dataset.getXValue(1, nj)); ++nj); - for (; nj < M && Double.isNaN(dataset.getXValue(1, nj)); ++nj); + int nj = j + 1; + for (; nj < M && !Double.isNaN(dataset.getXValue(1, nj)); ++nj) + ; + for (; nj < M && Double.isNaN(dataset.getXValue(1, nj)); ++nj) + ; if (ni == N && nj == M) { // no more splits log.debug("no more splits ...."); for (; i < ni; ++i) { - double x = dataset.getXValue(0, i); - double y = dataset.getYValue(0, i); - if (!Double.isNaN(x) - && !Double.isNaN(y) - && add(six, x)) { + final double x = dataset.getXValue(0, i); + final double y = dataset.getYValue(0, i); + if (!Double.isNaN(x) && !Double.isNaN(y) && add(six, x)) { siy.add(y); } } for (; j < nj; ++j) { - double x = dataset.getXValue(1, j); - double y = dataset.getYValue(1, j); - if (!Double.isNaN(x) - && !Double.isNaN(y) - && add(sjx, x)) { + final double x = dataset.getXValue(1, j); + final double y = dataset.getYValue(1, j); + if (!Double.isNaN(x) && !Double.isNaN(y) && add(sjx, x)) { sjy.add(y); } } if (!six.isEmpty() && !sjx.isEmpty()) { - DefaultXYDataset ds = new DefaultXYDataset(); + final DefaultXYDataset ds = new DefaultXYDataset(); addSeries(ds, dataset.getSeriesKey(0), six, siy); addSeries(ds, dataset.getSeriesKey(1), sjx, sjy); datasets.add(ds); @@ -720,15 +593,11 @@ log.debug("nj: " + nj + " " + M); } - double xni = ni < N - ? dataset.getXValue(0, ni) - : Double.MAX_VALUE; + final double xni = ni < N ? dataset.getXValue(0, ni) : Double.MAX_VALUE; - double xnj = nj < M - ? dataset.getXValue(1, nj) - : Double.MAX_VALUE; + final double xnj = nj < M ? dataset.getXValue(1, nj) : Double.MAX_VALUE; - double xns = Math.min(xni, xnj); + final double xns = Math.min(xni, xnj); double pushxi = Double.NaN; double pushyi = Double.NaN; @@ -736,8 +605,8 @@ double pushyj = Double.NaN; for (; i < ni; ++i) { - double x = dataset.getXValue(0, i); - double y = dataset.getYValue(0, i); + final double x = dataset.getXValue(0, i); + final double y = dataset.getYValue(0, i); if (Double.isNaN(x) || Double.isNaN(y)) { continue; } @@ -751,19 +620,16 @@ if (add(six, x)) { siy.add(y); } - pushxi = x; pushyi = y; - } - else { // x > xns: intersection + pushxi = x; + pushyi = y; + } else { // x > xns: intersection if (debug) { log.debug("xns: " + xns); log.debug("x/y: " + x + " / " + y); } - int SIX = six.size(); + final int SIX = six.size(); if (SIX > 0) { // should always be true - double yns = Linear.linear( - xns, - six.getQuick(SIX-1), x, - siy.getQuick(SIX-1), y); + final double yns = Linear.linear(xns, six.getQuick(SIX - 1), x, siy.getQuick(SIX - 1), y); if (debug) { log.debug("intersection at: " + yns); } @@ -778,8 +644,8 @@ } for (; j < nj; ++j) { - double x = dataset.getXValue(1, j); - double y = dataset.getYValue(1, j); + final double x = dataset.getXValue(1, j); + final double y = dataset.getYValue(1, j); if (Double.isNaN(x) || Double.isNaN(y)) { continue; } @@ -793,36 +659,36 @@ if (add(sjx, x)) { sjy.add(y); } - pushxj = x; pushyj = y; - } - else { // x > xns: intersection - int SJX = sjx.size(); + pushxj = x; + pushyj = y; + } else { // x > xns: intersection + final int SJX = sjx.size(); if (SJX > 0) { // should always be true - double yns = Linear.linear( - xns, - sjx.getQuick(SJX-1), x, - sjy.getQuick(SJX-1), y); + final double yns = Linear.linear(xns, sjx.getQuick(SJX - 1), x, sjy.getQuick(SJX - 1), y); if (debug) { log.debug("intersection at: " + yns); } if (add(sjx, xns)) { sjy.add(yns); } - pushxj = xns; pushyj = yns; + pushxj = xns; + pushyj = yns; } } break; // Split point reached. } if (!six.isEmpty() && !sjx.isEmpty()) { - DefaultXYDataset ds = new DefaultXYDataset(); + final DefaultXYDataset ds = new DefaultXYDataset(); addSeries(ds, dataset.getSeriesKey(0), six, siy); addSeries(ds, dataset.getSeriesKey(1), sjx, sjy); datasets.add(ds); } - six.resetQuick(); siy.resetQuick(); - sjx.resetQuick(); sjy.resetQuick(); + six.resetQuick(); + siy.resetQuick(); + sjx.resetQuick(); + sjy.resetQuick(); // Push split points. if (!Double.isNaN(pushxi)) { @@ -838,28 +704,24 @@ // Copy the rest. for (; i < N; ++i) { - double x = dataset.getXValue(0, i); - double y = dataset.getXValue(0, i); - if (!Double.isNaN(x) - && !Double.isNaN(y) - && add(six, x)) { + final double x = dataset.getXValue(0, i); + final double y = dataset.getXValue(0, i); + if (!Double.isNaN(x) && !Double.isNaN(y) && add(six, x)) { siy.add(y); } } for (; j < M; ++j) { - double x = dataset.getXValue(1, j); - double y = dataset.getXValue(1, j); - if (!Double.isNaN(x) - && !Double.isNaN(y) - && add(sjx, x)) { + final double x = dataset.getXValue(1, j); + final double y = dataset.getXValue(1, j); + if (!Double.isNaN(x) && !Double.isNaN(y) && add(sjx, x)) { sjy.add(y); } } // Build final dataset. if (!six.isEmpty() && !sjx.isEmpty()) { - DefaultXYDataset ds = new DefaultXYDataset(); + final DefaultXYDataset ds = new DefaultXYDataset(); addSeries(ds, dataset.getSeriesKey(0), six, siy); addSeries(ds, dataset.getSeriesKey(1), sjx, sjy); datasets.add(ds); @@ -870,137 +732,122 @@ } /* - log.debug("Begin dump datasets: "); - log.debug("Original"); - i=0; - dumpDataset(dataset, "Original" ); - for (XYDataset set: datasets) { - dumpDataset(dataset, "New: " + i++); - } - log.debug("End dump datasets: "); - */ + * log.debug("Begin dump datasets: "); + * log.debug("Original"); + * i=0; + * dumpDataset(dataset, "Original" ); + * for (XYDataset set: datasets) { + * dumpDataset(dataset, "New: " + i++); + * } + * log.debug("End dump datasets: "); + */ return datasets; } /* - public static void dumpDataset(XYDataset dataset, String msg) { - log.debug("Begin dump Dataset: " + msg); - - int N = dataset.getItemCount(0); - int M = dataset.getItemCount(1); + * public static void dumpDataset(XYDataset dataset, String msg) { + * log.debug("Begin dump Dataset: " + msg); + * int N = dataset.getItemCount(0); + * int M = dataset.getItemCount(1); + * int i = 0, j = 0; + * for (; i < N; ++i) { + * double x = dataset.getXValue(0, i); + * double y = dataset.getYValue(0, i); + * log.debug("0 " + i + " X: "+ x + "Y: "+ y); + * } + * for (; j < M; ++j) { + * double x = dataset.getXValue(1, j); + * double y = dataset.getYValue(1, j); + * log.debug("1 " + i + " X: "+ x + "Y: "+ y); + * } + * log.debug("End dump Dataset: " + msg); + * } + */ - int i = 0, j = 0; - for (; i < N; ++i) { - double x = dataset.getXValue(0, i); - double y = dataset.getYValue(0, i); - log.debug("0 " + i + " X: "+ x + "Y: "+ y); - } - - for (; j < M; ++j) { - double x = dataset.getXValue(1, j); - double y = dataset.getYValue(1, j); - log.debug("1 " + i + " X: "+ x + "Y: "+ y); - } - log.debug("End dump Dataset: " + msg); - } - */ - - - public static List<XYDataset> splitByNaNs(XYDataset dataset) { + private static List<XYDataset> splitByNaNs(final XYDataset dataset) { switch (dataset.getSeriesCount()) { - case 0: - return Collections.<XYDataset>emptyList(); - case 1: - return splitByNaNsOneSeries(dataset); - default: // two or more - return splitByNaNsTwoSeries(dataset); + case 0: + return Collections.<XYDataset>emptyList(); + case 1: + return splitByNaNsOneSeries(dataset); + default: // two or more + return splitByNaNsTwoSeries(dataset); } } - /** * Draws the visual representation of a single data item. * - * @param g2 the graphics device. - * @param state the renderer state. - * @param dataArea the area within which the data is being drawn. - * @param info collects information about the drawing. - * @param plot the plot (can be used to obtain standard color - * information etc). - * @param domainAxis the domain (horizontal) axis. - * @param rangeAxis the range (vertical) axis. - * @param dataset the dataset. - * @param series the series index (zero-based). - * @param item the item index (zero-based). - * @param crosshairState crosshair information for the plot - * (<code>null</code> permitted). - * @param pass the pass index. + * @param g2 + * the graphics device. + * @param state + * the renderer state. + * @param dataArea + * the area within which the data is being drawn. + * @param info + * collects information about the drawing. + * @param plot + * the plot (can be used to obtain standard color + * information etc). + * @param domainAxis + * the domain (horizontal) axis. + * @param rangeAxis + * the range (vertical) axis. + * @param dataset + * the dataset. + * @param series + * the series index (zero-based). + * @param item + * the item index (zero-based). + * @param crosshairState + * crosshair information for the plot + * (<code>null</code> permitted). + * @param pass + * the pass index. */ - public void drawItem(Graphics2D g2, - XYItemRendererState state, - Rectangle2D dataArea, - PlotRenderingInfo info, - XYPlot plot, - ValueAxis domainAxis, - ValueAxis rangeAxis, - XYDataset dataset, - int series, - int item, - CrosshairState crosshairState, - int pass) { + @Override + public void drawItem(final Graphics2D g2, final XYItemRendererState state, final Rectangle2D dataArea, final PlotRenderingInfo info, final XYPlot plot, + final ValueAxis domainAxis, final ValueAxis rangeAxis, final XYDataset dataset, final int series, final int item, + final CrosshairState crosshairState, final int pass) { switch (pass) { - case 0: - for (XYDataset ds: splitByNaNs(dataset)) { - drawItemPass0(g2, dataArea, info, - plot, domainAxis, rangeAxis, - ds, series, item, crosshairState); - } - break; - case 1: - drawItemPass1(g2, dataArea, info, - plot, domainAxis, rangeAxis, - dataset, series, item, crosshairState); + case 0: + for (final XYDataset ds : splitByNaNs(dataset)) { + drawItemPass0(g2, dataArea, info, plot, domainAxis, rangeAxis, ds, series, item, crosshairState); + } + break; + case 1: + drawItemPass1(g2, dataArea, info, plot, domainAxis, rangeAxis, dataset, series, item, crosshairState); } // Find geometric middle, calculate area and paint // a string with it here. - if (pass == 1 - && this.labelArea - && areaLabelNumberFormat != null - && areaLabelTamplate != null - ) { - double center_x = centroid.getX(); - double center_y = centroid.getY(); - center_x = domainAxis.valueToJava2D(center_x, dataArea, - plot.getDomainAxisEdge()); - center_y = rangeAxis.valueToJava2D(center_y, dataArea, - plot.getRangeAxisEdge()); + if (pass == 1 && this.labelArea && this.areaLabelNumberFormat != null && this.areaLabelTamplate != null) { + double center_x = this.centroid.getX(); + double center_y = this.centroid.getY(); + center_x = domainAxis.valueToJava2D(center_x, dataArea, plot.getDomainAxisEdge()); + center_y = rangeAxis.valueToJava2D(center_y, dataArea, plot.getRangeAxisEdge()); // Respect text-extend if text should appear really centered. float area = 0f; - if (areaCalculationMode == CALCULATE_POSITIVE_AREA - || areaCalculationMode == CALCULATE_ALL_AREA) { - area += Math.abs(positiveArea); + if (this.areaCalculationMode == CALCULATE_POSITIVE_AREA || this.areaCalculationMode == CALCULATE_ALL_AREA) { + area += Math.abs(this.positiveArea); } - if (areaCalculationMode == CALCULATE_NEGATIVE_AREA - || areaCalculationMode == CALCULATE_ALL_AREA) { - area += Math.abs(negativeArea); + if (this.areaCalculationMode == CALCULATE_NEGATIVE_AREA || this.areaCalculationMode == CALCULATE_ALL_AREA) { + area += Math.abs(this.negativeArea); } if (area != 0f) { - Color oldColor = g2.getColor(); - Font oldFont = g2.getFont(); - g2.setFont(labelFont); - String labelText = String.format(this.areaLabelTamplate, - areaLabelNumberFormat.format(area)); - if (labelBGColor != null) { - EnhancedLineAndShapeRenderer.drawTextBox(g2, labelText, - (float)center_x, (float)center_y, labelBGColor); + final Color oldColor = g2.getColor(); + final Font oldFont = g2.getFont(); + g2.setFont(this.labelFont); + final String labelText = String.format(this.areaLabelTamplate, this.areaLabelNumberFormat.format(area)); + if (this.labelBGColor != null) { + EnhancedLineAndShapeRenderer.drawTextBox(g2, labelText, (float) center_x, (float) center_y, this.labelBGColor); } - g2.setColor(labelColor); - g2.drawString(labelText, (float)center_x, (float)center_y); + g2.setColor(this.labelColor); + g2.drawString(labelText, (float) center_x, (float) center_y); g2.setFont(oldFont); g2.setColor(oldColor); } @@ -1010,35 +857,38 @@ /** * Draws the visual representation of a single data item, first pass. * - * @param x_graphics the graphics device. - * @param x_dataArea the area within which the data is being drawn. - * @param x_info collects information about the drawing. - * @param x_plot the plot (can be used to obtain standard color - * information etc). - * @param x_domainAxis the domain (horizontal) axis. - * @param x_rangeAxis the range (vertical) axis. - * @param x_dataset the dataset. - * @param x_series the series index (zero-based). - * @param x_item the item index (zero-based). - * @param x_crosshairState crosshair information for the plot - * (<code>null</code> permitted). + * @param x_graphics + * the graphics device. + * @param x_dataArea + * the area within which the data is being drawn. + * @param x_info + * collects information about the drawing. + * @param x_plot + * the plot (can be used to obtain standard color + * information etc). + * @param x_domainAxis + * the domain (horizontal) axis. + * @param x_rangeAxis + * the range (vertical) axis. + * @param x_dataset + * the dataset. + * @param x_series + * the series index (zero-based). + * @param x_item + * the item index (zero-based). + * @param x_crosshairState + * crosshair information for the plot + * (<code>null</code> permitted). */ - protected void drawItemPass0(Graphics2D x_graphics, - Rectangle2D x_dataArea, - PlotRenderingInfo x_info, - XYPlot x_plot, - ValueAxis x_domainAxis, - ValueAxis x_rangeAxis, - XYDataset x_dataset, - int x_series, - int x_item, - CrosshairState x_crosshairState) { + private void drawItemPass0(final Graphics2D x_graphics, final Rectangle2D x_dataArea, final PlotRenderingInfo x_info, final XYPlot x_plot, + final ValueAxis x_domainAxis, final ValueAxis x_rangeAxis, final XYDataset x_dataset, final int x_series, final int x_item, + final CrosshairState x_crosshairState) { if (!((0 == x_series) && (0 == x_item))) { return; } - boolean b_impliedZeroSubtrahend = (1 == x_dataset.getSeriesCount()); + final boolean b_impliedZeroSubtrahend = (1 == x_dataset.getSeriesCount()); // check if either series is a degenerate case (i.e. less than 2 points) if (isEitherSeriesDegenerate(x_dataset, b_impliedZeroSubtrahend)) { @@ -1051,60 +901,58 @@ } // polygon definitions - LinkedList l_minuendXs = new LinkedList(); - LinkedList l_minuendYs = new LinkedList(); - LinkedList l_subtrahendXs = new LinkedList(); - LinkedList l_subtrahendYs = new LinkedList(); - LinkedList l_polygonXs = new LinkedList(); - LinkedList l_polygonYs = new LinkedList(); + final List<Double> l_minuendXs = new LinkedList<>(); + final List<Double> l_minuendYs = new LinkedList<>(); + final List<Double> l_subtrahendXs = new LinkedList<>(); + final List<Double> l_subtrahendYs = new LinkedList<>(); + final List<Double> l_polygonXs = new LinkedList<>(); + final List<Double> l_polygonYs = new LinkedList<>(); // state - int l_minuendItem = 0; - int l_minuendItemCount = x_dataset.getItemCount(0); - Double l_minuendCurX = null; - Double l_minuendNextX = null; - Double l_minuendCurY = null; - Double l_minuendNextY = null; - double l_minuendMaxY = Double.NEGATIVE_INFINITY; - double l_minuendMinY = Double.POSITIVE_INFINITY; + int l_minuendItem = 0; + final int l_minuendItemCount = x_dataset.getItemCount(0); + Double l_minuendCurX = null; + Double l_minuendNextX = null; + Double l_minuendCurY = null; + Double l_minuendNextY = null; + double l_minuendMaxY = Double.NEGATIVE_INFINITY; + double l_minuendMinY = Double.POSITIVE_INFINITY; - int l_subtrahendItem = 0; + int l_subtrahendItem = 0; int l_subtrahendItemCount = 0; // actual value set below - Double l_subtrahendCurX = null; - Double l_subtrahendNextX = null; - Double l_subtrahendCurY = null; - Double l_subtrahendNextY = null; - double l_subtrahendMaxY = Double.NEGATIVE_INFINITY; - double l_subtrahendMinY = Double.POSITIVE_INFINITY; + Double l_subtrahendCurX = null; + Double l_subtrahendNextX = null; + Double l_subtrahendCurY = null; + Double l_subtrahendNextY = null; + double l_subtrahendMaxY = Double.NEGATIVE_INFINITY; + double l_subtrahendMinY = Double.POSITIVE_INFINITY; // if a subtrahend is not specified, assume it is zero if (b_impliedZeroSubtrahend) { - l_subtrahendItem = 0; + l_subtrahendItem = 0; l_subtrahendItemCount = 2; - l_subtrahendCurX = new Double(x_dataset.getXValue(0, 0)); - l_subtrahendNextX = new Double(x_dataset.getXValue(0, - (l_minuendItemCount - 1))); - l_subtrahendCurY = new Double(0.0); - l_subtrahendNextY = new Double(0.0); - l_subtrahendMaxY = 0.0; - l_subtrahendMinY = 0.0; + l_subtrahendCurX = new Double(x_dataset.getXValue(0, 0)); + l_subtrahendNextX = new Double(x_dataset.getXValue(0, (l_minuendItemCount - 1))); + l_subtrahendCurY = new Double(0.0); + l_subtrahendNextY = new Double(0.0); + l_subtrahendMaxY = 0.0; + l_subtrahendMinY = 0.0; l_subtrahendXs.add(l_subtrahendCurX); l_subtrahendYs.add(l_subtrahendCurY); - } - else { + } else { l_subtrahendItemCount = x_dataset.getItemCount(1); } - boolean b_minuendDone = false; - boolean b_minuendAdvanced = true; - boolean b_minuendAtIntersect = false; - boolean b_minuendFastForward = false; - boolean b_subtrahendDone = false; - boolean b_subtrahendAdvanced = true; + boolean b_minuendDone = false; + boolean b_minuendAdvanced = true; + boolean b_minuendAtIntersect = false; + boolean b_minuendFastForward = false; + boolean b_subtrahendDone = false; + boolean b_subtrahendAdvanced = true; boolean b_subtrahendAtIntersect = false; boolean b_subtrahendFastForward = false; - boolean b_colinear = false; + boolean b_colinear = false; boolean b_positive; @@ -1123,8 +971,8 @@ l_x2 = x_dataset.getXValue(0, l_minuendItem + 1); l_y2 = x_dataset.getYValue(0, l_minuendItem + 1); - l_minuendCurX = new Double(l_x1); - l_minuendCurY = new Double(l_y1); + l_minuendCurX = new Double(l_x1); + l_minuendCurY = new Double(l_y1); l_minuendNextX = new Double(l_x2); l_minuendNextY = new Double(l_y2); @@ -1133,15 +981,14 @@ l_y3 = l_subtrahendCurY.doubleValue(); l_x4 = l_subtrahendNextX.doubleValue(); l_y4 = l_subtrahendNextY.doubleValue(); - } - else { + } else { l_x3 = x_dataset.getXValue(1, l_subtrahendItem); l_y3 = x_dataset.getYValue(1, l_subtrahendItem); l_x4 = x_dataset.getXValue(1, l_subtrahendItem + 1); l_y4 = x_dataset.getYValue(1, l_subtrahendItem + 1); - l_subtrahendCurX = new Double(l_x3); - l_subtrahendCurY = new Double(l_y3); + l_subtrahendCurX = new Double(l_x3); + l_subtrahendCurY = new Double(l_y3); l_subtrahendNextX = new Double(l_x4); l_subtrahendNextY = new Double(l_y4); } @@ -1163,10 +1010,9 @@ // check if initial polygon needs to be clipped if ((l_x3 < l_x1) && (l_x1 < l_x4)) { // project onto subtrahend - double l_slope = (l_y4 - l_y3) / (l_x4 - l_x3); + final double l_slope = (l_y4 - l_y3) / (l_x4 - l_x3); l_subtrahendCurX = l_minuendCurX; - l_subtrahendCurY = new Double((l_slope * l_x1) - + (l_y3 - (l_slope * l_x3))); + l_subtrahendCurY = new Double((l_slope * l_x1) + (l_y3 - (l_slope * l_x3))); l_subtrahendXs.add(l_subtrahendCurX); l_subtrahendYs.add(l_subtrahendCurY); @@ -1174,17 +1020,16 @@ if ((l_x1 < l_x3) && (l_x3 < l_x2)) { // project onto minuend - double l_slope = (l_y2 - l_y1) / (l_x2 - l_x1); - l_minuendCurX = l_subtrahendCurX; - l_minuendCurY = new Double((l_slope * l_x3) - + (l_y1 - (l_slope * l_x1))); + final double l_slope = (l_y2 - l_y1) / (l_x2 - l_x1); + l_minuendCurX = l_subtrahendCurX; + l_minuendCurY = new Double((l_slope * l_x3) + (l_y1 - (l_slope * l_x1))); l_minuendXs.add(l_minuendCurX); l_minuendYs.add(l_minuendCurY); } - l_minuendMaxY = l_minuendCurY.doubleValue(); - l_minuendMinY = l_minuendCurY.doubleValue(); + l_minuendMaxY = l_minuendCurY.doubleValue(); + l_minuendMinY = l_minuendCurY.doubleValue(); l_subtrahendMaxY = l_subtrahendCurY.doubleValue(); l_subtrahendMinY = l_subtrahendCurY.doubleValue(); @@ -1214,8 +1059,7 @@ } // never updated the subtrahend if it is implied to be zero - if (!b_impliedZeroSubtrahend && !b_subtrahendDone - && !b_subtrahendFastForward && b_subtrahendAdvanced) { + if (!b_impliedZeroSubtrahend && !b_subtrahendDone && !b_subtrahendFastForward && b_subtrahendAdvanced) { l_x3 = x_dataset.getXValue(1, l_subtrahendItem); l_y3 = x_dataset.getYValue(1, l_subtrahendItem); l_subtrahendCurX = new Double(l_x3); @@ -1236,14 +1080,14 @@ } // deassert b_*FastForward (only matters for 1st time through loop) - b_minuendFastForward = false; + b_minuendFastForward = false; b_subtrahendFastForward = false; Double l_intersectX = null; Double l_intersectY = null; boolean b_intersect = false; - b_minuendAtIntersect = false; + b_minuendAtIntersect = false; b_subtrahendAtIntersect = false; // check for intersect @@ -1251,39 +1095,32 @@ // check if line segments are colinear if ((l_x1 == l_x3) && (l_y1 == l_y3)) { b_colinear = true; - } - else { + } else { // the intersect is at the next point for both the minuend // and subtrahend l_intersectX = new Double(l_x2); l_intersectY = new Double(l_y2); - b_intersect = true; - b_minuendAtIntersect = true; + b_intersect = true; + b_minuendAtIntersect = true; b_subtrahendAtIntersect = true; - } - } - else { + } + } else { // compute common denominator - double l_denominator = ((l_y4 - l_y3) * (l_x2 - l_x1)) - - ((l_x4 - l_x3) * (l_y2 - l_y1)); + final double l_denominator = ((l_y4 - l_y3) * (l_x2 - l_x1)) - ((l_x4 - l_x3) * (l_y2 - l_y1)); // compute common deltas - double l_deltaY = l_y1 - l_y3; - double l_deltaX = l_x1 - l_x3; + final double l_deltaY = l_y1 - l_y3; + final double l_deltaX = l_x1 - l_x3; // compute numerators - double l_numeratorA = ((l_x4 - l_x3) * l_deltaY) - - ((l_y4 - l_y3) * l_deltaX); - double l_numeratorB = ((l_x2 - l_x1) * l_deltaY) - - ((l_y2 - l_y1) * l_deltaX); + final double l_numeratorA = ((l_x4 - l_x3) * l_deltaY) - ((l_y4 - l_y3) * l_deltaX); + final double l_numeratorB = ((l_x2 - l_x1) * l_deltaY) - ((l_y2 - l_y1) * l_deltaX); // check if line segments are colinear - if ((0 == l_numeratorA) && (0 == l_numeratorB) - && (0 == l_denominator)) { + if ((0 == l_numeratorA) && (0 == l_numeratorB) && (0 == l_denominator)) { b_colinear = true; - } - else { + } else { // check if previously colinear if (b_colinear) { // clear colinear points and flag @@ -1297,36 +1134,30 @@ b_colinear = false; // set new starting point for the polygon - boolean b_useMinuend = ((l_x3 <= l_x1) - && (l_x1 <= l_x4)); - l_polygonXs.add(b_useMinuend ? l_minuendCurX - : l_subtrahendCurX); - l_polygonYs.add(b_useMinuend ? l_minuendCurY - : l_subtrahendCurY); + final boolean b_useMinuend = ((l_x3 <= l_x1) && (l_x1 <= l_x4)); + l_polygonXs.add(b_useMinuend ? l_minuendCurX : l_subtrahendCurX); + l_polygonYs.add(b_useMinuend ? l_minuendCurY : l_subtrahendCurY); } // compute slope components - double l_slopeA = l_numeratorA / l_denominator; - double l_slopeB = l_numeratorB / l_denominator; + final double l_slopeA = l_numeratorA / l_denominator; + final double l_slopeB = l_numeratorB / l_denominator; // check if the line segments intersect - if ((0 < l_slopeA) && (l_slopeA <= 1) && (0 < l_slopeB) - && (l_slopeB <= 1)) { + if ((0 < l_slopeA) && (l_slopeA <= 1) && (0 < l_slopeB) && (l_slopeB <= 1)) { // compute the point of intersection - double l_xi = l_x1 + (l_slopeA * (l_x2 - l_x1)); - double l_yi = l_y1 + (l_slopeA * (l_y2 - l_y1)); + final double l_xi = l_x1 + (l_slopeA * (l_x2 - l_x1)); + final double l_yi = l_y1 + (l_slopeA * (l_y2 - l_y1)); - l_intersectX = new Double(l_xi); - l_intersectY = new Double(l_yi); - b_intersect = true; - b_minuendAtIntersect = ((l_xi == l_x2) - && (l_yi == l_y2)); - b_subtrahendAtIntersect = ((l_xi == l_x4) - && (l_yi == l_y4)); + l_intersectX = new Double(l_xi); + l_intersectY = new Double(l_yi); + b_intersect = true; + b_minuendAtIntersect = ((l_xi == l_x2) && (l_yi == l_y2)); + b_subtrahendAtIntersect = ((l_xi == l_x4) && (l_yi == l_y4)); // advance minuend and subtrahend to intesect - l_minuendCurX = l_intersectX; - l_minuendCurY = l_intersectY; + l_minuendCurX = l_intersectX; + l_minuendCurY = l_intersectY; l_subtrahendCurX = l_intersectX; l_subtrahendCurY = l_intersectY; } @@ -1350,10 +1181,8 @@ l_polygonYs.addAll(l_subtrahendYs); // create an actual polygon - b_positive = (l_subtrahendMaxY <= l_minuendMaxY) - && (l_subtrahendMinY <= l_minuendMinY); - createPolygon(x_graphics, x_dataArea, x_plot, x_domainAxis, - x_rangeAxis, b_positive, l_polygonXs, l_polygonYs); + b_positive = (l_subtrahendMaxY <= l_minuendMaxY) && (l_subtrahendMinY <= l_minuendMinY); + createPolygon(x_graphics, x_dataArea, x_plot, x_domainAxis, x_rangeAxis, b_positive, l_polygonXs, l_polygonYs); // clear the point vectors l_minuendXs.clear(); @@ -1364,10 +1193,10 @@ l_polygonYs.clear(); // set the maxY and minY values to intersect y-value - double l_y = l_intersectY.doubleValue(); - l_minuendMaxY = l_y; + final double l_y = l_intersectY.doubleValue(); + l_minuendMaxY = l_y; l_subtrahendMaxY = l_y; - l_minuendMinY = l_y; + l_minuendMinY = l_y; l_subtrahendMinY = l_y; // add interection point to new polygon @@ -1379,8 +1208,7 @@ if (l_x2 <= l_x4) { l_minuendItem++; b_minuendAdvanced = true; - } - else { + } else { b_minuendAdvanced = false; } @@ -1388,43 +1216,35 @@ if (l_x4 <= l_x2) { l_subtrahendItem++; b_subtrahendAdvanced = true; - } - else { + } else { b_subtrahendAdvanced = false; } - b_minuendDone = (l_minuendItem == (l_minuendItemCount - 1)); - b_subtrahendDone = (l_subtrahendItem == (l_subtrahendItemCount - - 1)); + b_minuendDone = (l_minuendItem == (l_minuendItemCount - 1)); + b_subtrahendDone = (l_subtrahendItem == (l_subtrahendItemCount - 1)); } // check if the final polygon needs to be clipped if (b_minuendDone && (l_x3 < l_x2) && (l_x2 < l_x4)) { // project onto subtrahend - double l_slope = (l_y4 - l_y3) / (l_x4 - l_x3); + final double l_slope = (l_y4 - l_y3) / (l_x4 - l_x3); l_subtrahendNextX = l_minuendNextX; - l_subtrahendNextY = new Double((l_slope * l_x2) - + (l_y3 - (l_slope * l_x3))); + l_subtrahendNextY = new Double((l_slope * l_x2) + (l_y3 - (l_slope * l_x3))); } if (b_subtrahendDone && (l_x1 < l_x4) && (l_x4 < l_x2)) { // project onto minuend - double l_slope = (l_y2 - l_y1) / (l_x2 - l_x1); + final double l_slope = (l_y2 - l_y1) / (l_x2 - l_x1); l_minuendNextX = l_subtrahendNextX; - l_minuendNextY = new Double((l_slope * l_x4) - + (l_y1 - (l_slope * l_x1))); + l_minuendNextY = new Double((l_slope * l_x4) + (l_y1 - (l_slope * l_x1))); } // consider last point of minuend and subtrahend for determining // positivity - l_minuendMaxY = Math.max(l_minuendMaxY, - l_minuendNextY.doubleValue()); - l_subtrahendMaxY = Math.max(l_subtrahendMaxY, - l_subtrahendNextY.doubleValue()); - l_minuendMinY = Math.min(l_minuendMinY, - l_minuendNextY.doubleValue()); - l_subtrahendMinY = Math.min(l_subtrahendMinY, - l_subtrahendNextY.doubleValue()); + l_minuendMaxY = Math.max(l_minuendMaxY, l_minuendNextY.doubleValue()); + l_subtrahendMaxY = Math.max(l_subtrahendMaxY, l_subtrahendNextY.doubleValue()); + l_minuendMinY = Math.min(l_minuendMinY, l_minuendNextY.doubleValue()); + l_subtrahendMinY = Math.min(l_subtrahendMinY, l_subtrahendNextY.doubleValue()); // add the last point of the minuned and subtrahend l_minuendXs.add(l_minuendNextX); @@ -1444,40 +1264,41 @@ l_polygonYs.addAll(l_subtrahendYs); // create an actual polygon - b_positive = (l_subtrahendMaxY <= l_minuendMaxY) - && (l_subtrahendMinY <= l_minuendMinY); - createPolygon(x_graphics, x_dataArea, x_plot, x_domainAxis, - x_rangeAxis, b_positive, l_polygonXs, l_polygonYs); + b_positive = (l_subtrahendMaxY <= l_minuendMaxY) && (l_subtrahendMinY <= l_minuendMinY); + createPolygon(x_graphics, x_dataArea, x_plot, x_domainAxis, x_rangeAxis, b_positive, l_polygonXs, l_polygonYs); } /** - * Draws the visual representation of a single data item, second pass. In + * Draws the visual representation of a single data item, second pass. In * the second pass, the renderer draws the lines and shapes for the * individual points in the two series. * - * @param x_graphics the graphics device. - * @param x_dataArea the area within which the data is being drawn. - * @param x_info collects information about the drawing. - * @param x_plot the plot (can be used to obtain standard color - * information etc). - * @param x_domainAxis the domain (horizontal) axis. - * @param x_rangeAxis the range (vertical) axis. - * @param x_dataset the dataset. - * @param x_series the series index (zero-based). - * @param x_item the item index (zero-based). - * @param x_crosshairState crosshair information for the plot - * (<code>null</code> permitted). + * @param x_graphics + * the graphics device. + * @param x_dataArea + * the area within which the data is being drawn. + * @param x_info + * collects information about the drawing. + * @param x_plot + * the plot (can be used to obtain standard color + * information etc). + * @param x_domainAxis + * the domain (horizontal) axis. + * @param x_rangeAxis + * the range (vertical) axis. + * @param x_dataset + * the dataset. + * @param x_series + * the series index (zero-based). + * @param x_item + * the item index (zero-based). + * @param x_crosshairState + * crosshair information for the plot + * (<code>null</code> permitted). */ - protected void drawItemPass1(Graphics2D x_graphics, - Rectangle2D x_dataArea, - PlotRenderingInfo x_info, - XYPlot x_plot, - ValueAxis x_domainAxis, - ValueAxis x_rangeAxis, - XYDataset x_dataset, - int x_series, - int x_item, - CrosshairState x_crosshairState) { + private void drawItemPass1(final Graphics2D x_graphics, final Rectangle2D x_dataArea, final PlotRenderingInfo x_info, final XYPlot x_plot, + final ValueAxis x_domainAxis, final ValueAxis x_rangeAxis, final XYDataset x_dataset, final int x_series, final int x_item, + final CrosshairState x_crosshairState) { Shape l_entityArea = null; EntityCollection l_entities = null; @@ -1485,43 +1306,39 @@ l_entities = x_info.getOwner().getEntityCollection(); } - Paint l_seriesPaint = getItemPaint(x_series, x_item); - Stroke l_seriesStroke = getItemStroke(x_series, x_item); + final Paint l_seriesPaint = getItemPaint(x_series, x_item); + final Stroke l_seriesStroke = getItemStroke(x_series, x_item); x_graphics.setPaint(l_seriesPaint); x_graphics.setStroke(l_seriesStroke); - PlotOrientation l_orientation = x_plot.getOrientation(); - RectangleEdge l_domainAxisLocation = x_plot.getDomainAxisEdge(); - RectangleEdge l_rangeAxisLocation = x_plot.getRangeAxisEdge(); + final PlotOrientation l_orientation = x_plot.getOrientation(); + final RectangleEdge l_domainAxisLocation = x_plot.getDomainAxisEdge(); + final RectangleEdge l_rangeAxisLocation = x_plot.getRangeAxisEdge(); - double l_x0 = x_dataset.getXValue(x_series, x_item); - double l_y0 = x_dataset.getYValue(x_series, x_item); - double l_x1 = x_domainAxis.valueToJava2D(l_x0, x_dataArea, - l_domainAxisLocation); - double l_y1 = x_rangeAxis.valueToJava2D(l_y0, x_dataArea, - l_rangeAxisLocation); + final double l_x0 = x_dataset.getXValue(x_series, x_item); + final double l_y0 = x_dataset.getYValue(x_series, x_item); + final double l_x1 = x_domainAxis.valueToJava2D(l_x0, x_dataArea, l_domainAxisLocation); + final double l_y1 = x_rangeAxis.valueToJava2D(l_y0, x_dataArea, l_rangeAxisLocation); // These are the shapes of the series items. if (getShapesVisible()) { Shape l_shape = getItemShape(x_series, x_item); if (l_orientation == PlotOrientation.HORIZONTAL) { - l_shape = ShapeUtilities.createTranslatedShape(l_shape, - l_y1, l_x1); - } - else { - l_shape = ShapeUtilities.createTranslatedShape(l_shape, - l_x1, l_y1); + l_shape = ShapeUtilities.createTranslatedShape(l_shape, l_y1, l_x1); + } else { + l_shape = ShapeUtilities.createTranslatedShape(l_shape, l_x1, l_y1); } if (l_shape.intersects(x_dataArea)) { x_graphics.setPaint(getItemPaint(x_series, x_item)); x_graphics.fill(l_shape); - /* TODO We could draw the shapes of single items here. - if (drawOutline) { - x_graphics.setPaint(this.outlinePaint); - x_graphics.setStroke(this.outlineStroke); - x_graphics.draw(l_shape); - } - */ + /* + * TODO We could draw the shapes of single items here. + * if (drawOutline) { + * x_graphics.setPaint(this.outlinePaint); + * x_graphics.setStroke(this.outlineStroke); + * x_graphics.draw(l_shape); + * } + */ } l_entityArea = l_shape; } // if (getShapesVisible()) @@ -1529,59 +1346,49 @@ // add an entity for the item... if (null != l_entities) { if (null == l_entityArea) { - l_entityArea = new Rectangle2D.Double((l_x1 - 2), (l_y1 - 2), - 4, 4); + l_entityArea = new Rectangle2D.Double((l_x1 - 2), (l_y1 - 2), 4, 4); } String l_tip = null; - XYToolTipGenerator l_tipGenerator = getToolTipGenerator(x_series, - x_item); + final XYToolTipGenerator l_tipGenerator = getToolTipGenerator(x_series, x_item); if (null != l_tipGenerator) { - l_tip = l_tipGenerator.generateToolTip(x_dataset, x_series, - x_item); + l_tip = l_tipGenerator.generateToolTip(x_dataset, x_series, x_item); } String l_url = null; - XYURLGenerator l_urlGenerator = getURLGenerator(); + final XYURLGenerator l_urlGenerator = getURLGenerator(); if (null != l_urlGenerator) { - l_url = l_urlGenerator.generateURL(x_dataset, x_series, - x_item); + l_url = l_urlGenerator.generateURL(x_dataset, x_series, x_item); } - XYItemEntity l_entity = new XYItemEntity(l_entityArea, x_dataset, - x_series, x_item, l_tip, l_url); + final XYItemEntity l_entity = new XYItemEntity(l_entityArea, x_dataset, x_series, x_item, l_tip, l_url); l_entities.add(l_entity); } // draw the item label if there is one... if (isItemLabelVisible(x_series, x_item)) { - drawItemLabel(x_graphics, l_orientation, x_dataset, x_series, - x_item, l_x1, l_y1, (l_y1 < 0.0)); + drawItemLabel(x_graphics, l_orientation, x_dataset, x_series, x_item, l_x1, l_y1, (l_y1 < 0.0)); } - int l_domainAxisIndex = x_plot.getDomainAxisIndex(x_domainAxis); - int l_rangeAxisIndex = x_plot.getRangeAxisIndex(x_rangeAxis); - updateCrosshairValues(x_crosshairState, l_x0, l_y0, l_domainAxisIndex, - l_rangeAxisIndex, l_x1, l_y1, l_orientation); + final int l_domainAxisIndex = x_plot.getDomainAxisIndex(x_domainAxis); + final int l_rangeAxisIndex = x_plot.getRangeAxisIndex(x_rangeAxis); + updateCrosshairValues(x_crosshairState, l_x0, l_y0, l_domainAxisIndex, l_rangeAxisIndex, l_x1, l_y1, l_orientation); if (0 == x_item) { return; } - double l_x2 = x_domainAxis.valueToJava2D(x_dataset.getXValue(x_series, - (x_item - 1)), x_dataArea, l_domainAxisLocation); - double l_y2 = x_rangeAxis.valueToJava2D(x_dataset.getYValue(x_series, - (x_item - 1)), x_dataArea, l_rangeAxisLocation); + final double l_x2 = x_domainAxis.valueToJava2D(x_dataset.getXValue(x_series, (x_item - 1)), x_dataArea, l_domainAxisLocation); + final double l_y2 = x_rangeAxis.valueToJava2D(x_dataset.getYValue(x_series, (x_item - 1)), x_dataArea, l_rangeAxisLocation); Line2D l_line = null; if (PlotOrientation.HORIZONTAL == l_orientation) { l_line = new Line2D.Double(l_y1, l_x1, l_y2, l_x2); - } - else if (PlotOrientation.VERTICAL == l_orientation) { + } else if (PlotOrientation.VERTICAL == l_orientation) { l_line = new Line2D.Double(l_x1, l_y1, l_x2, l_y2); } if ((null != l_line) && l_line.intersects(x_dataArea)) { x_graphics.setPaint(getItemPaint(x_series, x_item)); x_graphics.setStroke(getItemStroke(x_series, x_item)); - if (drawOriginalSeries) { + if (this.drawOriginalSeries) { x_graphics.setPaint(this.outlinePaint); x_graphics.setStroke(this.outlineStroke); x_graphics.draw(l_line); @@ -1590,192 +1397,175 @@ } /** - * Determines if a dataset is degenerate. A degenerate dataset is a + * Determines if a dataset is degenerate. A degenerate dataset is a * dataset where either series has less than two (2) points. * - * @param x_dataset the dataset. - * @param x_impliedZeroSubtrahend if false, do not check the subtrahend + * @param x_dataset + * the dataset. + * @param x_impliedZeroSubtrahend + * if false, do not check the subtrahend * * @return true if the dataset is degenerate. */ - private boolean isEitherSeriesDegenerate(XYDataset x_dataset, - boolean x_impliedZeroSubtrahend) { + private boolean isEitherSeriesDegenerate(final XYDataset x_dataset, final boolean x_impliedZeroSubtrahend) { if (x_impliedZeroSubtrahend) { return (x_dataset.getItemCount(0) < 2); } - return ((x_dataset.getItemCount(0) < 2) - || (x_dataset.getItemCount(1) < 2)); + return ((x_dataset.getItemCount(0) < 2) || (x_dataset.getItemCount(1) < 2)); } /** * Determines if the two (2) series are disjoint. * Disjoint series do not overlap in the domain space. * - * @param x_dataset the dataset. + * @param x_dataset + * the dataset. * * @return true if the dataset is degenerate. */ - private boolean areSeriesDisjoint(XYDataset x_dataset) { - - int l_minuendItemCount = x_dataset.getItemCount(0); - double l_minuendFirst = x_dataset.getXValue(0, 0); - double l_minuendLast = x_dataset.getXValue(0, l_minuendItemCount - 1); + private boolean areSeriesDisjoint(final XYDataset x_dataset) { - int l_subtrahendItemCount = x_dataset.getItemCount(1); - double l_subtrahendFirst = x_dataset.getXValue(1, 0); - double l_subtrahendLast = x_dataset.getXValue(1, - l_subtrahendItemCount - 1); + final int l_minuendItemCount = x_dataset.getItemCount(0); + final double l_minuendFirst = x_dataset.getXValue(0, 0); + final double l_minuendLast = x_dataset.getXValue(0, l_minuendItemCount - 1); - return ((l_minuendLast < l_subtrahendFirst) - || (l_subtrahendLast < l_minuendFirst)); + final int l_subtrahendItemCount = x_dataset.getItemCount(1); + final double l_subtrahendFirst = x_dataset.getXValue(1, 0); + final double l_subtrahendLast = x_dataset.getXValue(1, l_subtrahendItemCount - 1); + + return ((l_minuendLast < l_subtrahendFirst) || (l_subtrahendLast < l_minuendFirst)); } - - public void updateCentroid(Object [] xValues, Object [] yValues) { + private void updateCentroid(final Object[] xValues, final Object[] yValues) { double x = 0d, y = 0d; for (int i = 0, N = xValues.length; i < N; ++i) { - x += ((Double)xValues[i]).doubleValue(); - y += ((Double)yValues[i]).doubleValue(); + x += ((Double) xValues[i]).doubleValue(); + y += ((Double) yValues[i]).doubleValue(); } x /= xValues.length; y /= yValues.length; - centroidNPoints++; - double factorNew = 1d / centroidNPoints; - double factorOld = 1d - factorNew; + this.centroidNPoints++; + final double factorNew = 1d / this.centroidNPoints; + final double factorOld = 1d - factorNew; - centroid = new Point2D.Double((factorNew * x + factorOld * centroid.x), - (factorNew * y + factorOld * centroid.y)); + this.centroid = new Point2D.Double((factorNew * x + factorOld * this.centroid.x), (factorNew * y + factorOld * this.centroid.y)); } - - public static double calculateArea(Object [] xValues, Object [] yValues) { + private static double calculateArea(final Object[] xValues, final Object[] yValues) { double area = 0d; for (int i = 0, N = xValues.length; i < N; ++i) { - int k = (i + 1) % N; - double xi = ((Double)xValues[i]).doubleValue(); - double yi = ((Double)yValues[i]).doubleValue(); - double xk = ((Double)xValues[k]).doubleValue(); - double yk = ((Double)yValues[k]).doubleValue(); + final int k = (i + 1) % N; + final double xi = ((Double) xValues[i]).doubleValue(); + final double yi = ((Double) yValues[i]).doubleValue(); + final double xk = ((Double) xValues[k]).doubleValue(); + final double yk = ((Double) yValues[k]).doubleValue(); - area += xi*yk; - area -= xk*yi; + area += xi * yk; + area -= xk * yi; // TODO centroid calculation here? } - return 0.5d*area; + return 0.5d * area; } /** * Draws the visual representation of a polygon * - * @param x_graphics the graphics device. - * @param x_dataArea the area within which the data is being drawn. - * @param x_plot the plot (can be used to obtain standard color - * information etc). - * @param x_domainAxis the domain (horizontal) axis. - * @param x_rangeAxis the range (vertical) axis. - * @param x_positive indicates if the polygon is positive (true) or - * negative (false). - * @param x_xValues a linked list of the x values (expects values to be - * of type Double). - * @param x_yValues a linked list of the y values (expects values to be - * of type Double). + * @param x_graphics + * the graphics device. + * @param x_dataArea + * the area within which the data is being drawn. + * @param x_plot + * the plot (can be used to obtain standard color + * information etc). + * @param x_domainAxis + * the domain (horizontal) axis. + * @param x_rangeAxis + * the range (vertical) axis. + * @param x_positive + * indicates if the polygon is positive (true) or + * negative (false). + * @param x_xValues + * a linked list of the x values (expects values to be + * of type Double). + * @param x_yValues + * a linked list of the y values (expects values to be + * of type Double). */ - private void createPolygon (Graphics2D x_graphics, - Rectangle2D x_dataArea, - XYPlot x_plot, - ValueAxis x_domainAxis, - ValueAxis x_rangeAxis, - boolean x_positive, - LinkedList x_xValues, - LinkedList x_yValues) { + private void createPolygon(final Graphics2D x_graphics, final Rectangle2D x_dataArea, final XYPlot x_plot, final ValueAxis x_domainAxis, + final ValueAxis x_rangeAxis, final boolean x_positive, final List<Double> x_xValues, final List<Double> x_yValues) { - PlotOrientation l_orientation = x_plot.getOrientation(); - RectangleEdge l_domainAxisLocation = x_plot.getDomainAxisEdge(); - RectangleEdge l_rangeAxisLocation = x_plot.getRangeAxisEdge(); + final PlotOrientation l_orientation = x_plot.getOrientation(); + final RectangleEdge l_domainAxisLocation = x_plot.getDomainAxisEdge(); + final RectangleEdge l_rangeAxisLocation = x_plot.getRangeAxisEdge(); - Object[] l_xValues = x_xValues.toArray(); - Object[] l_yValues = x_yValues.toArray(); + final Object[] l_xValues = x_xValues.toArray(); + final Object[] l_yValues = x_yValues.toArray(); - double area = calculateArea(l_xValues, l_yValues); - if (x_positive) positiveArea += area; - else negativeArea += area; + final double area = calculateArea(l_xValues, l_yValues); + if (x_positive) + this.positiveArea += area; + else + this.negativeArea += area; updateCentroid(l_xValues, l_yValues); - GeneralPath l_path = new GeneralPath(); + final GeneralPath l_path = new GeneralPath(); if (PlotOrientation.VERTICAL == l_orientation) { - double l_x = x_domainAxis.valueToJava2D(( - (Double) l_xValues[0]).doubleValue(), x_dataArea, - l_domainAxisLocation); + double l_x = x_domainAxis.valueToJava2D(((Double) l_xValues[0]).doubleValue(), x_dataArea, l_domainAxisLocation); if (this.roundXCoordinates) { l_x = Math.rint(l_x); } - double l_y = x_rangeAxis.valueToJava2D(( - (Double) l_yValues[0]).doubleValue(), x_dataArea, - l_rangeAxisLocation); + double l_y = x_rangeAxis.valueToJava2D(((Double) l_yValues[0]).doubleValue(), x_dataArea, l_rangeAxisLocation); l_path.moveTo((float) l_x, (float) l_y); for (int i = 1; i < l_xValues.length; i++) { - l_x = x_domainAxis.valueToJava2D(( - (Double) l_xValues[i]).doubleValue(), x_dataArea, - l_domainAxisLocation); + l_x = x_domainAxis.valueToJava2D(((Double) l_xValues[i]).doubleValue(), x_dataArea, l_domainAxisLocation); if (this.roundXCoordinates) { l_x = Math.rint(l_x); } - l_y = x_rangeAxis.valueToJava2D(( - (Double) l_yValues[i]).doubleValue(), x_dataArea, - l_rangeAxisLocation); + l_y = x_rangeAxis.valueToJava2D(((Double) l_yValues[i]).doubleValue(), x_dataArea, l_rangeAxisLocation); l_path.lineTo((float) l_x, (float) l_y); } l_path.closePath(); - } - else { - double l_x = x_domainAxis.valueToJava2D(( - (Double) l_xValues[0]).doubleValue(), x_dataArea, - l_domainAxisLocation); + } else { + double l_x = x_domainAxis.valueToJava2D(((Double) l_xValues[0]).doubleValue(), x_dataArea, l_domainAxisLocation); if (this.roundXCoordinates) { l_x = Math.rint(l_x); } - double l_y = x_rangeAxis.valueToJava2D(( - (Double) l_yValues[0]).doubleValue(), x_dataArea, - l_rangeAxisLocation); + double l_y = x_rangeAxis.valueToJava2D(((Double) l_yValues[0]).doubleValue(), x_dataArea, l_rangeAxisLocation); l_path.moveTo((float) l_y, (float) l_x); for (int i = 1; i < l_xValues.length; i++) { - l_x = x_domainAxis.valueToJava2D(( - (Double) l_xValues[i]).doubleValue(), x_dataArea, - l_domainAxisLocation); + l_x = x_domainAxis.valueToJava2D(((Double) l_xValues[i]).doubleValue(), x_dataArea, l_domainAxisLocation); if (this.roundXCoordinates) { l_x = Math.rint(l_x); } - l_y = x_rangeAxis.valueToJava2D(( - (Double) l_yValues[i]).doubleValue(), x_dataArea, - l_rangeAxisLocation); + l_y = x_rangeAxis.valueToJava2D(((Double) l_yValues[i]).doubleValue(), x_dataArea, l_rangeAxisLocation); l_path.lineTo((float) l_y, (float) l_x); } l_path.closePath(); } if (l_path.intersects(x_dataArea)) { - - final Paint paint = x_positive ? getPositivePaint(): getNegativePaint(); - if( paint != null ) { - x_graphics.setPaint(paint); - x_graphics.fill(l_path); + + final Paint paint = x_positive ? getPositivePaint() : getNegativePaint(); + if (this.drawArea && paint != null) { + x_graphics.setPaint(paint); + x_graphics.fill(l_path); } - - if (drawOutline) { + + if (this.drawOutline) { x_graphics.setStroke(this.outlineStroke); x_graphics.setPaint(this.outlinePaint); x_graphics.draw(l_path); @@ -1784,67 +1574,62 @@ } /** - * Returns a default legend item for the specified series. Subclasses + * Returns a default legend item for the specified series. Subclasses * should override this method to generate customised items. * - * @param datasetIndex the dataset index (zero-based). - * @param series the series index (zero-based). + * @param datasetIndex + * the dataset index (zero-based). + * @param series + * the series index (zero-based). * * @return A legend item for the series. */ - public LegendItem getLegendItem(int datasetIndex, int series) { - LegendItem result = null; - XYPlot p = getPlot(); - if (p != null) { - XYDataset dataset = p.getDataset(datasetIndex); - if (dataset != null) { - if (getItemVisible(series, 0)) { - String label = getLegendItemLabelGenerator().generateLabel( - dataset, series); - String description = label; - String toolTipText = null; - if (getLegendItemToolTipGenerator() != null) { - toolTipText - = getLegendItemToolTipGenerator().generateLabel( - dataset, series); - } - String urlText = null; - if (getLegendItemURLGenerator() != null) { - urlText = getLegendItemURLGenerator().generateLabel( - dataset, series); - } - // Individualized Paints: - //Paint paint = lookupSeriesPaint(series); + @Override + public LegendItem getLegendItem(final int datasetIndex, final int series) { + final XYPlot p = getPlot(); + if (p == null) + return null; - // "Area-Style"- Paint. - Paint paint = getPositivePaint(); - Stroke stroke = lookupSeriesStroke(series); - Shape line = getLegendLine(); - // Not-filled Shape: - //result = new LegendItem(label, description, - // toolTipText, urlText, line, stroke, paint); - - if (drawOutline) { - // TODO Include outline style in legenditem - // (there is a constructor for that) - } + final XYDataset dataset = p.getDataset(datasetIndex); + if (dataset == null) + return null; - // Filled Shape ("Area-Style"). - result = new LegendItem(label, description, - toolTipText, urlText, line, paint); - result.setLabelFont(lookupLegendTextFont(series)); - Paint labelPaint = lookupLegendTextPaint(series); - if (labelPaint != null) { - result.setLabelPaint(labelPaint); - } - result.setDataset(dataset); - result.setDatasetIndex(datasetIndex); - result.setSeriesKey(dataset.getSeriesKey(series)); - result.setSeriesIndex(series); - } - } + if (!getItemVisible(series, 0)) + return null; + final String label = getLegendItemLabelGenerator().generateLabel(dataset, series); + final String description = label; + String toolTipText = null; + if (getLegendItemToolTipGenerator() != null) { + toolTipText = getLegendItemToolTipGenerator().generateLabel(dataset, series); } + String urlText = null; + if (getLegendItemURLGenerator() != null) { + urlText = getLegendItemURLGenerator().generateLabel(dataset, series); + } + + // "Area-Style"- Paint. + final Paint paint = getPositivePaint(); + final Shape line = getLegendLine(); + + // Filled Shape ("Area-Style"). + final BasicStroke NULL_STROKE = new BasicStroke(0.0f); + final Shape NULL_SHAPE = new Line2D.Float(); + + final Paint outlPaint = this.drawOutline ? this.outlinePaint : Color.black; + final Stroke outlStroke = this.drawOutline ? this.outlineStroke : NULL_STROKE; + + final LegendItem result = new LegendItem(label, description, toolTipText, urlText, true, line, this.drawArea, paint, this.drawOutline, outlPaint, + outlStroke, false, NULL_SHAPE, NULL_STROKE, Color.black); + + result.setLabelFont(lookupLegendTextFont(series)); + final Paint labelPaint = lookupLegendTextPaint(series); + if (labelPaint != null) + result.setLabelPaint(labelPaint); + result.setDataset(dataset); + result.setDatasetIndex(datasetIndex); + result.setSeriesKey(dataset.getSeriesKey(series)); + result.setSeriesIndex(series); return result; } @@ -1852,11 +1637,13 @@ /** * Tests this renderer for equality with an arbitrary object. * - * @param obj the object (<code>null</code> permitted). + * @param obj + * the object (<code>null</code> permitted). * * @return A boolean. */ - public boolean equals(Object obj) { + @Override + public boolean equals(final Object obj) { if (obj == this) { return true; } @@ -1866,7 +1653,7 @@ if (!super.equals(obj)) { return false; } - StableXYDifferenceRenderer that = (StableXYDifferenceRenderer) obj; + final StableXYDifferenceRenderer that = (StableXYDifferenceRenderer) obj; if (!PaintUtilities.equal(this.positivePaint, that.positivePaint)) { return false; } @@ -1890,11 +1677,12 @@ * * @return A clone. * - * @throws CloneNotSupportedException if the renderer cannot be cloned. + * @throws CloneNotSupportedException + * if the renderer cannot be cloned. */ + @Override public Object clone() throws CloneNotSupportedException { - StableXYDifferenceRenderer clone = - (StableXYDifferenceRenderer) super.clone(); + final StableXYDifferenceRenderer clone = (StableXYDifferenceRenderer) super.clone(); clone.legendShape = ShapeUtilities.clone(this.legendShape); return clone; } @@ -1902,11 +1690,13 @@ /** * Provides serialization support. * - * @param stream the output stream. + * @param stream + * the output stream. * - * @throws IOException if there is an I/O error. + * @throws IOException + * if there is an I/O error. */ - private void writeObject(ObjectOutputStream stream) throws IOException { + private void writeObject(final ObjectOutputStream stream) throws IOException { stream.defaultWriteObject(); SerialUtilities.writePaint(this.positivePaint, stream); SerialUtilities.writePaint(this.negativePaint, stream); @@ -1916,17 +1706,18 @@ /** * Provides serialization support. * - * @param stream the input stream. + * @param stream + * the input stream. * - * @throws IOException if there is an I/O error. - * @throws ClassNotFoundException if there is a classpath problem. + * @throws IOException + * if there is an I/O error. + * @throws ClassNotFoundException + * if there is a classpath problem. */ - private void readObject(ObjectInputStream stream) - throws IOException, ClassNotFoundException { + private void readObject(final ObjectInputStream stream) throws IOException, ClassNotFoundException { stream.defaultReadObject(); this.positivePaint = SerialUtilities.readPaint(stream); this.negativePaint = SerialUtilities.readPaint(stream); this.legendShape = SerialUtilities.readShape(stream); } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : +} \ No newline at end of file
--- a/artifacts/src/main/java/org/dive4elements/river/jfree/StyledAreaSeriesCollection.java Tue Jun 26 20:18:18 2018 +0200 +++ b/artifacts/src/main/java/org/dive4elements/river/jfree/StyledAreaSeriesCollection.java Tue Jun 26 20:19:16 2018 +0200 @@ -17,10 +17,9 @@ import java.awt.geom.Rectangle2D; import java.awt.image.BufferedImage; +import org.dive4elements.river.themes.ThemeDocument; import org.jfree.data.xy.XYSeriesCollection; -import org.dive4elements.river.themes.ThemeDocument; - /** * One or more dataseries to draw a polygon (either "open up/downwards", or * the area between two curves), a theme-document and further display options. @@ -39,15 +38,15 @@ private FILL_MODE mode; /** Theme-document with attributes about actual visual representation. */ - private ThemeDocument theme; + private final ThemeDocument theme; /** * @param theme the theme-document. */ - public StyledAreaSeriesCollection(ThemeDocument theme) { + public StyledAreaSeriesCollection(final ThemeDocument theme) { this.theme = theme; this.mode = FILL_MODE.BETWEEN; - } + } /** Gets the Fill mode. */ @@ -57,7 +56,7 @@ /** Sets the Fill mode. */ - public void setMode(FILL_MODE fMode) { + public void setMode(final FILL_MODE fMode) { this.mode = fMode; } @@ -69,44 +68,38 @@ * @return \param renderer */ public StableXYDifferenceRenderer applyTheme( - StableXYDifferenceRenderer renderer - ) { + final StableXYDifferenceRenderer renderer + ) { applyFillColor(renderer); - applyShowShape(renderer); + applyShowBorder(renderer); + applyShowArea(renderer); applyOutlineColor(renderer); applyOutlineStyle(renderer); applyShowLine(renderer); applyShowAreaLabel(renderer); applyPointStyle(renderer); - if (mode == FILL_MODE.UNDER) { + if (this.mode == FILL_MODE.UNDER) { renderer.setAreaCalculationMode( - StableXYDifferenceRenderer.CALCULATE_NEGATIVE_AREA); + StableXYDifferenceRenderer.CALCULATE_NEGATIVE_AREA); } - else if (mode == FILL_MODE.ABOVE) { + else if (this.mode == FILL_MODE.ABOVE) { renderer.setAreaCalculationMode( - StableXYDifferenceRenderer.CALCULATE_POSITIVE_AREA); + StableXYDifferenceRenderer.CALCULATE_POSITIVE_AREA); } else { renderer.setAreaCalculationMode( - StableXYDifferenceRenderer.CALCULATE_ALL_AREA); + StableXYDifferenceRenderer.CALCULATE_ALL_AREA); } // Apply text style. - theme.parseComplexTextStyle().apply(renderer); + this.theme.parseComplexTextStyle().apply(renderer); return renderer; } private void applyFillColor(final StableXYDifferenceRenderer renderer) { - - final boolean showArea = theme.parseShowArea(); - if( !showArea ) { - renderer.setPositivePaint(null); - renderer.setNegativePaint(null); - return; - } Paint paint = parseFillPaint(); - + if (paint != null && this.getMode() == FILL_MODE.ABOVE) { renderer.setPositivePaint(paint); renderer.setNegativePaint(new Color(0,0,0,0)); @@ -118,7 +111,7 @@ else { if (paint == null) paint = new Color(177, 117, 102); - + renderer.setPositivePaint(paint); renderer.setNegativePaint(paint); } @@ -126,17 +119,17 @@ private Paint parseFillPaint() { final Color paint = this.theme.parseAreaBackgroundColor(); - final int transparency = theme.parseAreaTransparency(); - + final int transparency = this.theme.parseAreaTransparency(); + final Color alphaPaint = withAlpha(paint, transparency); - + final AreaFillPattern pattern = this.theme.parseAreaBackgroundPattern(); if( pattern == null || pattern == AreaFillPattern.patternFill ) return alphaPaint; - + final BufferedImage image = pattern.getImage(alphaPaint); - + final Rectangle2D anchor = new Rectangle2D.Double(0,0, image.getWidth(), image.getHeight()); return new TexturePaint(image, anchor); } @@ -145,7 +138,7 @@ if (transparency <= 0 || color == null) return color; - + return new Color( color.getRed(), color.getGreen(), @@ -153,32 +146,37 @@ (int)((100 - transparency) * 2.55f)); } - private void applyShowShape(StableXYDifferenceRenderer renderer) { - boolean show = theme.parseAreaShowBorder(); + private void applyShowBorder(final StableXYDifferenceRenderer renderer) { + final boolean show = this.theme.parseAreaShowBorder(); renderer.setDrawOutline(show); } + private void applyShowArea(final StableXYDifferenceRenderer renderer) { - private void applyShowLine(StableXYDifferenceRenderer renderer) { + final boolean showArea = this.theme.parseShowArea(); + renderer.setDrawArea(showArea); + } + + private void applyShowLine(final StableXYDifferenceRenderer renderer) { /* FIXME: strange: this will enable/disable showing the 'point' shapes at each vertex. */ /* FIXME: this will also now be overridden by the option 'showpoints' */ - final boolean show = theme.parseShowLine(); + final boolean show = this.theme.parseShowLine(); renderer.setShapesVisible(show); } - private void applyOutlineColor(StableXYDifferenceRenderer renderer) { - Color c = theme.parseLineColorField(); + private void applyOutlineColor(final StableXYDifferenceRenderer renderer) { + final Color c = this.theme.parseLineColorField(); renderer.setOutlinePaint(c); } /** Inform renderer whether it should draw a label. */ - private void applyShowAreaLabel(StableXYDifferenceRenderer renderer) { - renderer.setLabelArea(theme.parseShowAreaLabel()); + private void applyShowAreaLabel(final StableXYDifferenceRenderer renderer) { + renderer.setLabelArea(this.theme.parseShowAreaLabel()); } - private void applyOutlineStyle(StableXYDifferenceRenderer renderer) { - float[] dashes = theme.parseLineStyle(); - int size = theme.parseLineWidth(); + private void applyOutlineStyle(final StableXYDifferenceRenderer renderer) { + final float[] dashes = this.theme.parseLineStyle(); + final int size = this.theme.parseLineWidth(); Stroke stroke = null; @@ -187,11 +185,11 @@ } else { stroke = new BasicStroke(Integer.valueOf(size), - BasicStroke.CAP_BUTT, - BasicStroke.JOIN_ROUND, - 1.0f, - dashes, - 0.0f); + BasicStroke.CAP_BUTT, + BasicStroke.JOIN_ROUND, + 1.0f, + dashes, + 0.0f); } renderer.setOutlineStroke(stroke); @@ -203,12 +201,12 @@ renderer.setShapesVisible(showPoints); if( showPoints ) - { - final int size = theme.parsePointWidth(); + { + final int size = this.theme.parsePointWidth(); final int dim = 2 * size; final Ellipse2D pointShape = new Ellipse2D.Double(-size, -size, dim, dim); - final Color pointColor = theme.parsePointColor(); + final Color pointColor = this.theme.parsePointColor(); renderer.setSeriesPaint(0, pointColor); renderer.setSeriesPaint(1, pointColor); @@ -219,7 +217,7 @@ } public boolean shouldCalculateRange() { - return theme.parseCalculateRange(); + return this.theme.parseCalculateRange(); } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :