Search in sources :

Example 1 with IntervalCategoryDataset

use of org.jfree.data.category.IntervalCategoryDataset 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 IntervalCategoryDataset

use of org.jfree.data.category.IntervalCategoryDataset in project SIMVA-SoS by SESoS.

the class IntervalCategoryItemLabelGenerator method createItemArray.

/**
 * Creates the array of items that can be passed to the
 * <code>MessageFormat</code> class for creating labels.
 *
 * @param dataset  the dataset (<code>null</code> not permitted).
 * @param row  the row index (zero-based).
 * @param column  the column index (zero-based).
 *
 * @return The items (never <code>null</code>).
 */
@Override
protected Object[] createItemArray(CategoryDataset dataset, int row, int column) {
    Object[] result = new Object[5];
    result[0] = dataset.getRowKey(row).toString();
    result[1] = dataset.getColumnKey(column).toString();
    Number value = dataset.getValue(row, column);
    if (getNumberFormat() != null) {
        result[2] = getNumberFormat().format(value);
    } else if (getDateFormat() != null) {
        result[2] = getDateFormat().format(value);
    }
    if (dataset instanceof IntervalCategoryDataset) {
        IntervalCategoryDataset icd = (IntervalCategoryDataset) dataset;
        Number start = icd.getStartValue(row, column);
        Number end = icd.getEndValue(row, column);
        if (getNumberFormat() != null) {
            result[3] = getNumberFormat().format(start);
            result[4] = getNumberFormat().format(end);
        } else if (getDateFormat() != null) {
            result[3] = getDateFormat().format(start);
            result[4] = getDateFormat().format(end);
        }
    }
    return result;
}
Also used : IntervalCategoryDataset(org.jfree.data.category.IntervalCategoryDataset)

Example 3 with IntervalCategoryDataset

use of org.jfree.data.category.IntervalCategoryDataset in project SIMVA-SoS by SESoS.

the class DatasetUtilities method findMinimumRangeValue.

/**
 * Returns the minimum range value for the specified dataset.  This is
 * easy if the dataset implements the {@link RangeInfo} interface (a good
 * idea if there is an efficient way to determine the minimum value).
 * Otherwise, it involves iterating over the entire data-set.  Returns
 * <code>null</code> if all the data values in the dataset are
 * <code>null</code>.
 *
 * @param dataset  the dataset (<code>null</code> not permitted).
 *
 * @return The minimum value (possibly <code>null</code>).
 */
public static Number findMinimumRangeValue(CategoryDataset dataset) {
    ParamChecks.nullNotPermitted(dataset, "dataset");
    if (dataset instanceof RangeInfo) {
        RangeInfo info = (RangeInfo) dataset;
        return new Double(info.getRangeLowerBound(true));
    } else // hasn't implemented RangeInfo, so we'll have to iterate...
    {
        double minimum = Double.POSITIVE_INFINITY;
        int seriesCount = dataset.getRowCount();
        int itemCount = dataset.getColumnCount();
        for (int series = 0; series < seriesCount; series++) {
            for (int item = 0; item < itemCount; item++) {
                Number value;
                if (dataset instanceof IntervalCategoryDataset) {
                    IntervalCategoryDataset icd = (IntervalCategoryDataset) dataset;
                    value = icd.getStartValue(series, item);
                } else {
                    value = dataset.getValue(series, item);
                }
                if (value != null) {
                    minimum = Math.min(minimum, value.doubleValue());
                }
            }
        }
        if (minimum == Double.POSITIVE_INFINITY) {
            return null;
        } else {
            return new Double(minimum);
        }
    }
}
Also used : IntervalCategoryDataset(org.jfree.data.category.IntervalCategoryDataset) CategoryRangeInfo(org.jfree.data.category.CategoryRangeInfo) RangeInfo(org.jfree.data.RangeInfo) XYRangeInfo(org.jfree.data.xy.XYRangeInfo)

Example 4 with IntervalCategoryDataset

use of org.jfree.data.category.IntervalCategoryDataset in project SIMVA-SoS by SESoS.

the class DatasetUtilities method findMaximumRangeValue.

/**
 * Returns the maximum range value for the specified dataset.  This is easy
 * if the dataset implements the {@link RangeInfo} interface (a good idea
 * if there is an efficient way to determine the maximum value).
 * Otherwise, it involves iterating over the entire data-set.  Returns
 * <code>null</code> if all the data values are <code>null</code>.
 *
 * @param dataset  the dataset (<code>null</code> not permitted).
 *
 * @return The maximum value (possibly <code>null</code>).
 */
