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:OAT.ui.BarChartFrame.java

public void addDataset(ChartDataset dataset) {
    if (dataset == null || dataset.getSeriesCount() == 0) {
        return;/*w  ww  .  j a v  a2 s. c  o  m*/
    }

    XYPlot plot = getChart().getXYPlot();
    int i = plot.getDatasetCount();

    for (int j = 0; j < i; j++) {
        if (plot.getDataset(j).equals(dataset)) {
            //                System.out.println("eq " + i
            //                        + " " + ((ChartDataset) plot.getDataset(j)).getTitle()
            //                        + " " + dataset.getTitle());
            return;
        }
    }

    plot.setDataset(i, dataset);
    plot.setDatasetRenderingOrder(DatasetRenderingOrder.REVERSE);
    Double[] range = dataset.getAxisRange();

    //axis
    int axisId = 0;

    if (range != null) {
        //        if (range == null || range.length < 2) {
        //            plot.mapDatasetToRangeAxis(i, 0);
        //        } else {

        //scan for equal axis range, reuse if found
        boolean hasSameRange = false;

        if (range.length > 1) {
            for (int j = 1; j < plot.getRangeAxisCount(); j++) {
                Range otherRange = plot.getRangeAxis(j).getRange();

                if (otherRange != null && otherRange.getLowerBound() == range[0]
                        && otherRange.getUpperBound() == range[1]) {
                    axisId = j;
                    hasSameRange = true;
                    break;
                }
            }
        }

        if (!hasSameRange) {
            NumberAxis newAxis = new NumberAxis();

            if (range.length > 1) {
                newAxis.setAutoRange(false);
                newAxis.setRange(range[0], range[1]);
            }

            if (range.length > 2) {
                newAxis.setAutoTickUnitSelection(false, false);
                newAxis.setTickUnit(new NumberTickUnit(range[2]));
            }

            newAxis.setNumberFormatOverride(TextUtil.SIMPLE_FORMATTER);
            //                    newAxis.setAxisLinePaint(new Color(100, 0, 0));
            //                    newAxis.setLabelPaint(paints[i][0]);
            //                    newAxis.setTickLabelPaint(paints[i][0]);
            //                    newAxis.setTickMarkPaint(paints[i][0]);
            //                    newAxis.setTickLabelsVisible(true);

            axisId = plot.getRangeAxisCount();
            plot.setRangeAxis(axisId, newAxis, false);
            plot.setRangeAxisLocation(axisId, AxisLocation.BOTTOM_OR_LEFT, false);
        }
        //            plot.mapDatasetToRangeAxis(i, newAxisId);
    }
    plot.mapDatasetToRangeAxis(i, axisId);
    //

    //renderer
    XYLineAndShapeRenderer renderer;

    if (dataset instanceof TradeDataset) {
        renderer = new TradeRenderer();

        for (int j = 0; j < dataset.getSeriesCount(); j++) {
            renderer.setSeriesLinesVisible(j, false);
        }
    } else {

        Shape shape = Main.defaultShape;
        Paint[][] seriesPaints;
        Stroke stroke;

        if (dataset.getSource() instanceof Stopper && !(dataset.getSource() instanceof Calculator)) {
            seriesPaints = Main.greyPaints;
            stroke = Main.dottedStoke;
        } else {
            seriesPaints = Main.defaultPaints;
            stroke = Main.defaultStoke;
        }

        renderer = new IndicatorRenderer(seriesPaints[(i - 1) % seriesPaints.length], shape, stroke);
    }

    plot.setRenderer(i, renderer, false);
}

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  w  w. j  a v  a  2s . 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).
 */
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:anl.verdi.plot.jfree.XYBlockRenderer.java

/**
 * Returns the lower and upper bounds (range) of the x-values in the
 * specified dataset./*from w  w w.j  a  va2  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 findDomainBounds(XYDataset dataset) {
    if (dataset != null) {
        Range r = DatasetUtilities.findDomainBounds(dataset, false);
        return new Range(r.getLowerBound() + xOffset, r.getUpperBound() + blockWidth + xOffset);
    } else {
        return null;
    }
}

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

/**
 * A test to cover bug 3445507.  The issue does not affact
 * XYSeriesCollection./*from  w  ww .ja va2 s  .  c  o m*/
 */
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: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();//w ww .  j  a v a 2s  . c  o  m
    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:org.jfree.data.time.TimePeriodValuesCollectionTest.java

/**
 * Some checks for the getDomainBounds() method.
 *///from  ww w. j  av  a2  s  .  c o  m
@Test
public void testGetDomainBoundsWithoutInterval() {
    // check empty dataset
    TimePeriodValuesCollection dataset = new TimePeriodValuesCollection();
    dataset.setDomainIsPointsInTime(false);
    Range r = dataset.getDomainBounds(false);
    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(false);
    assertEquals(1500.0, r.getLowerBound(), EPSILON);
    assertEquals(1500.0, r.getUpperBound(), EPSILON);

    // check dataset with two time periods
    s1.add(new SimpleTimePeriod(1500L, 3000L), 2.0);
    r = dataset.getDomainBounds(false);
    assertEquals(1500.0, r.getLowerBound(), EPSILON);
    assertEquals(2250.0, r.getUpperBound(), EPSILON);
}

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

public void setFirstParameterRange(Range range) {
    lFirstParRange.setValue(range.getLowerBound());
    uFirstParRange.setValue(range.getUpperBound());
}

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

public void setsecondParameterRange(Range range) {
    lSecondParRange.setValue(range.getLowerBound());
    uSecondParRange.setValue(range.getUpperBound());
}

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

public void setVerticalRange(Range range) {
    lowerVRangeField.setValue(range.getLowerBound());
    upperVRangeField.setValue(range.getUpperBound());
}

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

public JFreeChart drawTimeSeries(ArrayList<VersatileTimeSeries> atsArray) {
    JFreeChart chart;/*w  w  w.jav a2 s.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;
}