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:ucar.unidata.idv.control.McVHistogramWrapper.java

/**
 * Assumes that {@code data} has been validated and is okay to actually try
 * loading./* w ww  . jav a 2  s.  co  m*/
 *
 * @param data Data to use in histogram. Cannot be {@code null} or all NaNs.
 *
 * @throws VisADException
 * @throws RemoteException
 */
private void reallyLoadData(FlatField data) throws VisADException, RemoteException {
    createChart();
    List dataChoiceWrappers = getDataChoiceWrappers();

    try {
        clearHistogram();

        ErrorEstimate[] errOut = new ErrorEstimate[1];
        for (int paramIdx = 0; paramIdx < dataChoiceWrappers.size(); paramIdx++) {
            DataChoiceWrapper wrapper = (DataChoiceWrapper) dataChoiceWrappers.get(paramIdx);

            DataChoice dataChoice = wrapper.getDataChoice();
            Unit defaultUnit = ucar.visad.Util.getDefaultRangeUnits((FlatField) data)[0];
            Unit unit = ((DisplayControlImpl) imageControl).getDisplayUnit();
            double[][] samples = data.getValues(false);
            double[] actualValues = filterData(samples[0], getTimeValues(samples, data))[0];
            if ((defaultUnit != null) && !defaultUnit.equals(unit)) {
                actualValues = Unit.transformUnits(unit, errOut, defaultUnit, null, actualValues);
            }
            final NumberAxis domainAxis = new NumberAxis(wrapper.getLabel(unit));

            domainAxis.setAutoRangeIncludesZero(false);

            XYItemRenderer renderer;
            if (getStacked()) {
                renderer = new StackedXYBarRenderer();
            } else {
                renderer = new XYBarRenderer();
            }
            if ((plot == null) && (chartPanel != null)) {
                plot = chartPanel.getChart().getXYPlot();
            }
            plot.setRenderer(paramIdx, renderer);
            Color c = wrapper.getColor(paramIdx);
            domainAxis.setLabelPaint(c);
            renderer.setSeriesPaint(0, c);

            MyHistogramDataset dataset = new MyHistogramDataset();
            dataset.setType(HistogramType.FREQUENCY);
            dataset.addSeries(dataChoice.getName() + " [" + unit + ']', actualValues, getBins());
            samples = null;
            actualValues = null;
            plot.setDomainAxis(paramIdx, domainAxis, false);
            plot.mapDatasetToDomainAxis(paramIdx, paramIdx);
            plot.setDataset(paramIdx, dataset);

            domainAxis.addChangeListener(new AxisChangeListener() {
                public void axisChanged(AxisChangeEvent ae) {
                    if (!imageControl.isInitDone()) {
                        return;
                    }

                    Range range = domainAxis.getRange();
                    double newLow = Math.floor(range.getLowerBound() + 0.5);
                    double newHigh = Math.floor(range.getUpperBound() + 0.5);
                    double prevLow = getLow();
                    double prevHigh = getHigh();
                    try {
                        ucar.unidata.util.Range newRange;
                        if (prevLow > prevHigh) {
                            newRange = new ucar.unidata.util.Range(newHigh, newLow);
                        } else {
                            newRange = new ucar.unidata.util.Range(newLow, newHigh);
                        }
                        ((DisplayControlImpl) imageControl).setRange(newRange);
                    } catch (Exception e) {
                        logger.error("Cannot change range", e);
                    }
                }
            });

            Range range = domainAxis.getRange();
            low = range.getLowerBound();
            high = range.getUpperBound();
        }

    } catch (Exception exc) {
        System.out.println("Exception exc=" + exc);
        LogUtil.logException("Error creating data set", exc);
    }
}

From source file:de.bund.bfr.knime.nls.chart.ChartCreator.java

public ChartCreator(Map<String, Plotable> plotables, Map<String, String> legend) {
    this.plotables = plotables;
    this.legend = legend;
    colors = new LinkedHashMap<>();
    shapes = new LinkedHashMap<>();

    chartPanel = new ChartPanel(new JFreeChart(new XYPlot())) {

        private static final long serialVersionUID = 1L;

        @Override//from  www  .j  av  a 2  s  . c  o m
        public void mouseReleased(MouseEvent e) {
            ValueAxis domainAxis = ((XYPlot) chartPanel.getChart().getPlot()).getDomainAxis();
            ValueAxis rangeAxis = ((XYPlot) chartPanel.getChart().getPlot()).getRangeAxis();

            Range xRange1 = domainAxis.getRange();
            Range yRange1 = rangeAxis.getRange();
            super.mouseReleased(e);
            Range xRange2 = domainAxis.getRange();
            Range yRange2 = rangeAxis.getRange();

            if (!xRange1.equals(xRange2) || !yRange1.equals(yRange2)) {
                minX = xRange2.getLowerBound();
                maxX = xRange2.getUpperBound();
                minY = yRange2.getLowerBound();
                maxY = yRange2.getUpperBound();
                fireZoomChanged();
            }
        }
    };
    chartPanel.getPopupMenu().removeAll();

    setLayout(new BorderLayout());
    add(chartPanel, BorderLayout.CENTER);
}

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

/**
 * Returns the range of the values in the dataset's domain, including
 * or excluding the interval around each x-value as specified.
 *
 * @param includeInterval  a flag that determines whether or not the
 *                         x-interval should be taken into account.
 *
 * @return The range.//from w  w w .ja v  a 2  s .  c  om
 */
@Override
public Range getDomainBounds(boolean includeInterval) {
    // first get the range without the interval, then expand it for the
    // interval width
    Range range = DatasetUtilities.findDomainBounds(this.dataset, false);
    if (includeInterval && range != null) {
        double lowerAdj = getIntervalWidth() * getIntervalPositionFactor();
        double upperAdj = getIntervalWidth() - lowerAdj;
        range = new Range(range.getLowerBound() - lowerAdj, range.getUpperBound() + upperAdj);
    }
    return range;
}

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

/**
 * Updates the threshold ranges./*from w w w . j  ava2  s  .co  m*/
 * 
 * @param range  the dial range
 */
private void updateThresholdRanges() {
    Range range = model.getRange();
    double warningThresh = model.getWarningThreshold() * (range.getLength());
    double criticalThresh = model.getCriticalThreshold() * (range.getLength());

    criticalMinimumThreshold = range.getLowerBound() + criticalThresh;
    warningMinimumThreshold = range.getLowerBound() + warningThresh;
    warningMaximumThreshold = range.getUpperBound() - warningThresh;
    criticalMaxThreshold = range.getUpperBound() - criticalThresh;

    // remove previous dial ranges
    for (StandardDialRange dialRange : thresholdDialRanges) {
        if (dialRange != null) {
            plot.removeLayer(dialRange);
        }
    }

    thresholdDialRanges[0] = new StandardDialRange(range.getLowerBound(), criticalMinimumThreshold, Color.red);
    thresholdDialRanges[0].setInnerRadius(0);
    thresholdDialRanges[0].setOuterRadius(0.9);
    plot.addLayer(thresholdDialRanges[0]);

    thresholdDialRanges[1] = new StandardDialRange(criticalMinimumThreshold, warningMinimumThreshold,
            Color.yellow);
    thresholdDialRanges[1].setInnerRadius(0);
    thresholdDialRanges[1].setOuterRadius(0.9);
    plot.addLayer(thresholdDialRanges[1]);

    thresholdDialRanges[2] = new StandardDialRange(warningMaximumThreshold, criticalMaxThreshold, Color.yellow);
    thresholdDialRanges[2].setInnerRadius(0);
    thresholdDialRanges[2].setOuterRadius(0.9);
    plot.addLayer(thresholdDialRanges[2]);

    thresholdDialRanges[3] = new StandardDialRange(criticalMaxThreshold, range.getUpperBound(), Color.red);
    thresholdDialRanges[3].setInnerRadius(0);
    thresholdDialRanges[3].setOuterRadius(0.9);
    plot.addLayer(thresholdDialRanges[3]);

    // make sure to do this after changing the dial ranges because it gets reset for some reason
    dialValueIndicator.setTemplateValue(-222.222e222);

    checkThresholds();
}

From source file:ch.algotrader.client.chart.ChartTab.java

public long getMaxDate() {

    Range range = getPlot().getDataRange(getPlot().getDomainAxis());
    if (range != null) {
        return (long) range.getUpperBound();
    } else {//from  w ww  .j ava  2 s  .  c  o m
        return 0;
    }
}

From source file:org.tsho.dmc2.core.chart.CowebRenderer.java

private void animateCowebPlot(Graphics2D g2, Rectangle2D dataArea) {

    Graphics2D g2bisec = (Graphics2D) g2.create();
    g2bisec.setColor(Color.blue);

    Stroke stroke = new BasicStroke(3f);
    Stroke origStroke = g2.getStroke();
    Color color = Color.BLACK;
    g2blink = (Graphics2D) g2.create();
    g2blink.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);

    g2blink.setXORMode(color);/*w  ww .  j  a va2s  .c  o  m*/
    g2blink.setStroke(stroke);

    if (plot.isAlpha()) {
        g2bisec.setComposite(AlphaComposite.SrcOver);
        g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, plot.getForegroundAlpha()));
    }

    /* transients */
    stepper.setInitialValue(initialValue);
    stepper.initialize();

    state = STATE_TRANSIENTS;

    for (int index = 0; index < transients; index++) {

        stepper.step();

        if (stopped) {
            state = STATE_STOPPED;
            return;
        }
    }

    state = STATE_RUNNING;

    Range xDataRange = plot.getDataRange(domainAxis);
    int transX, transY, transX1, transY1;

    transX = (int) this.domainAxis.valueToJava2D(xDataRange.getLowerBound(), dataArea, RectangleEdge.BOTTOM);
    transY = (int) this.rangeAxis.valueToJava2D(xDataRange.getLowerBound(), dataArea, RectangleEdge.LEFT);
    transX1 = (int) this.domainAxis.valueToJava2D(xDataRange.getUpperBound(), dataArea, RectangleEdge.BOTTOM);
    transY1 = (int) this.rangeAxis.valueToJava2D(xDataRange.getUpperBound(), dataArea, RectangleEdge.LEFT);

    g2bisec.drawLine(transX, transY, transX1, transY1);

    //renderer.reset();

    recurseCoweb(g2, dataArea);
}

From source file:userinterface.graph.PrismLogarithmicAxis.java

/**
 * Adjusts the axis range to match the data range that the axis is
 * required to display.// ww w. jav a2s. co  m
 */
protected void autoAdjustRange() {
    Plot plot = getPlot();
    if (plot == null) {
        return; // no plot, no data
    }

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

        Range r = vap.getDataRange(this);
        if (r == null) {
            r = getDefaultAutoRange();
        }

        double upper = r.getUpperBound();
        double lower = r.getLowerBound();
        double range = upper - lower;

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

            // apply the margins - these should apply to the exponent range
            //upper = upper + getUpperMargin() * range;
            //lower = lower - getLowerMargin() * range;
        }

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

}

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

/**
 * Pan the plot/*from   w ww  . j a v a  2s  .  c  om*/
 *
 * @param right to right
 * @param percent by how much
 */
protected void panPlot(boolean right, double percent) {
    if (!(plot instanceof XYPlot)) {
        return;
    }
    XYPlot xyPlot = (XYPlot) plot;
    int cnt = xyPlot.getDomainAxisCount();
    for (int i = 0; i < cnt; i++) {
        ValueAxis axis = (ValueAxis) xyPlot.getDomainAxis(i);
        org.jfree.data.Range range = axis.getRange();
        double width = range.getUpperBound() - range.getLowerBound();
        double width2 = width / 2.0;
        double step = (right ? width * percent : -width * percent);
        axis.centerRange(range.getLowerBound() + step + width2);
    }
}

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

/**
 * Move plot up/down./*from w w  w  . j a v  a  2s.  c o  m*/
 *
 * @param up up
 */
private void upDownPlot(boolean up) {
    if (!(plot instanceof XYPlot)) {
        return;
    }
    XYPlot xyPlot = (XYPlot) plot;

    int cnt = xyPlot.getRangeAxisCount();
    for (int i = 0; i < cnt; i++) {
        ValueAxis axis = (ValueAxis) xyPlot.getRangeAxis(i);
        org.jfree.data.Range range = axis.getRange();
        double width = range.getUpperBound() - range.getLowerBound();
        double width2 = width / 2.0;
        double step = (up ? width * 0.1 : -width * 0.1);
        axis.centerRange(range.getLowerBound() + step + width2);
    }
}

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

/**
 * Pan the plot/*from w  w w.j  a  v a  2s .c o m*/
 *
 * @param right to right
 * @param percent by how much
 */
protected void panPlot(boolean right, double percent) {
    if (!(chart.getPlot() instanceof XYPlot)) {
        return;
    }
    XYPlot plot = (XYPlot) chart.getPlot();
    int cnt = plot.getDomainAxisCount();
    for (int i = 0; i < cnt; i++) {
        ValueAxis axis = (ValueAxis) plot.getDomainAxis(i);
        org.jfree.data.Range range = axis.getRange();
        double width = range.getUpperBound() - range.getLowerBound();
        double width2 = width / 2.0;
        double step = (right ? width * percent : -width * percent);
        axis.centerRange(range.getLowerBound() + step + width2);
    }
}