Example usage for org.jfree.data Range Range

List of usage examples for org.jfree.data Range Range

Introduction

In this page you can find the example usage for org.jfree.data Range Range.

Prototype

public Range(double lower, double upper) 

Source Link

Document

Creates a new range.

Usage

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

/**
 * Returns the minimum and maximum values for the dataset's range,
 * assuming that the series are stacked, using the specified base value.
 *
 * @param dataset  the dataset (<code>null</code> not permitted).
 * @param base  the base value.//from   w w w .j a  va 2 s  .c  o  m
 *
 * @return The range (<code>null</code> if the dataset contains no values).
 */
public static Range findStackedRangeBounds(TableXYDataset dataset, double base) {
    ParamChecks.nullNotPermitted(dataset, "dataset");
    double minimum = base;
    double maximum = base;
    for (int itemNo = 0; itemNo < dataset.getItemCount(); itemNo++) {
        double positive = base;
        double negative = base;
        int seriesCount = dataset.getSeriesCount();
        for (int seriesNo = 0; seriesNo < seriesCount; seriesNo++) {
            double y = dataset.getYValue(seriesNo, itemNo);
            if (!Double.isNaN(y)) {
                if (y > 0.0) {
                    positive += y;
                } else {
                    negative += y;
                }
            }
        }
        if (positive > maximum) {
            maximum = positive;
        }
        if (negative < minimum) {
            minimum = negative;
        }
    }
    if (minimum <= maximum) {
        return new Range(minimum, maximum);
    } else {
        return null;
    }
}

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

/**
 * Calculates the range of values for a dataset where each item is the
 * running total of the items for the current series.
 *
 * @param dataset  the dataset ({@code null} not permitted).
 *
 * @return The range.//from   w w  w.j  av  a2  s.com
 *
 * @see #findRangeBounds(CategoryDataset)
 */
public static Range findCumulativeRangeBounds(CategoryDataset dataset) {
    Args.nullNotPermitted(dataset, "dataset");
    boolean allItemsNull = true; // we'll set this to false if there is at
                                 // least one non-null data item...
    double minimum = 0.0;
    double maximum = 0.0;
    for (int row = 0; row < dataset.getRowCount(); row++) {
        double runningTotal = 0.0;
        for (int column = 0; column <= dataset.getColumnCount() - 1; column++) {
            Number n = dataset.getValue(row, column);
            if (n != null) {
                allItemsNull = false;
                double value = n.doubleValue();
                if (!Double.isNaN(value)) {
                    runningTotal = runningTotal + value;
                    minimum = Math.min(minimum, runningTotal);
                    maximum = Math.max(maximum, runningTotal);
                }
            }
        }
    }
    if (!allItemsNull) {
        return new Range(minimum, maximum);
    } else {
        return null;
    }
}

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

/**
 * Calculates the range of values for a dataset where each item is the
 * running total of the items for the current series.
 *
 * @param dataset  the dataset (<code>null</code> not permitted).
 *
 * @return The range./*from  w w  w .  j  ava 2s. c o m*/
 *
 * @see #findRangeBounds(CategoryDataset)
 */
public static Range findCumulativeRangeBounds(CategoryDataset dataset) {
    ParamChecks.nullNotPermitted(dataset, "dataset");
    boolean allItemsNull = true; // we'll set this to false if there is at
                                 // least one non-null data item...
    double minimum = 0.0;
    double maximum = 0.0;
    for (int row = 0; row < dataset.getRowCount(); row++) {
        double runningTotal = 0.0;
        for (int column = 0; column <= dataset.getColumnCount() - 1; column++) {
            Number n = dataset.getValue(row, column);
            if (n != null) {
                allItemsNull = false;
                double value = n.doubleValue();
                if (!Double.isNaN(value)) {
                    runningTotal = runningTotal + value;
                    minimum = Math.min(minimum, runningTotal);
                    maximum = Math.max(maximum, runningTotal);
                }
            }
        }
    }
    if (!allItemsNull) {
        return new Range(minimum, maximum);
    } else {
        return null;
    }
}

From source file:org.fhcrc.cpl.viewer.gui.MRMDialog.java

