📄 fastscatterplot.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.]
*
* --------------------
* FastScatterPlot.java
* --------------------
* (C) Copyright 2002-2007, by Object Refinery Limited.
*
* Original Author: David Gilbert (for Object Refinery Limited);
* Contributor(s): Arnaud Lelievre;
*
* $Id: FastScatterPlot.java,v 1.11.2.5 2007/01/11 11:06:04 mungady Exp $
*
* Changes (from 29-Oct-2002)
* --------------------------
* 29-Oct-2002 : Added standard header (DG);
* 07-Nov-2002 : Fixed errors reported by Checkstyle (DG);
* 26-Mar-2003 : Implemented Serializable (DG);
* 19-Aug-2003 : Implemented Cloneable (DG);
* 08-Sep-2003 : Added internationalization via use of properties
* resourceBundle (RFE 690236) (AL);
* 16-Sep-2003 : Changed ChartRenderingInfo --> PlotRenderingInfo (DG);
* 12-Nov-2003 : Implemented zooming (DG);
* 21-Jan-2004 : Update for renamed method in ValueAxis (DG);
* 26-Jan-2004 : Added domain and range grid lines (DG);
* 25-Feb-2004 : Replaced CrosshairInfo with CrosshairState (DG);
* 29-Sep-2004 : Removed hard-coded color (DG);
* 04-Oct-2004 : Reworked equals() method and renamed ArrayUtils
* --> ArrayUtilities (DG);
* 12-Nov-2004 : Implemented the new Zoomable interface (DG);
* 05-May-2005 : Updated draw() method parameters (DG);
* 16-Jun-2005 : Added get/setData() methods (DG);
* ------------- JFREECHART 1.0.x ---------------------------------------------
* 10-Nov-2006 : Fixed bug 1593150, by not allowing null axes, and added
* setDomainAxis() and setRangeAxis() methods (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.Iterator;
import java.util.List;
import java.util.ResourceBundle;
import org.jfree.chart.axis.AxisSpace;
import org.jfree.chart.axis.AxisState;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.axis.ValueAxis;
import org.jfree.chart.axis.ValueTick;
import org.jfree.chart.event.PlotChangeEvent;
import org.jfree.data.Range;
import org.jfree.io.SerialUtilities;
import org.jfree.ui.RectangleEdge;
import org.jfree.ui.RectangleInsets;
import org.jfree.util.ArrayUtilities;
import org.jfree.util.ObjectUtilities;
import org.jfree.util.PaintUtilities;
/**
* A fast scatter plot.
*/
public class FastScatterPlot extends Plot implements ValueAxisPlot,
Zoomable,
Cloneable, Serializable {
/** For serialization. */
private static final long serialVersionUID = 7871545897358563521L;
/** 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 data. */
private float[][] data;
/** The x data range. */
private Range xDataRange;
/** The y data range. */
private Range yDataRange;
/** The domain axis (used for the x-values). */
private ValueAxis domainAxis;
/** The range axis (used for the y-values). */
private ValueAxis rangeAxis;
/** The paint used to plot data points. */
private transient Paint paint;
/** 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;
/** The resourceBundle for the localization. */
protected static ResourceBundle localizationResources =
ResourceBundle.getBundle("org.jfree.chart.plot.LocalizationBundle");
/**
* Creates a new instance of <code>FastScatterPlot</code> with default
* axes.
*/
public FastScatterPlot() {
this(null, new NumberAxis("X"), new NumberAxis("Y"));
}
/**
* Creates a new fast scatter plot.
* <p>
* The data is an array of x, y values: data[0][i] = x, data[1][i] = y.
*
* @param data the data (<code>null</code> permitted).
* @param domainAxis the domain (x) axis (<code>null</code> not permitted).
* @param rangeAxis the range (y) axis (<code>null</code> not permitted).
*/
public FastScatterPlot(float[][] data,
ValueAxis domainAxis, ValueAxis rangeAxis) {
super();
if (domainAxis == null) {
throw new IllegalArgumentException("Null 'domainAxis' argument.");
}
if (rangeAxis == null) {
throw new IllegalArgumentException("Null 'rangeAxis' argument.");
}
this.data = data;
this.xDataRange = calculateXDataRange(data);
this.yDataRange = calculateYDataRange(data);
this.domainAxis = domainAxis;
this.domainAxis.setPlot(this);
this.domainAxis.addChangeListener(this);
this.rangeAxis = rangeAxis;
this.rangeAxis.setPlot(this);
this.rangeAxis.addChangeListener(this);
this.paint = Color.red;
this.domainGridlinesVisible = true;
this.domainGridlinePaint = FastScatterPlot.DEFAULT_GRIDLINE_PAINT;
this.domainGridlineStroke = FastScatterPlot.DEFAULT_GRIDLINE_STROKE;
this.rangeGridlinesVisible = true;
this.rangeGridlinePaint = FastScatterPlot.DEFAULT_GRIDLINE_PAINT;
this.rangeGridlineStroke = FastScatterPlot.DEFAULT_GRIDLINE_STROKE;
}
/**
* Returns a short string describing the plot type.
*
* @return A short string describing the plot type.
*/
public String getPlotType() {
return localizationResources.getString("Fast_Scatter_Plot");
}
/**
* Returns the data array used by the plot.
*
* @return The data array (possibly <code>null</code>).
*
* @see #setData(float[][])
*/
public float[][] getData() {
return this.data;
}
/**
* Sets the data array used by the plot and sends a {@link PlotChangeEvent}
* to all registered listeners.
*
* @param data the data array (<code>null</code> permitted).
*
* @see #getData()
*/
public void setData(float[][] data) {
this.data = data;
notifyListeners(new PlotChangeEvent(this));
}
/**
* Returns the orientation of the plot.
*
* @return The orientation (always {@link PlotOrientation#VERTICAL}).
*/
public PlotOrientation getOrientation() {
return PlotOrientation.VERTICAL;
}
/**
* Returns the domain axis for the plot.
*
* @return The domain axis (never <code>null</code>).
*
* @see #setDomainAxis(ValueAxis)
*/
public ValueAxis getDomainAxis() {
return this.domainAxis;
}
/**
* Sets the domain axis and sends a {@link PlotChangeEvent} to all
* registered listeners.
*
* @param axis the axis (<code>null</code> not permitted).
*
* @since 1.0.3
*
* @see #getDomainAxis()
*/
public void setDomainAxis(ValueAxis axis) {
if (axis == null) {
throw new IllegalArgumentException("Null 'axis' argument.");
}
this.domainAxis = axis;
notifyListeners(new PlotChangeEvent(this));
}
/**
* Returns the range axis for the plot.
*
* @return The range axis (never <code>null</code>).
*
* @see #setRangeAxis(ValueAxis)
*/
public ValueAxis getRangeAxis() {
return this.rangeAxis;
}
/**
* Sets the range axis and sends a {@link PlotChangeEvent} to all
* registered listeners.
*
* @param axis the axis (<code>null</code> not permitted).
*
* @since 1.0.3
*
* @see #getRangeAxis()
*/
public void setRangeAxis(ValueAxis axis) {
if (axis == null) {
throw new IllegalArgumentException("Null 'axis' argument.");
}
this.rangeAxis = axis;
notifyListeners(new PlotChangeEvent(this));
}
/**
* Returns the paint used to plot data points. The default is
* <code>Color.red</code>.
*
* @return The paint.
*
* @see #setPaint(Paint)
*/
public Paint getPaint() {
return this.paint;
}
/**
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -