?? pieplot.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.
*
* ------------
* PiePlot.java
* ------------
* (C) Copyright 2000-2003, by Andrzej Porebski and Contributors.
*
* Original Author: Andrzej Porebski;
* Contributor(s): David Gilbert (for Object Refinery Limited);
* Martin Cordova (percentages in labels);
* Richard Atkinson (URL support for image maps);
* Christian W. Zuckschwerdt;
* Arnaud Lelievre;
*
* $Id: PiePlot.java,v 1.20 2003/09/08 22:08:02 mungady Exp $
*
* Changes (from 21-Jun-2001)
* --------------------------
* 21-Jun-2001 : Removed redundant JFreeChart parameter from constructors (DG);
* 18-Sep-2001 : Updated header (DG);
* 15-Oct-2001 : Data source classes moved to com.jrefinery.data.* (DG);
* 19-Oct-2001 : Moved series paint and stroke methods from JFreeChart.java to Plot.java (DG);
* 22-Oct-2001 : Renamed DataSource.java --> Dataset.java etc. (DG);
* 13-Nov-2001 : Modified plot subclasses so that null axes are possible for pie plot (DG);
* 17-Nov-2001 : Added PieDataset interface and amended this class accordingly, and completed
* removal of BlankAxis class as it is no longer required (DG);
* 19-Nov-2001 : Changed 'drawCircle' property to 'circular' property (DG);
* 21-Nov-2001 : Added options for exploding pie sections and filled out range of properties (DG);
* Added option for percentages in chart labels, based on code
* by Martin Cordova (DG);
* 30-Nov-2001 : Changed default font from "Arial" --> "SansSerif" (DG);
* 12-Dec-2001 : Removed unnecessary 'throws' clause in constructor (DG);
* 13-Dec-2001 : Added tooltips (DG);
* 16-Jan-2002 : Renamed tooltips class (DG);
* 22-Jan-2002 : Fixed bug correlating legend labels with pie data (DG);
* 05-Feb-2002 : Added alpha-transparency to plot class, and updated constructors accordingly (DG);
* 06-Feb-2002 : Added optional background image and alpha-transparency to Plot and subclasses.
* Clipped drawing within plot area (DG);
* 26-Mar-2002 : Added an empty zoom method (DG);
* 18-Apr-2002 : PieDataset is no longer sorted (oldman);
* 23-Apr-2002 : Moved dataset from JFreeChart to Plot. Added getLegendItemLabels() method (DG);
* 19-Jun-2002 : Added attributes to control starting angle and direction (default is now
* clockwise) (DG);
* 25-Jun-2002 : Removed redundant imports (DG);
* 02-Jul-2002 : Fixed sign of percentage bug introduced in 0.9.2 (DG);
* 16-Jul-2002 : Added check for null dataset in getLegendItemLabels(...) (DG);
* 30-Jul-2002 : Moved summation code to DatasetUtilities (DG);
* 05-Aug-2002 : Added URL support for image maps - new member variable for
* urlGenerator, modified constructor and minor change to the draw method (RA);
* 18-Sep-2002 : Modified the percent label creation and added setters for the formatters (AS);
* 24-Sep-2002 : Added getLegendItems() method (DG);
* 02-Oct-2002 : Fixed errors reported by Checkstyle (DG);
* 09-Oct-2002 : Added check for null entity collection (DG);
* 30-Oct-2002 : Changed PieDataset interface (DG);
* 18-Nov-2002 : Changed CategoryDataset to TableDataset (DG);
* 02-Jan-2003 : Fixed "no data" message (DG);
* 23-Jan-2003 : Modified to extract data from rows OR columns in CategoryDataset (DG);
* 14-Feb-2003 : Fixed label drawing so that foreground alpha does not apply (bug id 685536) (DG);
* 07-Mar-2003 : Modified to pass pieIndex on to PieSectionEntity and tooltip and
* URL generators (DG);
* 21-Mar-2003 : Added a minimum angle for drawing arcs (see bug id 620031) (DG);
* 24-Apr-2003 : Switched around PieDataset and KeyedValuesDataset (DG);
* 02-Jun-2003 : Fixed bug 721733 (DG);
* 30-Jul-2003 : Modified entity constructor (CZ);
* 19-Aug-2003 : Implemented Cloneable (DG);
* 29-Aug-2003 : Fixed bug 796936 (null pointer on setOutlinePaint(...)) (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.BasicStroke;
import java.awt.Color;
import java.awt.Composite;
import java.awt.Font;
import java.awt.Graphics2D;
import java.awt.Insets;
import java.awt.Paint;
import java.awt.Rectangle;
import java.awt.Shape;
import java.awt.Stroke;
import java.awt.font.FontRenderContext;
import java.awt.font.LineMetrics;
import java.awt.geom.Arc2D;
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.text.DecimalFormat;
import java.text.NumberFormat;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.ResourceBundle;
import org.jfree.chart.ChartRenderingInfo;
import org.jfree.chart.LegendItem;
import org.jfree.chart.LegendItemCollection;
import org.jfree.chart.entity.EntityCollection;
import org.jfree.chart.entity.PieSectionEntity;
import org.jfree.chart.event.PlotChangeEvent;
import org.jfree.chart.labels.PieItemLabelGenerator;
import org.jfree.chart.urls.PieURLGenerator;
import org.jfree.data.CategoryDataset;
import org.jfree.data.CategoryToPieDataset;
import org.jfree.data.Dataset;
import org.jfree.data.DatasetChangeEvent;
import org.jfree.data.DatasetUtilities;
import org.jfree.data.PieDataset;
import org.jfree.io.SerialUtilities;
import org.jfree.util.ObjectList;
import org.jfree.util.ObjectUtils;
import org.jfree.util.PaintList;
import org.jfree.util.Rotation;
import org.jfree.util.StrokeList;
/**
* A plot that displays data in the form of a pie chart, using data from any class that implements
* the {@link PieDataset} interface.
* <P>
* Special notes:
* <ol>
* <li>the default starting point is 12 o'clock and the pie sections proceed
* in a clockwise direction, but these settings can be changed</li>
* <li>negative values in the dataset are ignored</li>
* <li>there are utility methods for creating a {@link PieDataset} from a
* {@link CategoryDataset}</li>
* </ol>
*
* @see Plot
* @see PieDataset
*
* @author Andrzej Porebski
*/
public class PiePlot extends Plot implements Cloneable, Serializable {
/** A constant indicating the clockwise direction. */
public static final int CLOCKWISE = -1;
/** A constant representing the anti-clockwise direction. */
public static final int ANTICLOCKWISE = 1;
/** Constant indicating no labels on the pie sections. */
public static final int NO_LABELS = 0;
/** Constant indicating name labels on the pie sections. */
public static final int NAME_LABELS = 1;
/** Constant indicating value labels on the pie sections. */
public static final int VALUE_LABELS = 2;
/** Constant indicating percent labels on the pie sections. */
public static final int PERCENT_LABELS = 3;
/** Constant indicating percent labels on the pie sections. */
public static final int NAME_AND_VALUE_LABELS = 4;
/** Constant indicating percent labels on the pie sections. */
public static final int NAME_AND_PERCENT_LABELS = 5;
/** Constant indicating percent labels on the pie sections. */
public static final int VALUE_AND_PERCENT_LABELS = 6;
/** A useful constant for multiple pie charts. */
public static final int PER_ROW = 0;
/** A useful constant for multiple pie charts. */
public static final int PER_COLUMN = 1;
/** The default interior gap. */
public static final double DEFAULT_INTERIOR_GAP = 0.25;
/** The maximum interior gap (currently 40%). */
public static final double MAX_INTERIOR_GAP = 0.40;
/** The default radius percent (currently 100%). */
public static final double DEFAULT_RADIUS = 1.00;
/** The maximum radius (currently 100%). */
public static final double MAX_RADIUS = 1.00;
/** The default starting angle for the pie chart. */
public static final double DEFAULT_START_ANGLE = 90.0;
/** The default direction for the pie chart. */
public static final int DEFAULT_DIRECTION = CLOCKWISE;
/** The default section label type. */
public static final int DEFAULT_SECTION_LABEL_TYPE = NAME_LABELS;
/** The default section label font. */
public static final Font DEFAULT_SECTION_LABEL_FONT = new Font("SansSerif", Font.PLAIN, 10);
/** The default section label paint. */
public static final Paint DEFAULT_SECTION_LABEL_PAINT = Color.black;
/** The default section label gap (currently 10%). */
public static final double DEFAULT_SECTION_LABEL_GAP = 0.10;
/** The maximum interior gap (currently 30%). */
public static final double MAX_SECTION_LABEL_GAP = 0.30;
/** The default value label formatter. */
public static final NumberFormat DEFAULT_VALUE_FORMATTER = NumberFormat.getNumberInstance();
/** The default percent label formatter. */
public static final NumberFormat DEFAULT_PERCENT_FORMATTER = NumberFormat.getPercentInstance();
/** The default series label font. */
public static final Font DEFAULT_SERIES_LABEL_FONT = new Font("SansSerif", Font.PLAIN, 12);
/** The default series label paint. */
public static final Paint DEFAULT_SERIES_LABEL_PAINT = Color.black;
/** The default for the show series labels flag */
public static final boolean DEFAULT_SHOW_SERIES_LABELS = true;
/** The default minimum arc angle to draw. */
public static final double DEFAULT_MINIMUM_ARC_ANGLE_TO_DRAW = 0.00001;
/** The dataset for the pie chart. */
private PieDataset dataset;
/** The dataset for multi pie charts. */
private CategoryDataset multiDataset;
/** The amount of space left around the outside of the pie plot, expressed as a percentage. */
private double interiorGap;
/** Flag determining whether to draw an ellipse or a perfect circle. */
private boolean circular;
/** The radius (as a percentage of the available drawing area). */
private double radius;
/** The starting angle. */
private double startAngle;
/** The direction for the pie segments. */
private Rotation direction;
/** Label type (NO_LABELS, NAME_LABELS, PERCENT_LABELS, NAME_AND_PERCENT_LABELS). */
private int sectionLabelType;
/** The font used to display the section labels. */
private Font sectionLabelFont;
/** The color used to draw the section labels. */
private transient Paint sectionLabelPaint;
/** The gap between the labels and the pie sections, as a percentage of the radius. */
private double sectionLabelGap;
/** The percentage amount to explode each pie section. */
private ObjectList explodePercentages;
/** A formatter for displayed values. */
private NumberFormat valueFormatter;
/** A formatter for displayed percentages. */
private NumberFormat percentFormatter;
/** The item label generator. */
private PieItemLabelGenerator itemLabelGenerator;
/** The URL generator. */
private PieURLGenerator urlGenerator;
/** Flag used to determine whether series labels are shown */
private boolean showSeriesLabels = true;
/** The font used to display the series labels. */
private Font seriesLabelFont = DEFAULT_SERIES_LABEL_FONT;
/** The color used to draw the series labels. */
private transient Paint seriesLabelPaint = DEFAULT_SERIES_LABEL_PAINT;
/** The paint used for ALL sections (if specified). */
private transient Paint sectionPaint;
/** The lookup list for paints for the plot. */
private PaintList sectionPaintList;
/** A flag that controls whether or not the sectionPaintList is filled automatically. */
private boolean sectionPaintListAutoFill;
/** The section outline paint (if null, the lookup table is used instead). */
private Paint sectionOutlinePaint;
/** The lookup list for outline paints for the sections in the plot. */
private PaintList sectionOutlinePaintList;
/** A flag that controls whether or not the sectionOutlinePaintList is filled automatically. */
private boolean sectionOutlinePaintListAutoFill;
/** The default stroke. */
private transient Stroke sectionOutlineStroke;
/** The lookup list for strokes for the plot. */
private StrokeList sectionOutlineStrokeList;
/**
* A flag that controls whether or not the sectionOutlineStrokeList is filled automatically.
*/
private boolean sectionOutlineStrokeListAutoFill;
/** The data extract type. */
private int extractType;
/**
* The smallest arc angle that will get drawn (this is to avoid a bug in various Java
* implementations that causes the JVM to crash).
*/
private double minimumArcAngleToDraw;
/** The resourceBundle for the localization. */
static protected ResourceBundle localizationResources =
ResourceBundle.getBundle("org.jfree.chart.plot.LocalizationBundle");
/**
* Creates a new plot.
*/
public PiePlot() {
this(null);
}
/**
* Creates a pie chart.
*
* @param dataset the dataset.
*/
public PiePlot(PieDataset dataset) {
super();
this.dataset = dataset;
this.multiDataset = null;
initialise();
}
/**
* Creates a new plot that will draw multiple pie charts, one for each row or column (as
* requested) in the dataset.
*
* @param dataset the dataset.
* @param type controls how pie data is extracted (PER_ROW or PER_COLUMN).
*/
public PiePlot(CategoryDataset dataset, int type) {
super();
this.dataset = null;
this.multiDataset = dataset;
initialise();
this.extractType = type;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -