📄 ringplot.java
字号:
notifyListeners(new PlotChangeEvent(this));
}
/**
* Draws a single data item.
*
* @param g2 the graphics device (<code>null</code> not permitted).
* @param section the section index.
* @param dataArea the data plot area.
* @param state state information for one chart.
* @param currentPass the current pass index.
*/
protected void drawItem(Graphics2D g2,
int section,
Rectangle2D dataArea,
PiePlotState state,
int currentPass) {
PieDataset dataset = getDataset();
Number n = dataset.getValue(section);
if (n == null) {
return;
}
double value = n.doubleValue();
double angle1 = 0.0;
double angle2 = 0.0;
Rotation direction = getDirection();
if (direction == Rotation.CLOCKWISE) {
angle1 = state.getLatestAngle();
angle2 = angle1 - value / state.getTotal() * 360.0;
}
else if (direction == Rotation.ANTICLOCKWISE) {
angle1 = state.getLatestAngle();
angle2 = angle1 + value / state.getTotal() * 360.0;
}
else {
throw new IllegalStateException("Rotation type not recognised.");
}
double angle = (angle2 - angle1);
if (Math.abs(angle) > getMinimumArcAngleToDraw()) {
double ep = 0.0;
double mep = getMaximumExplodePercent();
if (mep > 0.0) {
ep = getExplodePercent(section) / mep;
}
Rectangle2D arcBounds = getArcBounds(
state.getPieArea(), state.getExplodedPieArea(),
angle1, angle, ep
);
Arc2D.Double arc = new Arc2D.Double(
arcBounds, angle1, angle, Arc2D.OPEN
);
// create the bounds for the inner arc
RectangleInsets s = new RectangleInsets(
UnitType.RELATIVE, 0.10, 0.10, 0.10, 0.10
);
Rectangle2D innerArcBounds = new Rectangle2D.Double();
innerArcBounds.setRect(arcBounds);
s.trim(innerArcBounds);
// calculate inner arc in reverse direction, for later
// GeneralPath construction
Arc2D.Double arc2 = new Arc2D.Double(
innerArcBounds, angle1 + angle, -angle, Arc2D.OPEN
);
GeneralPath path = new GeneralPath();
path.moveTo(
(float) arc.getStartPoint().getX(),
(float) arc.getStartPoint().getY()
);
path.append(arc.getPathIterator(null), false);
path.append(arc2.getPathIterator(null), true);
path.closePath();
Line2D separator = new Line2D.Double(
arc2.getEndPoint(), arc.getStartPoint()
);
if (currentPass == 0) {
Paint shadowPaint = getShadowPaint();
double shadowXOffset = getShadowXOffset();
double shadowYOffset = getShadowYOffset();
if (shadowPaint != null) {
Shape shadowArc = ShapeUtilities.createTranslatedShape(
path, (float) shadowXOffset, (float) shadowYOffset
);
g2.setPaint(shadowPaint);
g2.fill(shadowArc);
}
}
else if (currentPass == 1) {
Paint paint = getSectionPaint(section);
g2.setPaint(paint);
g2.fill(path);
Paint outlinePaint = getSectionOutlinePaint(section);
Stroke outlineStroke = getSectionOutlineStroke(section);
if (outlinePaint != null && outlineStroke != null) {
g2.setPaint(outlinePaint);
g2.setStroke(outlineStroke);
g2.draw(path);
}
if (this.separatorsVisible) {
Line2D extendedSeparator = extendLine(
separator, this.innerSeparatorExtension,
this.innerSeparatorExtension
);
g2.setStroke(this.separatorStroke);
g2.setPaint(this.separatorPaint);
g2.draw(extendedSeparator);
}
// add an entity for the pie section
if (state.getInfo() != null) {
EntityCollection entities = state.getEntityCollection();
if (entities != null) {
Comparable key = dataset.getKey(section);
String tip = null;
PieToolTipGenerator toolTipGenerator
= getToolTipGenerator();
if (toolTipGenerator != null) {
tip = toolTipGenerator.generateToolTip(
dataset, key
);
}
String url = null;
PieURLGenerator urlGenerator = getURLGenerator();
if (urlGenerator != null) {
url = urlGenerator.generateURL(
dataset, key, getPieIndex()
);
}
PieSectionEntity entity = new PieSectionEntity(
path, dataset, getPieIndex(), section, key, tip, url
);
entities.add(entity);
}
}
}
}
state.setLatestAngle(angle2);
}
/**
* Tests this plot for equality with an arbitrary object.
*
* @param obj the object to test against (<code>null</code> permitted).
*
* @return A boolean.
*/
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (!(obj instanceof RingPlot)) {
return false;
}
if (!super.equals(obj)) {
return false;
}
RingPlot that = (RingPlot) obj;
if (this.separatorsVisible != that.separatorsVisible) {
return false;
}
if (!ObjectUtilities.equal(
this.separatorStroke, that.separatorStroke
)) {
return false;
}
if (!PaintUtilities.equal(this.separatorPaint, that.separatorPaint)) {
return false;
}
if (this.innerSeparatorExtension != that.innerSeparatorExtension) {
return false;
}
if (this.outerSeparatorExtension != that.outerSeparatorExtension) {
return false;
}
return true;
}
/**
* Creates a new line by extending an existing line.
*
* @param line the line (<code>null</code> not permitted).
* @param startPercent the amount to extend the line at the start point
* end.
* @param endPercent the amount to extend the line at the end point end.
*
* @return A new line.
*/
private Line2D extendLine(Line2D line, double startPercent,
double endPercent) {
if (line == null) {
throw new IllegalArgumentException("Null 'line' argument.");
}
double x1 = line.getX1();
double x2 = line.getX2();
double deltaX = x2 - x1;
double y1 = line.getY1();
double y2 = line.getY2();
double deltaY = y2 - y1;
x1 = x1 - (startPercent * deltaX);
y1 = y1 - (startPercent * deltaY);
x2 = x2 + (endPercent * deltaX);
y2 = y2 + (endPercent * deltaY);
return new Line2D.Double(x1, y1, x2, y2);
}
/**
* Provides serialization support.
*
* @param stream the output stream.
*
* @throws IOException if there is an I/O error.
*/
private void writeObject(ObjectOutputStream stream) throws IOException {
stream.defaultWriteObject();
SerialUtilities.writeStroke(this.separatorStroke, stream);
SerialUtilities.writePaint(this.separatorPaint, stream);
}
/**
* Provides serialization support.
*
* @param stream the input stream.
*
* @throws IOException if there is an I/O error.
* @throws ClassNotFoundException if there is a classpath problem.
*/
private void readObject(ObjectInputStream stream)
throws IOException, ClassNotFoundException {
stream.defaultReadObject();
this.separatorStroke = SerialUtilities.readStroke(stream);
this.separatorPaint = SerialUtilities.readPaint(stream);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -