📄 xyboxandwhiskerrenderer.java
字号:
}
}
Paint p = getBoxPaint();
if (p != null) {
g2.setPaint(p);
}
Stroke s = getItemStroke(series, item);
g2.setStroke(s);
// draw the upper shadow
g2.draw(new Line2D.Double(xx, yyMax, xx, yyQ3Median));
g2.draw(new Line2D.Double(xx - width / 2, yyMax, xx + width / 2,
yyMax));
// draw the lower shadow
g2.draw(new Line2D.Double(xx, yyMin, xx, yyQ1Median));
g2.draw(new Line2D.Double(xx - width / 2, yyMin, xx + width / 2,
yyMin));
// draw the body
Shape box = null;
if (yyQ1Median > yyQ3Median) {
box = new Rectangle2D.Double(xx - width / 2, yyQ3Median, width,
yyQ1Median - yyQ3Median);
}
else {
box = new Rectangle2D.Double(xx - width / 2, yyQ1Median, width,
yyQ3Median - yyQ1Median);
}
if (this.fillBox) {
g2.fill(box);
}
g2.draw(box);
// draw median
g2.setPaint(getArtifactPaint());
g2.draw(new Line2D.Double(xx - width / 2, yyMedian, xx + width / 2,
yyMedian));
double aRadius = 0; // average radius
double oRadius = width / 3; // outlier radius
// draw average - SPECIAL AIMS REQUIREMENT
if (yAverage != null) {
aRadius = width / 4;
Ellipse2D.Double avgEllipse = new Ellipse2D.Double(xx - aRadius,
yyAverage - aRadius, aRadius * 2, aRadius * 2);
g2.fill(avgEllipse);
g2.draw(avgEllipse);
}
List outliers = new ArrayList();
OutlierListCollection outlierListCollection
= new OutlierListCollection();
/* From outlier array sort out which are outliers and put these into
* an arraylist. If there are any farouts, set the flag on the
* OutlierListCollection
*/
for (int i = 0; i < yOutliers.size(); i++) {
double outlier = ((Number) yOutliers.get(i)).doubleValue();
if (outlier > boxAndWhiskerData.getMaxOutlier(series,
item).doubleValue()) {
outlierListCollection.setHighFarOut(true);
}
else if (outlier < boxAndWhiskerData.getMinOutlier(series,
item).doubleValue()) {
outlierListCollection.setLowFarOut(true);
}
else if (outlier > boxAndWhiskerData.getMaxRegularValue(series,
item).doubleValue()) {
yyOutlier = rangeAxis.valueToJava2D(outlier, dataArea,
location);
outliers.add(new Outlier(xx, yyOutlier, oRadius));
}
else if (outlier < boxAndWhiskerData.getMinRegularValue(series,
item).doubleValue()) {
yyOutlier = rangeAxis.valueToJava2D(outlier, dataArea,
location);
outliers.add(new Outlier(xx, yyOutlier, oRadius));
}
Collections.sort(outliers);
}
// Process outliers. Each outlier is either added to the appropriate
// outlier list or a new outlier list is made
for (Iterator iterator = outliers.iterator(); iterator.hasNext();) {
Outlier outlier = (Outlier) iterator.next();
outlierListCollection.add(outlier);
}
// draw yOutliers
double maxAxisValue = rangeAxis.valueToJava2D(rangeAxis.getUpperBound(),
dataArea, location) + aRadius;
double minAxisValue = rangeAxis.valueToJava2D(rangeAxis.getLowerBound(),
dataArea, location) - aRadius;
// draw outliers
for (Iterator iterator = outlierListCollection.iterator();
iterator.hasNext();) {
OutlierList list = (OutlierList) iterator.next();
Outlier outlier = list.getAveragedOutlier();
Point2D point = outlier.getPoint();
if (list.isMultiple()) {
drawMultipleEllipse(point, width, oRadius, g2);
}
else {
drawEllipse(point, oRadius, g2);
}
}
// draw farout
if (outlierListCollection.isHighFarOut()) {
drawHighFarOut(aRadius, g2, xx, maxAxisValue);
}
if (outlierListCollection.isLowFarOut()) {
drawLowFarOut(aRadius, g2, xx, minAxisValue);
}
// add an entity for the item...
if (entities != null && box.intersects(dataArea)) {
addEntity(entities, box, dataset, series, item, xx, yyAverage);
}
}
/**
* Draws an ellipse to represent an outlier.
*
* @param point the location.
* @param oRadius the radius.
* @param g2 the graphics device.
*/
protected void drawEllipse(Point2D point, double oRadius, Graphics2D g2) {
Ellipse2D.Double dot = new Ellipse2D.Double(point.getX() + oRadius / 2,
point.getY(), oRadius, oRadius);
g2.draw(dot);
}
/**
* Draws two ellipses to represent overlapping outliers.
*
* @param point the location.
* @param boxWidth the box width.
* @param oRadius the radius.
* @param g2 the graphics device.
*/
protected void drawMultipleEllipse(Point2D point, double boxWidth,
double oRadius, Graphics2D g2) {
Ellipse2D.Double dot1 = new Ellipse2D.Double(point.getX()
- (boxWidth / 2) + oRadius, point.getY(), oRadius, oRadius);
Ellipse2D.Double dot2 = new Ellipse2D.Double(point.getX()
+ (boxWidth / 2), point.getY(), oRadius, oRadius);
g2.draw(dot1);
g2.draw(dot2);
}
/**
* Draws a triangle to indicate the presence of far out values.
*
* @param aRadius the radius.
* @param g2 the graphics device.
* @param xx the x value.
* @param m the max y value.
*/
protected void drawHighFarOut(double aRadius, Graphics2D g2, double xx,
double m) {
double side = aRadius * 2;
g2.draw(new Line2D.Double(xx - side, m + side, xx + side, m + side));
g2.draw(new Line2D.Double(xx - side, m + side, xx, m));
g2.draw(new Line2D.Double(xx + side, m + side, xx, m));
}
/**
* Draws a triangle to indicate the presence of far out values.
*
* @param aRadius the radius.
* @param g2 the graphics device.
* @param xx the x value.
* @param m the min y value.
*/
protected void drawLowFarOut(double aRadius, Graphics2D g2, double xx,
double m) {
double side = aRadius * 2;
g2.draw(new Line2D.Double(xx - side, m - side, xx + side, m - side));
g2.draw(new Line2D.Double(xx - side, m - side, xx, m));
g2.draw(new Line2D.Double(xx + side, m - side, xx, m));
}
/**
* Tests this renderer for equality with another object.
*
* @param obj the object (<code>null</code> permitted).
*
* @return <code>true</code> or <code>false</code>.
*/
public boolean equals(Object obj) {
if (obj == this) {
return true;
}
if (!(obj instanceof XYBoxAndWhiskerRenderer)) {
return false;
}
if (!super.equals(obj)) {
return false;
}
XYBoxAndWhiskerRenderer that = (XYBoxAndWhiskerRenderer) obj;
if (this.boxWidth != that.getBoxWidth()) {
return false;
}
if (!PaintUtilities.equal(this.boxPaint, that.boxPaint)) {
return false;
}
if (!PaintUtilities.equal(this.artifactPaint, that.artifactPaint)) {
return false;
}
if (this.fillBox != that.fillBox) {
return false;
}
return true;
}
/**
* 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.writePaint(this.boxPaint, stream);
SerialUtilities.writePaint(this.artifactPaint, 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.boxPaint = SerialUtilities.readPaint(stream);
this.artifactPaint = SerialUtilities.readPaint(stream);
}
/**
* Returns a clone of the renderer.
*
* @return A clone.
*
* @throws CloneNotSupportedException if the renderer cannot be cloned.
*/
public Object clone() throws CloneNotSupportedException {
return super.clone();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -