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:ec.ui.view.RevisionSaSeriesView.java

private void setRange(TimeSeriesCollection chartSeries, TimeSeriesCollection startSeries) {
    double min, max;
    Range chart = chartSeries.getRangeBounds(true);
    Range start = startSeries.getRangeBounds(true);
    min = chart.getLowerBound();//ww  w.j  a va 2 s  .  c om
    max = chart.getUpperBound();

    if (min > start.getLowerBound()) {
        min = start.getLowerBound();
    }

    if (max < start.getUpperBound()) {
        max = start.getUpperBound();
    }

    min -= (Math.abs(min) * .03);
    max += (Math.abs(max) * .03);

    range = new Range(min, max);
}

From source file:de.unibayreuth.bayeos.goat.panels.timeseries.JPanelChart.java

/**
 * used for zooming// ww  w  .j  a v a  2  s.c o m
 * 
 * @param axis  the axis.
 * @param range  the range.
 * @param zoomFactor  the zoom factor.
 * @param anchorValue  the anchor value.
 */
private void adjustRange(ValueAxis axis, Range range, double zoomFactor, double anchorValue) {

    if (axis == null || range == null) {
        return;
    }

    double rangeMinVal = range.getLowerBound() - range.getLength() * axis.getLowerMargin();
    double rangeMaxVal = range.getUpperBound() + range.getLength() * axis.getUpperMargin();
    double halfLength = axis.getRange().getLength() * zoomFactor / 2;
    double zoomedMinVal = anchorValue - halfLength;
    double zoomedMaxVal = anchorValue + halfLength;
    double adjMinVal = zoomedMinVal;
    if (zoomedMinVal < rangeMinVal) {
        adjMinVal = rangeMinVal;
        zoomedMaxVal += rangeMinVal - zoomedMinVal;
    }
    double adjMaxVal = zoomedMaxVal;
    if (zoomedMaxVal > rangeMaxVal) {
        adjMaxVal = rangeMaxVal;
        zoomedMinVal -= zoomedMaxVal - rangeMaxVal;
        adjMinVal = Math.max(zoomedMinVal, rangeMinVal);
    }

    Range adjusted = new Range(adjMinVal, adjMaxVal);
    axis.setRange(adjusted);
}

From source file:com.graphhopper.jsprit.analysis.toolbox.Plotter.java

private XYPlot createPlot(final XYSeriesCollection problem, XYSeriesCollection shipments,
        XYSeriesCollection solution) {/* www . j  ava 2s  . c  o  m*/
    XYPlot plot = new XYPlot();
    plot.setBackgroundPaint(Color.LIGHT_GRAY);
    plot.setRangeGridlinePaint(Color.LIGHT_GRAY);
    plot.setDomainGridlinePaint(Color.LIGHT_GRAY);

    XYLineAndShapeRenderer problemRenderer = getProblemRenderer(problem);
    plot.setDataset(0, problem);
    plot.setRenderer(0, problemRenderer);

    XYItemRenderer shipmentsRenderer = getShipmentRenderer(shipments);
    plot.setDataset(1, shipments);
    plot.setRenderer(1, shipmentsRenderer);

    if (solution != null) {
        XYItemRenderer solutionRenderer = getRouteRenderer(solution);
        plot.setDataset(2, solution);
        plot.setRenderer(2, solutionRenderer);
    }

    NumberAxis xAxis = new NumberAxis();
    NumberAxis yAxis = new NumberAxis();

    if (boundingBox == null) {
        xAxis.setRangeWithMargins(getDomainRange(problem));
        yAxis.setRangeWithMargins(getRange(problem));
    } else {
        xAxis.setRangeWithMargins(new Range(boundingBox.minX, boundingBox.maxX));
        yAxis.setRangeWithMargins(new Range(boundingBox.minY, boundingBox.maxY));
    }

    plot.setDomainAxis(xAxis);
    plot.setRangeAxis(yAxis);

    return plot;
}

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

@Test
public void testGetRangeBounds2() {
    TimeZone tzone = TimeZone.getTimeZone("Europe/London");
    Calendar calendar = new GregorianCalendar(tzone, Locale.UK);
    calendar.clear();/* w w w.j a  v a2 s . c o m*/
    calendar.set(2014, Calendar.FEBRUARY, 23, 6, 0);
    long start = calendar.getTimeInMillis();
    calendar.clear();
    calendar.set(2014, Calendar.FEBRUARY, 24, 18, 0);
    long end = calendar.getTimeInMillis();
    Range range = new Range(start, end);

    TimeSeriesCollection collection = new TimeSeriesCollection(tzone);
    assertNull(collection.getRangeBounds(Collections.EMPTY_LIST, range, true));

    TimeSeries s1 = new TimeSeries("S1");
    s1.add(new Day(24, 2, 2014), 10.0);
    collection.addSeries(s1);
    assertEquals(new Range(10.0, 10.0), collection.getRangeBounds(Arrays.asList("S1"), range, true));
    collection.setXPosition(TimePeriodAnchor.MIDDLE);
    assertEquals(new Range(10.0, 10.0), collection.getRangeBounds(Arrays.asList("S1"), range, true));
    collection.setXPosition(TimePeriodAnchor.END);
    assertNull(collection.getRangeBounds(Arrays.asList("S1"), range, true));
}