public static Number findMaximumRangeValue(CategoryDataset dataset) {
    ParamChecks.nullNotPermitted(dataset, "dataset");
    // work out the minimum value...
    if (dataset instanceof RangeInfo) {
        RangeInfo info = (RangeInfo) dataset;
        return new Double(info.getRangeUpperBound(true));
    } else // hasn't implemented RangeInfo, so we'll have to iterate...
    {
        double maximum = Double.NEGATIVE_INFINITY;
        int seriesCount = dataset.getRowCount();
        int itemCount = dataset.getColumnCount();
        for (int series = 0; series < seriesCount; series++) {
            for (int item = 0; item < itemCount; item++) {
                Number value;
                if (dataset instanceof IntervalCategoryDataset) {
                    IntervalCategoryDataset icd = (IntervalCategoryDataset) dataset;
                    value = icd.getEndValue(series, item);
                } else {
                    value = dataset.getValue(series, item);
                }
                if (value != null) {
                    maximum = Math.max(maximum, value.doubleValue());
                }
            }
        }
        if (maximum == Double.NEGATIVE_INFINITY) {
            return null;
        } else {
            return new Double(maximum);
        }
    }
}
Also used : IntervalCategoryDataset(org.jfree.data.category.IntervalCategoryDataset) CategoryRangeInfo(org.jfree.data.category.CategoryRangeInfo) RangeInfo(org.jfree.data.RangeInfo) XYRangeInfo(org.jfree.data.xy.XYRangeInfo)

Example 5 with IntervalCategoryDataset

use of org.jfree.data.category.IntervalCategoryDataset in project SIMVA-SoS by SESoS.

the class DatasetUtilities method iterateRangeBounds.

/**
 * 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.
 *
 * @return The range (possibly <code>null</code>).
 *
 * @since 1.0.10
 */
public static Range iterateRangeBounds(CategoryDataset dataset, boolean includeInterval) {
    double minimum = Double.POSITIVE_INFINITY;
    double maximum = Double.NEGATIVE_INFINITY;
    int rowCount = dataset.getRowCount();
    int columnCount = dataset.getColumnCount();
    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 value, lvalue, uvalue;
        for (int row = 0; row < rowCount; row++) {
            for (int column = 0; column < columnCount; column++) {
                value = icd.getValue(row, column);
                double v;
                if ((value != null) && !Double.isNaN(v = value.doubleValue())) {
                    minimum = Math.min(v, minimum);
                    maximum = Math.max(v, maximum);
                }
                lvalue = icd.getStartValue(row, column);
                if (lvalue != null && !Double.isNaN(v = lvalue.doubleValue())) {
                    minimum = Math.min(v, minimum);
                    maximum = Math.max(v, maximum);
                }
                uvalue = icd.getEndValue(row, column);
                if (uvalue != null && !Double.isNaN(v = uvalue.doubleValue())) {
                    minimum = Math.min(v, minimum);
                    maximum = Math.max(v, maximum);
                }
            }
        }
    } else {
        // handle the standard case (plain CategoryDataset)
        for (int row = 0; row < rowCount; row++) {
            for (int column = 0; column < columnCount; column++) {
                Number value = dataset.getValue(row, 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 : IntervalCategoryDataset(org.jfree.data.category.IntervalCategoryDataset) Range(org.jfree.data.Range)

Aggregations

IntervalCategoryDataset (org.jfree.data.category.IntervalCategoryDataset)7 Range (org.jfree.data.Range)2 RangeInfo (org.jfree.data.RangeInfo)2 CategoryRangeInfo (org.jfree.data.category.CategoryRangeInfo)2 XYRangeInfo (org.jfree.data.xy.XYRangeInfo)2 ArrayList (java.util.ArrayList)1 Iterator (java.util.Iterator)1 List (java.util.List)1 BoxAndWhiskerCategoryDataset (org.jfree.data.statistics.BoxAndWhiskerCategoryDataset)1 MultiValueCategoryDataset (org.jfree.data.statistics.MultiValueCategoryDataset)1 StatisticalCategoryDataset (org.jfree.data.statistics.StatisticalCategoryDataset)1