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.chart.PlotWrapper.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 (!(chart.getPlot() instanceof XYPlot)) {
        return;
    }
    XYPlot plot = (XYPlot) chart.getPlot();

    int cnt = plot.getRangeAxisCount();
    for (int i = 0; i < cnt; i++) {
        ValueAxis axis = (ValueAxis) plot.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:org.esa.beam.timeseries.ui.graph.TimeSeriesGraphModel.java

void updateAnnotation(RasterDataNode raster) {
    removeAnnotation();/*from w w  w .  ja v a2  s.co m*/

    final AbstractTimeSeries timeSeries = getTimeSeries();
    TimeCoding timeCoding = timeSeries.getRasterTimeMap().get(raster);
    if (timeCoding != null) {
        final ProductData.UTC startTime = timeCoding.getStartTime();
        final Millisecond timePeriod = new Millisecond(startTime.getAsDate(), ProductData.UTC.UTC_TIME_ZONE,
                Locale.getDefault());

        double millisecond = timePeriod.getFirstMillisecond();
        Range valueRange = null;
        for (int i = 0; i < timeSeriesPlot.getRangeAxisCount(); i++) {
            valueRange = Range.combine(valueRange, timeSeriesPlot.getRangeAxis(i).getRange());
        }
        if (valueRange != null) {
            XYAnnotation annotation = new XYLineAnnotation(millisecond, valueRange.getLowerBound(), millisecond,
                    valueRange.getUpperBound());
            timeSeriesPlot.addAnnotation(annotation, true);
        }
    }
}

From source file:org.fhcrc.cpl.viewer.gui.SpectrumComponent.java

protected void copyChartData() {
    if (null == _chart || null == _spectrum)
        return;//  w ww .  j  a  v a  2 s  .  c  o  m
    XYPlot xyplot;
    if (_chart.getPlot() instanceof XYPlot) {
        xyplot = _chart.getXYPlot();
    } else {
        // UNDONE:
        return;
    }
    ValueAxis domainAxis = xyplot.getDomainAxis();
    Range range = domainAxis.getRange();
    double min = range.getLowerBound();
    double max = range.getUpperBound();

    float[] x = _spectrum[0];
    float[] y = _spectrum[1];
    int start = Arrays.binarySearch(x, (float) min);
    if (start < 0)
        start = -(start + 1);
    int end = Arrays.binarySearch(x, (float) max);
    if (end < 0)
        end = -(end + 1);

    StringBuffer sb = new StringBuffer(20 * (end - start));
    for (int i = start; i < end; i++)
        sb.append(x[i]).append('\t').append(y[i]).append('\n');
    StringSelection sel = new StringSelection(sb.toString());
    Toolkit.getDefaultToolkit().getSystemClipboard().setContents(sel, sel);
}

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

/**
 * used for zooming/*  www  . ja  v  a  2 s  .  c om*/
 * 
 * @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:org.pentaho.platform.uifoundation.chart.DialWidgetDefinition.java

/**
 * Add an interval (MeterInterval) to the dial definition. The interval defines a range and how it should be
 * painted./*  w w w .j a va  2 s  .  c om*/
 * <p/>
 * The dial images here have three intervals. The lowest interval has a minimum of 0 and a maximum of 30.
 * <p/>
 * Intervals have a color. In this image the lowest interval color is set to red. <br/>
 * <img src="doc-files/DialWidgetDefinition-5.png">
 * <p/>
 * Intervals have a text color. In this image the lowest interval text color is set to red. This affects the
 * outer rim, the interval value text <br/>
 * <img src="doc-files/DialWidgetDefinition-6.png">
 * 
 * @param interval
 *          A MeterInterval that defines an interval (range) on the dial
 */
public void addInterval(final MeterInterval interval) {
    intervals.add(interval);
    Range range = interval.getRange();
    double min = range.getLowerBound();
    double max = range.getUpperBound();
    if (rangeLimited && (intervals.size() == 1)) {
        setMinimum(min);
        setMaximum(max);
    } else {
        if (min < getMinimum()) {
            setMinimum(min);
        }
        if (max > getMaximum()) {
            setMaximum(max);
        }
    }
}

From source file:org.trade.ui.chart.CandlestickChart.java

/**
 * A demonstration application showing a candlestick chart.
 * //ww w .ja  v  a  2s .c  om
 * @param title
 *            the frame title.
 * @param strategyData
 *            StrategyData
 */
public CandlestickChart(final String title, StrategyData strategyData, Tradingday tradingday) {

    this.strategyData = strategyData;
    this.setLayout(new BorderLayout());
    // Used to mark the current price
    stroke = new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 0, new float[] { 10, 3 }, 0);
    valueMarker = new ValueMarker(0.00, Color.black, stroke);

    this.chart = createChart(this.strategyData, title, tradingday);

    BlockContainer container = new BlockContainer(new BorderArrangement());
    container.add(titleLegend1, RectangleEdge.LEFT);
    container.add(titleLegend2, RectangleEdge.RIGHT);
    container.add(new EmptyBlock(2000, 0));
    CompositeTitle legends = new CompositeTitle(container);
    legends.setPosition(RectangleEdge.BOTTOM);
    this.chart.addSubtitle(legends);

    final ChartPanel chartPanel = new ChartPanel(this.chart);
    chartPanel.setFillZoomRectangle(true);
    chartPanel.setMouseZoomable(true, true);
    chartPanel.setRefreshBuffer(true);
    chartPanel.setDoubleBuffered(true);
    chartPanel.setVerticalAxisTrace(true);
    chartPanel.setHorizontalAxisTrace(true);
    chartPanel.addChartMouseListener(new ChartMouseListener() {

        public void chartMouseMoved(ChartMouseEvent e) {
        }

        public void chartMouseClicked(final ChartMouseEvent e) {
            CombinedDomainXYPlot combinedXYplot = (CombinedDomainXYPlot) e.getChart().getPlot();
            @SuppressWarnings("unchecked")
            List<XYPlot> subplots = combinedXYplot.getSubplots();
            if (e.getTrigger().getClickCount() == 2) {
                double xItem = 0;
                double yItem = 0;
                if (e.getEntity() instanceof XYItemEntity) {
                    XYItemEntity xYItemEntity = ((XYItemEntity) e.getEntity());
                    xItem = xYItemEntity.getDataset().getXValue(xYItemEntity.getSeriesIndex(),
                            xYItemEntity.getItem());
                    yItem = xYItemEntity.getDataset().getYValue(xYItemEntity.getSeriesIndex(),
                            xYItemEntity.getItem());
                } else {
                    PlotEntity plotEntity = ((PlotEntity) e.getEntity());
                    XYPlot plot = (XYPlot) plotEntity.getPlot();
                    xItem = plot.getDomainCrosshairValue();
                    yItem = plot.getRangeCrosshairValue();
                }

                for (XYPlot xyplot : subplots) {

                    double x = xyplot.getDomainCrosshairValue();
                    double y = xyplot.getRangeCrosshairValue();

                    /*
                     * If the cross hair is from a right-hand y axis we need
                     * to convert this to a left-hand y axis.
                     */
                    String rightAxisName = ", Price: ";
                    double rangeLowerLeft = 0;
                    double rangeUpperLeft = 0;
                    double rangeLowerRight = 0;
                    double rangeUpperRight = 0;
                    double yRightLocation = 0;
                    for (int index = 0; index < xyplot.getRangeAxisCount(); index++) {
                        AxisLocation axisLocation = xyplot.getRangeAxisLocation(index);
                        Range range = xyplot.getRangeAxis(index).getRange();

                        if (axisLocation.equals(AxisLocation.BOTTOM_OR_LEFT)
                                || axisLocation.equals(AxisLocation.TOP_OR_LEFT)) {
                            rangeLowerLeft = range.getLowerBound();
                            rangeUpperLeft = range.getUpperBound();
                            rightAxisName = ", " + xyplot.getRangeAxis(index).getLabel() + ": ";
                        }
                        if (y >= range.getLowerBound() && y <= range.getUpperBound()
                                && (axisLocation.equals(AxisLocation.BOTTOM_OR_RIGHT)
                                        || axisLocation.equals(AxisLocation.TOP_OR_RIGHT))) {
                            rangeUpperRight = range.getUpperBound();
                            rangeLowerRight = range.getLowerBound();
                        }
                    }
                    if ((rangeUpperRight - rangeLowerRight) > 0) {
                        yRightLocation = rangeLowerLeft + ((rangeUpperLeft - rangeLowerLeft)
                                * ((y - rangeLowerRight) / (rangeUpperRight - rangeLowerRight)));
                    } else {
                        yRightLocation = y;
                    }

                    String text = " Time: " + dateFormatShort.format(new Date((long) (x))) + rightAxisName
                            + new Money(y);
                    if (x == xItem && y == yItem) {
                        titleLegend1.setText(text);
                        if (null == clickCrossHairs) {
                            clickCrossHairs = new XYTextAnnotation(text, x, yRightLocation);
                            clickCrossHairs.setTextAnchor(TextAnchor.BOTTOM_LEFT);
                            xyplot.addAnnotation(clickCrossHairs);
                        } else {
                            clickCrossHairs.setText(text);
                            clickCrossHairs.setX(x);
                            clickCrossHairs.setY(yRightLocation);
                        }
                    }
                }
            } else if (e.getTrigger().getClickCount() == 1 && null != clickCrossHairs) {
                for (XYPlot xyplot : subplots) {
                    if (xyplot.removeAnnotation(clickCrossHairs)) {
                        clickCrossHairs = null;
                        titleLegend1.setText(" Time: 0, Price :0.0");
                        break;
                    }
                }
            }
        }
    });
    this.add(chartPanel, null);
    this.strategyData.getCandleDataset().getSeries(0).addChangeListener(this);
}

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

