Example usage for org.jfree.data.statistics StatisticalCategoryDataset getMeanValue

List of usage examples for org.jfree.data.statistics StatisticalCategoryDataset getMeanValue

Introduction

In this page you can find the example usage for org.jfree.data.statistics StatisticalCategoryDataset getMeanValue.

Prototype

public Number getMeanValue(Comparable rowKey, Comparable columnKey);

Source Link

Document

Returns the mean value for an item.

Usage

From source file:nl.strohalm.cyclos.utils.jfreeAsymmetric.AsymmetricStatisticalBarRenderer.java

/**
 * Draws an item for a plot with a vertical orientation.
 * //ww w.  ja  v  a2s  . c om
 * @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 dataset the data.
 * @param row the row index (zero-based).
 * @param column the column index (zero-based).
 */
protected void drawVerticalItem(final Graphics2D g2, final CategoryItemRendererState state,
        final Rectangle2D dataArea, final CategoryPlot plot, final CategoryAxis domainAxis,
        final ValueAxis rangeAxis, final StatisticalCategoryDataset dataset, final int row, final int column) {
    // nothing is drawn for null... //ADDED THIS BLOCK, RINKE
    final Number v = dataset.getValue(row, column);
    if (v == null) {
        return;
    }

    final RectangleEdge xAxisLocation = plot.getDomainAxisEdge();

    // BAR X
    double rectX = domainAxis.getCategoryStart(column, getColumnCount(), dataArea, xAxisLocation);

    final int seriesCount = getRowCount();
    final int categoryCount = getColumnCount();
    if (seriesCount > 1) {
        final double seriesGap = dataArea.getWidth() * getItemMargin() / (categoryCount * (seriesCount - 1));
        rectX = rectX + row * (state.getBarWidth() + seriesGap);
    } else {
        rectX = rectX + row * state.getBarWidth();
    }

    // BAR Y
    final Number meanValue = dataset.getMeanValue(row, column);

    double value = meanValue.doubleValue();
    double base = 0.0;
    final double lclip = getLowerClip();
    final double uclip = getUpperClip();

    if (uclip <= 0.0) { // cases 1, 2, 3 and 4
        if (value >= uclip) {
            return; // bar is not visible
        }
        base = uclip;
        if (value <= lclip) {
            value = lclip;
        }
    } else if (lclip <= 0.0) { // cases 5, 6, 7 and 8
        if (value >= uclip) {
            value = uclip;
        } else {
            if (value <= lclip) {
                value = lclip;
            }
        }
    } else { // cases 9, 10, 11 and 12
        if (value <= lclip) {
            return; // bar is not visible
        }
        base = getLowerClip();
        if (value >= uclip) {
            value = uclip;
        }
    }

    final RectangleEdge yAxisLocation = plot.getRangeAxisEdge();
    final double transY1 = rangeAxis.valueToJava2D(base, dataArea, yAxisLocation);
    final double transY2 = rangeAxis.valueToJava2D(value, dataArea, yAxisLocation);
    final double rectY = Math.min(transY2, transY1);

    final double rectWidth = state.getBarWidth();
    final double rectHeight = Math.abs(transY2 - transY1);

    final Rectangle2D bar = new Rectangle2D.Double(rectX, rectY, rectWidth, rectHeight);
    final Paint seriesPaint = getItemPaint(row, column);
    g2.setPaint(seriesPaint);
    g2.fill(bar);
    if (state.getBarWidth() > 3) {
        g2.setStroke(getItemStroke(row, column));
        g2.setPaint(getItemOutlinePaint(row, column));
        g2.draw(bar);
    }

    // standard deviation lines
    final AsymmetricStatisticalCategoryDataset asymmDataset = (AsymmetricStatisticalCategoryDataset) dataset;
    final Number highValRaw = asymmDataset.getUpperValue(row, column);
    final Number lowValRaw = asymmDataset.getLowerValue(row, column);
    // only draw if both error bars items are not null
    if (highValRaw != null && lowValRaw != null) { // ADDED THIS IF, RINKE
        final double highVal = rangeAxis.valueToJava2D(highValRaw.doubleValue(), dataArea, yAxisLocation);
        final double lowVal = rangeAxis.valueToJava2D(lowValRaw.doubleValue(), dataArea, yAxisLocation);

        if (getErrorIndicatorPaint() != null) {
            g2.setPaint(getErrorIndicatorPaint());
        } else {
            g2.setPaint(getItemOutlinePaint(row, column));
        }
        Line2D line = null;
        line = new Line2D.Double(rectX + rectWidth / 2.0d, lowVal, rectX + rectWidth / 2.0d, highVal);
        g2.draw(line);
        line = new Line2D.Double(rectX + rectWidth / 2.0d - 5.0d, highVal, rectX + rectWidth / 2.0d + 5.0d,
                highVal);
        g2.draw(line);
        line = new Line2D.Double(rectX + rectWidth / 2.0d - 5.0d, lowVal, rectX + rectWidth / 2.0d + 5.0d,
                lowVal);
        g2.draw(line);
    }

    final CategoryItemLabelGenerator generator = getItemLabelGenerator(row, column);
    if (generator != null && isItemLabelVisible(row, column)) {
        drawItemLabel(g2, dataset, row, column, plot, generator, bar, (value < 0.0));
    }

    // add an item entity, if this information is being collected
    final EntityCollection entities = state.getEntityCollection();
    if (entities != null) {
        addItemEntity(entities, dataset, row, column, bar);
    }
}

From source file:nl.strohalm.cyclos.utils.jfreeAsymmetric.AsymmetricStatisticalBarRenderer.java

/**
 * Draws an item for a plot with a horizontal orientation.
 * /*from www .j a  v a 2 s.c  o m*/
 * @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 dataset the data.
 * @param row the row index (zero-based).
 * @param column the column index (zero-based).
 */
protected void drawHorizontalItem(final Graphics2D g2, final CategoryItemRendererState state,
        final Rectangle2D dataArea, final CategoryPlot plot, final CategoryAxis domainAxis,
        final ValueAxis rangeAxis, final StatisticalCategoryDataset dataset, final int row, final int column) {
    // nothing is drawn for null... //added this test block, Rinke
    final Number v = dataset.getValue(row, column);
    if (v == null) {
        return;
    }

    final RectangleEdge xAxisLocation = plot.getDomainAxisEdge();

    // BAR Y
    double rectY = domainAxis.getCategoryStart(column, getColumnCount(), dataArea, xAxisLocation);

    final int seriesCount = getRowCount();
    final int categoryCount = getColumnCount();
    if (seriesCount > 1) {
        final double seriesGap = dataArea.getHeight() * getItemMargin() / (categoryCount * (seriesCount - 1));
        rectY = rectY + row * (state.getBarWidth() + seriesGap);
    } else {
        rectY = rectY + row * state.getBarWidth();
    }

    // BAR X
    final Number meanValue = dataset.getMeanValue(row, column);

    double value = meanValue.doubleValue();
    double base = 0.0;
    final double lclip = getLowerClip();
    final double uclip = getUpperClip();

    if (uclip <= 0.0) { // cases 1, 2, 3 and 4
        if (value >= uclip) {
            return; // bar is not visible
        }
        base = uclip;
        if (value <= lclip) {
            value = lclip;
        }
    } else if (lclip <= 0.0) { // cases 5, 6, 7 and 8
        if (value >= uclip) {
            value = uclip;
        } else {
            if (value <= lclip) {
                value = lclip;
            }
        }
    } else { // cases 9, 10, 11 and 12
        if (value <= lclip) {
            return; // bar is not visible
        }
        base = getLowerClip();
        if (value >= uclip) {
            value = uclip;
        }
    }

    final RectangleEdge yAxisLocation = plot.getRangeAxisEdge();
    final double transY1 = rangeAxis.valueToJava2D(base, dataArea, yAxisLocation);
    final double transY2 = rangeAxis.valueToJava2D(value, dataArea, yAxisLocation);
    final double rectX = Math.min(transY2, transY1);

    final double rectHeight = state.getBarWidth();
    final double rectWidth = Math.abs(transY2 - transY1);

    final Rectangle2D bar = new Rectangle2D.Double(rectX, rectY, rectWidth, rectHeight);
    final Paint seriesPaint = getItemPaint(row, column);
    g2.setPaint(seriesPaint);
    g2.fill(bar);
    if (state.getBarWidth() > 3) {
        g2.setStroke(getItemStroke(row, column));
        g2.setPaint(getItemOutlinePaint(row, column));
        g2.draw(bar);
    }
    // ********** BLOCK WITH CHANGES RELATIVE TO StatisticalBarRenderere *********************
    // standard deviation lines
    final AsymmetricStatisticalCategoryDataset asymmDataset = (AsymmetricStatisticalCategoryDataset) dataset;
    final Number highValRaw = asymmDataset.getUpperValue(row, column);
    final Number lowValRaw = asymmDataset.getLowerValue(row, column);
    if (highValRaw != null && lowValRaw != null) { // ADDED THIS IF, RINKE
        final double highVal = rangeAxis.valueToJava2D(highValRaw.doubleValue(), dataArea, yAxisLocation);
        final double lowVal = rangeAxis.valueToJava2D(lowValRaw.doubleValue(), dataArea, yAxisLocation);
        // *************************** end of block with changes ******************************

        if (getErrorIndicatorPaint() != null) {
            g2.setPaint(getErrorIndicatorPaint());
        } else {
            g2.setPaint(getItemOutlinePaint(row, column));
        }
        Line2D line = null;
        line = new Line2D.Double(lowVal, rectY + rectHeight / 2.0d, highVal, rectY + rectHeight / 2.0d);
        g2.draw(line);
        line = new Line2D.Double(highVal, rectY + rectHeight * 0.25, highVal, rectY + rectHeight * 0.75);
        g2.draw(line);
        line = new Line2D.Double(lowVal, rectY + rectHeight * 0.25, lowVal, rectY + rectHeight * 0.75);
        g2.draw(line);
    }

    final CategoryItemLabelGenerator generator = getItemLabelGenerator(row, column);
    if (generator != null && isItemLabelVisible(row, column)) {
        drawItemLabel(g2, dataset, row, column, plot, generator, bar, (value < 0.0));
    }

    // add an item entity, if this information is being collected
    final EntityCollection entities = state.getEntityCollection();
    if (entities != null) {
        addItemEntity(entities, dataset, row, column, bar);
    }

}

From source file:org.jfree.data.general.DatasetUtils.java

/**
 * Iterates over the data item of the category dataset to find
 * the range bounds.//from  w ww.j  ava2s  . c  om
 *
 * @param dataset  the dataset ({@code null} 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}).
 *
 * @since 1.0.13
 */
public static Range iterateToFindRangeBounds(CategoryDataset dataset, List visibleSeriesKeys,
        boolean includeInterval) {

    Args.nullNotPermitted(dataset, "dataset");
    Args.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);
    }
}

From source file:org.jfree.data.general.DatasetUtilities.java

/**
 * Iterates over the data item of the category dataset to find
 * the range bounds./*from www . ja  va2 s.c  o m*/
 *
 * @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);
    }
}