📄 pieplot.java
字号:
private StrokeTable outlineStrokeTable;
/** The default stroke. */
private transient Stroke defaultOutlineStroke;
/** 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;
/**
* 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;
}
/**
* Initialisation shared by constructors.
*/
private void initialise() {
this.interiorGap = DEFAULT_INTERIOR_GAP;
this.circular = true;
this.radius = DEFAULT_RADIUS;
this.startAngle = DEFAULT_START_ANGLE;
this.direction = DEFAULT_DIRECTION;
this.sectionLabelType = DEFAULT_SECTION_LABEL_TYPE;
this.sectionLabelFont = DEFAULT_SECTION_LABEL_FONT;
this.sectionLabelPaint = DEFAULT_SECTION_LABEL_PAINT;
this.sectionLabelGap = DEFAULT_SECTION_LABEL_GAP;
this.valueFormatter = DEFAULT_VALUE_FORMATTER;
this.percentFormatter = DEFAULT_PERCENT_FORMATTER;
this.toolTipGenerator = null;
this.urlGenerator = null;
this.paintTableActive = true;
this.paintTable = new PaintTable();
this.defaultPaint = null;
this.outlinePaintTableActive = false;
this.outlinePaintTable = null;
this.defaultOutlinePaint = Color.lightGray;
this.outlineStrokeTableActive = false;
this.outlineStrokeTable = null;
this.defaultOutlineStroke = new BasicStroke(1.0f);
this.minimumArcAngleToDraw = DEFAULT_MINIMUM_ARC_ANGLE_TO_DRAW;
}
/**
* Returns the dataset.
*
* @return The dataset.
*/
public PieDataset getDataset() {
return this.dataset;
}
/**
* Sets the dataset. A {@link DatasetChangeEvent} is sent to all registered listeners.
*
* @param dataset the dataset.
*/
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 dataset for multiple pies.
*
* @return The dataset.
*/
public CategoryDataset getMultiDataset() {
return this.multiDataset;
}
/**
* Sets the dataset for multiplie pies. A {@link DatasetChangeEvent} is sent to all
* registered listeners.
*
* @param dataset the dataset.
*/
public void setMultiDataset(CategoryDataset dataset) {
// if there is an existing dataset, remove the plot from the list of change listeners...
CategoryDataset existing = this.multiDataset;
if (existing != null) {
existing.removeChangeListener(this);
}
// set the new dataset, and register the chart as a change listener...
this.multiDataset = 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 start angle for the first pie section.
* <P>
* This is measured in degrees starting from 3 o'clock and measuring anti-clockwise.
*
* @return the start angle.
*/
public double getStartAngle() {
return this.startAngle;
}
/**
* Sets the starting angle.
* <P>
* 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).
*/
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.
*/
public int getDirection() {
return this.direction;
}
/**
* Sets the direction (use the constants CLOCKWISE or ANTICLOCKWISE).
*
* @param direction the new direction.
*/
public void setDirection(int direction) {
// check argument...
if ((direction != CLOCKWISE) && (direction != ANTICLOCKWISE)) {
throw new IllegalArgumentException("PiePlot.setDirection(int): invalid direction.");
}
// make the change...
this.direction = direction;
notifyListeners(new PlotChangeEvent(this));
}
/**
* Returns the interior gap, measured as a percentage of the available drawing space.
*
* @return The gap percentage.
*/
public double getInteriorGap() {
return this.interiorGap;
}
/**
* Sets the interior gap.
*
* @param percent The gap.
*/
public void setInteriorGap(double percent) {
// check arguments...
if ((percent < 0.0) || (percent > MAX_INTERIOR_GAP)) {
throw new IllegalArgumentException(
"PiePlot.setInteriorGapPercent(double): percentage outside valid range.");
}
// 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.
*/
public boolean isCircular() {
return circular;
}
/**
* A flag indicating whether the pie chart is circular, or stretched into
* an elliptical shape.
*
* @param flag the new value.
*/
public void setCircular(boolean flag) {
// no argument checking required...
// make the change...
if (circular != flag) {
circular = flag;
notifyListeners(new PlotChangeEvent(this));
}
}
/**
* Sets the circular attribute, with no side effects.
*
* @param circular the new value of the flag.
*/
protected void setCircularAttribute(boolean circular) {
this.circular = circular;
}
/**
* Returns the radius (a percentage of the available space).
*
* @return The radius percentage.
*/
public double getRadius() {
return this.radius;
}
/**
* Sets the radius.
*
* @param percent the new value.
*/
public void setRadius(double percent) {
// check arguments...
if ((percent <= 0.0) || (percent > MAX_RADIUS)) {
throw new IllegalArgumentException(
"PiePlot.setRadiusPercent(double): percentage outside valid range.");
}
// make the change (if necessary)...
if (this.radius != percent) {
this.radius = percent;
notifyListeners(new PlotChangeEvent(this));
}
}
/**
* Returns the amount that a section should be 'exploded'.
*
* @param section the section number.
*
* @return the amount that a section should be 'exploded'.
*/
public double getExplodePercent(int section) {
// check argument...
if (section < 0) {
throw new IllegalArgumentException(
"PiePlot.getExplodePercent(int): section outside valid range.");
}
// fetch the result...
double result = 0.0;
if (this.explodePercentages != null) {
if (section < this.explodePercentages.length) {
result = explodePercentages[section];
}
}
return result;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -