Example usage for org.jfree.data Range getUpperBound

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

Introduction

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

Prototype

public double getUpperBound() 

Source Link

Document

Returns the upper bound for the range.

Usage

From source file:org.jfree.data.time.TimePeriodValuesCollectionTest.java

/**
 * Some more checks for the getDomainBounds() method.
 * /*from   w  ww. j a va  2 s  .c om*/
 * @see #testGetDomainBoundsWithoutInterval()
 */
@Test
public void testGetDomainBoundsWithInterval() {
    // check empty dataset
    TimePeriodValuesCollection dataset = new TimePeriodValuesCollection();
    Range r = dataset.getDomainBounds(true);
    assertNull(r);

    // check dataset with one time period
    TimePeriodValues s1 = new TimePeriodValues("S1");
    s1.add(new SimpleTimePeriod(1000L, 2000L), 1.0);
    dataset.addSeries(s1);
    r = dataset.getDomainBounds(true);
    assertEquals(1000.0, r.getLowerBound(), EPSILON);
    assertEquals(2000.0, r.getUpperBound(), EPSILON);

    // check dataset with two time periods
    s1.add(new SimpleTimePeriod(1500L, 3000L), 2.0);
    r = dataset.getDomainBounds(true);
    assertEquals(1000.0, r.getLowerBound(), EPSILON);
    assertEquals(3000.0, r.getUpperBound(), EPSILON);

    // add a third time period
    s1.add(new SimpleTimePeriod(6000L, 7000L), 1.5);
    r = dataset.getDomainBounds(true);
    assertEquals(1000.0, r.getLowerBound(), EPSILON);
    assertEquals(7000.0, r.getUpperBound(), EPSILON);

    // add a fourth time period
    s1.add(new SimpleTimePeriod(4000L, 5000L), 1.4);
    r = dataset.getDomainBounds(true);
    assertEquals(1000.0, r.getLowerBound(), EPSILON);
    assertEquals(7000.0, r.getUpperBound(), EPSILON);
}

From source file:info.financialecology.finance.utilities.datastruct.VersatileChart.java

public JFreeChart drawTimeSeriesCollections(ArrayList<VersatileTimeSeriesCollection> atscArray) {
    JFreeChart chart;/*from  ww w  .j a  v a  2s .  co  m*/
    ArrayList<String> visibleKeys = new ArrayList<String>();

    if (params.ticks) {
        XYSeriesCollection dataSet = new XYSeriesCollection();

        for (VersatileTimeSeriesCollection atsc : atscArray) {
            List<VersatileTimeSeries> atsList = atsc.getSeries();

            for (VersatileTimeSeries ats : atsList) {
                XYSeries xySeries = new XYSeries(ats.getKey());
                dataSet.addSeries(xySeries);

                for (int i = 0; i < ats.getItemCount(); i++)
                    xySeries.add(i, ats.getValue(i));
            }
        }

        chart = ChartFactory.createXYLineChart(params.title, params.xLabel, params.yLabel, dataSet,
                PlotOrientation.VERTICAL, params.legend, params.toolTips, false);

        if (params.autoRange) {
            Range currentRange = dataSet.getRangeBounds(true);
            Range newRange = new Range((1 - params.autoRangePadding) * currentRange.getLowerBound(),
                    (1 + params.autoRangePadding) * currentRange.getUpperBound());
            chart.getXYPlot().getRangeAxis().setRange(newRange);
        }
    } else {
        TimeSeriesCollection dataSet = new TimeSeriesCollection();

        for (VersatileTimeSeriesCollection atsc : atscArray) {
            List<VersatileTimeSeries> atsList = atsc.getSeries();

            for (VersatileTimeSeries ats : atsList) {
                dataSet.addSeries(ats);
                visibleKeys.add((String) ats.getKey());
            }
        }

        chart = ChartFactory.createTimeSeriesChart(params.title, params.xLabel, params.yLabel, dataSet,
                params.legend, params.toolTips, false);

        if (params.autoRange) {
            Range currentRange = dataSet.getRangeBounds(visibleKeys, dataSet.getDomainBounds(true), true);
            Range newRange = new Range((1 - params.autoRangePadding) * currentRange.getLowerBound(),
                    (1 + params.autoRangePadding) * currentRange.getUpperBound());
            chart.getXYPlot().getRangeAxis().setRange(newRange);
        }
    }

    return chart;
}

From source file:org.jfree.data.contour.DefaultContourDataset.java

/**
 * Returns the maximum z-value within visible region of plot.
 *
 * @param x  the x range./*from  w ww.  ja v a2  s  .c  o  m*/
 * @param y  the y range.
 *
 * @return The z range.
 */
@Override
public Range getZValueRange(Range x, Range y) {

    double minX = x.getLowerBound();
    double minY = y.getLowerBound();
    double maxX = x.getUpperBound();
    double maxY = y.getUpperBound();

    double zMin = 1.e20;
    double zMax = -1.e20;
    for (int k = 0; k < this.zValues.length; k++) {
        if (this.xValues[k].doubleValue() >= minX && this.xValues[k].doubleValue() <= maxX
                && this.yValues[k].doubleValue() >= minY && this.yValues[k].doubleValue() <= maxY) {
            if (this.zValues[k] != null) {
                zMin = Math.min(zMin, this.zValues[k].doubleValue());
                zMax = Math.max(zMax, this.zValues[k].doubleValue());
            }
        }
    }

    return new Range(zMin, zMax);
}

From source file:org.jfree.data.xy.XYSeriesCollectionTest.java

/**
 * A test to cover bug 3445507.  The issue does not affect
 * XYSeriesCollection./* w  w  w. ja v  a 2 s.  c o m*/
 */
@Test
public void testBug3445507() {
    XYSeries s1 = new XYSeries("S1");
    s1.add(1.0, null);
    s1.add(2.0, null);

    XYSeries s2 = new XYSeries("S2");
    s1.add(1.0, 5.0);
    s1.add(2.0, 6.0);

    XYSeriesCollection dataset = new XYSeriesCollection();
    dataset.addSeries(s1);
    dataset.addSeries(s2);

    Range r = dataset.getRangeBounds(false);
    assertEquals(5.0, r.getLowerBound(), EPSILON);
    assertEquals(6.0, r.getUpperBound(), EPSILON);
}

From source file:nl.vu.nat.jfreechartcustom.XYBlockRenderer.java

/**
 * Returns the range of values the renderer requires to display all the
 * items from the specified dataset./*from   ww w  .  ja  v  a  2s  .  c  om*/
 *
 * @param dataset  the dataset (<code>null</code> permitted).
 *
 * @return The range (<code>null</code> if the dataset is <code>null</code>
 *         or empty).
 *
 * @see #findDomainBounds(XYDataset)
 */
public Range findRangeBounds(XYDataset dataset) {
    if (dataset != null) {
        Range r = DatasetUtilities.findRangeBounds(dataset, false);
        if (r == null) {
            return null;
        } else {
            return new Range(r.getLowerBound() + this.yOffset,
                    r.getUpperBound() + this.blockHeight + this.yOffset);
        }
    } else {
        return null;
    }
}

From source file:nl.vu.nat.jfreechartcustom.XYBlockRenderer.java

/**
 * Returns the lower and upper bounds (range) of the x-values in the
 * specified dataset.//from  w w  w. ja v  a2  s  . c o m
 *
 * @param dataset  the dataset (<code>null</code> permitted).
 *
 * @return The range (<code>null</code> if the dataset is <code>null</code>
 *         or empty).
 *
 * @see #findRangeBounds(XYDataset)
 */
@Override
public Range findDomainBounds(XYDataset dataset) {
    if (dataset != null) {
        Range r = DatasetUtilities.findDomainBounds(dataset, false);
        if (r == null) {
            return null;
        } else {
            return new Range(r.getLowerBound() + this.xOffset,
                    r.getUpperBound() + this.blockWidth + this.xOffset);
        }
    } else {
        return null;
    }
}

From source file:org.jfree.experimental.chart.axis.LogAxis.java

/**
 * Converts a value on the axis scale to a Java2D coordinate relative to 
 * the given <code>area</code>, based on the axis running along the 
 * specified <code>edge</code>.
 * //from   w ww. j  a  v  a 2 s.c  o m
 * @param value  the data value.
 * @param area  the area.
 * @param edge  the edge.
 * 
 * @return The Java2D coordinate corresponding to <code>value</code>.
 */
public double valueToJava2D(double value, Rectangle2D area, RectangleEdge edge) {

    Range range = getRange();
    double axisMin = calculateLog(range.getLowerBound());
    double axisMax = calculateLog(range.getUpperBound());
    value = calculateLog(value);

    double min = 0.0;
    double max = 0.0;
    if (RectangleEdge.isTopOrBottom(edge)) {
        min = area.getX();
        max = area.getMaxX();
    } else if (RectangleEdge.isLeftOrRight(edge)) {
        max = area.getMinY();
        min = area.getMaxY();
    }
    if (isInverted()) {
        return max - ((value - axisMin) / (axisMax - axisMin)) * (max - min);
    } else {
        return min + ((value - axisMin) / (axisMax - axisMin)) * (max - min);
    }
}

From source file:org.jfree.experimental.chart.axis.LogAxis.java

/**
 * Converts a Java2D coordinate to an axis value, assuming that the
 * axis covers the specified <code>edge</code> of the <code>area</code>.
 * // ww w  . j  a v a 2s.  co m
 * @param java2DValue  the Java2D coordinate.
 * @param area  the area.
 * @param edge  the edge that the axis belongs to.
 * 
 * @return A value along the axis scale.
 */
public double java2DToValue(double java2DValue, Rectangle2D area, RectangleEdge edge) {

    Range range = getRange();
    double axisMin = calculateLog(range.getLowerBound());
    double axisMax = calculateLog(range.getUpperBound());

    double min = 0.0;
    double max = 0.0;
    if (RectangleEdge.isTopOrBottom(edge)) {
        min = area.getX();
        max = area.getMaxX();
    } else if (RectangleEdge.isLeftOrRight(edge)) {
        min = area.getMaxY();
        max = area.getY();
    }
    double log = 0.0;
    if (isInverted()) {
        log = axisMax - (java2DValue - min) / (max - min) * (axisMax - axisMin);
    } else {
        log = axisMin + (java2DValue - min) / (max - min) * (axisMax - axisMin);
    }
    return calculateValue(log);
}

From source file:org.tsho.dmc2.core.chart.DmcLyapunovPlot.java

public void initializeVsTime(VariableDoubles parameters, VariableDoubles initialValues, Range timeRange) {

    this.parameters.putAll(parameters);
    this.initialPoint.putAll(initialValues);
    this.lower = (int) timeRange.getLowerBound();
    this.upper = (int) timeRange.getUpperBound();

    this.type = VSTIME;
}

From source file:org.jfree.data.time.TimeSeriesCollectionTest.java

/**
 * A test to cover bug 3445507./* www  .j  a  v a2  s  . c  om*/
 */
@Test
public void testBug3445507() {
    TimeSeries s1 = new TimeSeries("S1");
    s1.add(new Year(2011), null);
    s1.add(new Year(2012), null);

    TimeSeries s2 = new TimeSeries("S2");
    s2.add(new Year(2011), 5.0);
    s2.add(new Year(2012), 6.0);

    TimeSeriesCollection dataset = new TimeSeriesCollection();
    dataset.addSeries(s1);
    dataset.addSeries(s2);

    List keys = new ArrayList();
    keys.add("S1");
    keys.add("S2");
    Range r = dataset.getRangeBounds(keys, new Range(Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY),
            false);
    assertEquals(5.0, r.getLowerBound(), EPSILON);
    assertEquals(6.0, r.getUpperBound(), EPSILON);
}