📄 pieplot.java
字号:
private boolean labelLinksVisible;
/** The link margin. */
private double labelLinkMargin = 0.05;
/** The paint used for the label linking lines. */
private transient Paint labelLinkPaint = Color.black;
/** The stroke used for the label linking lines. */
private transient Stroke labelLinkStroke = new BasicStroke(0.5f);
/**
* The pie section label distributor.
*
* @since 1.0.6
*/
private AbstractPieLabelDistributor labelDistributor;
/** The tooltip generator. */
private PieToolTipGenerator toolTipGenerator;
/** The URL generator. */
private PieURLGenerator urlGenerator;
/** The legend label generator. */
private PieSectionLabelGenerator legendLabelGenerator;
/** A tool tip generator for the legend. */
private PieSectionLabelGenerator legendLabelToolTipGenerator;
/**
* A URL generator for the legend items (optional).
*
* @since 1.0.4.
*/
private PieURLGenerator legendLabelURLGenerator;
/**
* A flag that controls whether <code>null</code> values are ignored.
*/
private boolean ignoreNullValues;
/**
* A flag that controls whether zero values are ignored.
*/
private boolean ignoreZeroValues;
/** The legend item shape. */
private transient Shape legendItemShape;
/**
* The smallest arc angle that will get drawn (this is to avoid a bug in
* various Java implementations that causes the JVM to crash). See this
* link for details:
*
* http://www.jfree.org/phpBB2/viewtopic.php?t=2707
*
* ...and this bug report in the Java Bug Parade:
*
* http://developer.java.sun.com/developer/bugParade/bugs/4836495.html
*/
private double minimumArcAngleToDraw;
/** The resourceBundle for the localization. */
protected static ResourceBundle localizationResources =
ResourceBundle.getBundle("org.jfree.chart.plot.LocalizationBundle");
/**
* Creates a new plot. The dataset is initially set to <code>null</code>.
*/
public PiePlot() {
this(null);
}
/**
* Creates a plot that will draw a pie chart for the specified dataset.
*
* @param dataset the dataset (<code>null</code> permitted).
*/
public PiePlot(PieDataset dataset) {
super();
this.dataset = dataset;
if (dataset != null) {
dataset.addChangeListener(this);
}
this.pieIndex = 0;
this.interiorGap = DEFAULT_INTERIOR_GAP;
this.circular = true;
this.startAngle = DEFAULT_START_ANGLE;
this.direction = Rotation.CLOCKWISE;
this.minimumArcAngleToDraw = DEFAULT_MINIMUM_ARC_ANGLE_TO_DRAW;
this.sectionPaint = null;
this.sectionPaintMap = new PaintMap();
this.baseSectionPaint = Color.gray;
this.sectionOutlinesVisible = true;
this.sectionOutlinePaint = null;
this.sectionOutlinePaintMap = new PaintMap();
this.baseSectionOutlinePaint = DEFAULT_OUTLINE_PAINT;
this.sectionOutlineStroke = null;
this.sectionOutlineStrokeMap = new StrokeMap();
this.baseSectionOutlineStroke = DEFAULT_OUTLINE_STROKE;
this.explodePercentages = new TreeMap();
this.labelGenerator = new StandardPieSectionLabelGenerator();
this.labelFont = DEFAULT_LABEL_FONT;
this.labelPaint = DEFAULT_LABEL_PAINT;
this.labelBackgroundPaint = DEFAULT_LABEL_BACKGROUND_PAINT;
this.labelOutlinePaint = DEFAULT_LABEL_OUTLINE_PAINT;
this.labelOutlineStroke = DEFAULT_LABEL_OUTLINE_STROKE;
this.labelShadowPaint = DEFAULT_LABEL_SHADOW_PAINT;
this.labelLinksVisible = true;
this.labelDistributor = new PieLabelDistributor(0);
this.toolTipGenerator = null;
this.urlGenerator = null;
this.legendLabelGenerator = new StandardPieSectionLabelGenerator();
this.legendLabelToolTipGenerator = null;
this.legendLabelURLGenerator = null;
this.legendItemShape = Plot.DEFAULT_LEGEND_ITEM_CIRCLE;
this.ignoreNullValues = false;
this.ignoreZeroValues = false;
}
/**
* Returns the dataset.
*
* @return The dataset (possibly <code>null</code>).
*
* @see #setDataset(PieDataset)
*/
public PieDataset getDataset() {
return this.dataset;
}
/**
* Sets the dataset and sends a {@link DatasetChangeEvent} to 'this'.
*
* @param dataset the dataset (<code>null</code> permitted).
*
* @see #getDataset()
*/
public void setDataset(PieDataset dataset) {
// if there is an existing dataset, remove the plot from the list of
// change listeners...
PieDataset existing = this.dataset;
if (existing != null) {
existing.removeChangeListener(this);
}
// set the new dataset, and register the chart as a change listener...
this.dataset = dataset;
if (dataset != null) {
setDatasetGroup(dataset.getGroup());
dataset.addChangeListener(this);
}
// send a dataset change event to self...
DatasetChangeEvent event = new DatasetChangeEvent(this, dataset);
datasetChanged(event);
}
/**
* Returns the pie index (this is used by the {@link MultiplePiePlot} class
* to track subplots).
*
* @return The pie index.
*
* @see #setPieIndex(int)
*/
public int getPieIndex() {
return this.pieIndex;
}
/**
* Sets the pie index (this is used by the {@link MultiplePiePlot} class to
* track subplots).
*
* @param index the index.
*
* @see #getPieIndex()
*/
public void setPieIndex(int index) {
this.pieIndex = index;
}
/**
* Returns the start angle for the first pie section. This is measured in
* degrees starting from 3 o'clock and measuring anti-clockwise.
*
* @return The start angle.
*
* @see #setStartAngle(double)
*/
public double getStartAngle() {
return this.startAngle;
}
/**
* Sets the starting angle and sends a {@link PlotChangeEvent} to all
* registered listeners. The initial default value is 90 degrees, which
* corresponds to 12 o'clock. A value of zero corresponds to 3 o'clock...
* this is the encoding used by Java's Arc2D class.
*
* @param angle the angle (in degrees).
*
* @see #getStartAngle()
*/
public void setStartAngle(double angle) {
this.startAngle = angle;
notifyListeners(new PlotChangeEvent(this));
}
/**
* Returns the direction in which the pie sections are drawn (clockwise or
* anti-clockwise).
*
* @return The direction (never <code>null</code>).
*
* @see #setDirection(Rotation)
*/
public Rotation getDirection() {
return this.direction;
}
/**
* Sets the direction in which the pie sections are drawn and sends a
* {@link PlotChangeEvent} to all registered listeners.
*
* @param direction the direction (<code>null</code> not permitted).
*
* @see #getDirection()
*/
public void setDirection(Rotation direction) {
if (direction == null) {
throw new IllegalArgumentException("Null 'direction' argument.");
}
this.direction = direction;
notifyListeners(new PlotChangeEvent(this));
}
/**
* Returns the interior gap, measured as a percentage of the available
* drawing space.
*
* @return The gap (as a percentage of the available drawing space).
*
* @see #setInteriorGap(double)
*/
public double getInteriorGap() {
return this.interiorGap;
}
/**
* Sets the interior gap and sends a {@link PlotChangeEvent} to all
* registered listeners. This controls the space between the edges of the
* pie plot and the plot area itself (the region where the section labels
* appear).
*
* @param percent the gap (as a percentage of the available drawing space).
*
* @see #getInteriorGap()
*/
public void setInteriorGap(double percent) {
// check arguments...
if ((percent < 0.0) || (percent > MAX_INTERIOR_GAP)) {
throw new IllegalArgumentException(
"Invalid 'percent' (" + percent + ") argument.");
}
// make the change...
if (this.interiorGap != percent) {
this.interiorGap = percent;
notifyListeners(new PlotChangeEvent(this));
}
}
/**
* Returns a flag indicating whether the pie chart is circular, or
* stretched into an elliptical shape.
*
* @return A flag indicating whether the pie chart is circular.
*
* @see #setCircular(boolean)
*/
public boolean isCircular() {
return this.circular;
}
/**
* A flag indicating whether the pie chart is circular, or stretched into
* an elliptical shape.
*
* @param flag the new value.
*
* @see #isCircular()
*/
public void setCircular(boolean flag) {
setCircular(flag, true);
}
/**
* Sets the circular attribute and, if requested, sends a
* {@link PlotChangeEvent} to all registered listeners.
*
* @param circular the new value of the flag.
* @param notify notify listeners?
*
* @see #isCircular()
*/
public void setCircular(boolean circular, boolean notify) {
this.circular = circular;
if (notify) {
notifyListeners(new PlotChangeEvent(this));
}
}
/**
* Returns the flag that controls whether <code>null</code> values in the
* dataset are ignored.
*
* @return A boolean.
*
* @see #setIgnoreNullValues(boolean)
*/
public boolean getIgnoreNullValues() {
return this.ignoreNullValues;
}
/**
* Sets a flag that controls whether <code>null</code> values are ignored,
* and sends a {@link PlotChangeEvent} to all registered listeners. At
* present, this only affects whether or not the key is presented in the
* legend.
*
* @param flag the flag.
*
* @see #getIgnoreNullValues()
* @see #setIgnoreZeroValues(boolean)
*/
public void setIgnoreNullValues(boolean flag) {
this.ignoreNullValues = flag;
notifyListeners(new PlotChangeEvent(this));
}
/**
* Returns the flag that controls whether zero values in the
* dataset are ignored.
*
* @return A boolean.
*
* @see #setIgnoreZeroValues(boolean)
*/
public boolean getIgnoreZeroValues() {
return this.ignoreZeroValues;
}
/**
* Sets a flag that controls whether zero values are ignored,
* and sends a {@link PlotChangeEvent} to all registered listeners. This
* only affects whether or not a label appears for the non-visible
* pie section.
*
* @param flag the flag.
*
* @see #getIgnoreZeroValues()
* @see #setIgnoreNullValues(boolean)
*/
public void setIgnoreZeroValues(boolean flag) {
this.ignoreZeroValues = flag;
notifyListeners(new PlotChangeEvent(this));
}
//// SECTION PAINT ////////////////////////////////////////////////////////
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -