📄 stackedxyarearenderer.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.] * * -------------------------- * StackedXYAreaRenderer.java * -------------------------- * (C) Copyright 2003, 2004, by Richard Atkinson and Contributors. * * Original Author: Richard Atkinson; * Contributor(s): Christian W. Zuckschwerdt; * David Gilbert (for Object Refinery Limited); * * $Id: StackedXYAreaRenderer.java,v 1.10 2004/04/30 08:42:50 mungady Exp $ * * Changes: * -------- * 27-Jul-2003 : Initial version (RA); * 30-Jul-2003 : Modified entity constructor (CZ); * 18-Aug-2003 : Now handles null values (RA); * 20-Aug-2003 : Implemented Cloneable, PublicCloneable and Serializable (DG); * 22-Sep-2003 : Changed to be a two pass renderer with optional shape Paint and Stroke (RA); * 07-Oct-2003 : Added renderer state (DG); * 10-Feb-2004 : Updated state object and changed drawItem() method to make overriding * easier (DG); * 25-Feb-2004 : Replaced CrosshairInfo with CrosshairState. Renamed XYToolTipGenerator * --> XYItemLabelGenerator (DG); * */package org.jfree.chart.renderer;import java.awt.Graphics2D;import java.awt.Paint;import java.awt.Point;import java.awt.Polygon;import java.awt.Shape;import java.awt.Stroke;import java.awt.geom.Line2D;import java.awt.geom.Rectangle2D;import java.io.Serializable;import java.util.Stack;import org.jfree.chart.axis.ValueAxis;import org.jfree.chart.entity.EntityCollection;import org.jfree.chart.entity.XYItemEntity;import org.jfree.chart.labels.XYToolTipGenerator;import org.jfree.chart.plot.CrosshairState;import org.jfree.chart.plot.PlotOrientation;import org.jfree.chart.plot.PlotRenderingInfo;import org.jfree.chart.plot.XYPlot;import org.jfree.chart.urls.XYURLGenerator;import org.jfree.data.DatasetUtilities;import org.jfree.data.Range;import org.jfree.data.TableXYDataset;import org.jfree.data.XYDataset;import org.jfree.util.PublicCloneable;/** * A stacked area renderer for the {@link XYPlot} class. * * @author Richard Atkinson */public class StackedXYAreaRenderer extends XYAreaRenderer implements Cloneable, PublicCloneable, Serializable { /** * A state object for use by this renderer. */ static class StackedXYAreaRendererState extends XYItemRendererState { /** The area for the current series. */ private Polygon seriesArea; /** The line. */ private Line2D line; /** The points from the last series. */ private Stack lastSeriesPoints; /** The points for the current series. */ private Stack currentSeriesPoints; /** * Creates a new state for the renderer. * * @param info the plot rendering info. */ public StackedXYAreaRendererState(PlotRenderingInfo info) { super(info); this.seriesArea = null; this.line = null; this.lastSeriesPoints = new Stack(); this.currentSeriesPoints = null; } /** * Returns the series area. * * @return the series area. */ public Polygon getSeriesArea() { return this.seriesArea; } /** * Sets the series area. * * @param area the area. */ public void setSeriesArea(Polygon area) { this.seriesArea = area; } /** * Returns the working line. * * @return the working line. */ public Line2D getLine() { return this.line; } /** * Returns the current series points. * * @return the current series points. */ public Stack getCurrentSeriesPoints() { return this.currentSeriesPoints; } /** * Sets the current series points. * * @param points the points. */ public void setCurrentSeriesPoints(Stack points) { this.currentSeriesPoints = points; } /** * Returns the last series points. * * @return the last series points. */ public Stack getLastSeriesPoints() { return this.lastSeriesPoints; } /** * Sets the last series points. * * @param points the points. */ public void setLastSeriesPoints(Stack points) { this.lastSeriesPoints = points; } } /** Custom Paint for drawing all shapes, if null defaults to series shapes */ private Paint shapePaint = null; /** Custom Stroke for drawing all shapes, if null defaults to series strokes */ private Stroke shapeStroke = null; /** * Creates a new renderer. */ public StackedXYAreaRenderer() { this(AREA); } /** * Constructs a new renderer. * * @param type the type of the renderer. */ public StackedXYAreaRenderer(int type) { this(type, null, null); } /** * Constructs a new renderer. * <p> * To specify the type of renderer, use one of the constants: SHAPES, LINES, * SHAPES_AND_LINES, AREA or AREA_AND_SHAPES. * * @param type the type of renderer. * @param labelGenerator the tool tip generator to use. <code>null</code> is none. * @param urlGenerator the URL generator (null permitted). */ public StackedXYAreaRenderer(int type, XYToolTipGenerator labelGenerator, XYURLGenerator urlGenerator) { super(type, labelGenerator, urlGenerator); } /** * Returns the range type. * * @return The range type (never <code>null</code>). */ public RangeType getRangeType() { return RangeType.STACKED; } /** * Returns the range of values the renderer requires to display all the items from the * specified dataset. * * @param dataset the dataset (<code>null</code> permitted). * * @return The range (or <code>null</code> if the dataset is <code>null</code> or empty). */ public Range getRangeExtent(XYDataset dataset) { return DatasetUtilities.getStackedRangeExtent((TableXYDataset) dataset); } /** * Initialises the renderer. * <P> * This method will be called before the first item is rendered, giving the * renderer an opportunity to initialise any state information it wants to maintain. * The renderer can do nothing if it chooses. * * @param g2 the graphics device. * @param dataArea the area inside the axes. * @param plot the plot. * @param data the data. * @param info an optional info collection object to return data back to the caller. * * @return A state object that should be passed to subsequent calls to the drawItem() method. */ public XYItemRendererState initialise(Graphics2D g2, Rectangle2D dataArea, XYPlot plot, XYDataset data, PlotRenderingInfo info) { return new StackedXYAreaRendererState(info); } /** * Returns the number of passes required by the renderer. * * @return 2. */ public int getPassCount() { return 2; } /** * Draws the visual representation of a single data item. * * @param g2 the graphics device. * @param state the renderer state. * @param dataArea the area within which the data is being drawn. * @param info collects information about the drawing.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -