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.statistics.DefaultBoxAndWhiskerCategoryDatasetTest.java

/**
 * Some checks for the remove method./*from ww  w  .  j a  va 2s  .  c om*/
 */
@Test
public void testRemove() {
    DefaultBoxAndWhiskerCategoryDataset data = new DefaultBoxAndWhiskerCategoryDataset();

    boolean pass = false;
    try {
        data.remove("R1", "R2");
    } catch (UnknownKeyException e) {
        pass = true;
    }
    assertTrue(pass);
    data.add(new BoxAndWhiskerItem(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, new ArrayList()), "R1", "C1");
    assertEquals(new Range(7.0, 8.0), data.getRangeBounds(false));
    assertEquals(new Range(7.0, 8.0), data.getRangeBounds(true));

    data.add(new BoxAndWhiskerItem(2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5, new ArrayList()), "R2", "C1");
    assertEquals(new Range(7.0, 9.5), data.getRangeBounds(false));
    assertEquals(new Range(7.0, 9.5), data.getRangeBounds(true));

    data.remove("R1", "C1");
    assertEquals(new Range(8.5, 9.5), data.getRangeBounds(false));
    assertEquals(new Range(8.5, 9.5), data.getRangeBounds(true));
}

From source file:netplot.GenericPlotPanel.java

void genericConfig(JFreeChart chart, XYPlot plot, int plotIndex) {
    if (!enableLegend) {
        chart.removeLegend();/* w ww. ja  va2s  .c o  m*/
    }

    XYItemRenderer xyItemRenderer = plot.getRenderer();
    //May also be XYBarRenderer
    if (xyItemRenderer instanceof XYLineAndShapeRenderer) {
        XYToolTipGenerator xyToolTipGenerator = xyItemRenderer.getBaseToolTipGenerator();
        //If currently an XYLineAndShapeRenderer replace it so that we inc the colour for every plotIndex
        XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(linesEnabled, shapesEnabled);
        //Ensure we don't loose the tool tips on the new renderer
        renderer.setBaseToolTipGenerator(xyToolTipGenerator);
        renderer.setBasePaint(getPlotColour(plotIndex));
        renderer.setSeriesStroke(0, new BasicStroke(lineWidth, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL),
                true);
        plot.setRenderer(plotIndex, renderer);
    }

    //If we have a new y axis then we need a new data set
    if (yAxisName != null && yAxisName.length() > 0) {
        if (logYAxis) {
            LogAxis yAxis = new LogAxis(yAxisName);
            yAxis.setAutoRange(false);
            yAxis.setNumberFormatOverride(new LogFormat(10, "10", true));
            yAxis.setRange(minScaleValue, maxScaleValue);
            yAxis.setLowerBound(minScaleValue);
            yAxis.setUpperBound(maxScaleValue);
            plot.setRangeAxis(yAxisIndex, yAxis);
            plot.setRangeAxisLocation(yAxisIndex, AxisLocation.BOTTOM_OR_LEFT);
        } else {
            NumberAxis axis = new NumberAxis(yAxisName);
            axis.setAutoRangeIncludesZero(zeroOnYScale);
            if (autoScaleEnabled) {
                axis.setAutoRange(true);
            } else {
                Range range = new Range(minScaleValue, maxScaleValue);
                axis.setRangeWithMargins(range, true, true);
            }
            if (yAxisTickCount > 0) {
                NumberTickUnit tick = new NumberTickUnit(yAxisTickCount);
                axis.setTickUnit(tick);
            }
            plot.setRangeAxis(yAxisIndex, axis);
            plot.setRangeAxisLocation(yAxisIndex, AxisLocation.BOTTOM_OR_LEFT);
        }
        yAxisIndex++;
    }
    plot.mapDatasetToRangeAxis(plotIndex, yAxisIndex - 1);
    ValueAxis a = plot.getDomainAxis();
    if (xAxisName.length() > 0) {
        a.setLabel(xAxisName);
    }
    //We can enable/disable zero on the axis if we have a NumberAxis
    if (a instanceof NumberAxis) {
        ((NumberAxis) a).setAutoRangeIncludesZero(zeroOnXScale);
    }
}

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

/**
 * Some checks for the getDomainBounds() method.
 *///from  w  ww .  j a  v a2  s.  c o m
@Test
public void testGetDomainBounds() {
    XYSeriesCollection dataset = new XYSeriesCollection();
    Range r = dataset.getDomainBounds(false);
    assertNull(r);
    r = dataset.getDomainBounds(true);
    assertNull(r);

    XYSeries series = new XYSeries("S1");
    dataset.addSeries(series);
    r = dataset.getDomainBounds(false);
    assertNull(r);
    r = dataset.getDomainBounds(true);
    assertNull(r);

    series.add(1.0, 1.1);
    r = dataset.getDomainBounds(false);
    assertEquals(new Range(1.0, 1.0), r);
    r = dataset.getDomainBounds(true);
    assertEquals(new Range(0.5, 1.5), r);

    series.add(-1.0, -1.1);
    r = dataset.getDomainBounds(false);
    assertEquals(new Range(-1.0, 1.0), r);
    r = dataset.getDomainBounds(true);
    assertEquals(new Range(-1.5, 1.5), r);
}

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

