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.Range.java

/**
 * Creates a new range by adding margins to an existing range.
 *
 * @param range  the range (<code>null</code> not permitted).
 * @param lowerMargin  the lower margin (expressed as a percentage of the
 *                     range length).//from   ww w  .java 2s .c  o  m
 * @param upperMargin  the upper margin (expressed as a percentage of the
 *                     range length).
 *
 * @return The expanded range.
 */
public static Range expand(Range range, double lowerMargin, double upperMargin) {
    ParamChecks.nullNotPermitted(range, "range");
    double length = range.getLength();
    double lower = range.getLowerBound() - length * lowerMargin;
    double upper = range.getUpperBound() + length * upperMargin;
    if (lower > upper) {
        lower = lower / 2.0 + upper / 2.0;
        upper = lower;
    }
    return new Range(lower, upper);
}

From source file:org.rdv.viz.dial.DialPanel.java

/**
 * Sets the range of the dial according to the range text fields.
 *//*from w w  w .j  a v  a2 s  . com*/
private void setRangeFromTextFields() {
    double lowerBound;
    double upperBound;
    try {
        lowerBound = Double.parseDouble(lowerBoundTextField.getText());
        upperBound = Double.parseDouble(upperBoundTextField.getText());

        if (lowerBound >= upperBound) {
            throw new NumberFormatException();
        }
    } catch (NumberFormatException e) {
        lowerBoundTextField.setText(engineeringFormat.format(model.getRange().getLowerBound()));
        upperBoundTextField.setText(engineeringFormat.format(model.getRange().getUpperBound()));
        return;
    }

    model.setRange(new Range(lowerBound, upperBound));
}

From source file:userinterface.graph.PrismLogarithmicAxis.java

/**
 * Creates a new <code>LogAxis</code> with the given label.
 * /*  w  ww  .j  a v  a 2s . co m*/
 * @param label  the axis label (<code>null</code> permitted).
 */
public PrismLogarithmicAxis(String label) {
    super(label, NumberAxis.createIntegerTickUnits());
    setDefaultAutoRange(new Range(0.01, 1.0));
    this.tickUnit = new NumberTickUnit(1.0);
    this.minorTickCount = 10;
    this.setTickMarksVisible(false);
    this.baseAndExponentFormatOverride = true;
}

From source file:ucar.unidata.idv.control.chart.MyScatterPlot.java

/**
 * Calculates the X data range./*from ww w.  java 2 s .  c o  m*/
 *
 * @param data  the data.
 *
 * @return The range.
 */
private Range calculateXDataRange(double[][] data) {
    Range result = null;
    //      double[][] data =  (double[][]) series.get(0);
    if (data != null) {
        double lowest = Double.POSITIVE_INFINITY;
        double highest = Double.NEGATIVE_INFINITY;
        for (int i = 0; i < data[0].length; i++) {
            double v = data[0][i];
            if (v < lowest) {
                lowest = v;
            }
            if (v > highest) {
                highest = v;
            }
        }
        if (lowest <= highest) {
            result = new Range(lowest, highest);
        }
    }

    return result;

}

From source file:br.ufrgs.enq.jcosmo.test.VLEdiagrams.java

/**
 * VLE diagrams using sigma profile by MOPAC
 * //from  ww  w.j a v  a  2s  .  c  o  m
 * @return
 * @throws Exception 
 */
