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:netplot.BarPlotPanel.java

public void addPlot() {
    plot.getRangeAxis().setAutoRange(autoScaleEnabled);
    if (!logYAxis && !autoScaleEnabled) {
        Range range = new Range(minScaleValue, maxScaleValue);
        plot.getRangeAxis().setRangeWithMargins(range, true, true);
    }/*  w  ww .j av a 2s . com*/
    genericConfig(chart, plot, 0);
}

From source file:org.kalypso.ogc.sensor.diagview.jfreechart.NumberAxisDefault.java

/**
 * Rescales the axis to ensure that all data is visible.
 *//*from w w  w.j  a v a  2s.c om*/
@Override
protected void autoAdjustRange() {
    final Plot plot = getPlot();
    if (plot == null) {
        return; // no plot, no data
    }

    if (plot instanceof ValueAxisPlot) {
        final ValueAxisPlot vap = (ValueAxisPlot) plot;

        Range r = vap.getDataRange(this);
        if (r == null) {
            r = new Range(DEFAULT_LOWER_BOUND, DEFAULT_UPPER_BOUND);
        }

        double upper = r.getUpperBound();
        double lower = r.getLowerBound();
        if (autoRangeIncludesZero()) {
            lower = Math.min(lower, 0.0);
            upper = Math.max(upper, 0.0);
        }
        final double range = upper - lower;

        // if fixed auto range, then derive lower bound...
        final double fixedAutoRange = getFixedAutoRange();
        if (fixedAutoRange > 0.0) {
            lower = upper - fixedAutoRange;
        } else {
            // ensure the autorange is at least <minRange> in size...
            final double minRange = getAutoRangeMinimumSize();
            if (range < minRange) {
                // double expand = ( minRange - range ) / 2;
                upper = minRange; // upper + expand;
                lower = 0; // getlower - expand;
            }

            if (autoRangeStickyZero()) {
                if (upper <= 0.0) {
                    upper = Math.min(0.0, upper + getUpperMargin() * range);
                } else {
                    upper = upper + getUpperMargin() * range;
                }
                if (lower >= 0.0) {
                    lower = Math.max(0.0, lower - getLowerMargin() * range);
                } else {
                    lower = lower - getLowerMargin() * range;
                }
            } else {
                upper = upper + getUpperMargin() * range;
                lower = lower - getLowerMargin() * range;
            }
        }

        if (m_min != null && lower > m_min.doubleValue())
            lower = m_min.doubleValue();

        if (m_max != null && upper < m_max.doubleValue())
            upper = m_max.doubleValue();

        setRange(new Range(lower, upper), false, false);
    }
}

From source file:max.hubbard.Factoring.Graphing.java

private static JFreeChart createChart(final XYDataset dataset, String equation) {

    // create the chart...
    final JFreeChart chart = ChartFactory.createXYLineChart(equation, // chart title
            "X", // x axis label
            "Y", // y axis label
            dataset, // data
            PlotOrientation.VERTICAL, true, // include legend
            true, // tooltips
            false // urls
    );/*from  ww  w.  ja va  2 s .  co  m*/

    // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...
    chart.setBackgroundPaint(Color.white);

    //        final StandardLegend legend = (StandardLegend) chart.getLegend();
    //              legend.setDisplaySeriesShapes(true);

    // get a reference to the plot for further customisation...
    final XYPlot plot = chart.getXYPlot();
    plot.setBackgroundPaint(Color.lightGray);
    //    plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 5.0, 5.0, 5.0, 5.0));
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);

    final XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    renderer.setSeriesLinesVisible(0, true);
    renderer.setSeriesShapesVisible(0, true);
    plot.setRenderer(renderer);

    // change the auto tick unit selection to integer units only...
    final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setRange(new Range(-50, 50));
    // OPTIONAL CUSTOMISATION COMPLETED.

    return chart;

}

From source file:org.jfree.chart.demo.MeterChartDemo.java

/**
 * Displays a meter chart./*w w  w . jav  a  2s . co  m*/
 *
 * @param value  the value.
 * @param shape  the dial shape.
 */
void displayMeterChart(final double value, final DialShape shape) {

    final DefaultValueDataset data = new DefaultValueDataset(75.0);
    final MeterPlot plot = new MeterPlot(data);
    plot.setUnits("Degrees");
    plot.setRange(new Range(20.0, 140.0));
    //        plot.setNormalRange(new Range(70.0, 100.0));
    //      plot.setWarningRange(new Range(100.0, 120.0));
    //    plot.setCriticalRange(new Range(120.0, 140.0));

    plot.setDialShape(shape);
    plot.setNeedlePaint(Color.white);
    plot.setTickLabelFont(new Font("SansSerif", Font.BOLD, 9));

    //  plot.setInsets(new Insets(5, 5, 5, 5));
    final JFreeChart chart = new JFreeChart("Meter Chart", JFreeChart.DEFAULT_TITLE_FONT, plot, false);

    //        final MeterLegend legend = new MeterLegend("Sample Meter");
    //      chart.setLegend(legend);

    chart.setBackgroundPaint(new GradientPaint(0, 0, Color.white, 0, 1000, Color.blue));

    final JFrame chartFrame = new ChartFrame("Meter Chart", chart);
    chartFrame.addWindowListener(new WindowAdapter() {
        /**
         * Invoked when a window is in the process of being closed.
         * The close operation can be overridden at this point.
         */
        public void windowClosing(final WindowEvent e) {
            System.exit(0);
        }
    });
    chartFrame.pack();
    RefineryUtilities.positionFrameRandomly(chartFrame);
    chartFrame.setSize(250, 250);
    chartFrame.setVisible(true);

}

From source file:com.rapidminer.gui.new_plotter.engine.jfreechart.link_and_brush.axis.CustomSymbolAxis.java

@Override
public void resizeRange(double percent, double anchorValue) {
    if (percent > 0.0) {
        double halfLength = getRange().getLength() * percent / 2;
        Range adjusted = new Range(anchorValue - halfLength, anchorValue + halfLength);
        setRange(adjusted);/*from   w w w  .  j a va2s. com*/
    } else {
        setRange(new Range(lowerBoundCache, upperBoundCache));
    }
}

From source file:com.rapidminer.gui.new_plotter.engine.jfreechart.link_and_brush.axis.CustomDateAxis.java

@Override
public Range calculateZoomRange(double lowerPercent, double upperPercent, boolean zoomIn) {
    double start = getRange().getLowerBound();
    double length = getRange().getLength();
    Range adjusted = null;//  w w  w  .j a  va  2 s .c om
    if (isInverted()) {
        adjusted = new Range(start + (length * (1 - upperPercent)), start + (length * (1 - lowerPercent)));
    } else {
        adjusted = new Range(start + length * lowerPercent, start + length * upperPercent);
    }
    if (zoomIn) {
        setRange(adjusted);
    }
    return adjusted;
}

From source file:org.gvsig.remotesensing.scatterplot.chart.ScatterPlotChart.java

/**
 *  Metodo que devuelve el Rango de la seleccion en el eje x.
 * //w w w.j a v  a2  s .c o m
 **/
public Range getRangeX(double lowerPercent, double upperPercent, PlotRenderingInfo info, Point2D source) {

    double start = super.getDomainAxis().getRange().getLowerBound();
    double length = super.getDomainAxis().getRange().getLength();
    Range adjusted = null;
    if (super.getDomainAxis().isInverted()) {
        adjusted = new Range(start + (length * (1 - upperPercent)), start + (length * (1 - lowerPercent)));
    } else {
        adjusted = new Range(start + length * lowerPercent, start + length * upperPercent);
    }
    return adjusted;
}

From source file:org.jfree.data.statistics.DefaultStatisticalCategoryDatasetTest.java

/**
 * Some checks for the getRangeBounds() method.
 *///  w w w .jav  a 2s. c o m
@Test
public void testGetRangeBounds() {
    DefaultStatisticalCategoryDataset d = new DefaultStatisticalCategoryDataset();

    // an empty dataset should return null for bounds
    assertNull(d.getRangeBounds(true));

    // try a dataset with a single value
    d.add(4.5, 1.0, "R1", "C1");
    assertEquals(new Range(4.5, 4.5), d.getRangeBounds(false));
    assertEquals(new Range(3.5, 5.5), d.getRangeBounds(true));

    // try a dataset with two values
    d.add(0.5, 2.0, "R1", "C2");
    assertEquals(new Range(0.5, 4.5), d.getRangeBounds(false));
    assertEquals(new Range(-1.5, 5.5), d.getRangeBounds(true));

    // try a Double.NaN
    d.add(Double.NaN, 0.0, "R1", "C3");
    assertEquals(new Range(0.5, 4.5), d.getRangeBounds(false));
    assertEquals(new Range(-1.5, 5.5), d.getRangeBounds(true));

    // try a Double.NEGATIVE_INFINITY
    d.add(Double.NEGATIVE_INFINITY, 0.0, "R1", "C3");
    assertEquals(new Range(Double.NEGATIVE_INFINITY, 4.5), d.getRangeBounds(false));
    assertEquals(new Range(Double.NEGATIVE_INFINITY, 5.5), d.getRangeBounds(true));

    // try a Double.POSITIVE_INFINITY
    d.add(Double.POSITIVE_INFINITY, 0.0, "R1", "C3");
    assertEquals(new Range(0.5, Double.POSITIVE_INFINITY), d.getRangeBounds(false));
    assertEquals(new Range(-1.5, Double.POSITIVE_INFINITY), d.getRangeBounds(true));
}

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

/**
 * Confirm that the equals method can distinguish all the required fields.
 *//*  w  w w  .j a va 2 s.  c o m*/
@Test
public void testEquals() {
    Range r1 = new Range(0.0, 1.0);
    Range r2 = new Range(0.0, 1.0);
    assertEquals(r1, r2);
    assertEquals(r2, r1);

    r1 = new Range(0.0, 1.0);
    r2 = new Range(0.5, 1.0);
    assertFalse(r1.equals(r2));

    r1 = new Range(0.0, 1.0);
    r2 = new Range(0.0, 2.0);
    assertFalse(r1.equals(r2));

    // a Range object cannot be equal to a different object type
    assertFalse(r1.equals(new Double(0.0)));
}

From source file:org.jfree.data.statistics.DefaultMultiValueCategoryDataset.java

/**
 * Creates a new dataset.// w w  w . j  a v  a  2  s.  co m
 */
public DefaultMultiValueCategoryDataset() {
    this.data = new KeyedObjects2D();
    this.minimumRangeValue = null;
    this.maximumRangeValue = null;
    this.rangeBounds = new Range(0.0, 0.0);
}