Search in sources :

Example 1 with BoxAndWhiskerXYDataset

use of org.jfree.data.statistics.BoxAndWhiskerXYDataset in project SIMVA-SoS by SESoS.

the class DatasetUtilities method iterateToFindRangeBounds.

/**
 * Returns the range of y-values in the specified dataset for the
 * data items belonging to the visible series and with x-values in the
 * given range.
 *
 * @param dataset  the dataset (<code>null</code> not permitted).
 * @param visibleSeriesKeys  the visible series keys (<code>null</code> not
 *     permitted).
 * @param xRange  the x-range (<code>null</code> not permitted).
 * @param includeInterval  a flag that determines whether or not the
 *     y-interval for the dataset is included (this only applies if the
 *     dataset is an instance of IntervalXYDataset).
 *
 * @return The y-range (possibly <code>null</code>).
 *
 * @since 1.0.13
 */
public static Range iterateToFindRangeBounds(XYDataset dataset, List visibleSeriesKeys, Range xRange, boolean includeInterval) {
    ParamChecks.nullNotPermitted(dataset, "dataset");
    ParamChecks.nullNotPermitted(visibleSeriesKeys, "visibleSeriesKeys");
    ParamChecks.nullNotPermitted(xRange, "xRange");
    double minimum = Double.POSITIVE_INFINITY;
    double maximum = Double.NEGATIVE_INFINITY;
    // handle three cases by dataset type
    if (includeInterval && dataset instanceof OHLCDataset) {
        // handle special case of OHLCDataset
        OHLCDataset ohlc = (OHLCDataset) dataset;
        Iterator iterator = visibleSeriesKeys.iterator();
        while (iterator.hasNext()) {
            Comparable seriesKey = (Comparable) iterator.next();
            int series = dataset.indexOf(seriesKey);
            int itemCount = dataset.getItemCount(series);
            for (int item = 0; item < itemCount; item++) {
                double x = ohlc.getXValue(series, item);
                if (xRange.contains(x)) {
                    double lvalue = ohlc.getLowValue(series, item);
                    double uvalue = ohlc.getHighValue(series, item);
                    if (!Double.isNaN(lvalue)) {
                        minimum = Math.min(minimum, lvalue);
                    }
                    if (!Double.isNaN(uvalue)) {
                        maximum = Math.max(maximum, uvalue);
                    }
                }
            }
        }
    } else if (includeInterval && dataset instanceof BoxAndWhiskerXYDataset) {
        // handle special case of BoxAndWhiskerXYDataset
        BoxAndWhiskerXYDataset bx = (BoxAndWhiskerXYDataset) dataset;
        Iterator iterator = visibleSeriesKeys.iterator();
        while (iterator.hasNext()) {
            Comparable seriesKey = (Comparable) iterator.next();
            int series = dataset.indexOf(seriesKey);
            int itemCount = dataset.getItemCount(series);
            for (int item = 0; item < itemCount; item++) {
                double x = bx.getXValue(series, item);
                if (xRange.contains(x)) {
                    Number lvalue = bx.getMinRegularValue(series, item);
                    Number uvalue = bx.getMaxRegularValue(series, item);
                    if (lvalue != null) {
                        minimum = Math.min(minimum, lvalue.doubleValue());
                    }
                    if (uvalue != null) {
                        maximum = Math.max(maximum, uvalue.doubleValue());
                    }
                }
            }
        }
    } else if (includeInterval && dataset instanceof IntervalXYDataset) {
        // handle special case of IntervalXYDataset
        IntervalXYDataset ixyd = (IntervalXYDataset) dataset;
        Iterator iterator = visibleSeriesKeys.iterator();
        while (iterator.hasNext()) {
            Comparable seriesKey = (Comparable) iterator.next();
            int series = dataset.indexOf(seriesKey);
            int itemCount = dataset.getItemCount(series);
            for (int item = 0; item < itemCount; item++) {
                double x = ixyd.getXValue(series, item);
                if (xRange.contains(x)) {
                    double lvalue = ixyd.getStartYValue(series, item);
                    double uvalue = ixyd.getEndYValue(series, item);
                    if (!Double.isNaN(lvalue)) {
                        minimum = Math.min(minimum, lvalue);
                    }
                    if (!Double.isNaN(uvalue)) {
                        maximum = Math.max(maximum, uvalue);
                    }
                }
            }
        }
    } else {
        // standard case - plain XYDataset
        Iterator iterator = visibleSeriesKeys.iterator();
        while (iterator.hasNext()) {
            Comparable seriesKey = (Comparable) iterator.next();
            int series = dataset.indexOf(seriesKey);
            int itemCount = dataset.getItemCount(series);
            for (int item = 0; item < itemCount; item++) {
                double x = dataset.getXValue(series, item);
                double y = dataset.getYValue(series, item);
                if (xRange.contains(x)) {
                    if (!Double.isNaN(y)) {
                        minimum = Math.min(minimum, y);
                        maximum = Math.max(maximum, y);
                    }
                }
            }
        }
    }
    if (minimum == Double.POSITIVE_INFINITY) {
        return null;
    } else {
        return new Range(minimum, maximum);
    }
}
Also used : OHLCDataset(org.jfree.data.xy.OHLCDataset) IntervalXYDataset(org.jfree.data.xy.IntervalXYDataset) Iterator(java.util.Iterator) Range(org.jfree.data.Range) BoxAndWhiskerXYDataset(org.jfree.data.statistics.BoxAndWhiskerXYDataset)

