Example usage for org.jfree.data Range getLength

List of usage examples for org.jfree.data Range getLength

Introduction

In this page you can find the example usage for org.jfree.data Range getLength.

Prototype

public double getLength() 

Source Link

Document

Returns the length of the range.

Usage

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

/**
 * Updates the threshold ranges.//from   w w w .  j  a va  2s  . c  o 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:org.eurocarbdb.application.glycoworkbench.plugin.PeakAnnotationCalibrationPanel.java

public void onZoomNone() {
    if (!isChartEmpty()) {
        Range mz_range = theDocument.getMZRange();
        if (mz_range.getLength() == 0.)
            mz_range = new Range(mz_range.getLowerBound() - 10, mz_range.getLowerBound() + 10);
        thePlot.getDomainAxis().setRange(mz_range);

        if (accuracy_unit.equals("da")) {
            Range acc_range = theDocument.getAccuracyRange(current_ind);
            if (acc_range.getLength() == 0.)
                acc_range = new Range(acc_range.getLowerBound() - 0.1, acc_range.getLowerBound() + 0.1);
            thePlot.getRangeAxis().setRange(acc_range);
        } else {// w ww.j  a v a 2 s. c  o m
            Range acc_range = theDocument.getAccuracyRangePPM(current_ind);
            if (acc_range.getLength() == 0.)
                acc_range = new Range(acc_range.getLowerBound() - 100, acc_range.getLowerBound() + 100);
            thePlot.getRangeAxis().setRange(acc_range);
        }
    } else {
        thePlot.getDomainAxis().setRange(new Range(0., 1.));
        if (accuracy_unit.equals("da"))
            thePlot.getRangeAxis().setRange(new Range(-1., 1.));
        else
            thePlot.getRangeAxis().setRange(new Range(-1000., 1000.));
    }
}

From source file:org.jfree.experimental.chart.annotations.XYTitleAnnotation.java

/**
 * Draws the annotation.  This method is called by the drawing code in the 
 * {@link XYPlot} class, you don't normally need to call this method 
 * directly./*from   ww w .j a v  a  2  s .  co  m*/
 *
 * @param g2  the graphics device.
 * @param plot  the plot.
 * @param dataArea  the data area.
 * @param domainAxis  the domain axis.
 * @param rangeAxis  the range axis.
 * @param rendererIndex  the renderer index.
 * @param info  if supplied, this info object will be populated with
 *              entity information.
 */
