boxandwhiskerrenderer.java

来自「JfreeChart 常用图表例子」· Java 代码 · 共 898 行 · 第 1/3 页

JAVA
898
字号
                        // 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) {            EntityCollection entities                 = state.getInfo().getOwner().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, row, dataset.getColumnKey(column),                     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 && super.equals(obj)) {            BoxAndWhiskerRenderer r = (BoxAndWhiskerRenderer) obj;            if (!ObjectUtilities.equal(r.artifactPaint, this.artifactPaint)) {                return false;            }            if (!(r.fillBox == this.fillBox)) {                return false;               }            if (!(r.itemMargin == this.itemMargin)) {                return false;               }            return true;        }        return false;    }        /**     * 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 + =
减小字号Ctrl + -
显示快捷键?