protected void updateDaughterCharts(boolean clear, graphZone gz) {
    XYSeriesCollection daughterDatasets = new XYSeriesCollection();
    if (clear) {//from  w  ww .j ava  2  s.co  m
        transitionOnPlot = null;
    } else {
        daughterDatasets = makeDaughterCollection();
    }

    //Center daughter data on graph by finding the time associated
    //with the most data (a centroid or center of mass), centering
    //this time on the plot, and scaling to assure the extreme
    //timepoints are included
    /*
    double weightedAverageTime = getWeightedAverageDaughtersTime(daughterDatasets);
    double extremeHalf = Math.max(weightedAverageTime-getMinRetentionTimeForPlot(transitionOnPlot),getMaxRetentionTimeForPlot(transitionsOnPlot)-weightedAverageTime);
    double left = weightedAverageTime-extremeHalf;
    double right = weightedAverageTime+extremeHalf;
    */
    Range r = null;
    if (transitionOnPlot != null)
        r = gz.getRange(transitionOnPlot);
    if (r == null) {
        r = new Range(transitionOnPlot.getMinTimeOfAllDaughters(), transitionOnPlot.getMaxTimeOfAllDaughters());
    }
    createChartInPanel(daughterContainerPanel, daughterDatasets, r.getLowerBound(), r.getUpperBound(),
            getDrawingSupplierForPlot(transitionOnPlot), whichGraph.Daughter);
}

From source file:org.fhcrc.cpl.viewer.gui.MRMDialog.java

protected void updatePrecursorChart(boolean clear, graphZone gz) {
    XYSeriesCollection precursorDatasets = new XYSeriesCollection();
    if (clear) {/*from w  ww . j a va 2  s. c  o  m*/
        transitionOnPlot = null;
    } else {
        if (transitionOnPlot.getGraphData() == null)
            //transitionOnPlot.setGraphData(makeParentSeries(transitionOnPlot));
            ApplicationContext
                    .infoMessage("Precursor data for '" + transitionOnPlot.toString() + "' wasn't initialized");
        precursorDatasets.addSeries(transitionOnPlot.getGraphData());
    }
    //Center daughter data on graph by finding the time associated
    //with the most data (a centroid or center of mass), centering
    //this time on the plot, and scaling to assure the extreme
    //timepoints are included
    /*
    double weightedAverageTime = getWeightedAverageDaughtersTime(makeDaughterCollection());
    double extremeHalf = Math.max(weightedAverageTime-getMinRetentionTimeForPlot(transitionsOnPlot),getMaxRetentionTimeForPlot(transitionsOnPlot)-weightedAverageTime);
    double left = weightedAverageTime-extremeHalf;
    double right = weightedAverageTime+extremeHalf;
    */

    Range r = null;

    if (transitionOnPlot != null)
        r = gz.getRange(transitionOnPlot);
    if (r == null)
        r = new Range(0, 100);
    createChartInPanel(precursorContainerPanel, precursorDatasets, r.getLowerBound(), r.getUpperBound(), null,
            whichGraph.Precursor);
}

From source file:gda.plots.SimplePlot.java

/**
 * Sets the x axis limits./*from  w  w w .ja  va 2  s. com*/
 * 
 * @param xmin
 *            the minimum x value
 * @param xmax
 *            the maximum x value
 */
public void setXAxisLimits(double xmin, double xmax) {
    linearXAxis.setRange(new Range(xmin, xmax));
    logarithmicXAxis.setRange(new Range(xmin, xmax));
}

From source file:gda.plots.SimplePlot.java

/**
 * Sets the y axis limits.//from  w  ww. j  av a2  s.  c  om
 * 
 * @param ymin
 *            the minimum y value
 * @param ymax
 *            the maximum y value
 */
public void setYAxisLimits(double ymin, double ymax) {
    linearYAxis.setRange(new Range(ymin, ymax));
    logarithmicYAxis.setRange(new Range(ymin, ymax));
}

From source file:gda.plots.SimplePlot.java

/**
 * Sets the second y axis limits.//from   ww w  . ja  va  2 s.  c  om
 * 
 * @param ymin
 *            the minimum y value
 * @param ymax
 *            the maximum y value
 */
public void setYAxisTwoLimits(double ymin, double ymax) {
    linearYAxisTwo.setRange(new Range(ymin, ymax));
    logarithmicYAxisTwo.setRange(new Range(ymin, ymax));
}

From source file:gda.plots.SimplePlot.java

/**
 * @param collection/*  ww  w  .  java  2  s. co m*/
 * @param includeInterval
 * @return range for the range axis Y
 */