public void draw(Graphics2D g2, XYPlot plot, Rectangle2D dataArea, ValueAxis domainAxis, ValueAxis rangeAxis,
        int rendererIndex, PlotRenderingInfo info) {

    PlotOrientation orientation = plot.getOrientation();
    AxisLocation domainAxisLocation = plot.getDomainAxisLocation();
    AxisLocation rangeAxisLocation = plot.getRangeAxisLocation();
    RectangleEdge domainEdge = Plot.resolveDomainAxisLocation(domainAxisLocation, orientation);
    RectangleEdge rangeEdge = Plot.resolveRangeAxisLocation(rangeAxisLocation, orientation);
    Range xRange = domainAxis.getRange();
    Range yRange = rangeAxis.getRange();
    double anchorX = 0.0;
    double anchorY = 0.0;
    if (this.coordinateType == XYCoordinateType.RELATIVE) {
        anchorX = xRange.getLowerBound() + (this.x * xRange.getLength());
        anchorY = yRange.getLowerBound() + (this.y * yRange.getLength());
    } else {
        anchorX = domainAxis.valueToJava2D(this.x, dataArea, domainEdge);
        anchorY = rangeAxis.valueToJava2D(this.y, dataArea, rangeEdge);
    }

    float j2DX = (float) domainAxis.valueToJava2D(anchorX, dataArea, domainEdge);
    float j2DY = (float) rangeAxis.valueToJava2D(anchorY, dataArea, rangeEdge);
    float xx = 0.0f;
    float yy = 0.0f;
    if (orientation == PlotOrientation.HORIZONTAL) {
        xx = j2DY;
        yy = j2DX;
    } else if (orientation == PlotOrientation.VERTICAL) {
        xx = j2DX;
        yy = j2DY;
    }

    double maxW = dataArea.getWidth();
    double maxH = dataArea.getHeight();
    if (this.coordinateType == XYCoordinateType.RELATIVE) {
        if (this.maxWidth > 0.0) {
            maxW = maxW * this.maxWidth;
        }
        if (this.maxHeight > 0.0) {
            maxH = maxH * this.maxHeight;
        }
    }
    if (this.coordinateType == XYCoordinateType.DATA) {
        maxW = this.maxWidth;
        maxH = this.maxHeight;
    }
    RectangleConstraint rc = new RectangleConstraint(new Range(0, maxW), new Range(0, maxH));

    Size2D size = this.title.arrange(g2, rc);
    Rectangle2D titleRect = new Rectangle2D.Double(0, 0, size.width, size.height);
    Point2D anchorPoint = RectangleAnchor.coordinates(titleRect, this.anchor);
    xx = xx - (float) anchorPoint.getX();
    yy = yy - (float) anchorPoint.getY();
    titleRect.setRect(xx, yy, titleRect.getWidth(), titleRect.getHeight());
    BlockParams p = new BlockParams();
    if (info != null) {
        if (info.getOwner().getEntityCollection() != null) {
            p.setGenerateEntities(true);
        }
    }
    Object result = this.title.draw(g2, titleRect, p);
    if (result instanceof EntityBlockResult) {
        EntityBlockResult ebr = (EntityBlockResult) result;
        info.getOwner().getEntityCollection().addAll(ebr.getEntityCollection());
    }
    String toolTip = getToolTipText();
    String url = getURL();
    if (toolTip != null || url != null) {
        addEntity(info, new Rectangle2D.Float(xx, yy, (float) size.width, (float) size.height), rendererIndex,
                toolTip, url);
    }
}

From source file:org.jfree.eastwood.ChartEngine.java

/**
 * Adds a marker to the chart./*from  w  ww.j av a 2s. c om*/
 *
 * @param markerStr  the string encoding of the marker.
 * @param chart  the chart to apply the marker to.
 */
private static void addMarker(String markerStr, JFreeChart chart) {
    String[] args = breakString(markerStr, ',');
    Plot p = chart.getPlot();
    Color c = parseColor(args[1]);
    if (args[0].startsWith("t")) {
        String text = args[0].substring(1);
        int dataset = Integer.parseInt(args[2]);
        int datapoint = Integer.parseInt(args[3]);
        float fontsize = Float.parseFloat(args[4]);
        if (p instanceof CategoryPlot) {
            CategoryPlot cp = (CategoryPlot) p;

            CategoryItemRenderer r = cp.getRenderer();
            GCategoryPlot.LabelGenerator label = (GCategoryPlot.LabelGenerator) r.getItemLabelGenerator(dataset,
                    datapoint);
            label.setLabel(dataset, datapoint, text);
        } else if (p instanceof XYPlot) {
            XYPlot xyp = (XYPlot) p;
            XYItemRenderer r = xyp.getRenderer();
            ((GXYPlot.LabelGenerator) r.getItemLabelGenerator(dataset, datapoint)).setLabel(dataset, datapoint,
                    text);
            //XYDataset d = xyp.getDataset();
            //XYPointerAnnotation a = new XYPointerAnnotation(text, d.getXValue(dataset, datapoint), d.getYValue(dataset, datapoint), Math.random()-2);
            //xyp.addAnnotation(a);
        }
    } else if ("r".equals(args[0])) {
        // add a range marker
        float f0 = Float.parseFloat(args[3]);
        float f1 = Float.parseFloat(args[4]);
        if (p instanceof CategoryPlot) {
            CategoryPlot cp = (CategoryPlot) p;
            Range yRange = cp.getRangeAxis().getRange();
            double r0 = yRange.getLowerBound();
            double rl = yRange.getLength();
            IntervalMarker m = new IntervalMarker(r0 + Math.min(f0, f1) * rl, r0 + Math.max(f0, f1) * rl);
            m.setPaint(c);
            cp.addRangeMarker(m, Layer.BACKGROUND);
        } else if (p instanceof XYPlot) {
            XYPlot cp = (XYPlot) p;
            Range yRange = cp.getRangeAxis().getRange();
            double r0 = yRange.getLowerBound();
            double rl = yRange.getLength();
            IntervalMarker m = new IntervalMarker(r0 + Math.min(f0, f1) * rl, r0 + Math.max(f0, f1) * rl);
            m.setPaint(c);
            cp.addRangeMarker(m, Layer.BACKGROUND);
        }

    } else if ("R".equals(args[0])) {
        // add a domain marker
        float f0 = Float.parseFloat(args[3]);
        float f1 = Float.parseFloat(args[4]);
        if (p instanceof XYPlot) {
            XYPlot xyp = (XYPlot) p;
            Range yRange = xyp.getRangeAxis().getRange();
            double r0 = yRange.getLowerBound();
            double rl = yRange.getLength();
            IntervalMarker m = new IntervalMarker(r0 + Math.min(f0, f1) * rl, r0 + Math.max(f0, f1) * rl);
            m.setPaint(c);
            xyp.addDomainMarker(m, Layer.BACKGROUND);
        }
    }
}

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

/**
 * Updates the dial range.//from w  ww .j  a va2s . c  o  m
 * 
 * @param range  the dial range
 */
private void updateRange() {
    Range range = model.getRange();

    lowerBoundTextField.setText(engineeringFormat.format(model.getRange().getLowerBound()));
    upperBoundTextField.setText(engineeringFormat.format(model.getRange().getUpperBound()));

    dialScale.setLowerBound(range.getLowerBound());
    dialScale.setUpperBound(range.getUpperBound());

    double tickIncrement = range.getLength() / 10;
    dialScale.setMajorTickIncrement(tickIncrement);

    plot.addScale(0, dialScale);

    updateThresholdRanges();
}

From source file:de.unibayreuth.bayeos.goat.panels.timeseries.JPanelChart.java

public void chartChanged(ChartChangeEvent event) {
    try {//from w  w w.  jav  a2  s.c  o m
        if (event.getChart() == null) {
            return;
        }

        BoundedRangeModel scrollBarModel = this.chartScrollBar.getModel();
        if (scrollBarModel == null) {
            return;
        }

        boolean chartIsZoomed = false;

        Plot plot = event.getChart().getPlot();
        if (plot instanceof XYPlot) {
            XYPlot hvp = (XYPlot) plot;
            ValueAxis xAxis = hvp.getDomainAxis();
            Range xAxisRange = xAxis.getRange();

            // avoid recursion
            scrollBarModel.removeChangeListener(this);

            int low = (int) (xAxisRange.getLowerBound() * scrollFactor);
            scrollBarModel.setValue(low);
            int ext = (int) (xAxisRange.getUpperBound() * scrollFactor - low);
            scrollBarModel.setExtent(ext);

            // restore
            scrollBarModel.addChangeListener(this);

            // check if zoomed horizontally
            //Range hdr = hvp.getHorizontalDataRange(xAxis);
            Range hdr = hvp.getDataRange(xAxis);

            double len = hdr == null ? 0 : hdr.getLength();
            chartIsZoomed |= xAxisRange.getLength() < len;
        }

        if (!chartIsZoomed && plot instanceof XYPlot) {
            // check if zoomed vertically
            XYPlot vvp = (XYPlot) plot;
            ValueAxis yAxis = vvp.getRangeAxis();
            if (yAxis != null) {
                chartIsZoomed = yAxis.getLowerBound() > yMin || yAxis.getUpperBound() < yMax;
            }
        }

        // enable "zoom-out-buttons" if chart is zoomed
        // otherwise disable them
        chartPanButton.setEnabled(chartIsZoomed);
        chartZoomOutButton.setEnabled(chartIsZoomed);
        chartFitButton.setEnabled(chartIsZoomed);
        chartScrollBar.setEnabled(chartIsZoomed);
        if (!chartIsZoomed) {
            setPanMode(false);
            chartZoomButton.setSelected(true);
        }
    } catch (Exception e) {
        MsgBox.error(e.getMessage());
    }
}

From source file:de.unibayreuth.bayeos.goat.panels.timeseries.JPanelChart.java

/**
 * used for zooming//  w w w .  j  a v  a  2s .  c o  m
 * 
 * @param axis  the axis.
 * @param range  the range.
 * @param zoomFactor  the zoom factor.
 * @param anchorValue  the anchor value.
 */
private void adjustRange(ValueAxis axis, Range range, double zoomFactor, double anchorValue) {

    if (axis == null || range == null) {
        return;
    }

    double rangeMinVal = range.getLowerBound() - range.getLength() * axis.getLowerMargin();
    double rangeMaxVal = range.getUpperBound() + range.getLength() * axis.getUpperMargin();
    double halfLength = axis.getRange().getLength() * zoomFactor / 2;
    double zoomedMinVal = anchorValue - halfLength;
    double zoomedMaxVal = anchorValue + halfLength;
    double adjMinVal = zoomedMinVal;
    if (zoomedMinVal < rangeMinVal) {
        adjMinVal = rangeMinVal;
        zoomedMaxVal += rangeMinVal - zoomedMinVal;
    }
    double adjMaxVal = zoomedMaxVal;
    if (zoomedMaxVal > rangeMaxVal) {
        adjMaxVal = rangeMaxVal;
        zoomedMinVal -= zoomedMaxVal - rangeMaxVal;
        adjMinVal = Math.max(zoomedMinVal, rangeMinVal);
    }

    Range adjusted = new Range(adjMinVal, adjMaxVal);
    axis.setRange(adjusted);
}

From source file:de.unibayreuth.bayeos.goat.panels.timeseries.JPanelChart.java

private void recalcScrollBar(Plot plot) {
    if (plot instanceof XYPlot) {
        XYPlot hvp = (XYPlot) plot;/*from   ww  w.  j  a va2s . com*/
        ValueAxis axis = hvp.getDomainAxis();

        axis.setLowerMargin(0);
        axis.setUpperMargin(0);

        Range rng = axis.getRange();

        BoundedRangeModel scrollBarModel = this.chartScrollBar.getModel();
        int len = scrollBarModel.getMaximum() - scrollBarModel.getMinimum();
        if (rng.getLength() > 0) {
            scrollFactor = len / rng.getLength();
        }

        double dblow = rng.getLowerBound();
        int ilow = (int) (dblow * scrollFactor);
        scrollBarModel.setMinimum(ilow);
        int val = ilow;
        scrollBarModel.setValue(val);

        double dbup = rng.getUpperBound();
        int iup = (int) (dbup * scrollFactor);
        scrollBarModel.setMaximum(iup);
        int ext = iup - ilow;
        scrollBarModel.setExtent(ext);

        scrollBarModel.addChangeListener(this);
    }
}

From source file:apidemo.PanScrollZoomDemo.java

/**
 * Handles a {@link ChartChangeEvent}.//from ww  w . ja  v a  2 s.  com
 * 
 * @param event  the event.
 */
public void chartChanged(final ChartChangeEvent event) {
    try {
        if (event.getChart() == null) {
            return;
        }

        final BoundedRangeModel scrollBarModel = this.scrollBar.getModel();
        if (scrollBarModel == null) {
            return;
        }

        boolean chartIsZoomed = false;

        final Plot plot = event.getChart().getPlot();
        if (plot instanceof XYPlot) {
            final XYPlot hvp = (XYPlot) plot;
            final ValueAxis xAxis = hvp.getDomainAxis();
            final Range xAxisRange = xAxis.getRange();

            // avoid recursion
            scrollBarModel.removeChangeListener(this);

            final int low = (int) (xAxisRange.getLowerBound() * this.scrollFactor);
            scrollBarModel.setValue(low);
            final int ext = (int) (xAxisRange.getUpperBound() * this.scrollFactor - low);
            scrollBarModel.setExtent(ext);

            // restore
            scrollBarModel.addChangeListener(this);

            // check if zoomed horizontally
            //Range hdr = hvp.getHorizontalDataRange(xAxis);
            final Range hdr = hvp.getDataRange(xAxis);

            final double len = hdr == null ? 0 : hdr.getLength();
            chartIsZoomed |= xAxisRange.getLength() < len;
        }

        if (!chartIsZoomed && plot instanceof XYPlot) {
            // check if zoomed vertically
            final XYPlot vvp = (XYPlot) plot;
            ValueAxis yAxis = vvp.getRangeAxis();
            if (yAxis != null) {
                chartIsZoomed = yAxis.getLowerBound() > this.primYMinMax[0]
                        || yAxis.getUpperBound() < this.primYMinMax[1];

                // right y-axis
                if (!chartIsZoomed && plot instanceof XYPlot) {
                    final XYPlot xyPlot = (XYPlot) plot;
                    yAxis = xyPlot.getRangeAxis(1);
                    if (yAxis != null) {
                        chartIsZoomed = yAxis.getLowerBound() > this.secondYMinMax[0]
                                || yAxis.getUpperBound() < this.secondYMinMax[1];
                    }
                }
            }
        }

        // enable "zoom-out-buttons" if chart is zoomed
        // otherwise disable them
        this.panButton.setEnabled(chartIsZoomed);
        this.zoomOutButton.setEnabled(chartIsZoomed);
        this.fitButton.setEnabled(chartIsZoomed);
        this.scrollBar.setEnabled(chartIsZoomed);
        if (!chartIsZoomed) {
            setPanMode(false);
            this.zoomButton.setSelected(true);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:apidemo.PanScrollZoomDemo.java

/**
 * used for zooming/*from   w  ww  . j  a  va  2 s .  c o m*/
 * 
 * @param axis  the axis.
 * @param range  the range.
 * @param zoomFactor  the zoom factor.
 * @param anchorValue  the anchor value.
 */
private void adjustRange(final ValueAxis axis, final Range range, final double zoomFactor,
        final double anchorValue) {

    if (axis == null || range == null) {
        return;
    }

    final double rangeMinVal = range.getLowerBound() - range.getLength() * axis.getLowerMargin();
    final double rangeMaxVal = range.getUpperBound() + range.getLength() * axis.getUpperMargin();
    final double halfLength = axis.getRange().getLength() * zoomFactor / 2;
    double zoomedMinVal = anchorValue - halfLength;
    double zoomedMaxVal = anchorValue + halfLength;
    double adjMinVal = zoomedMinVal;
    if (zoomedMinVal < rangeMinVal) {
        adjMinVal = rangeMinVal;
        zoomedMaxVal += rangeMinVal - zoomedMinVal;
    }
    double adjMaxVal = zoomedMaxVal;
    if (zoomedMaxVal > rangeMaxVal) {
        adjMaxVal = rangeMaxVal;
        zoomedMinVal -= zoomedMaxVal - rangeMaxVal;
        adjMinVal = Math.max(zoomedMinVal, rangeMinVal);
    }

    final Range adjusted = new Range(adjMinVal, adjMaxVal);
    axis.setRange(adjusted);
}