Search in sources :

Example 1 with Outlier

use of org.jfree.chart.renderer.Outlier in project SIMVA-SoS by SESoS.

the class BoxAndWhiskerRenderer method drawVerticalItem.

/**
 * Draws the visual representation of a single data item when the plot has
 * a vertical orientation.
 *
 * @param g2  the graphics device.
 * @param state  the renderer state.
 * @param dataArea  the area within which the plot is being drawn.
 * @param plot  the plot (can be used to obtain standard color information
 *              etc).
 * @param domainAxis  the domain axis.
 * @param rangeAxis  the range axis.
 * @param dataset  the dataset (must be an instance of
 *                 {@link BoxAndWhiskerCategoryDataset}).
 * @param row  the row index (zero-based).
 * @param column  the column index (zero-based).
 */
public void drawVerticalItem(Graphics2D g2, CategoryItemRendererState state, Rectangle2D dataArea, CategoryPlot plot, CategoryAxis domainAxis, ValueAxis rangeAxis, CategoryDataset dataset, int row, int column) {
    BoxAndWhiskerCategoryDataset bawDataset = (BoxAndWhiskerCategoryDataset) dataset;
    double categoryEnd = domainAxis.getCategoryEnd(column, getColumnCount(), dataArea, plot.getDomainAxisEdge());
    double categoryStart = domainAxis.getCategoryStart(column, getColumnCount(), dataArea, plot.getDomainAxisEdge());
    double categoryWidth = categoryEnd - categoryStart;
    double xx = categoryStart;
    int seriesCount = getRowCount();
    int categoryCount = getColumnCount();
    if (seriesCount > 1) {
        double seriesGap = dataArea.getWidth() * getItemMargin() / (categoryCount * (seriesCount - 1));
        double usedWidth = (state.getBarWidth() * seriesCount) + (seriesGap * (seriesCount - 1));
        // offset the start of the boxes if the total width used is smaller
        // than the category width
        double offset = (categoryWidth - usedWidth) / 2;
        xx = xx + offset + (row * (state.getBarWidth() + seriesGap));
    } else {
        // offset the start of the box if the box width is smaller than the
        // category width
        double offset = (categoryWidth - state.getBarWidth()) / 2;
        xx = xx + offset;
    }
    double yyAverage;
    double yyOutlier;
    Paint itemPaint = getItemPaint(row, column);
    g2.setPaint(itemPaint);
    Stroke s = getItemStroke(row, column);
    g2.setStroke(s);
    // average radius
    double aRadius = 0;
    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;
        double halfW = (state.getBarWidth() / 2.0) * this.whiskerWidth;
        // draw the body...
        box = new Rectangle2D.Double(xx, Math.min(yyQ1, yyQ3), state.getBarWidth(), Math.abs(yyQ1 - yyQ3));
        if (this.fillBox) {
            g2.fill(box);
        }
        Paint outlinePaint = getItemOutlinePaint(row, column);
        if (this.useOutlinePaintForWhiskers) {
            g2.setPaint(outlinePaint);
        }
        // draw the upper shadow...
        g2.draw(new Line2D.Double(xxmid, yyMax, xxmid, yyQ3));
        g2.draw(new Line2D.Double(xxmid - halfW, yyMax, xxmid + halfW, yyMax));
        // draw the lower shadow...
        g2.draw(new Line2D.Double(xxmid, yyMin, xxmid, yyQ1));
        g2.draw(new Line2D.Double(xxmid - halfW, yyMin, xxmid + halfW, yyMin));
        g2.setStroke(getItemOutlineStroke(row, column));
        g2.setPaint(outlinePaint);
        g2.draw(box);
    }
    g2.setPaint(this.artifactPaint);
    // draw mean - SPECIAL AIMS REQUIREMENT...
    if (this.meanVisible) {
        Number yMean = bawDataset.getMeanValue(row, column);
        if (yMean != null) {
            yyAverage = rangeAxis.valueToJava2D(yMean.doubleValue(), dataArea, location);
            aRadius = state.getBarWidth() / 4;
            // visible before drawing it...
            if ((yyAverage > (dataArea.getMinY() - aRadius)) && (yyAverage < (dataArea.getMaxY() + aRadius))) {
                Ellipse2D.Double avgEllipse = new Ellipse2D.Double(xx + aRadius, yyAverage - aRadius, aRadius * 2, aRadius * 2);
                g2.fill(avgEllipse);
                g2.draw(avgEllipse);
            }
        }
    }
    // draw median...
    if (this.medianVisible) {
        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(itemPaint);
    // draw outliers
    // outlier radius
    double oRadius = state.getBarWidth() / 3;
    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);
        }
        // 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) {
            addItemEntity(entities, dataset, row, column, box);
        }
    }
}
Also used : OutlierList(org.jfree.chart.renderer.OutlierList) Stroke(java.awt.Stroke) Shape(java.awt.Shape) Rectangle2D(java.awt.geom.Rectangle2D) ArrayList(java.util.ArrayList) Paint(java.awt.Paint) Line2D(java.awt.geom.Line2D) Paint(java.awt.Paint) Ellipse2D(java.awt.geom.Ellipse2D) BoxAndWhiskerCategoryDataset(org.jfree.data.statistics.BoxAndWhiskerCategoryDataset) Outlier(org.jfree.chart.renderer.Outlier) Point2D(java.awt.geom.Point2D) EntityCollection(org.jfree.chart.entity.EntityCollection) OutlierListCollection(org.jfree.chart.renderer.OutlierListCollection) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) OutlierList(org.jfree.chart.renderer.OutlierList) List(java.util.List) RectangleEdge(org.jfree.ui.RectangleEdge)