/**
 * Calculates the Y data range.//from  w w  w  .j  a v  a  2s.co m
 *
 * @param data  the data.
 *
 * @return The range.
 */
private Range calculateYDataRange(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[1][i];
            if (v < lowest) {
                lowest = v;
            }
            if (v > highest) {
                highest = v;
            }
        }
        if (lowest <= highest) {
            result = new Range(lowest, highest);
        }
    }
    return result;

}

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

/**
 * Shifts the range by the specified amount.
 *
 * @param base  the base range (<code>null</code> not permitted).
 * @param delta  the shift amount./*from  www .  ja v a  2  s .c  o  m*/
 * @param allowZeroCrossing  a flag that determines whether or not the
 *                           bounds of the range are allowed to cross
 *                           zero after adjustment.
 *
 * @return A new range.
 */
public static Range shift(Range base, double delta, boolean allowZeroCrossing) {
    ParamChecks.nullNotPermitted(base, "base");
    if (allowZeroCrossing) {
        return new Range(base.getLowerBound() + delta, base.getUpperBound() + delta);
    } else {
        return new Range(shiftWithNoZeroCrossing(base.getLowerBound(), delta),
                shiftWithNoZeroCrossing(base.getUpperBound(), delta));
    }
}

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

public JPanel calcMethanolOctanol() throws Exception {
    double T = 293.15;
    setLayout(new BorderLayout());

    COSMOSACDataBase db = COSMOSACDataBase.getInstance();
    COSMOSACCompound c1 = db.getComp("methanol");
    COSMOSACCompound c2 = db.getComp("1-octanol");

    double[] cavityVolume = new double[2];
    cavityVolume[0] = c1.Vcosmo;//www.  j  a v  a  2  s .co m
    cavityVolume[1] = c2.Vcosmo;

    double[][] sigma = new double[2][];

    sigma[0] = c1.sigma;
    sigma[1] = c2.sigma;

    SigmaProfileGenerator c1Sigma = new SigmaProfileGenerator(SigmaProfileGenerator.FileType.GAMESS,
            c1.name.toLowerCase() + ".log");
    SigmaProfileGenerator c2Sigma = new SigmaProfileGenerator(SigmaProfileGenerator.FileType.GAMESS,
            c2.name.toLowerCase() + ".log");
    sigma[0] = c1Sigma.getSigmaProfile();
    sigma[1] = c2Sigma.getSigmaProfile();

    COSMOSAC cosmosac = new COSMOSAC();
    cosmosac.setParameters(cavityVolume, c1.charge, sigma);
    cosmosac.setIgnoreSG(true);
    cosmosac.setSigmaHB(COSMOSAC.SIGMAHB * 1.2);

    cosmosac.setTemperature(T);

    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[] Psat = new double[2];
    Psat[0] = 350;
    Psat[1] = 470;
    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.setDataset(dataset);

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

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

    return jp1;
}

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

@Test
public void testIsNaNRange() {
    assertTrue(new Range(Double.NaN, Double.NaN).isNaNRange());
    assertFalse(new Range(1.0, 2.0).isNaNRange());
    assertFalse(new Range(Double.NaN, 2.0).isNaNRange());
    assertFalse(new Range(1.0, Double.NaN).isNaNRange());
}

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

/**
 * Some checks for the getDomainBounds() method.
 *//*  w  w w.ja v a  2 s .  com*/
public void testGetDomainBounds() {
    XYSeriesCollection dataset = new XYSeriesCollection();
    Range r = dataset.getDomainBounds(false);
    assertNull(r);
    r = dataset.getDomainBounds(true);
    assertNull(r);

    XYSeries series = new XYSeries("S1");
    dataset.addSeries(series);
    r = dataset.getDomainBounds(false);
    assertNull(r);
    r = dataset.getDomainBounds(true);
    assertNull(r);

    series.add(1.0, 1.1);
    r = dataset.getDomainBounds(false);
    assertEquals(new Range(1.0, 1.0), r);
    r = dataset.getDomainBounds(true);
    assertEquals(new Range(0.5, 1.5), r);

    series.add(-1.0, -1.1);
    r = dataset.getDomainBounds(false);
    assertEquals(new Range(-1.0, 1.0), r);
    r = dataset.getDomainBounds(true);
    assertEquals(new Range(-1.5, 1.5), r);
}

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

/**
 * Some checks for the getRangeBounds() method.
 *///from  ww  w .  j  a  va  2 s.  com
