📄 fastscatterplot.java
字号:
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2004, 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., 59 Temple Place, Suite 330, * Boston, MA 02111-1307, USA. * * [Java is a trademark or registered trademark of Sun Microsystems, Inc. * in the United States and other countries.] * * -------------------- * FastScatterPlot.java * -------------------- * (C) Copyright 2002-2004, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): Arnaud Lelievre; * * $Id: FastScatterPlot.java,v 1.31 2004/04/15 13:58:28 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); * */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.Insets;import java.awt.Paint;import java.awt.Shape;import java.awt.Stroke;import java.awt.geom.Line2D;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.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.util.ArrayUtils;import org.jfree.util.ObjectUtils;/** * A fast scatter plot. * */public class FastScatterPlot extends Plot implements ValueAxisPlot, Cloneable, Serializable { /** 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 an empty plot. */ public FastScatterPlot() { this(null, null, null); } /** * 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. * @param domainAxis the domain (x) axis. * @param rangeAxis the range (y) axis. */ public FastScatterPlot(float[][] data, ValueAxis domainAxis, ValueAxis rangeAxis) { super(); this.data = data; this.xDataRange = calculateXDataRange(data); this.yDataRange = calculateYDataRange(data); this.domainAxis = domainAxis; if (domainAxis != null) { domainAxis.setPlot(this); domainAxis.addChangeListener(this); } this.rangeAxis = rangeAxis; if (rangeAxis != null) { rangeAxis.setPlot(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 domain axis for the plot. If the domain axis for this plot * is null, then the method will return the parent plot's domain axis (if * there is a parent plot). * * @return the domain axis. */ public ValueAxis getDomainAxis() { return this.domainAxis; } /** * Returns the range axis for the plot. If the range axis for this plot is * null, then the method will return the parent plot's range axis (if * there is a parent plot). * * @return the range axis. */ public ValueAxis getRangeAxis() { return this.rangeAxis; } /** * Returns the paint used to plot data points. * * @return The paint. */ public Paint getPaint() { return this.paint; } /** * Sets the color for the data points and sends a {@link PlotChangeEvent} to all * registered listeners. * * @param paint the paint. */ public void setPaint(Paint paint) { this.paint = paint; notifyListeners(new PlotChangeEvent(this)); } /** * Returns <code>true</code> if the domain gridlines are visible, and <code>false<code> * otherwise. * * @return <code>true</code> or <code>false</code>. */ public boolean isDomainGridlinesVisible() { return this.domainGridlinesVisible; } /** * Sets the flag that controls whether or not the domain grid-lines are visible. * <p> * If the flag value is changed, a {@link PlotChangeEvent} is sent to all registered listeners. * * @param visible the new value of the flag. */ public void setDomainGridlinesVisible(boolean visible) { if (this.domainGridlinesVisible != visible) { this.domainGridlinesVisible = visible; notifyListeners(new PlotChangeEvent(this)); } } /** * Returns the stroke for the grid-lines (if any) plotted against the domain axis. * * @return the stroke. */ public Stroke getDomainGridlineStroke() { return this.domainGridlineStroke; } /** * Sets the stroke for the grid lines plotted against the domain axis. * <p> * If you set this to <code>null</code>, no grid lines will be drawn. * * @param stroke the stroke (<code>null</code> permitted). */ public void setDomainGridlineStroke(Stroke stroke) { this.domainGridlineStroke = stroke; notifyListeners(new PlotChangeEvent(this)); } /** * Returns the paint for the grid lines (if any) plotted against the domain axis. * * @return the paint. */ public Paint getDomainGridlinePaint() { return this.domainGridlinePaint; } /** * Sets the paint for the grid lines plotted against the domain axis. * <p> * If you set this to <code>null</code>, no grid lines will be drawn. * * @param paint the paint (<code>null</code> permitted). */ public void setDomainGridlinePaint(Paint paint) { this.domainGridlinePaint = paint; notifyListeners(new PlotChangeEvent(this)); } /** * Returns <code>true</code> if the range axis grid is visible, and <code>false<code> * otherwise. * * @return <code>true</code> or <code>false</code>. */ public boolean isRangeGridlinesVisible() { return this.rangeGridlinesVisible; } /** * Sets the flag that controls whether or not the range axis grid lines are visible. * <p> * If the flag value is changed, a {@link PlotChangeEvent} is sent to all registered listeners. * * @param visible the new value of the flag. */ public void setRangeGridlinesVisible(boolean visible) { if (this.rangeGridlinesVisible != visible) { this.rangeGridlinesVisible = visible; notifyListeners(new PlotChangeEvent(this)); } } /** * Returns the stroke for the grid lines (if any) plotted against the range axis. * * @return the stroke. */ public Stroke getRangeGridlineStroke() { return this.rangeGridlineStroke; } /** * Sets the stroke for the grid lines plotted against the range axis. * <p> * If you set this to <code>null</code>, no grid lines will be drawn. * * @param stroke the stroke (<code>null</code> permitted). */ public void setRangeGridlineStroke(Stroke stroke) { this.rangeGridlineStroke = stroke; notifyListeners(new PlotChangeEvent(this)); } /** * Returns the paint for the grid lines (if any) plotted against the range axis. * * @return the paint. */ public Paint getRangeGridlinePaint() { return this.rangeGridlinePaint; } /** * Sets the paint for the grid lines plotted against the range axis. * <p> * If you set this to <code>null</code>, no grid lines will be drawn. * * @param paint the paint (<code>null</code> permitted). */ public void setRangeGridlinePaint(Paint paint) { this.rangeGridlinePaint = paint; notifyListeners(new PlotChangeEvent(this)); } /** * Draws the fast scatter plot on a Java 2D graphics device (such as the screen or * a printer). * * @param g2 the graphics device. * @param plotArea the area within which the plot (including axis labels) should be drawn. * @param parentState the state from the parent plot, if there is one. * @param info collects chart drawing information (<code>null</code> permitted). */ public void draw(Graphics2D g2, Rectangle2D plotArea, PlotState parentState, PlotRenderingInfo info) { // set up info collection... if (info != null) { info.setPlotArea(plotArea); } // adjust the drawing area for plot insets (if any)... Insets insets = getInsets(); if (insets != null) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -