001/* ===========================================================
002 * JFreeChart : a free chart library for the Java(tm) platform
003 * ===========================================================
004 *
005 * (C) Copyright 2000-2017, by Object Refinery Limited and Contributors.
006 *
007 * Project Info:  http://www.jfree.org/jfreechart/index.html
008 *
009 * This library is free software; you can redistribute it and/or modify it
010 * under the terms of the GNU Lesser General Public License as published by
011 * the Free Software Foundation; either version 2.1 of the License, or
012 * (at your option) any later version.
013 *
014 * This library is distributed in the hope that it will be useful, but
015 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
016 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
017 * License for more details.
018 *
019 * You should have received a copy of the GNU Lesser General Public
020 * License along with this library; if not, write to the Free Software
021 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
022 * USA.
023 *
024 * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. 
025 * Other names may be trademarks of their respective owners.]
026 *
027 * -------------------
028 * XYAreaRenderer.java
029 * -------------------
030 * (C) Copyright 2002-2017, by Hari and Contributors.
031 *
032 * Original Author:  Hari (ourhari@hotmail.com);
033 * Contributor(s):   David Gilbert (for Object Refinery Limited);
034 *                   Richard Atkinson;
035 *                   Christian W. Zuckschwerdt;
036 *                   Martin Krauskopf;
037 *                   Ulrich Voigt (patch #312);
038 *
039 * Changes:
040 * --------
041 * 03-Apr-2002 : Version 1, contributed by Hari.  This class is based on the
042 *               StandardXYItemRenderer class (DG);
043 * 09-Apr-2002 : Removed the translated zero from the drawItem method -
044 *               overridden the initialise() method to calculate it (DG);
045 * 30-May-2002 : Added tool tip generator to constructor to match super
046 *               class (DG);
047 * 25-Jun-2002 : Removed unnecessary local variable (DG);
048 * 05-Aug-2002 : Small modification to drawItem method to support URLs for HTML
049 *               image maps (RA);
050 * 01-Oct-2002 : Fixed errors reported by Checkstyle (DG);
051 * 07-Nov-2002 : Renamed AreaXYItemRenderer --> XYAreaRenderer (DG);
052 * 25-Mar-2003 : Implemented Serializable (DG);
053 * 01-May-2003 : Modified drawItem() method signature (DG);
054 * 27-Jul-2003 : Made line and polygon properties protected rather than
055 *               private (RA);
056 * 30-Jul-2003 : Modified entity constructor (CZ);
057 * 20-Aug-2003 : Implemented Cloneable and PublicCloneable (DG);
058 * 16-Sep-2003 : Changed ChartRenderingInfo --> PlotRenderingInfo (DG);
059 * 07-Oct-2003 : Added renderer state (DG);
060 * 08-Dec-2003 : Modified hotspot for chart entity (DG);
061 * 10-Feb-2004 : Changed the drawItem() method to make cut-and-paste overriding
062 *               easier.  Also moved state class into this class (DG);
063 * 25-Feb-2004 : Replaced CrosshairInfo with CrosshairState.  Renamed
064 *               XYToolTipGenerator --> XYItemLabelGenerator (DG);
065 * 15-Jul-2004 : Switched getX() with getXValue() and getY() with
066 *               getYValue() (DG);
067 * 11-Nov-2004 : Now uses ShapeUtilities to translate shapes (DG);
068 * 19-Jan-2005 : Now accesses primitives only from dataset (DG);
069 * 21-Mar-2005 : Override getLegendItem() and equals() methods (DG);
070 * 20-Apr-2005 : Use generators for legend tooltips and URLs (DG);
071 * ------------- JFREECHART 1.0.x ---------------------------------------------
072 * 06-Feb-2007 : Fixed bug 1086307, crosshairs with multiple axes (DG);
073 * 14-Feb-2007 : Fixed bug in clone() (DG);
074 * 20-Apr-2007 : Updated getLegendItem() for renderer change (DG);
075 * 04-May-2007 : Set processVisibleItemsOnly flag to false (DG);
076 * 17-May-2007 : Set datasetIndex and seriesIndex in getLegendItem() (DG);
077 * 18-May-2007 : Set dataset and seriesKey for LegendItem (DG);
078 * 17-Jun-2008 : Apply legend font and paint attributes (DG);
079 * 31-Dec-2008 : Fix for bug 2471906 - dashed outlines performance issue (DG);
080 * 11-Jun-2009 : Added a useFillPaint flag and a GradientPaintTransformer for
081 *               the paint under the series (DG);
082 * 06-Oct-2011 : Avoid GeneralPath methods requiring Java 1.5 (MK);
083 * 03-Jul-2013 : Use ParamChecks (DG);
084 * 04-Aug-2014 : Restrict entity hotspot to plot area (patch #312) (UV);
085 * 18-Feb-2017 : Updates for crosshairs (bug #36) (DG);
086 *
087 */
088
089package org.jfree.chart.renderer.xy;
090
091import java.awt.BasicStroke;
092import java.awt.GradientPaint;
093import java.awt.Graphics2D;
094import java.awt.Paint;
095import java.awt.Shape;
096import java.awt.Stroke;
097import java.awt.geom.Area;
098import java.awt.geom.GeneralPath;
099import java.awt.geom.Line2D;
100import java.awt.geom.Rectangle2D;
101import java.io.IOException;
102import java.io.ObjectInputStream;
103import java.io.ObjectOutputStream;
104
105import org.jfree.chart.HashUtils;
106import org.jfree.chart.LegendItem;
107import org.jfree.chart.axis.ValueAxis;
108import org.jfree.chart.entity.EntityCollection;
109import org.jfree.chart.event.RendererChangeEvent;
110import org.jfree.chart.labels.XYSeriesLabelGenerator;
111import org.jfree.chart.labels.XYToolTipGenerator;
112import org.jfree.chart.plot.CrosshairState;
113import org.jfree.chart.plot.PlotOrientation;
114import org.jfree.chart.plot.PlotRenderingInfo;
115import org.jfree.chart.plot.XYPlot;
116import org.jfree.chart.ui.GradientPaintTransformer;
117import org.jfree.chart.ui.StandardGradientPaintTransformer;
118import org.jfree.chart.urls.XYURLGenerator;
119import org.jfree.chart.util.Args;
120import org.jfree.chart.util.PublicCloneable;
121import org.jfree.chart.util.SerialUtils;
122import org.jfree.chart.util.ShapeUtils;
123import org.jfree.data.xy.XYDataset;
124
125/**
126 * Area item renderer for an {@link XYPlot}.  This class can draw (a) shapes at
127 * each point, or (b) lines between points, or (c) both shapes and lines,
128 * or (d) filled areas, or (e) filled areas and shapes. The example shown here
129 * is generated by the {@code XYAreaRendererDemo1.java} program included
130 * in the JFreeChart demo collection:
131 * <br><br>
132 * <img src="../../../../../images/XYAreaRendererSample.png"
133 * alt="XYAreaRendererSample.png">
134 */
135public class XYAreaRenderer extends AbstractXYItemRenderer
136        implements XYItemRenderer, PublicCloneable {
137
138    /** For serialization. */
139    private static final long serialVersionUID = -4481971353973876747L;
140
141    /**
142     * A state object used by this renderer.
143     */
144    static class XYAreaRendererState extends XYItemRendererState {
145
146        /** Working storage for the area under one series. */
147        public GeneralPath area;
148
149        /** Working line that can be recycled. */
150        public Line2D line;
151
152        /**
153         * Creates a new state.
154         *
155         * @param info  the plot rendering info.
156         */
157        public XYAreaRendererState(PlotRenderingInfo info) {
158            super(info);
159            this.area = new GeneralPath();
160            this.line = new Line2D.Double();
161        }
162
163    }
164
165    /** Useful constant for specifying the type of rendering (shapes only). */
166    public static final int SHAPES = 1;
167
168    /** Useful constant for specifying the type of rendering (lines only). */
169    public static final int LINES = 2;
170
171    /**
172     * Useful constant for specifying the type of rendering (shapes and lines).
173     */
174    public static final int SHAPES_AND_LINES = 3;
175
176    /** Useful constant for specifying the type of rendering (area only). */
177    public static final int AREA = 4;
178
179    /**
180     * Useful constant for specifying the type of rendering (area and shapes).
181     */
182    public static final int AREA_AND_SHAPES = 5;
183
184    /** A flag indicating whether or not shapes are drawn at each XY point. */
185    private boolean plotShapes;
186
187    /** A flag indicating whether or not lines are drawn between XY points. */
188    private boolean plotLines;
189
190    /** A flag indicating whether or not Area are drawn at each XY point. */
191    private boolean plotArea;
192
193    /** A flag that controls whether or not the outline is shown. */
194    private boolean showOutline;
195
196    /**
197     * The shape used to represent an area in each legend item (this should
198     * never be {@code null}).
199     */
200    private transient Shape legendArea;
201
202    /**
203     * A flag that can be set to specify that the fill paint should be used
204     * to fill the area under the renderer.
205     * 
206     * @since 1.0.14
207     */
208    private boolean useFillPaint;
209
210    /**
211     * A transformer that is applied to the paint used to fill under the
212     * area *if* it is an instance of GradientPaint.
213     *
214     * @since 1.0.14
215     */
216    private GradientPaintTransformer gradientTransformer;
217
218    /**
219     * Constructs a new renderer.
220     */
221    public XYAreaRenderer() {
222        this(AREA);
223    }
224
225    /**
226     * Constructs a new renderer.
227     *
228     * @param type  the type of the renderer.
229     */
230    public XYAreaRenderer(int type) {
231        this(type, null, null);
232    }
233
234    /**
235     * Constructs a new renderer.  To specify the type of renderer, use one of
236     * the constants: {@code SHAPES}, {@code LINES}, {@code SHAPES_AND_LINES}, 
237     * {@code AREA} or {@code AREA_AND_SHAPES}.
238     *
239     * @param type  the type of renderer.
240     * @param toolTipGenerator  the tool tip generator ({@code null} permitted).
241     * @param urlGenerator  the URL generator ({@code null} permitted).
242     */
243    public XYAreaRenderer(int type, XYToolTipGenerator toolTipGenerator,
244                          XYURLGenerator urlGenerator) {
245
246        super();
247        setDefaultToolTipGenerator(toolTipGenerator);
248        setURLGenerator(urlGenerator);
249
250        if (type == SHAPES) {
251            this.plotShapes = true;
252        }
253        if (type == LINES) {
254            this.plotLines = true;
255        }
256        if (type == SHAPES_AND_LINES) {
257            this.plotShapes = true;
258            this.plotLines = true;
259        }
260        if (type == AREA) {
261            this.plotArea = true;
262        }
263        if (type == AREA_AND_SHAPES) {
264            this.plotArea = true;
265            this.plotShapes = true;
266        }
267        this.showOutline = false;
268        GeneralPath area = new GeneralPath();
269        area.moveTo(0.0f, -4.0f);
270        area.lineTo(3.0f, -2.0f);
271        area.lineTo(4.0f, 4.0f);
272        area.lineTo(-4.0f, 4.0f);
273        area.lineTo(-3.0f, -2.0f);
274        area.closePath();
275        this.legendArea = area;
276        this.useFillPaint = false;
277        this.gradientTransformer = new StandardGradientPaintTransformer();
278    }
279
280    /**
281     * Returns true if shapes are being plotted by the renderer.
282     *
283     * @return {@code true} if shapes are being plotted by the renderer.
284     */
285    public boolean getPlotShapes() {
286        return this.plotShapes;
287    }
288
289    /**
290     * Returns true if lines are being plotted by the renderer.
291     *
292     * @return {@code true} if lines are being plotted by the renderer.
293     */
294    public boolean getPlotLines() {
295        return this.plotLines;
296    }
297
298    /**
299     * Returns true if Area is being plotted by the renderer.
300     *
301     * @return {@code true} if Area is being plotted by the renderer.
302     */
303    public boolean getPlotArea() {
304        return this.plotArea;
305    }
306
307    /**
308     * Returns a flag that controls whether or not outlines of the areas are
309     * drawn.
310     *
311     * @return The flag.
312     *
313     * @see #setOutline(boolean)
314     */
315    public boolean isOutline() {
316        return this.showOutline;
317    }
318
319    /**
320     * Sets a flag that controls whether or not outlines of the areas are drawn
321     * and sends a {@link RendererChangeEvent} to all registered listeners.
322     *
323     * @param show  the flag.
324     *
325     * @see #isOutline()
326     */
327    public void setOutline(boolean show) {
328        this.showOutline = show;
329        fireChangeEvent();
330    }
331
332    /**
333     * Returns the shape used to represent an area in the legend.
334     *
335     * @return The legend area (never {@code null}).
336     */
337    public Shape getLegendArea() {
338        return this.legendArea;
339    }
340
341    /**
342     * Sets the shape used as an area in each legend item and sends a
343     * {@link RendererChangeEvent} to all registered listeners.
344     *
345     * @param area  the area ({@code null} not permitted).
346     */
347    public void setLegendArea(Shape area) {
348        Args.nullNotPermitted(area, "area");
349        this.legendArea = area;
350        fireChangeEvent();
351    }
352
353    /**
354     * Returns the flag that controls whether the series fill paint is used to
355     * fill the area under the line.
356     *
357     * @return A boolean.
358     *
359     * @since 1.0.14
360     */
361    public boolean getUseFillPaint() {
362        return this.useFillPaint;
363    }
364
365    /**
366     * Sets the flag that controls whether or not the series fill paint is
367     * used to fill the area under the line and sends a
368     * {@link RendererChangeEvent} to all listeners.
369     *
370     * @param use  the new flag value.
371     *
372     * @since 1.0.14
373     */
374    public void setUseFillPaint(boolean use) {
375        this.useFillPaint = use;
376        fireChangeEvent();
377    }
378
379    /**
380     * Returns the gradient paint transformer.
381     *
382     * @return The gradient paint transformer (never {@code null}).
383     *
384     * @since 1.0.14
385     */
386    public GradientPaintTransformer getGradientTransformer() {
387        return this.gradientTransformer;
388    }
389
390    /**
391     * Sets the gradient paint transformer and sends a
392     * {@link RendererChangeEvent} to all registered listeners.
393     *
394     * @param transformer  the transformer ({@code null} not permitted).
395     *
396     * @since 1.0.14
397     */
398    public void setGradientTransformer(GradientPaintTransformer transformer) {
399        Args.nullNotPermitted(transformer, "transformer");
400        this.gradientTransformer = transformer;
401        fireChangeEvent();
402    }
403
404    /**
405     * Initialises the renderer and returns a state object that should be
406     * passed to all subsequent calls to the drawItem() method.
407     *
408     * @param g2  the graphics device.
409     * @param dataArea  the area inside the axes.
410     * @param plot  the plot.
411     * @param data  the data.
412     * @param info  an optional info collection object to return data back to
413     *              the caller.
414     *
415     * @return A state object for use by the renderer.
416     */
417    @Override
418    public XYItemRendererState initialise(Graphics2D g2, Rectangle2D dataArea,
419            XYPlot plot, XYDataset data, PlotRenderingInfo info) {
420        XYAreaRendererState state = new XYAreaRendererState(info);
421
422        // in the rendering process, there is special handling for item
423        // zero, so we can't support processing of visible data items only
424        state.setProcessVisibleItemsOnly(false);
425        return state;
426    }
427
428    /**
429     * Returns a default legend item for the specified series.  Subclasses
430     * should override this method to generate customised items.
431     *
432     * @param datasetIndex  the dataset index (zero-based).
433     * @param series  the series index (zero-based).
434     *
435     * @return A legend item for the series.
436     */
437    @Override
438    public LegendItem getLegendItem(int datasetIndex, int series) {
439        LegendItem result = null;
440        XYPlot xyplot = getPlot();
441        if (xyplot != null) {
442            XYDataset dataset = xyplot.getDataset(datasetIndex);
443            if (dataset != null) {
444                XYSeriesLabelGenerator lg = getLegendItemLabelGenerator();
445                String label = lg.generateLabel(dataset, series);
446                String description = label;
447                String toolTipText = null;
448                if (getLegendItemToolTipGenerator() != null) {
449                    toolTipText = getLegendItemToolTipGenerator().generateLabel(
450                            dataset, series);
451                }
452                String urlText = null;
453                if (getLegendItemURLGenerator() != null) {
454                    urlText = getLegendItemURLGenerator().generateLabel(
455                            dataset, series);
456                }
457                Paint paint = lookupSeriesPaint(series);
458                result = new LegendItem(label, description, toolTipText,
459                        urlText, this.legendArea, paint);
460                result.setLabelFont(lookupLegendTextFont(series));
461                Paint labelPaint = lookupLegendTextPaint(series);
462                if (labelPaint != null) {
463                    result.setLabelPaint(labelPaint);
464                }
465                result.setDataset(dataset);
466                result.setDatasetIndex(datasetIndex);
467                result.setSeriesKey(dataset.getSeriesKey(series));
468                result.setSeriesIndex(series);
469            }
470        }
471        return result;
472    }
473
474    /**
475     * Draws the visual representation of a single data item.
476     *
477     * @param g2  the graphics device.
478     * @param state  the renderer state.
479     * @param dataArea  the area within which the data is being drawn.
480     * @param info  collects information about the drawing.
481     * @param plot  the plot (can be used to obtain standard color information
482     *              etc).
483     * @param domainAxis  the domain axis.
484     * @param rangeAxis  the range axis.
485     * @param dataset  the dataset.
486     * @param series  the series index (zero-based).
487     * @param item  the item index (zero-based).
488     * @param crosshairState  crosshair information for the plot
489     *                        ({@code null} permitted).
490     * @param pass  the pass index.
491     */
492    @Override
493    public void drawItem(Graphics2D g2, XYItemRendererState state,
494            Rectangle2D dataArea, PlotRenderingInfo info, XYPlot plot,
495            ValueAxis domainAxis, ValueAxis rangeAxis, XYDataset dataset,
496            int series, int item, CrosshairState crosshairState, int pass) {
497
498        if (!getItemVisible(series, item)) {
499            return;
500        }
501        XYAreaRendererState areaState = (XYAreaRendererState) state;
502
503        // get the data point...
504        double x1 = dataset.getXValue(series, item);
505        double y1 = dataset.getYValue(series, item);
506        if (Double.isNaN(y1)) {
507            y1 = 0.0;
508        }
509        double transX1 = domainAxis.valueToJava2D(x1, dataArea,
510                plot.getDomainAxisEdge());
511        double transY1 = rangeAxis.valueToJava2D(y1, dataArea,
512                plot.getRangeAxisEdge());
513
514        // get the previous point and the next point so we can calculate a
515        // "hot spot" for the area (used by the chart entity)...
516        int itemCount = dataset.getItemCount(series);
517        double x0 = dataset.getXValue(series, Math.max(item - 1, 0));
518        double y0 = dataset.getYValue(series, Math.max(item - 1, 0));
519        if (Double.isNaN(y0)) {
520            y0 = 0.0;
521        }
522        double transX0 = domainAxis.valueToJava2D(x0, dataArea,
523                plot.getDomainAxisEdge());
524        double transY0 = rangeAxis.valueToJava2D(y0, dataArea,
525                plot.getRangeAxisEdge());
526
527        double x2 = dataset.getXValue(series, Math.min(item + 1,
528                itemCount - 1));
529        double y2 = dataset.getYValue(series, Math.min(item + 1,
530                itemCount - 1));
531        if (Double.isNaN(y2)) {
532            y2 = 0.0;
533        }
534        double transX2 = domainAxis.valueToJava2D(x2, dataArea,
535                plot.getDomainAxisEdge());
536        double transY2 = rangeAxis.valueToJava2D(y2, dataArea,
537                plot.getRangeAxisEdge());
538
539        double transZero = rangeAxis.valueToJava2D(0.0, dataArea,
540                plot.getRangeAxisEdge());
541
542        if (item == 0) {  // create a new area polygon for the series
543            areaState.area = new GeneralPath();
544            // the first point is (x, 0)
545            double zero = rangeAxis.valueToJava2D(0.0, dataArea,
546                    plot.getRangeAxisEdge());
547            if (plot.getOrientation().isVertical()) {
548                moveTo(areaState.area, transX1, zero);
549            } else if (plot.getOrientation().isHorizontal()) {
550                moveTo(areaState.area, zero, transX1);
551            }
552        }
553
554        // Add each point to Area (x, y)
555        if (plot.getOrientation().isVertical()) {
556            lineTo(areaState.area, transX1, transY1);
557        } else if (plot.getOrientation().isHorizontal()) {
558            lineTo(areaState.area, transY1, transX1);
559        }
560
561        PlotOrientation orientation = plot.getOrientation();
562        Paint paint = getItemPaint(series, item);
563        Stroke stroke = getItemStroke(series, item);
564        g2.setPaint(paint);
565        g2.setStroke(stroke);
566
567        Shape shape;
568        if (getPlotShapes()) {
569            shape = getItemShape(series, item);
570            if (orientation == PlotOrientation.VERTICAL) {
571                shape = ShapeUtils.createTranslatedShape(shape, transX1,
572                        transY1);
573            } else if (orientation == PlotOrientation.HORIZONTAL) {
574                shape = ShapeUtils.createTranslatedShape(shape, transY1,
575                        transX1);
576            }
577            g2.draw(shape);
578        }
579
580        if (getPlotLines()) {
581            if (item > 0) {
582                if (plot.getOrientation() == PlotOrientation.VERTICAL) {
583                    areaState.line.setLine(transX0, transY0, transX1, transY1);
584                } else if (plot.getOrientation() == PlotOrientation.HORIZONTAL) {
585                    areaState.line.setLine(transY0, transX0, transY1, transX1);
586                }
587                g2.draw(areaState.line);
588            }
589        }
590
591        // Check if the item is the last item for the series.
592        // and number of items > 0.  We can't draw an area for a single point.
593        if (getPlotArea() && item > 0 && item == (itemCount - 1)) {
594
595            if (orientation == PlotOrientation.VERTICAL) {
596                // Add the last point (x,0)
597                lineTo(areaState.area, transX1, transZero);
598                areaState.area.closePath();
599            } else if (orientation == PlotOrientation.HORIZONTAL) {
600                // Add the last point (x,0)
601                lineTo(areaState.area, transZero, transX1);
602                areaState.area.closePath();
603            }
604
605            if (this.useFillPaint) {
606                paint = lookupSeriesFillPaint(series);
607            }
608            if (paint instanceof GradientPaint) {
609                GradientPaint gp = (GradientPaint) paint;
610                GradientPaint adjGP = this.gradientTransformer.transform(gp,
611                        dataArea);
612                g2.setPaint(adjGP);
613            }
614            g2.fill(areaState.area);
615
616            // draw an outline around the Area.
617            if (isOutline()) {
618                Shape area = areaState.area;
619
620                // Java2D has some issues drawing dashed lines around "large"
621                // geometrical shapes - for example, see bug 6620013 in the
622                // Java bug database.  So, we'll check if the outline is
623                // dashed and, if it is, do our own clipping before drawing
624                // the outline...
625                Stroke outlineStroke = lookupSeriesOutlineStroke(series);
626                if (outlineStroke instanceof BasicStroke) {
627                    BasicStroke bs = (BasicStroke) outlineStroke;
628                    if (bs.getDashArray() != null) {
629                        Area poly = new Area(areaState.area);
630                        // we make the clip region slightly larger than the
631                        // dataArea so that the clipped edges don't show lines
632                        // on the chart
633                        Area clip = new Area(new Rectangle2D.Double(
634                                dataArea.getX() - 5.0, dataArea.getY() - 5.0,
635                                dataArea.getWidth() + 10.0,
636                                dataArea.getHeight() + 10.0));
637                        poly.intersect(clip);
638                        area = poly;
639                    }
640                } // end of workaround
641
642                g2.setStroke(outlineStroke);
643                g2.setPaint(lookupSeriesOutlinePaint(series));
644                g2.draw(area);
645            }
646        }
647
648        int datasetIndex = plot.indexOf(dataset);
649        updateCrosshairValues(crosshairState, x1, y1, datasetIndex,
650                transX1, transY1, orientation);
651
652        // collect entity and tool tip information...
653        EntityCollection entities = state.getEntityCollection();
654        if (entities != null) {
655            GeneralPath hotspot = new GeneralPath();
656            if (plot.getOrientation() == PlotOrientation.HORIZONTAL) {
657                moveTo(hotspot, transZero, ((transX0 + transX1) / 2.0));
658                lineTo(hotspot, ((transY0 + transY1) / 2.0), ((transX0 + transX1) / 2.0));
659                lineTo(hotspot, transY1, transX1);
660                lineTo(hotspot, ((transY1 + transY2) / 2.0), ((transX1 + transX2) / 2.0));
661                lineTo(hotspot, transZero, ((transX1 + transX2) / 2.0));
662            } else { // vertical orientation
663                moveTo(hotspot, ((transX0 + transX1) / 2.0), transZero);
664                lineTo(hotspot, ((transX0 + transX1) / 2.0), ((transY0 + transY1) / 2.0));
665                lineTo(hotspot, transX1, transY1);
666                lineTo(hotspot, ((transX1 + transX2) / 2.0), ((transY1 + transY2) / 2.0));
667                lineTo(hotspot, ((transX1 + transX2) / 2.0), transZero);
668            }
669            hotspot.closePath();
670
671            // limit the entity hotspot area to the data area
672            Area dataAreaHotspot = new Area(hotspot);
673            dataAreaHotspot.intersect(new Area(dataArea));
674
675            if (dataAreaHotspot.isEmpty() == false) {
676                addEntity(entities, dataAreaHotspot, dataset, series, item, 
677                        0.0, 0.0);
678            }
679        }
680
681    }
682
683    /**
684     * Returns a clone of the renderer.
685     *
686     * @return A clone.
687     *
688     * @throws CloneNotSupportedException  if the renderer cannot be cloned.
689     */
690    @Override
691    public Object clone() throws CloneNotSupportedException {
692        XYAreaRenderer clone = (XYAreaRenderer) super.clone();
693        clone.legendArea = ShapeUtils.clone(this.legendArea);
694        return clone;
695    }
696
697    /**
698     * Tests this renderer for equality with an arbitrary object.
699     *
700     * @param obj  the object ({@code null} permitted).
701     *
702     * @return A boolean.
703     */
704    @Override
705    public boolean equals(Object obj) {
706        if (obj == this) {
707            return true;
708        }
709        if (!(obj instanceof XYAreaRenderer)) {
710            return false;
711        }
712        XYAreaRenderer that = (XYAreaRenderer) obj;
713        if (this.plotArea != that.plotArea) {
714            return false;
715        }
716        if (this.plotLines != that.plotLines) {
717            return false;
718        }
719        if (this.plotShapes != that.plotShapes) {
720            return false;
721        }
722        if (this.showOutline != that.showOutline) {
723            return false;
724        }
725        if (this.useFillPaint != that.useFillPaint) {
726            return false;
727        }
728        if (!this.gradientTransformer.equals(that.gradientTransformer)) {
729            return false;
730        }
731        if (!ShapeUtils.equal(this.legendArea, that.legendArea)) {
732            return false;
733        }
734        return true;
735    }
736
737    /**
738     * Returns a hash code for this instance.
739     *
740     * @return A hash code.
741     */
742    @Override
743    public int hashCode() {
744        int result = super.hashCode();
745        result = HashUtils.hashCode(result, this.plotArea);
746        result = HashUtils.hashCode(result, this.plotLines);
747        result = HashUtils.hashCode(result, this.plotShapes);
748        result = HashUtils.hashCode(result, this.useFillPaint);
749        return result;
750    }
751
752    /**
753     * Provides serialization support.
754     *
755     * @param stream  the input stream.
756     *
757     * @throws IOException  if there is an I/O error.
758     * @throws ClassNotFoundException  if there is a classpath problem.
759     */
760    private void readObject(ObjectInputStream stream)
761            throws IOException, ClassNotFoundException {
762        stream.defaultReadObject();
763        this.legendArea = SerialUtils.readShape(stream);
764    }
765
766    /**
767     * Provides serialization support.
768     *
769     * @param stream  the output stream.
770     *
771     * @throws IOException  if there is an I/O error.
772     */
773    private void writeObject(ObjectOutputStream stream) throws IOException {
774        stream.defaultWriteObject();
775        SerialUtils.writeShape(this.legendArea, stream);
776    }
777}