From source file:org.tsho.dmc2.ui.bifurcation.BifurcationControlForm2.java

public Range getVerticalRange() throws InvalidData {
    if (lowerVRangeField.getValue() >= upperVRangeField.getValue()) {
        throw new InvalidData("Invalid vertical range.");
    }//from  w ww .  ja va2s. c  o m
    return new Range(lowerVRangeField.getValue(), upperVRangeField.getValue());
}

From source file:org.eumetsat.metop.visat.IasiInfoView.java

private void configureSpectrumPlotXAxis(NumberAxis axis) {
    axis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    axis.setLabel("Wavenumber (cm-1)");
    axis.setRange(new Range(645.0, 2760.0), true, false);
}

From source file:org.eurocarbdb.application.glycoworkbench.plugin.PeakListChartPanel.java

public void updateChart() {
    // auto zoom//from w  ww.  j a v a  2  s .  c  o  m
    if (theDocument.size() > 0) {
        Range mz_range = thePlot.getDomainAxis().getRange();

        // update data
        double mz_toll = screenToDataX(1.);
        double[][] data = theDocument.getData(mz_range.getLowerBound(), mz_range.getUpperBound());

        // update visible data and compute intensity range
        visibleData.clear();
        double min_int = (data[0].length > 0) ? data[1][0] : 0.;
        double max_int = (data[0].length > 0) ? data[1][0] : 0.;
        for (int i = 0; i < data[0].length; i++) {
            min_int = Math.min(min_int, data[1][i]);
            max_int = Math.max(max_int, data[1][i]);
            visibleData.put(data[0][i], data[1][i]);
        }
        //Range new_int_range = new Range(min_int,max_int);
        Range new_int_range = new Range(0., max_int);

        // make space for annotations
        Rectangle2D data_area = theChartPanel.getScreenDataArea();
        if (data_area.getHeight() > 0)
            new_int_range = Range.expand(new_int_range, 0., 12. / data_area.getHeight());

        // resize y axis
        thePlot.getRangeAxis().setRange(new_int_range);

        // reload dataset
        theDataset.removeSeries("intensities");
        theDataset.addSeries("intensities", data);
    } else {
        thePlot.getRangeAxis().setRange(new Range(0., 1.));
        theDataset.removeSeries("intensities");
    }

    // restore annotation shapes
    showSelection();
}

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

/**
 * Finds the range of y-values that fall within the specified range of
 * x-values (where the x-values are interpreted as milliseconds since the
 * epoch and converted to time periods using the specified timezone).
 * /*from   www.j a  va 2  s .c  o m*/
 * @param xRange  the subset of x-values to use (<code>null</code> not
 *     permitted).
 * @param xAnchor  the anchor point for the x-values (<code>null</code>
 *     not permitted).
 * @param zone  the time zone (<code>null</code> not permitted).
 * 
 * @return The range of y-values.
 * 
 * @since 1.0.18
 */
public Range findValueRange(Range xRange, TimePeriodAnchor xAnchor, TimeZone zone) {
    ParamChecks.nullNotPermitted(xRange, "xRange");
    ParamChecks.nullNotPermitted(xAnchor, "xAnchor");
    ParamChecks.nullNotPermitted(zone, "zone");
    if (this.data.isEmpty()) {
        return null;
    }
    Calendar calendar = Calendar.getInstance(zone);
    // since the items are ordered, we could be more clever here and avoid
    // iterating over all the data
    double lowY = Double.POSITIVE_INFINITY;
    double highY = Double.NEGATIVE_INFINITY;
    for (int i = 0; i < this.data.size(); i++) {
        TimeSeriesDataItem item = (TimeSeriesDataItem) this.data.get(i);
        long millis = item.getPeriod().getMillisecond(xAnchor, calendar);
        if (xRange.contains(millis)) {
            Number n = item.getValue();
            if (n != null) {
                double v = n.doubleValue();
                lowY = Math.min(lowY, v);
                highY = Math.max(highY, v);
            }
        }
    }
    if (Double.isInfinite(lowY) && Double.isInfinite(highY)) {
        if (lowY < highY) {
            return new Range(lowY, highY);
        } else {
            return new Range(Double.NaN, Double.NaN);
        }
    }
    return new Range(lowY, highY);
}

From source file:org.eumetsat.metop.visat.IasiInfoView.java

private void configureSpectrumPlotYAxis(NumberAxis axis) {
    axis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    axis.setLabel("Brightness Temperature (K)");
    axis.setRange(new Range(180.0, 320.0), true, false);
}

From source file:ec.util.chart.swing.JTimeSeriesChart.java

public void setZoom(double[] zoom) {
    if (zoom.length == 4) {
        for (XYPlot o : roSubPlots) {
            o.getDomainAxis().setRange(new Range(zoom[0], zoom[1]));
            o.getRangeAxis().setRange(new Range(zoom[2], zoom[3]));
        }//from www.  j av  a 2  s. c o m
    } else {
        resetZoom();
    }
}