Example 2 with BoxAndWhiskerXYDataset

use of org.jfree.data.statistics.BoxAndWhiskerXYDataset in project SIMVA-SoS by SESoS.

the class BoxAndWhiskerXYToolTipGenerator method createItemArray.

/**
 * Creates the array of items that can be passed to the
 * {@link MessageFormat} class for creating labels.
 *
 * @param dataset  the dataset (<code>null</code> not permitted).
 * @param series  the series (zero-based index).
 * @param item  the item (zero-based index).
 *
 * @return The items (never <code>null</code>).
 */
@Override
protected Object[] createItemArray(XYDataset dataset, int series, int item) {
    Object[] result = new Object[8];
    result[0] = dataset.getSeriesKey(series).toString();
    Number x = dataset.getX(series, item);
    if (getXDateFormat() != null) {
        result[1] = getXDateFormat().format(new Date(x.longValue()));
    } else {
        result[1] = getXFormat().format(x);
    }
    NumberFormat formatter = getYFormat();
    if (dataset instanceof BoxAndWhiskerXYDataset) {
        BoxAndWhiskerXYDataset d = (BoxAndWhiskerXYDataset) dataset;
        result[2] = formatter.format(d.getMeanValue(series, item));
        result[3] = formatter.format(d.getMedianValue(series, item));
        result[4] = formatter.format(d.getMinRegularValue(series, item));
        result[5] = formatter.format(d.getMaxRegularValue(series, item));
        result[6] = formatter.format(d.getQ1Value(series, item));
        result[7] = formatter.format(d.getQ3Value(series, item));
    }
    return result;
}
Also used : BoxAndWhiskerXYDataset(org.jfree.data.statistics.BoxAndWhiskerXYDataset) Date(java.util.Date) NumberFormat(java.text.NumberFormat)

Example 3 with BoxAndWhiskerXYDataset

use of org.jfree.data.statistics.BoxAndWhiskerXYDataset in project SIMVA-SoS by SESoS.

the class XYBoxAndWhiskerRenderer method drawHorizontalItem.

/**
 * 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 drawHorizontalItem(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);
    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 exactBoxWidth = getBoxWidth();
    double width = exactBoxWidth;
    double dataAreaX = dataArea.getHeight();
    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(yyMax, xx, yyQ3Median, xx));
    g2.draw(new Line2D.Double(yyMax, xx - width / 2, yyMax, xx + width / 2));
    // draw the lower shadow
    g2.draw(new Line2D.Double(yyMin, xx, yyQ1Median, xx));
    g2.draw(new Line2D.Double(yyMin, xx - width / 2, yyMin, xx + width / 2));
    // draw the body
    Shape box;
    if (yyQ1Median < yyQ3Median) {
        box = new Rectangle2D.Double(yyQ1Median, xx - width / 2, yyQ3Median - yyQ1Median, width);
    } else {
        box = new Rectangle2D.Double(yyQ3Median, xx - width / 2, yyQ1Median - yyQ3Median, width);
    }
    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(yyMedian, xx - width / 2, yyMedian, xx + width / 2));
    // draw average - SPECIAL AIMS REQUIREMENT
    if (yAverage != null) {
        double aRadius = width / 4;
        // before drawing it...
        if ((yyAverage > (dataArea.getMinX() - aRadius)) && (yyAverage < (dataArea.getMaxX() + aRadius))) {
            Ellipse2D.Double avgEllipse = new Ellipse2D.Double(yyAverage - aRadius, xx - aRadius, aRadius * 2, aRadius * 2);
            g2.fill(avgEllipse);
            g2.draw(avgEllipse);
        }
    }
    // add an entity for the item...
    if (entities != null && box.intersects(dataArea)) {
        addEntity(entities, box, dataset, series, item, yyAverage, xx);
    }
}
Also used : Stroke(java.awt.Stroke) Shape(java.awt.Shape) Rectangle2D(java.awt.geom.Rectangle2D) Line2D(java.awt.geom.Line2D) Paint(java.awt.Paint) Ellipse2D(java.awt.geom.Ellipse2D) EntityCollection(org.jfree.chart.entity.EntityCollection) BoxAndWhiskerXYDataset(org.jfree.data.statistics.BoxAndWhiskerXYDataset) RectangleEdge(org.jfree.ui.RectangleEdge)

Example 4 with BoxAndWhiskerXYDataset

use of org.jfree.data.statistics.BoxAndWhiskerXYDataset 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

BoxAndWhiskerXYDataset (org.jfree.data.statistics.BoxAndWhiskerXYDataset)4 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 Rectangle2D (java.awt.geom.Rectangle2D)2 Iterator (java.util.Iterator)2 EntityCollection (org.jfree.chart.entity.EntityCollection)2 RectangleEdge (org.jfree.ui.RectangleEdge)2 Point2D (java.awt.geom.Point2D)1 NumberFormat (java.text.NumberFormat)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 List (java.util.List)1 Outlier (org.jfree.chart.renderer.Outlier)1 OutlierList (org.jfree.chart.renderer.OutlierList)1 OutlierListCollection (org.jfree.chart.renderer.OutlierListCollection)1 Range (org.jfree.data.Range)1 IntervalXYDataset (org.jfree.data.xy.IntervalXYDataset)1