public Range getRangeBounds(SimpleXYSeriesCollection collection,
        @SuppressWarnings("unused") boolean includeInterval) {
    if (!isTurboMode())
        return null;

    Range domainBounds = null;
    Range rangeBounds = null;
    if (collection == leftSeriesCollection) {
        domainBounds = leftDomainBounds;
        rangeBounds = leftRangeBounds;
    } else if (collection == rightSeriesCollection) {
        domainBounds = rightDomainBounds;
        rangeBounds = rightRangeBounds;
    }
    if (rangeBounds != null)
        return rangeBounds;

    Double min = Double.POSITIVE_INFINITY;
    Double max = Double.NEGATIVE_INFINITY;

    if (isStripMode()) {
        synchronized (linesChanged) {
            if (linesChanged.size() == 0)
                return null;
            Iterator<Integer> iter = linesChanged.iterator();
            while (iter.hasNext()) {
                SimpleXYSeries sxys = collection.find(iter.next());
                // is it in this collection?
                if (sxys != null && sxys.isVisible()) {

                    Double sxys_min, sxys_max;
                    Double sxys_Xmax = sxys.getMaxX();
                    if (Double.isInfinite(sxys_Xmax))
                        return null;
                    /*
                     * create range in data units over which we want to get the y min and max
                     */
                    SimpleValueTransformer valTrans = collection.getXValueTransformer();
                    Double maxXTransformed = valTrans.transformValue(sxys_Xmax);
                    double minX = valTrans.transformValueBack(maxXTransformed - stripWidth);
                    Double[] extents = sxys.getBounds(new Range(minX, sxys_Xmax));
                    sxys_min = extents[2];
                    sxys_max = extents[3];
                    if (Double.isInfinite(sxys_min) || Double.isInfinite(sxys_max))
                        return null;
                    min = Math.min(min, sxys_min);
                    max = Math.max(max, sxys_max);
                }

            }
        }
    } else {
        for (Object obj : collection.getSeries()) {
            if (obj != null && obj instanceof SimpleXYSeries) {
                SimpleXYSeries sxys = (SimpleXYSeries) obj;
                if (sxys.isVisible()) {
                    if (domainBounds == null) {
                        double sxys_min, sxys_max;
                        sxys_min = sxys.getMinY();
                        sxys_max = sxys.getMaxY();
                        min = Math.min(min, sxys_min);
                        max = Math.max(max, sxys_max);
                    } else {
                        double sxys_min, sxys_max;
                        Double[] extents = sxys.getBounds(domainBounds);
                        sxys_min = extents[2];
                        sxys_max = extents[3];
                        if (Double.isInfinite(sxys_min) || Double.isInfinite(sxys_max))
                            return null;
                        min = Math.min(min, sxys_min);
                        max = Math.max(max, sxys_max);
                    }
                }
            }
        }
    }
    if (Double.isInfinite(min) || Double.isInfinite(max))
        return null;

    Range newRange = new Range(min, max);
    if (collection == leftSeriesCollection)
        lastRangeBoundsLeft = newRange;
    if (collection == rightSeriesCollection)
        lastRangeBoundsRight = newRange;
    return newRange;
}

From source file:gda.plots.SimplePlot.java

/**
 * @param collection/*from   ww  w  .  j av a2s .com*/
 * @param includeInterval
 * @return range for the domain axis X
 */
public Range getDomainBounds(SimpleXYSeriesCollection collection,
        @SuppressWarnings("unused") boolean includeInterval) {
    Double min = Double.POSITIVE_INFINITY;
    Double max = Double.NEGATIVE_INFINITY;
    if (!isTurboMode())
        return null;

    if (collection == leftSeriesCollection && leftDomainBounds != null)
        return leftDomainBounds;
    if (collection == rightSeriesCollection && rightDomainBounds != null)
        return rightDomainBounds;

    if (isStripMode()) {
        /*
         * In stripMode get max of changed lines - min will be the max minus the stripWidth
         */
        synchronized (linesChanged) {
            if (linesChanged.size() == 0)
                return null;
            Iterator<Integer> iter = linesChanged.iterator();
            while (iter.hasNext()) {
                SimpleXYSeries sxys = collection.find(iter.next());
                // is it in this collection?
                if (sxys != null && sxys.isVisible()) {
                    double sxys_max;
                    sxys_max = sxys.getMaxX();
                    max = Math.max(max, sxys_max);
                }

            }
            min = max; //we remove the stripWidth later as stripWidth is in final units after transformation
        }
    } else {
        /*
         * go through all visible lines are get min and max
         */
        for (Object obj : collection.getSeries()) {
            if (obj != null && obj instanceof SimpleXYSeries) {
                SimpleXYSeries sxys = (SimpleXYSeries) obj;
                if (sxys.isVisible()) {
                    double sxys_min, sxys_max;
                    sxys_min = sxys.getMinX();
                    sxys_max = sxys.getMaxX();
                    min = Math.min(min, sxys_min);
                    max = Math.max(max, sxys_max);
                }
            }
        }
    }
    if (Double.isInfinite(min) || Double.isInfinite(max))
        return null;
    SimpleValueTransformer valTrans = collection.getXValueTransformer();
    Double maxTransformed = valTrans.transformValue(max);
    Double minTransformed = stripWidth != null ? maxTransformed - stripWidth : valTrans.transformValue(min);
    Range newRange = new Range(minTransformed, maxTransformed);

    if (collection == leftSeriesCollection)
        lastDomainBoundsLeft = newRange;
    if (collection == rightSeriesCollection)
        lastDomainBoundsRight = newRange;
    return newRange;
}