@Test
public void testGetRangeBounds() {
    XYSeriesCollection dataset = new XYSeriesCollection();

    // when the dataset contains no series, we expect the value range to 
    // be null
    assertNull(dataset.getRangeBounds(false));
    assertNull(dataset.getRangeBounds(true));

    // when the dataset contains one or more series, but those series 
    // contain no items, we expect the value range to be null
    XYSeries series = new XYSeries("S1");
    dataset.addSeries(series);
    assertNull(dataset.getRangeBounds(false));
    assertNull(dataset.getRangeBounds(true));

    // tests with values
    series.add(1.0, 1.1);
    assertEquals(new Range(1.1, 1.1), dataset.getRangeBounds(false));
    assertEquals(new Range(1.1, 1.1), dataset.getRangeBounds(true));

    series.add(-1.0, -1.1);
    assertEquals(new Range(-1.1, 1.1), dataset.getRangeBounds(false));
    assertEquals(new Range(-1.1, 1.1), dataset.getRangeBounds(true));

    series.add(0.0, null);
    assertEquals(new Range(-1.1, 1.1), dataset.getRangeBounds(false));
    assertEquals(new Range(-1.1, 1.1), dataset.getRangeBounds(true));

    XYSeries s2 = new XYSeries("S2");
    dataset.addSeries(s2);
    assertEquals(new Range(-1.1, 1.1), dataset.getRangeBounds(false));
    assertEquals(new Range(-1.1, 1.1), dataset.getRangeBounds(true));

    s2.add(2.0, 5.0);
    assertEquals(new Range(-1.1, 5.0), dataset.getRangeBounds(false));
    assertEquals(new Range(-1.1, 5.0), dataset.getRangeBounds(true));
}

From source file:org.jax.haplotype.analysis.visualization.GenomicGraphFactory.java

/**
 * Create a SNP block graph for the given parameters. This graph
 * will show where the intervals do and don't exist. Interval lists
 * are organized with the X axis label matching the list's key
 * @param snpIntervals/*from w  w w  .j  a  va  2  s. co  m*/
 *          the blocks
 * @param startInBasePairs
 *          the x location to start the graph at
 * @param extentInBasePairs
 *          the extent to use for the graph
 * @param maximumImageBlockCount
 *          the max # of separate image blocks to use
 * @param renderAxes
 *          if true render the axes... otherwise dont
 * @param legendText
 *          the text to use for the legend
 * @param yAxisText
 *          the text to use for the y axis
 * @param trueColor
 *          the color to use for true
 * @param falseColor
 *          the color to use for false 
 * @return
 *          the graph
 */
public JFreeChart createSnpIntervalGraph(
        final Map<String, ? extends List<? extends BasePairInterval>> snpIntervals, final long startInBasePairs,
        final long extentInBasePairs, final int maximumImageBlockCount, final boolean renderAxes,
        final String legendText, final String yAxisText, final Color trueColor, final Color falseColor) {
    XYDataset dataset = snpIntervalsToDataset(snpIntervals, startInBasePairs, extentInBasePairs,
            maximumImageBlockCount);

    NumberAxis xAxis = new NumberAxis("SNP Position (Base Pairs)");
    xAxis.setAutoRangeIncludesZero(false);
    xAxis.setRange(new Range(startInBasePairs, startInBasePairs + extentInBasePairs));
    String[] sortedStrainNames = extractSortedStrainNames(snpIntervals);
    for (int strainIndex = 0; strainIndex < sortedStrainNames.length; strainIndex++) {
        LOG.info("Strain Name: " + sortedStrainNames[strainIndex]);
    }
    SymbolAxis yAxis = new SymbolAxis(yAxisText == null ? "" : yAxisText, sortedStrainNames);

    XYPlot plot = new XYPlot(dataset, xAxis, yAxis, null);
    LegendItemCollection items = new LegendItemCollection();
    if (legendText != null) {
        items.add(new LegendItem(legendText, null, null, null, new Rectangle2D.Double(-3.0, -3.0, 6.0, 6.0),
                trueColor, new BasicStroke(), Color.BLACK));
    }
    plot.setFixedLegendItems(items);

    XYBlockRenderer r = new XYBlockRenderer();
    SmoothPaintScale ps = new SmoothPaintScale(0.0, 1.0, falseColor, trueColor);

    r.setPaintScale(ps);
    r.setBlockHeight(1.0);
    r.setBlockWidth(1.0);
    plot.setRenderer(r);

    final JFreeChart chart;
    if (renderAxes) {
        chart = new JFreeChart("Identical By State Blocks", JFreeChart.DEFAULT_TITLE_FONT, plot, true);
    } else {
        xAxis.setVisible(false);
        yAxis.setVisible(false);
        plot.setInsets(new RectangleInsets(0.0, 0.0, 0.0, 0.0));
        chart = new JFreeChart(plot);
    }

    chart.setBackgroundPaint(Color.WHITE);

    return chart;
}