public void initializeVsTime(VariableDoubles parameters, VariableDoubles initialValues, Range timeRange) {

    this.parameters.putAll(parameters);
    this.initialPoint.putAll(initialValues);
    this.lower = (int) timeRange.getLowerBound();
    this.upper = (int) timeRange.getUpperBound();

    this.type = TYPE_VSTIME;
}

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

public void initializeVsTime(VariableDoubles parameters, VariableDoubles initialValues, Range timeRange,
        double stepSize) {

    this.parameters.putAll(parameters);
    this.initialPoint.putAll(initialValues);
    this.lower = (int) timeRange.getLowerBound();
    this.upper = (int) timeRange.getUpperBound();
    this.stepSize = stepSize;
    this.type = TYPE_VSTIME;
}

From source file:net.sf.fspdfs.chartthemes.spring.AegeanChartTheme.java

/**
 *
 *//*  ww  w  .  ja va2 s. c  o m*/
protected JFreeChart createDialChart() throws JRException {

    JRMeterPlot jrPlot = (JRMeterPlot) getPlot();

    // get data for diagrams
    DialPlot dialPlot = new DialPlot();
    if (getDataset() != null) {
        dialPlot.setDataset((ValueDataset) getDataset());
    }
    StandardDialFrame dialFrame = new StandardDialFrame();
    dialFrame.setForegroundPaint(Color.BLACK);
    dialFrame.setBackgroundPaint(Color.BLACK);
    dialFrame.setStroke(new BasicStroke(1f));
    dialPlot.setDialFrame(dialFrame);

    DialBackground db = new DialBackground(ChartThemesConstants.TRANSPARENT_PAINT);
    dialPlot.setBackground(db);
    ScaledDialScale scale = null;
    int dialUnitScale = 1;
    Range range = convertRange(jrPlot.getDataRange());
    if (range != null) {
        double bound = Math.max(Math.abs(range.getUpperBound()), Math.abs(range.getLowerBound()));
        dialUnitScale = ChartThemesUtilities.getScale(bound);

        double lowerBound = ChartThemesUtilities.getTruncatedValue(range.getLowerBound(), dialUnitScale);
        double upperBound = ChartThemesUtilities.getTruncatedValue(range.getUpperBound(), dialUnitScale);

        scale = new ScaledDialScale(lowerBound, upperBound, 210, -240, (upperBound - lowerBound) / 6, 1);
        if ((lowerBound == (int) lowerBound && upperBound == (int) upperBound
                && scale.getMajorTickIncrement() == (int) scale.getMajorTickIncrement()) || dialUnitScale > 1) {
            scale.setTickLabelFormatter(new DecimalFormat("#,##0"));
        } else if (dialUnitScale == 1) {

            scale.setTickLabelFormatter(new DecimalFormat("#,##0.0"));
        } else if (dialUnitScale <= 0) {
            scale.setTickLabelFormatter(new DecimalFormat("#,##0.00"));
        }
    } else {
        scale = new ScaledDialScale();
    }
    scale.setTickRadius(0.9);
    scale.setTickLabelOffset(0.16);
    JRFont tickLabelFont = jrPlot.getTickLabelFont();
    Integer defaultBaseFontSize = (Integer) getDefaultValue(defaultChartPropertiesMap,
            ChartThemesConstants.BASEFONT_SIZE);
    Font themeTickLabelFont = getFont(
            (JRFont) getDefaultValue(defaultPlotPropertiesMap, ChartThemesConstants.PLOT_TICK_LABEL_FONT),
            tickLabelFont, defaultBaseFontSize);
    scale.setTickLabelFont(themeTickLabelFont);
    scale.setMajorTickStroke(new BasicStroke(1f));
    scale.setMinorTickStroke(new BasicStroke(0.7f));
    scale.setMajorTickPaint(Color.BLACK);
    scale.setMinorTickPaint(Color.BLACK);
    scale.setTickLabelsVisible(true);
    scale.setFirstTickLabelVisible(true);
    dialPlot.addScale(0, scale);

    List intervals = jrPlot.getIntervals();
    if (intervals != null && intervals.size() > 0) {
        int size = Math.min(3, intervals.size());

        int colorStep = 0;
        if (size > 3)
            colorStep = 255 / (size - 3);

        for (int i = 0; i < size; i++) {
            JRMeterInterval interval = (JRMeterInterval) intervals.get(i);
            Range intervalRange = convertRange(interval.getDataRange());
            double intervalLowerBound = ChartThemesUtilities.getTruncatedValue(intervalRange.getLowerBound(),
                    dialUnitScale);
            double intervalUpperBound = ChartThemesUtilities.getTruncatedValue(intervalRange.getUpperBound(),
                    dialUnitScale);

            Color color = i < 3 ? (Color) ChartThemesConstants.AEGEAN_INTERVAL_COLORS.get(i)
                    : new Color(255 - colorStep * (i - 3), 0 + colorStep * (i - 3), 0);
            ScaledDialRange dialRange = new ScaledDialRange(intervalLowerBound, intervalUpperBound,
                    interval.getBackgroundColor() == null ? color : interval.getBackgroundColor(), 15f);
            dialRange.setInnerRadius(0.5);
            dialRange.setOuterRadius(0.5);
            dialPlot.addLayer(dialRange);
        }

    }
    JRValueDisplay display = jrPlot.getValueDisplay();

    String displayVisibility = display != null && getChart().hasProperties()
            ? getChart().getPropertiesMap().getProperty(DefaultChartTheme.PROPERTY_DIAL_VALUE_DISPLAY_VISIBLE)
            : "false";

    if (Boolean.valueOf(displayVisibility).booleanValue()) {
        ScaledDialValueIndicator dvi = new ScaledDialValueIndicator(0, dialUnitScale);
        dvi.setBackgroundPaint(ChartThemesConstants.TRANSPARENT_PAINT);
        //         dvi.setFont(JRFontUtil.getAwtFont(jrFont).deriveFont(10f).deriveFont(Font.BOLD));
        dvi.setOutlinePaint(ChartThemesConstants.TRANSPARENT_PAINT);
        dvi.setPaint(Color.WHITE);

        String pattern = display.getMask() != null ? display.getMask() : "#,##0.####";
        if (pattern != null)
            dvi.setNumberFormat(new DecimalFormat(pattern));
        dvi.setRadius(0.15);
        dvi.setValueAnchor(RectangleAnchor.CENTER);
        dvi.setTextAnchor(TextAnchor.CENTER);
        //dvi.setTemplateValue(Double.valueOf(getDialTickValue(dialPlot.getValue(0),dialUnitScale)));
        dialPlot.addLayer(dvi);
    }

    String label = getChart().hasProperties()
            ? getChart().getPropertiesMap().getProperty(DefaultChartTheme.PROPERTY_DIAL_LABEL)
            : null;

    if (label != null) {
        if (dialUnitScale < 0)
            label = new MessageFormat(label)
                    .format(new Object[] { String.valueOf(Math.pow(10, dialUnitScale)) });
        else if (dialUnitScale < 3)
            label = new MessageFormat(label).format(new Object[] { "1" });
        else
            label = new MessageFormat(label)
                    .format(new Object[] { String.valueOf((int) Math.pow(10, dialUnitScale - 2)) });

        JRFont displayFont = jrPlot.getValueDisplay().getFont();
        Font themeDisplayFont = getFont(
                (JRFont) getDefaultValue(defaultPlotPropertiesMap, ChartThemesConstants.PLOT_DISPLAY_FONT),
                displayFont, defaultBaseFontSize);

        String[] textLines = label.split("\\n");
        for (int i = 0; i < textLines.length; i++) {
            DialTextAnnotation dialAnnotation = new DialTextAnnotation(textLines[i]);
            dialAnnotation.setFont(themeDisplayFont);
            dialAnnotation.setPaint(Color.BLACK);
            dialAnnotation.setRadius(Math.sin(Math.PI / 6.0) + i / 10.0);
            dialAnnotation.setAnchor(TextAnchor.CENTER);
            dialPlot.addLayer(dialAnnotation);
        }
    }

    DialPointer needle = new ScaledDialPointer(dialUnitScale, 0.047);

    needle.setVisible(true);
    needle.setRadius(0.7);
    dialPlot.addLayer(needle);

    DialCap cap = new DialCap();
    cap.setRadius(0.05);
    cap.setFillPaint(Color.BLACK);
    cap.setOutlinePaint(ChartThemesConstants.TRANSPARENT_PAINT);
    dialPlot.setCap(cap);

    JFreeChart jfreeChart = new JFreeChart((String) evaluateExpression(getChart().getTitleExpression()), null,
            dialPlot, getChart().getShowLegend() == null ? false : getChart().getShowLegend().booleanValue());

    // Set all the generic options
    configureChart(jfreeChart, getPlot());

    jfreeChart.setBackgroundPaint(ChartThemesConstants.TRANSPARENT_PAINT);
    jfreeChart.setBorderVisible(false);

    return jfreeChart;

}

From source file:de.bund.bfr.knime.pmmlite.views.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<>();
    colorLists = new LinkedHashMap<>();
    shapeLists = new LinkedHashMap<>();

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

        private static final long serialVersionUID = 1L;

        @Override/*ww  w  .  ja  va 2s.  c  o  m*/
        public void mouseReleased(MouseEvent e) {
            ValueAxis domainAxis = ((XYPlot) getChart().getPlot()).getDomainAxis();
            ValueAxis rangeAxis = ((XYPlot) 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);
}