@SuppressWarnings("deprecation")
public JPanel calcEthTolMOPAC() throws Exception {
    super.setTitle("P vs x1");
    double T = 60;
    setLayout(new BorderLayout());

    COSMOSACDataBase db = COSMOSACDataBase.getInstance();

    COSMOSACCompound comps[] = new COSMOSACCompound[2];
    comps[0] = db.getComp("ethanol");
    comps[1] = db.getComp("toluene");

    COSMOSAC cosmosac = new COSMOPAC();
    cosmosac.setComponents(comps);

    cosmosac.setTemperature(T + 273.15);

    double[] x1 = new double[n];
    double[] x2 = new double[n];
    double[] gamma1 = new double[n];
    double[] gamma2 = new double[n];
    double[] z = new double[2];
    double[] lnGamma = new double[2];
    z[0] = 0.00;
    int j = 0;
    while (z[0] < 1.0001) {
        z[1] = 1 - z[0];
        x1[j] = z[0];
        x2[j] = z[1];
        cosmosac.setComposition(z);
        cosmosac.activityCoefficient(lnGamma);
        gamma1[j] = Math.exp(lnGamma[0]);
        gamma2[j] = Math.exp(lnGamma[1]);
        z[0] += 0.05;
        j++;
    }

    double[][] parAntoine = new double[3][3];
    parAntoine[0][0] = 16.8958;
    parAntoine[0][1] = 3795.17;
    parAntoine[0][2] = 230.918;
    parAntoine[1][0] = 13.9320;
    parAntoine[1][1] = 3056.96;
    parAntoine[1][2] = 217.625;

    double[] Psat = pSat(parAntoine, T);
    double[] P = calcPx(x1, x2, gamma1, gamma2, Psat);
    double[] y1 = calcY(x1, gamma1, Psat, P);

    XYPlot plot1;
    XYSeriesCollection dataset = new XYSeriesCollection();
    XYSeries liq = new XYSeries("liquid");
    XYSeries vap = new XYSeries("vapor");
    XYSeries raoult = new XYSeries("Raoult's Law");
    for (int i = 0; i < n; i++) {
        liq.add(x1[i], P[i]);
        vap.add(y1[i], P[i]);
    }
    ;
    raoult.add(0, Psat[1]);
    raoult.add(1, Psat[0]);
    dataset.addSeries(liq);
    dataset.addSeries(vap);
    dataset.addSeries(raoult);

    JFreeChart chart = ChartFactory.createXYLineChart(null, "Mole Fraction: x1, y1", "P/KPa", null,
            PlotOrientation.VERTICAL, true, true, false);
    plot1 = (XYPlot) chart.getPlot();
    plot1.getDomainAxis().setRange(new Range(0.0, 1.0));
    plot1.getRangeAxis().setRange(new Range(15.0, 50.0));

    plot1.setDataset(dataset);

    XYSplineRenderer r = new XYSplineRenderer();
    BasicStroke stroke = new BasicStroke(2f);
    r.setStroke(stroke);
    plot1.setRenderer(r);
    r.setBaseShapesVisible(false);

    ChartPanel chartPanel = new ChartPanel(chart);
    JPanel jp = new JPanel(new BorderLayout());
    jp.add(chartPanel);

    add(jp, BorderLayout.CENTER);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setSize(400, 500);

    return jp;
}

From source file:org.jfree.data.RangeTest.java

/**
 * Some checks for the combineIgnoringNaN() method.
 *///from   ww  w .  jav a2  s. co  m
@Test
public void testCombineIgnoringNaN() {
    Range r1 = new Range(1.0, 2.0);
    Range r2 = new Range(1.5, 2.5);

    assertNull(Range.combineIgnoringNaN(null, null));
    assertEquals(r1, Range.combineIgnoringNaN(r1, null));
    assertEquals(r2, Range.combineIgnoringNaN(null, r2));
    assertEquals(new Range(1.0, 2.5), Range.combineIgnoringNaN(r1, r2));

    Range r3 = new Range(Double.NaN, 1.3);
    Range rr = Range.combineIgnoringNaN(r1, r3);
    assertEquals(1.0, rr.getLowerBound(), EPSILON);
    assertEquals(2.0, rr.getUpperBound(), EPSILON);

    Range r4 = new Range(1.7, Double.NaN);
    rr = Range.combineIgnoringNaN(r4, r1);
    assertEquals(1.0, rr.getLowerBound(), EPSILON);
    assertEquals(2.0, rr.getUpperBound(), EPSILON);
}

From source file:anl.verdi.plot.jfree.XYBlockRenderer.java

/**
 * Returns the range of values the renderer requires to display all the
 * items from the specified dataset./*from   w ww .j av  a 2  s  .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).
 */
public Range findRangeBounds(XYDataset dataset) {
    if (dataset != null) {
        Range r = DatasetUtilities.findRangeBounds(dataset, false);
        return new Range(r.getLowerBound() + yOffset, r.getUpperBound() + blockHeight + yOffset);
    } else {
        return null;
    }
}

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