Example 2 with Outlier

use of org.jfree.chart.renderer.Outlier in project SIMVA-SoS by SESoS.

the class XYBoxAndWhiskerRenderer method drawVerticalItem.

/**
 * Draws the visual representation of a single data item.
 *
 * @param g2  the graphics device.
 * @param dataArea  the area within which the plot is being drawn.
 * @param info  collects info about the drawing.
 * @param plot  the plot (can be used to obtain standard color
 *              information etc).
 * @param domainAxis  the domain axis.
 * @param rangeAxis  the range axis.
 * @param dataset  the dataset (must be an instance of
 *                 {@link BoxAndWhiskerXYDataset}).
 * @param series  the series index (zero-based).
 * @param item  the item index (zero-based).
 * @param crosshairState  crosshair information for the plot
 *                        (<code>null</code> permitted).
 * @param pass  the pass index.
 */
public void drawVerticalItem(Graphics2D g2, Rectangle2D dataArea, PlotRenderingInfo info, XYPlot plot, ValueAxis domainAxis, ValueAxis rangeAxis, XYDataset dataset, int series, int item, CrosshairState crosshairState, int pass) {
    // setup for collecting optional entity info...
    EntityCollection entities = null;
    if (info != null) {
        entities = info.getOwner().getEntityCollection();
    }
    BoxAndWhiskerXYDataset boxAndWhiskerData = (BoxAndWhiskerXYDataset) dataset;
    Number x = boxAndWhiskerData.getX(series, item);
    Number yMax = boxAndWhiskerData.getMaxRegularValue(series, item);
    Number yMin = boxAndWhiskerData.getMinRegularValue(series, item);
    Number yMedian = boxAndWhiskerData.getMedianValue(series, item);
    Number yAverage = boxAndWhiskerData.getMeanValue(series, item);
    Number yQ1Median = boxAndWhiskerData.getQ1Value(series, item);
    Number yQ3Median = boxAndWhiskerData.getQ3Value(series, item);
    List yOutliers = boxAndWhiskerData.getOutliers(series, item);
    // that case...
    if (yOutliers == null) {
        yOutliers = Collections.EMPTY_LIST;
    }
    double xx = domainAxis.valueToJava2D(x.doubleValue(), dataArea, plot.getDomainAxisEdge());
    RectangleEdge location = plot.getRangeAxisEdge();
    double yyMax = rangeAxis.valueToJava2D(yMax.doubleValue(), dataArea, location);
    double yyMin = rangeAxis.valueToJava2D(yMin.doubleValue(), dataArea, location);
    double yyMedian = rangeAxis.valueToJava2D(yMedian.doubleValue(), dataArea, location);
    double yyAverage = 0.0;
    if (yAverage != null) {
        yyAverage = rangeAxis.valueToJava2D(yAverage.doubleValue(), dataArea, location);
    }
    double yyQ1Median = rangeAxis.valueToJava2D(yQ1Median.doubleValue(), dataArea, location);
    double yyQ3Median = rangeAxis.valueToJava2D(yQ3Median.doubleValue(), dataArea, location);
    double yyOutlier;
    double exactBoxWidth = getBoxWidth();
    double width = exactBoxWidth;
    double dataAreaX = dataArea.getMaxX() - dataArea.getMinX();
    double maxBoxPercent = 0.1;
    double maxBoxWidth = dataAreaX * maxBoxPercent;
    if (exactBoxWidth <= 0.0) {
        int itemCount = boxAndWhiskerData.getItemCount(series);
        exactBoxWidth = dataAreaX / itemCount * 4.5 / 7;
        if (exactBoxWidth < 3) {
            width = 3;
        } else if (exactBoxWidth > maxBoxWidth) {
            width = maxBoxWidth;
        } else {
            width = exactBoxWidth;
        }
    }
    g2.setPaint(getItemPaint(series, item));
    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;
    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.setPaint(lookupBoxPaint(series, item));
        g2.fill(box);
    }
    g2.setStroke(getItemOutlineStroke(series, item));
    g2.setPaint(getItemOutlinePaint(series, item));
    g2.draw(box);
    // draw median
    g2.setPaint(getArtifactPaint());
    g2.draw(new Line2D.Double(xx - width / 2, yyMedian, xx + width / 2, yyMedian));
    // average radius
    double aRadius = 0;
    // outlier radius
    double oRadius = width / 3;
    // draw average - SPECIAL AIMS REQUIREMENT
    if (yAverage != null) {
        aRadius = width / 4;
        // before drawing it...
        if ((yyAverage > (dataArea.getMinY() - aRadius)) && (yyAverage < (dataArea.getMaxY() + aRadius))) {
            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);
    }
    // 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);
    }
}
Also used : OutlierList(org.jfree.chart.renderer.OutlierList) Stroke(java.awt.Stroke) Shape(java.awt.Shape) Rectangle2D(java.awt.geom.Rectangle2D) ArrayList(java.util.ArrayList) Line2D(java.awt.geom.Line2D) Paint(java.awt.Paint) Ellipse2D(java.awt.geom.Ellipse2D) Outlier(org.jfree.chart.renderer.Outlier) EntityCollection(org.jfree.chart.entity.EntityCollection) Point2D(java.awt.geom.Point2D) OutlierListCollection(org.jfree.chart.renderer.OutlierListCollection) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) OutlierList(org.jfree.chart.renderer.OutlierList) List(java.util.List) BoxAndWhiskerXYDataset(org.jfree.data.statistics.BoxAndWhiskerXYDataset) RectangleEdge(org.jfree.ui.RectangleEdge)

Aggregations

Paint (java.awt.Paint)2 Shape (java.awt.Shape)2 Stroke (java.awt.Stroke)2 Ellipse2D (java.awt.geom.Ellipse2D)2 Line2D (java.awt.geom.Line2D)2 Point2D (java.awt.geom.Point2D)2 Rectangle2D (java.awt.geom.Rectangle2D)2 ArrayList (java.util.ArrayList)2 Iterator (java.util.Iterator)2 List (java.util.List)2 EntityCollection (org.jfree.chart.entity.EntityCollection)2 Outlier (org.jfree.chart.renderer.Outlier)2 OutlierList (org.jfree.chart.renderer.OutlierList)2 OutlierListCollection (org.jfree.chart.renderer.OutlierListCollection)2 RectangleEdge (org.jfree.ui.RectangleEdge)2 BoxAndWhiskerCategoryDataset (org.jfree.data.statistics.BoxAndWhiskerCategoryDataset)1 BoxAndWhiskerXYDataset (org.jfree.data.statistics.BoxAndWhiskerXYDataset)1