📄 xyplot.java
字号:
/* ===========================================================
* JFreeChart : a free chart library for the Java(tm) platform
* ===========================================================
*
* (C) Copyright 2000-2007, by Object Refinery Limited and Contributors.
*
* Project Info: http://www.jfree.org/jfreechart/index.html
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
* USA.
*
* [Java is a trademark or registered trademark of Sun Microsystems, Inc.
* in the United States and other countries.]
*
* -----------
* XYPlot.java
* -----------
* (C) Copyright 2000-2007, by Object Refinery Limited and Contributors.
*
* Original Author: David Gilbert (for Object Refinery Limited);
* Contributor(s): Craig MacFarlane;
* Mark Watson (www.markwatson.com);
* Jonathan Nash;
* Gideon Krause;
* Klaus Rheinwald;
* Xavier Poinsard;
* Richard Atkinson;
* Arnaud Lelievre;
* Nicolas Brodu;
* Eduardo Ramalho;
* Sergei Ivanov;
*
* $Id: XYPlot.java,v 1.44.2.29 2007/06/07 12:49:36 mungady Exp $
*
* Changes (from 21-Jun-2001)
* --------------------------
* 21-Jun-2001 : Removed redundant JFreeChart parameter from constructors (DG);
* 18-Sep-2001 : Updated header and fixed DOS encoding problem (DG);
* 15-Oct-2001 : Data source classes moved to com.jrefinery.data.* (DG);
* 19-Oct-2001 : Removed the code for drawing the visual representation of each
* data point into a separate class StandardXYItemRenderer.
* This will make it easier to add variations to the way the
* charts are drawn. Based on code contributed by Mark
* Watson (DG);
* 22-Oct-2001 : Renamed DataSource.java --> Dataset.java etc. (DG);
* 20-Nov-2001 : Fixed clipping bug that shows up when chart is displayed
* inside JScrollPane (DG);
* 12-Dec-2001 : Removed unnecessary 'throws' clauses from constructor (DG);
* 13-Dec-2001 : Added skeleton code for tooltips. Added new constructor. (DG);
* 16-Jan-2002 : Renamed the tooltips class (DG);
* 22-Jan-2002 : Added DrawInfo class, incorporating tooltips and crosshairs.
* Crosshairs based on code by Jonathan Nash (DG);
* 05-Feb-2002 : Added alpha-transparency setting based on code by Sylvain
* Vieujot (DG);
* 26-Feb-2002 : Updated getMinimumXXX() and getMaximumXXX() methods to handle
* special case when chart is null (DG);
* 28-Feb-2002 : Renamed Datasets.java --> DatasetUtilities.java (DG);
* 28-Mar-2002 : The plot now registers with the renderer as a property change
* listener. Also added a new constructor (DG);
* 09-Apr-2002 : Removed the transRangeZero from the renderer.drawItem()
* method. Moved the tooltip generator into the renderer (DG);
* 23-Apr-2002 : Fixed bug in methods for drawing horizontal and vertical
* lines (DG);
* 13-May-2002 : Small change to the draw() method so that it works for
* OverlaidXYPlot also (DG);
* 25-Jun-2002 : Removed redundant import (DG);
* 20-Aug-2002 : Renamed getItemRenderer() --> getRenderer(), and
* setXYItemRenderer() --> setRenderer() (DG);
* 28-Aug-2002 : Added mechanism for (optional) plot annotations (DG);
* 02-Oct-2002 : Fixed errors reported by Checkstyle (DG);
* 18-Nov-2002 : Added grid settings for both domain and range axis (previously
* these were set in the axes) (DG);
* 09-Jan-2003 : Further additions to the grid settings, plus integrated plot
* border bug fix contributed by Gideon Krause (DG);
* 22-Jan-2003 : Removed monolithic constructor (DG);
* 04-Mar-2003 : Added 'no data' message, see bug report 691634. Added
* secondary range markers using code contributed by Klaus
* Rheinwald (DG);
* 26-Mar-2003 : Implemented Serializable (DG);
* 03-Apr-2003 : Added setDomainAxisLocation() method (DG);
* 30-Apr-2003 : Moved annotation drawing into a separate method (DG);
* 01-May-2003 : Added multi-pass mechanism for renderers (DG);
* 02-May-2003 : Changed axis locations from int to AxisLocation (DG);
* 15-May-2003 : Added an orientation attribute (DG);
* 02-Jun-2003 : Removed range axis compatibility test (DG);
* 05-Jun-2003 : Added domain and range grid bands (sponsored by Focus Computer
* Services Ltd) (DG);
* 26-Jun-2003 : Fixed bug (757303) in getDataRange() method (DG);
* 02-Jul-2003 : Added patch from bug report 698646 (secondary axes for
* overlaid plots) (DG);
* 23-Jul-2003 : Added support for multiple secondary datasets, axes and
* renderers (DG);
* 27-Jul-2003 : Added support for stacked XY area charts (RA);
* 19-Aug-2003 : Implemented Cloneable (DG);
* 01-Sep-2003 : Fixed bug where change to secondary datasets didn't generate
* change event (797466) (DG)
* 08-Sep-2003 : Added internationalization via use of properties
* resourceBundle (RFE 690236) (AL);
* 08-Sep-2003 : Changed ValueAxis API (DG);
* 08-Sep-2003 : Fixes for serialization (NB);
* 16-Sep-2003 : Changed ChartRenderingInfo --> PlotRenderingInfo (DG);
* 17-Sep-2003 : Fixed zooming to include secondary domain axes (DG);
* 18-Sep-2003 : Added getSecondaryDomainAxisCount() and
* getSecondaryRangeAxisCount() methods suggested by Eduardo
* Ramalho (RFE 808548) (DG);
* 23-Sep-2003 : Split domain and range markers into foreground and
* background (DG);
* 06-Oct-2003 : Fixed bug in clearDomainMarkers() and clearRangeMarkers()
* methods. Fixed bug (815876) in addSecondaryRangeMarker()
* method. Added new addSecondaryDomainMarker methods (see bug
* id 815869) (DG);
* 10-Nov-2003 : Added getSecondaryDomain/RangeAxisMappedToDataset() methods
* requested by Eduardo Ramalho (DG);
* 24-Nov-2003 : Removed unnecessary notification when updating axis anchor
* values (DG);
* 21-Jan-2004 : Update for renamed method in ValueAxis (DG);
* 25-Feb-2004 : Replaced CrosshairInfo with CrosshairState (DG);
* 12-Mar-2004 : Fixed bug where primary renderer is always used to determine
* range type (DG);
* 22-Mar-2004 : Fixed cloning bug (DG);
* 23-Mar-2004 : Fixed more cloning bugs (DG);
* 07-Apr-2004 : Fixed problem with axis range when the secondary renderer is
* stacked, see this post in the forum:
* http://www.jfree.org/phpBB2/viewtopic.php?t=8204 (DG);
* 07-Apr-2004 : Added get/setDatasetRenderingOrder() methods (DG);
* 26-Apr-2004 : Added option to fill quadrant areas in the background of the
* plot (DG);
* 27-Apr-2004 : Removed major distinction between primary and secondary
* datasets, renderers and axes (DG);
* 30-Apr-2004 : Modified to make use of the new getRangeExtent() method in the
* renderer interface (DG);
* 13-May-2004 : Added optional fixedLegendItems attribute (DG);
* 19-May-2004 : Added indexOf() method (DG);
* 03-Jun-2004 : Fixed zooming bug (DG);
* 18-Aug-2004 : Added removedAnnotation() method (by tkram01) (DG);
* 05-Oct-2004 : Modified storage type for dataset-to-axis maps (DG);
* 06-Oct-2004 : Modified getDataRange() method to use renderer to determine
* the x-value range (now matches behaviour for y-values). Added
* getDomainAxisIndex() method (DG);
* 12-Nov-2004 : Implemented new Zoomable interface (DG);
* 25-Nov-2004 : Small update to clone() implementation (DG);
* 22-Feb-2005 : Changed axis offsets from Spacer --> RectangleInsets (DG);
* 24-Feb-2005 : Added indexOf(XYItemRenderer) method (DG);
* 21-Mar-2005 : Register plot as change listener in setRenderer() method (DG);
* 21-Apr-2005 : Added get/setSeriesRenderingOrder() methods (ET);
* 26-Apr-2005 : Removed LOGGER (DG);
* 04-May-2005 : Fixed serialization of domain and range markers (DG);
* 05-May-2005 : Removed unused draw() method (DG);
* 20-May-2005 : Added setDomainAxes() and setRangeAxes() methods, as per
* RFE 1183100 (DG);
* 01-Jun-2005 : Upon deserialization, register plot as a listener with its
* axes, dataset(s) and renderer(s) - see patch 1209475 (DG);
* 01-Jun-2005 : Added clearDomainMarkers(int) method to match
* clearRangeMarkers(int) (DG);
* 06-Jun-2005 : Fixed equals() method to handle GradientPaint (DG);
* 09-Jun-2005 : Added setRenderers(), as per RFE 1183100 (DG);
* 06-Jul-2005 : Fixed crosshair bug (id = 1233336) (DG);
* ------------- JFREECHART 1.0.x ---------------------------------------------
* 26-Jan-2006 : Added getAnnotations() method (DG);
* 05-Sep-2006 : Added MarkerChangeEvent support (DG);
* 13-Oct-2006 : Fixed initialisation of CrosshairState - see bug report
* 1565168 (DG);
* 22-Nov-2006 : Fixed equals() and cloning() for quadrant attributes, plus
* API doc updates (DG);
* 29-Nov-2006 : Added argument checks (DG);
* 15-Jan-2007 : Fixed bug in drawRangeMarkers() (DG);
* 07-Feb-2007 : Fixed bug 1654215, renderer with no dataset (DG);
* 26-Feb-2007 : Added missing setDomainAxisLocation() and
* setRangeAxisLocation() methods (DG);
* 02-Mar-2007 : Fix for crosshair positioning with horizontal orientation
* (see patch 1671648 by Sergei Ivanov) (DG);
* 13-Mar-2007 : Added null argument checks for crosshair attributes (DG);
* 23-Mar-2007 : Added domain zero base line facility (DG);
* 04-May-2007 : Render only visible data items if possible (DG);
* 24-May-2007 : Fixed bug in render method for an empty series (DG);
* 07-Jun-2007 : Modified drawBackground() to pass orientation to
* fillBackground() for handling GradientPaint (DG);
*
*/
package org.jfree.chart.plot;
import java.awt.AlphaComposite;
import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Composite;
import java.awt.Graphics2D;
import java.awt.Paint;
import java.awt.Shape;
import java.awt.Stroke;
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.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.ResourceBundle;
import java.util.Set;
import java.util.TreeMap;
import org.jfree.chart.LegendItem;
import org.jfree.chart.LegendItemCollection;
import org.jfree.chart.annotations.XYAnnotation;
import org.jfree.chart.axis.Axis;
import org.jfree.chart.axis.AxisCollection;
import org.jfree.chart.axis.AxisLocation;
import org.jfree.chart.axis.AxisSpace;
import org.jfree.chart.axis.AxisState;
import org.jfree.chart.axis.ValueAxis;
import org.jfree.chart.axis.ValueTick;
import org.jfree.chart.event.ChartChangeEventType;
import org.jfree.chart.event.PlotChangeEvent;
import org.jfree.chart.event.RendererChangeEvent;
import org.jfree.chart.event.RendererChangeListener;
import org.jfree.chart.renderer.RendererUtilities;
import org.jfree.chart.renderer.xy.AbstractXYItemRenderer;
import org.jfree.chart.renderer.xy.XYItemRenderer;
import org.jfree.chart.renderer.xy.XYItemRendererState;
import org.jfree.data.Range;
import org.jfree.data.general.Dataset;
import org.jfree.data.general.DatasetChangeEvent;
import org.jfree.data.general.DatasetUtilities;
import org.jfree.data.xy.XYDataset;
import org.jfree.io.SerialUtilities;
import org.jfree.ui.Layer;
import org.jfree.ui.RectangleEdge;
import org.jfree.ui.RectangleInsets;
import org.jfree.util.ObjectList;
import org.jfree.util.ObjectUtilities;
import org.jfree.util.PaintUtilities;
import org.jfree.util.PublicCloneable;
/**
* A general class for plotting data in the form of (x, y) pairs. This plot can
* use data from any class that implements the {@link XYDataset} interface.
* <P>
* <code>XYPlot</code> makes use of an {@link XYItemRenderer} to draw each point
* on the plot. By using different renderers, various chart types can be
* produced.
* <p>
* The {@link org.jfree.chart.ChartFactory} class contains static methods for
* creating pre-configured charts.
*/
public class XYPlot extends Plot implements ValueAxisPlot,
Zoomable,
RendererChangeListener,
Cloneable, PublicCloneable,
Serializable {
/** For serialization. */
private static final long serialVersionUID = 7044148245716569264L;
/** The default grid line stroke. */
public static final Stroke DEFAULT_GRIDLINE_STROKE = new BasicStroke(0.5f,
BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 0.0f,
new float[] {2.0f, 2.0f}, 0.0f);
/** The default grid line paint. */
public static final Paint DEFAULT_GRIDLINE_PAINT = Color.lightGray;
/** The default crosshair visibility. */
public static final boolean DEFAULT_CROSSHAIR_VISIBLE = false;
/** The default crosshair stroke. */
public static final Stroke DEFAULT_CROSSHAIR_STROKE
= DEFAULT_GRIDLINE_STROKE;
/** The default crosshair paint. */
public static final Paint DEFAULT_CROSSHAIR_PAINT = Color.blue;
/** The resourceBundle for the localization. */
protected static ResourceBundle localizationResources
= ResourceBundle.getBundle(
"org.jfree.chart.plot.LocalizationBundle");
/** The plot orientation. */
private PlotOrientation orientation;
/** The offset between the data area and the axes. */
private RectangleInsets axisOffset;
/** The domain axis / axes (used for the x-values). */
private ObjectList domainAxes;
/** The domain axis locations. */
private ObjectList domainAxisLocations;
/** The range axis (used for the y-values). */
private ObjectList rangeAxes;
/** The range axis location. */
private ObjectList rangeAxisLocations;
/** Storage for the datasets. */
private ObjectList datasets;
/** Storage for the renderers. */
private ObjectList renderers;
/**
* Storage for keys that map datasets/renderers to domain axes. If the
* map contains no entry for a dataset, it is assumed to map to the
* primary domain axis (index = 0).
*/
private Map datasetToDomainAxisMap;
/**
* Storage for keys that map datasets/renderers to range axes. If the
* map contains no entry for a dataset, it is assumed to map to the
* primary domain axis (index = 0).
*/
private Map datasetToRangeAxisMap;
/** The origin point for the quadrants (if drawn). */
private transient Point2D quadrantOrigin = new Point2D.Double(0.0, 0.0);
/** The paint used for each quadrant. */
private transient Paint[] quadrantPaint
= new Paint[] {null, null, null, null};
/** A flag that controls whether the domain grid-lines are visible. */
private boolean domainGridlinesVisible;
/** The stroke used to draw the domain grid-lines. */
private transient Stroke domainGridlineStroke;
/** The paint used to draw the domain grid-lines. */
private transient Paint domainGridlinePaint;
/** A flag that controls whether the range grid-lines are visible. */
private boolean rangeGridlinesVisible;
/** The stroke used to draw the range grid-lines. */
private transient Stroke rangeGridlineStroke;
/** The paint used to draw the range grid-lines. */
private transient Paint rangeGridlinePaint;
/**
* A flag that controls whether or not the zero baseline against the domain
* axis is visible.
*
* @since 1.0.5
*/
private boolean domainZeroBaselineVisible;
/**
* The stroke used for the zero baseline against the domain axis.
*
* @since 1.0.5
*/
private transient Stroke domainZeroBaselineStroke;
/**
* The paint used for the zero baseline against the domain axis.
*
* @since 1.0.5
*/
private transient Paint domainZeroBaselinePaint;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -