?? fastscatterplot.java
字號:
/* ======================================
* JFreeChart : a free Java chart library
* ======================================
*
* Project Info: http://www.jfree.org/jfreechart/index.html
* Project Lead: David Gilbert (david.gilbert@object-refinery.com);
*
* (C) Copyright 2000-2003, by Object Refinery Limited and Contributors.
*
* 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.
*
* --------------------
* FastScatterPlot.java
* --------------------
* (C) Copyright 2002, 2003, by Object Refinery Limited.
*
* Original Author: David Gilbert (for Object Refinery Limited);
* Contributor(s): Arnaud Lelievre;
*
* $Id: FastScatterPlot.java,v 1.16 2003/09/08 22:08:02 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);
*
*/
package org.jfree.chart.plot;
import java.awt.AlphaComposite;
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.geom.Rectangle2D;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.util.ResourceBundle;
import org.jfree.chart.ChartRenderingInfo;
import org.jfree.chart.CrosshairInfo;
import org.jfree.chart.axis.AxisSpace;
import org.jfree.chart.axis.ValueAxis;
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.
*
* @author David Gilbert
*/
public class FastScatterPlot extends Plot implements ValueAxisPlot, Cloneable, Serializable {
/** 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;
/** The resourceBundle for the localization. */
static protected 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;
}
/**
* 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.
*
* @param paint the paint.
*/
public void setPaint(Paint paint) {
this.paint = paint;
this.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 info collects chart drawing information (<code>null</code> permitted).
*/
public void draw(Graphics2D g2, Rectangle2D plotArea, ChartRenderingInfo 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) {
plotArea.setRect(plotArea.getX() + insets.left,
plotArea.getY() + insets.top,
plotArea.getWidth() - insets.left - insets.right,
plotArea.getHeight() - insets.top - insets.bottom);
}
AxisSpace space = new AxisSpace();
space = this.domainAxis.reserveSpace(g2, this, plotArea, RectangleEdge.BOTTOM, space);
space = this.rangeAxis.reserveSpace(g2, this, plotArea, RectangleEdge.LEFT, space);
Rectangle2D dataArea = space.shrink(plotArea, null);
if (info != null) {
info.setDataArea(dataArea);
}
// draw the plot background and axes...
drawBackground(g2, dataArea);
double cursor;
if (this.domainAxis != null) {
cursor = dataArea.getMaxY();
cursor = this.domainAxis.draw(g2, cursor, plotArea, dataArea, RectangleEdge.BOTTOM);
}
if (this.rangeAxis != null) {
cursor = dataArea.getMinX();
cursor = this.rangeAxis.draw(g2, cursor, plotArea, dataArea, RectangleEdge.LEFT);
}
Shape originalClip = g2.getClip();
Composite originalComposite = g2.getComposite();
g2.clip(dataArea);
g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER,
getForegroundAlpha()));
render(g2, dataArea, info, null);
g2.setClip(originalClip);
g2.setComposite(originalComposite);
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -