Search in sources :

Example 1 with StatisticalCategoryDataset

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

the class DatasetUtilities method iterateToFindRangeBounds.

/**
 * Iterates over the data item of the category dataset to find
 * the range bounds.
 *
 * @param dataset  the dataset (<code>null</code> not permitted).
 * @param includeInterval  a flag that determines whether or not the
 *                         y-interval is taken into account.
 * @param visibleSeriesKeys  the visible series keys.
 *
 * @return The range (possibly <code>null</code>).
 *
 * @since 1.0.13
 */
public static Range iterateToFindRangeBounds(CategoryDataset dataset, List visibleSeriesKeys, boolean includeInterval) {
    ParamChecks.nullNotPermitted(dataset, "dataset");
    ParamChecks.nullNotPermitted(visibleSeriesKeys, "visibleSeriesKeys");
    double minimum = Double.POSITIVE_INFINITY;
    double maximum = Double.NEGATIVE_INFINITY;
    int columnCount = dataset.getColumnCount();
    if (includeInterval && dataset instanceof BoxAndWhiskerCategoryDataset) {
        // handle special case of BoxAndWhiskerDataset
        BoxAndWhiskerCategoryDataset bx = (BoxAndWhiskerCategoryDataset) dataset;
        Iterator iterator = visibleSeriesKeys.iterator();
        while (iterator.hasNext()) {
            Comparable seriesKey = (Comparable) iterator.next();
            int series = dataset.getRowIndex(seriesKey);
            int itemCount = dataset.getColumnCount();
            for (int item = 0; item < itemCount; item++) {
                Number lvalue = bx.getMinRegularValue(series, item);
                if (lvalue == null) {
                    lvalue = bx.getValue(series, item);
                }
                Number uvalue = bx.getMaxRegularValue(series, item);
                if (uvalue == null) {
                    uvalue = bx.getValue(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 IntervalCategoryDataset) {
        // handle the special case where the dataset has y-intervals that
        // we want to measure
        IntervalCategoryDataset icd = (IntervalCategoryDataset) dataset;
        Number lvalue, uvalue;
        Iterator iterator = visibleSeriesKeys.iterator();
        while (iterator.hasNext()) {
            Comparable seriesKey = (Comparable) iterator.next();
            int series = dataset.getRowIndex(seriesKey);
            for (int column = 0; column < columnCount; column++) {
                lvalue = icd.getStartValue(series, column);
                uvalue = icd.getEndValue(series, column);
                if (lvalue != null && !Double.isNaN(lvalue.doubleValue())) {
                    minimum = Math.min(minimum, lvalue.doubleValue());
                }
                if (uvalue != null && !Double.isNaN(uvalue.doubleValue())) {
                    maximum = Math.max(maximum, uvalue.doubleValue());
                }
            }
        }
    } else if (includeInterval && dataset instanceof MultiValueCategoryDataset) {
        // handle the special case where the dataset has y-intervals that
        // we want to measure
        MultiValueCategoryDataset mvcd = (MultiValueCategoryDataset) dataset;
        Iterator iterator = visibleSeriesKeys.iterator();
        while (iterator.hasNext()) {
            Comparable seriesKey = (Comparable) iterator.next();
            int series = dataset.getRowIndex(seriesKey);
            for (int column = 0; column < columnCount; column++) {
                List values = mvcd.getValues(series, column);
                Iterator valueIterator = values.iterator();
                while (valueIterator.hasNext()) {
                    Object o = valueIterator.next();
                    if (o instanceof Number) {
                        double v = ((Number) o).doubleValue();
                        if (!Double.isNaN(v)) {
                            minimum = Math.min(minimum, v);
                            maximum = Math.max(maximum, v);
                        }
                    }
                }
            }
        }
    } else if (includeInterval && dataset instanceof StatisticalCategoryDataset) {
        // handle the special case where the dataset has y-intervals that
        // we want to measure
        StatisticalCategoryDataset scd = (StatisticalCategoryDataset) dataset;
        Iterator iterator = visibleSeriesKeys.iterator();
        while (iterator.hasNext()) {
            Comparable seriesKey = (Comparable) iterator.next();
            int series = dataset.getRowIndex(seriesKey);
            for (int column = 0; column < columnCount; column++) {
                Number meanN = scd.getMeanValue(series, column);
                if (meanN != null) {
                    double std = 0.0;
                    Number stdN = scd.getStdDevValue(series, column);
                    if (stdN != null) {
                        std = stdN.doubleValue();
                        if (Double.isNaN(std)) {
                            std = 0.0;
                        }
                    }
                    double mean = meanN.doubleValue();
                    if (!Double.isNaN(mean)) {
                        minimum = Math.min(minimum, mean - std);
                        maximum = Math.max(maximum, mean + std);
                    }
                }
            }
        }
    } else {
        // handle the standard case (plain CategoryDataset)
        Iterator iterator = visibleSeriesKeys.iterator();
        while (iterator.hasNext()) {
            Comparable seriesKey = (Comparable) iterator.next();
            int series = dataset.getRowIndex(seriesKey);
            for (int column = 0; column < columnCount; column++) {
                Number value = dataset.getValue(series, column);
                if (value != null) {
                    double v = value.doubleValue();
                    if (!Double.isNaN(v)) {
                        minimum = Math.min(minimum, v);
                        maximum = Math.max(maximum, v);
                    }
                }
            }
        }
    }
    if (minimum == Double.POSITIVE_INFINITY) {
        return null;
    } else {
        return new Range(minimum, maximum);
    }
}
Also used : BoxAndWhiskerCategoryDataset(org.jfree.data.statistics.BoxAndWhiskerCategoryDataset) IntervalCategoryDataset(org.jfree.data.category.IntervalCategoryDataset) StatisticalCategoryDataset(org.jfree.data.statistics.StatisticalCategoryDataset) MultiValueCategoryDataset(org.jfree.data.statistics.MultiValueCategoryDataset) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) Range(org.jfree.data.Range)

Example 2 with StatisticalCategoryDataset

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

the class StatisticalLineAndShapeRenderer method drawItem.

/**
 * Draw a single data item.
 *
 * @param g2  the graphics device.
 * @param state  the renderer state.
 * @param dataArea  the area in which the data is drawn.
 * @param plot  the plot.
 * @param domainAxis  the domain axis.
 * @param rangeAxis  the range axis.
 * @param dataset  the dataset (a {@link StatisticalCategoryDataset} is
 *                 required).
 * @param row  the row index (zero-based).
 * @param column  the column index (zero-based).
 * @param pass  the pass.
 */
@Override
public void drawItem(Graphics2D g2, CategoryItemRendererState state, Rectangle2D dataArea, CategoryPlot plot, CategoryAxis domainAxis, ValueAxis rangeAxis, CategoryDataset dataset, int row, int column, int pass) {
    // do nothing if item is not visible
    if (!getItemVisible(row, column)) {
        return;
    }
    // to the superclass (LineAndShapeRenderer) behaviour...
    if (!(dataset instanceof StatisticalCategoryDataset)) {
        super.drawItem(g2, state, dataArea, plot, domainAxis, rangeAxis, dataset, row, column, pass);
        return;
    }
    int visibleRow = state.getVisibleSeriesIndex(row);
    if (visibleRow < 0) {
        return;
    }
    int visibleRowCount = state.getVisibleSeriesCount();
    StatisticalCategoryDataset statDataset = (StatisticalCategoryDataset) dataset;
    Number meanValue = statDataset.getMeanValue(row, column);
    if (meanValue == null) {
        return;
    }
    PlotOrientation orientation = plot.getOrientation();
    // current data point...
    double x1;
    if (getUseSeriesOffset()) {
        x1 = domainAxis.getCategorySeriesMiddle(column, dataset.getColumnCount(), visibleRow, visibleRowCount, getItemMargin(), dataArea, plot.getDomainAxisEdge());
    } else {
        x1 = domainAxis.getCategoryMiddle(column, getColumnCount(), dataArea, plot.getDomainAxisEdge());
    }
    double y1 = rangeAxis.valueToJava2D(meanValue.doubleValue(), dataArea, plot.getRangeAxisEdge());
    // draw the standard deviation lines *before* the shapes (if they're
    // visible) - it looks better if the shape fill colour is different to
    // the line colour
    Number sdv = statDataset.getStdDevValue(row, column);
    if (pass == 1 && sdv != null) {
        // standard deviation lines
        RectangleEdge yAxisLocation = plot.getRangeAxisEdge();
        double valueDelta = sdv.doubleValue();
        double highVal, lowVal;
        if ((meanValue.doubleValue() + valueDelta) > rangeAxis.getRange().getUpperBound()) {
            highVal = rangeAxis.valueToJava2D(rangeAxis.getRange().getUpperBound(), dataArea, yAxisLocation);
        } else {
            highVal = rangeAxis.valueToJava2D(meanValue.doubleValue() + valueDelta, dataArea, yAxisLocation);
        }
        if ((meanValue.doubleValue() + valueDelta) < rangeAxis.getRange().getLowerBound()) {
            lowVal = rangeAxis.valueToJava2D(rangeAxis.getRange().getLowerBound(), dataArea, yAxisLocation);
        } else {
            lowVal = rangeAxis.valueToJava2D(meanValue.doubleValue() - valueDelta, dataArea, yAxisLocation);
        }
        if (this.errorIndicatorPaint != null) {
            g2.setPaint(this.errorIndicatorPaint);
        } else {
            g2.setPaint(getItemPaint(row, column));
        }
        if (this.errorIndicatorStroke != null) {
            g2.setStroke(this.errorIndicatorStroke);
        } else {
            g2.setStroke(getItemOutlineStroke(row, column));
        }
        Line2D line = new Line2D.Double();
        if (orientation == PlotOrientation.HORIZONTAL) {
            line.setLine(lowVal, x1, highVal, x1);
            g2.draw(line);
            line.setLine(lowVal, x1 - 5.0d, lowVal, x1 + 5.0d);
            g2.draw(line);
            line.setLine(highVal, x1 - 5.0d, highVal, x1 + 5.0d);
            g2.draw(line);
        } else {
            // PlotOrientation.VERTICAL
            line.setLine(x1, lowVal, x1, highVal);
            g2.draw(line);
            line.setLine(x1 - 5.0d, highVal, x1 + 5.0d, highVal);
            g2.draw(line);
            line.setLine(x1 - 5.0d, lowVal, x1 + 5.0d, lowVal);
            g2.draw(line);
        }
    }
    Shape hotspot = null;
    if (pass == 1 && getItemShapeVisible(row, column)) {
        Shape shape = getItemShape(row, column);
        if (orientation == PlotOrientation.HORIZONTAL) {
            shape = ShapeUtilities.createTranslatedShape(shape, y1, x1);
        } else if (orientation == PlotOrientation.VERTICAL) {
            shape = ShapeUtilities.createTranslatedShape(shape, x1, y1);
        }
        hotspot = shape;
        if (getItemShapeFilled(row, column)) {
            if (getUseFillPaint()) {
                g2.setPaint(getItemFillPaint(row, column));
            } else {
                g2.setPaint(getItemPaint(row, column));
            }
            g2.fill(shape);
        }
        if (getDrawOutlines()) {
            if (getUseOutlinePaint()) {
                g2.setPaint(getItemOutlinePaint(row, column));
            } else {
                g2.setPaint(getItemPaint(row, column));
            }
            g2.setStroke(getItemOutlineStroke(row, column));
            g2.draw(shape);
        }
        // draw the item label if there is one...
        if (isItemLabelVisible(row, column)) {
            if (orientation == PlotOrientation.HORIZONTAL) {
                drawItemLabel(g2, orientation, dataset, row, column, y1, x1, (meanValue.doubleValue() < 0.0));
            } else if (orientation == PlotOrientation.VERTICAL) {
                drawItemLabel(g2, orientation, dataset, row, column, x1, y1, (meanValue.doubleValue() < 0.0));
            }
        }
    }
    if (pass == 0 && getItemLineVisible(row, column)) {
        if (column != 0) {
            Number previousValue = statDataset.getValue(row, column - 1);
            if (previousValue != null) {
                // previous data point...
                double previous = previousValue.doubleValue();
                double x0;
                if (getUseSeriesOffset()) {
                    x0 = domainAxis.getCategorySeriesMiddle(column - 1, dataset.getColumnCount(), visibleRow, visibleRowCount, getItemMargin(), dataArea, plot.getDomainAxisEdge());
                } else {
                    x0 = domainAxis.getCategoryMiddle(column - 1, getColumnCount(), dataArea, plot.getDomainAxisEdge());
                }
                double y0 = rangeAxis.valueToJava2D(previous, dataArea, plot.getRangeAxisEdge());
                Line2D line = null;
                if (orientation == PlotOrientation.HORIZONTAL) {
                    line = new Line2D.Double(y0, x0, y1, x1);
                } else if (orientation == PlotOrientation.VERTICAL) {
                    line = new Line2D.Double(x0, y0, x1, y1);
                }
                g2.setPaint(getItemPaint(row, column));
                g2.setStroke(getItemStroke(row, column));
                g2.draw(line);
            }
        }
    }
    if (pass == 1) {
        // add an item entity, if this information is being collected
        EntityCollection entities = state.getEntityCollection();
        if (entities != null) {
            addEntity(entities, hotspot, dataset, row, column, x1, y1);
        }
    }
}
Also used : StatisticalCategoryDataset(org.jfree.data.statistics.StatisticalCategoryDataset) PlotOrientation(org.jfree.chart.plot.PlotOrientation) Shape(java.awt.Shape) EntityCollection(org.jfree.chart.entity.EntityCollection) Line2D(java.awt.geom.Line2D) Paint(java.awt.Paint) RectangleEdge(org.jfree.ui.RectangleEdge)

Example 3 with StatisticalCategoryDataset

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

the class StatisticalBarRenderer method drawItem.

/**
 * Draws the bar with its standard deviation line range for a single
 * (series, category) data item.
 *
 * @param g2  the graphics device.
 * @param state  the renderer state.
 * @param dataArea  the data area.
 * @param plot  the plot.
 * @param domainAxis  the domain axis.
 * @param rangeAxis  the range axis.
 * @param data  the data.
 * @param row  the row index (zero-based).
 * @param column  the column index (zero-based).
 * @param pass  the pass index.
 */
@Override
public void drawItem(Graphics2D g2, CategoryItemRendererState state, Rectangle2D dataArea, CategoryPlot plot, CategoryAxis domainAxis, ValueAxis rangeAxis, CategoryDataset data, int row, int column, int pass) {
    int visibleRow = state.getVisibleSeriesIndex(row);
    if (visibleRow < 0) {
        return;
    }
    // defensive check
    if (!(data instanceof StatisticalCategoryDataset)) {
        throw new IllegalArgumentException("Requires StatisticalCategoryDataset.");
    }
    StatisticalCategoryDataset statData = (StatisticalCategoryDataset) data;
    PlotOrientation orientation = plot.getOrientation();
    if (orientation == PlotOrientation.HORIZONTAL) {
        drawHorizontalItem(g2, state, dataArea, plot, domainAxis, rangeAxis, statData, visibleRow, row, column);
    } else if (orientation == PlotOrientation.VERTICAL) {
        drawVerticalItem(g2, state, dataArea, plot, domainAxis, rangeAxis, statData, visibleRow, row, column);
    }
}
Also used : StatisticalCategoryDataset(org.jfree.data.statistics.StatisticalCategoryDataset) PlotOrientation(org.jfree.chart.plot.PlotOrientation) Paint(java.awt.Paint) GradientPaint(java.awt.GradientPaint)

Aggregations

StatisticalCategoryDataset (org.jfree.data.statistics.StatisticalCategoryDataset)3 Paint (java.awt.Paint)2 PlotOrientation (org.jfree.chart.plot.PlotOrientation)2 GradientPaint (java.awt.GradientPaint)1 Shape (java.awt.Shape)1 Line2D (java.awt.geom.Line2D)1 ArrayList (java.util.ArrayList)1 Iterator (java.util.Iterator)1 List (java.util.List)1 EntityCollection (org.jfree.chart.entity.EntityCollection)1 Range (org.jfree.data.Range)1 IntervalCategoryDataset (org.jfree.data.category.IntervalCategoryDataset)1 BoxAndWhiskerCategoryDataset (org.jfree.data.statistics.BoxAndWhiskerCategoryDataset)1 MultiValueCategoryDataset (org.jfree.data.statistics.MultiValueCategoryDataset)1 RectangleEdge (org.jfree.ui.RectangleEdge)1