public JFreeChart drawTimeSeries(ArrayList<VersatileTimeSeries> atsArray) {
    JFreeChart chart;/*w w w .j av a  2s.  c o m*/
    ArrayList<String> visibleKeys = new ArrayList<String>();

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

        for (VersatileTimeSeries ats : atsArray) {
            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 (VersatileTimeSeries ats : atsArray) {
            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:de.bund.bfr.knime.pmmlite.views.chart.ChartCreator.java

public JFreeChart getChart(List<String> idsToPaint) throws ParseException, UnitException {
    if (varX == null || varY == null || varX.getName() == null || varY.getName() == null) {
        return new JFreeChart(null, JFreeChart.DEFAULT_TITLE_FONT, new XYPlot(), showLegend);
    }/*  w ww  .ja va 2s  .  co m*/

    NumberAxis xAxis = new NumberAxis(varX.getDisplayString());
    NumberAxis yAxis = new NumberAxis(varY.getDisplayString());
    XYPlot plot = new XYPlot(null, xAxis, yAxis, null);
    double usedMinX = Double.POSITIVE_INFINITY;
    double usedMaxX = Double.NEGATIVE_INFINITY;
    int index = 0;
    List<Color> defaultColors = ChartUtils.createColorList(idsToPaint.size());
    List<NamedShape> defaultShapes = ChartUtils.createShapeList(idsToPaint.size());

    for (String id : idsToPaint) {
        Plotable plotable = plotables.get(id);

        if (plotable == null) {
            continue;
        }

        if (plotable.getType() == Plotable.Type.BOTH || plotable.getType() == Plotable.Type.BOTH_MANY
                || plotable.getType() == Plotable.Type.FUNCTION
                || plotable.getType() == Plotable.Type.FUNCTION_SAMPLE) {
            double minArg = varX.to(MathUtils.nullToNan(plotable.getMinValues().get(varX.getName())),
                    plotable.getUnits().get(varX.getName()));
            double maxArg = varX.to(MathUtils.nullToNan(plotable.getMaxValues().get(varX.getName())),
                    plotable.getUnits().get(varX.getName()));

            if (Double.isFinite(minArg)) {
                usedMinX = Math.min(usedMinX, minArg);
            }

            if (Double.isFinite(maxArg)) {
                usedMaxX = Math.max(usedMaxX, maxArg);
            }
        }

        if (plotable.getType() == Plotable.Type.BOTH || plotable.getType() == Plotable.Type.BOTH_MANY) {
            for (Map<String, Integer> choice : plotable.getAllChoices(varX.getName())) {
                double[][] points = plotable.getPoints(varX, varY, choice);

                if (points != null) {
                    for (int i = 0; i < points[0].length; i++) {
                        usedMinX = Math.min(usedMinX, points[0][i]);
                        usedMaxX = Math.max(usedMaxX, points[0][i]);
                    }
                }
            }
        }

        if (plotable.getType() == Plotable.Type.DATASET || plotable.getType() == Plotable.Type.DATASET_MANY) {
            double[][] points = plotable.getPoints(varX, varY);

            if (points != null) {
                for (int i = 0; i < points[0].length; i++) {
                    usedMinX = Math.min(usedMinX, points[0][i]);
                    usedMaxX = Math.max(usedMaxX, points[0][i]);
                }
            }
        }

        if (plotable.getType() == Plotable.Type.FUNCTION_SAMPLE) {
            for (Double x : plotable.getSamples()) {
                if (x != null && Double.isFinite(x)) {
                    usedMinX = Math.min(usedMinX, x);
                    usedMaxX = Math.max(usedMaxX, x);
                }
            }
        }
    }

    if (Double.isInfinite(usedMinX)) {
        usedMinX = 0.0;
    }

    if (Double.isInfinite(usedMaxX)) {
        usedMaxX = 100.0;
    }

    if (varX.getName().equals(PmmUtils.TIME) || varX.getName().equals(PmmUtils.CONCENTRATION)) {
        usedMinX = Math.min(usedMinX, 0.0);
        xAxis.setAutoRangeIncludesZero(true);
    } else {
        xAxis.setAutoRangeIncludesZero(false);
    }

    if (varY.getName().equals(PmmUtils.TIME) || varY.getName().equals(PmmUtils.CONCENTRATION)) {
        yAxis.setAutoRangeIncludesZero(true);
    } else {
        yAxis.setAutoRangeIncludesZero(false);
    }

    if (usedMinX == usedMaxX) {
        usedMinX -= 1.0;
        usedMaxX += 1.0;
    }

    if (useManualRange && minX < maxX && minY < maxY) {
        usedMinX = minX;
        usedMaxX = maxX;
        xAxis.setRange(new Range(minX, maxX));
        yAxis.setRange(new Range(minY, maxY));
    }

    for (String id : idsToPaint) {
        Plotable plotable = plotables.get(id);

        if (plotable == null) {
            continue;
        }

        plotable.setFunctionSteps(resolution);

        switch (plotable.getType()) {
        case DATASET:
            plotDataSet(plot, plotable, id, defaultColors.get(index), defaultShapes.get(index));
            break;
        case DATASET_MANY:
            plotDataSetStrict(plot, plotable, id);
            break;
        case FUNCTION:
            plotFunction(plot, plotable, id, defaultColors.get(index), defaultShapes.get(index), usedMinX,
                    usedMaxX);
            break;
        case FUNCTION_SAMPLE:
            plotFunctionSample(plot, plotable, id, defaultColors.get(index), defaultShapes.get(index), usedMinX,
                    usedMaxX);
            break;
        case BOTH:
            plotBoth(plot, plotable, id, defaultColors.get(index), defaultShapes.get(index), usedMinX,
                    usedMaxX);
            break;
        case BOTH_MANY:
            plotBothStrict(plot, plotable, id, usedMinX, usedMaxX);
            break;
        default:
            throw new RuntimeException("Unknown type of plotable: " + plotable.getType());
        }

        index++;
    }

    return new JFreeChart(null, JFreeChart.DEFAULT_TITLE_FONT, plot, showLegend);
}

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 w w  w.j  a  va  2 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 #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;
    }
}