📄 boxandwhiskerrenderer.java
字号:
double aRadius = 0; // average radius
RectangleEdge location = plot.getRangeAxisEdge();
Number yQ1 = bawDataset.getQ1Value(row, column);
Number yQ3 = bawDataset.getQ3Value(row, column);
Number yMax = bawDataset.getMaxRegularValue(row, column);
Number yMin = bawDataset.getMinRegularValue(row, column);
Shape box = null;
if (yQ1 != null && yQ3 != null && yMax != null && yMin != null) {
double yyQ1 = rangeAxis.valueToJava2D(yQ1.doubleValue(), dataArea,
location);
double yyQ3 = rangeAxis.valueToJava2D(yQ3.doubleValue(), dataArea,
location);
double yyMax = rangeAxis.valueToJava2D(yMax.doubleValue(),
dataArea, location);
double yyMin = rangeAxis.valueToJava2D(yMin.doubleValue(),
dataArea, location);
double xxmid = xx + state.getBarWidth() / 2.0;
// draw the upper shadow...
g2.draw(new Line2D.Double(xxmid, yyMax, xxmid, yyQ3));
g2.draw(new Line2D.Double(xx, yyMax, xx + state.getBarWidth(),
yyMax));
// draw the lower shadow...
g2.draw(new Line2D.Double(xxmid, yyMin, xxmid, yyQ1));
g2.draw(new Line2D.Double(xx, yyMin, xx + state.getBarWidth(),
yyMin));
// draw the body...
box = new Rectangle2D.Double(xx, Math.min(yyQ1, yyQ3),
state.getBarWidth(), Math.abs(yyQ1 - yyQ3));
if (this.fillBox) {
g2.fill(box);
}
g2.draw(box);
}
g2.setPaint(this.artifactPaint);
// draw mean - SPECIAL AIMS REQUIREMENT...
Number yMean = bawDataset.getMeanValue(row, column);
if (yMean != null) {
yyAverage = rangeAxis.valueToJava2D(yMean.doubleValue(),
dataArea, location);
aRadius = state.getBarWidth() / 4;
Ellipse2D.Double avgEllipse = new Ellipse2D.Double(xx + aRadius,
yyAverage - aRadius, aRadius * 2, aRadius * 2);
g2.fill(avgEllipse);
g2.draw(avgEllipse);
}
// draw median...
Number yMedian = bawDataset.getMedianValue(row, column);
if (yMedian != null) {
double yyMedian = rangeAxis.valueToJava2D(yMedian.doubleValue(),
dataArea, location);
g2.draw(new Line2D.Double(xx, yyMedian, xx + state.getBarWidth(),
yyMedian));
}
// draw yOutliers...
double maxAxisValue = rangeAxis.valueToJava2D(
rangeAxis.getUpperBound(), dataArea, location) + aRadius;
double minAxisValue = rangeAxis.valueToJava2D(
rangeAxis.getLowerBound(), dataArea, location) - aRadius;
g2.setPaint(p);
// draw outliers
double oRadius = state.getBarWidth() / 3; // outlier radius
List outliers = new ArrayList();
OutlierListCollection outlierListCollection
= new OutlierListCollection();
// From outlier array sort out which are outliers and put these into a
// list If there are any farouts, set the flag on the
// OutlierListCollection
List yOutliers = bawDataset.getOutliers(row, column);
if (yOutliers != null) {
for (int i = 0; i < yOutliers.size(); i++) {
double outlier = ((Number) yOutliers.get(i)).doubleValue();
Number minOutlier = bawDataset.getMinOutlier(row, column);
Number maxOutlier = bawDataset.getMaxOutlier(row, column);
Number minRegular = bawDataset.getMinRegularValue(row, column);
Number maxRegular = bawDataset.getMaxRegularValue(row, column);
if (outlier > maxOutlier.doubleValue()) {
outlierListCollection.setHighFarOut(true);
}
else if (outlier < minOutlier.doubleValue()) {
outlierListCollection.setLowFarOut(true);
}
else if (outlier > maxRegular.doubleValue()) {
yyOutlier = rangeAxis.valueToJava2D(outlier, dataArea,
location);
outliers.add(new Outlier(xx + state.getBarWidth() / 2.0,
yyOutlier, oRadius));
}
else if (outlier < minRegular.doubleValue()) {
yyOutlier = rangeAxis.valueToJava2D(outlier, dataArea,
location);
outliers.add(new Outlier(xx + state.getBarWidth() / 2.0,
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);
}
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, state.getBarWidth(), oRadius,
g2);
}
else {
drawEllipse(point, oRadius, g2);
}
}
// draw farout indicators
if (outlierListCollection.isHighFarOut()) {
drawHighFarOut(aRadius / 2.0, g2,
xx + state.getBarWidth() / 2.0, maxAxisValue);
}
if (outlierListCollection.isLowFarOut()) {
drawLowFarOut(aRadius / 2.0, g2,
xx + state.getBarWidth() / 2.0, minAxisValue);
}
}
// collect entity and tool tip information...
if (state.getInfo() != null && box != null) {
EntityCollection entities = state.getEntityCollection();
if (entities != null) {
String tip = null;
CategoryToolTipGenerator tipster
= getToolTipGenerator(row, column);
if (tipster != null) {
tip = tipster.generateToolTip(dataset, row, column);
}
String url = null;
if (getItemURLGenerator(row, column) != null) {
url = getItemURLGenerator(row, column).generateURL(dataset,
row, column);
}
CategoryItemEntity entity = new CategoryItemEntity(box, tip,
url, dataset, dataset.getRowKey(row),
dataset.getColumnKey(column));
entities.add(entity);
}
}
}
/**
* Draws a dot to represent an outlier.
*
* @param point the location.
* @param oRadius the radius.
* @param g2 the graphics device.
*/
private void drawEllipse(Point2D point, double oRadius, Graphics2D g2) {
Ellipse2D dot = new Ellipse2D.Double(point.getX() + oRadius / 2,
point.getY(), oRadius, oRadius);
g2.draw(dot);
}
/**
* Draws two dots to represent the average value of more than one outlier.
*
* @param point the location
* @param boxWidth the box width.
* @param oRadius the radius.
* @param g2 the graphics device.
*/
private void drawMultipleEllipse(Point2D point, double boxWidth,
double oRadius, Graphics2D g2) {
Ellipse2D dot1 = new Ellipse2D.Double(point.getX() - (boxWidth / 2)
+ oRadius, point.getY(), oRadius, oRadius);
Ellipse2D 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 coordinate.
* @param m the y coordinate.
*/
private 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 coordinate.
* @param m the y coordinate.
*/
private 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 an arbitrary 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 BoxAndWhiskerRenderer)) {
return false;
}
if (!super.equals(obj)) {
return false;
}
BoxAndWhiskerRenderer that = (BoxAndWhiskerRenderer) obj;
if (!PaintUtilities.equal(this.artifactPaint, that.artifactPaint)) {
return false;
}
if (!(this.fillBox == that.fillBox)) {
return false;
}
if (!(this.itemMargin == that.itemMargin)) {
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.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.artifactPaint = SerialUtilities.readPaint(stream);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -