Example usage for org.jfree.chart.axis ValueAxis getRange

List of usage examples for org.jfree.chart.axis ValueAxis getRange

Introduction

In this page you can find the example usage for org.jfree.chart.axis ValueAxis getRange.

Prototype

public Range getRange() 

Source Link

Document

Returns the range for the axis.

Usage

From source file:net.commerce.zocalo.freechart.ChartGenerator.java

private static ValueAxis setBoundsLoosely(JFreeChart chart) {
    ValueAxis rangeAxis = setLowerBoundsZero(chart);
    double highY = rangeAxis.getRange().getUpperBound();
    double top = Math.min((Math.ceil(highY / 10) + 1) * 10, 100);
    rangeAxis.setUpperBound(top);//from   w  ww.j  a  v a2  s . c o m
    return rangeAxis;
}

From source file:org.lmn.fc.frameworks.starbase.plugins.observatory.ui.tabs.charts.ChartUIHelper.java

/***********************************************************************************************
 * Update the Domain Slider Crosshair./*from  ww  w  .j av  a2  s.  c om*/
 *
 * @param chartui
 * @param movingindex
 * @param domainstart
 * @param domainend
 * @param movingslidervalue
 * @param sliderminimum
 * @param slidermaximum     *
 * @param debug
 *
 * @return double
 */

public static double updateDomainCrosshairForDomainSlider(final ChartUIComponentPlugin chartui,
        final int movingindex, final int domainstart, final int domainend, final int movingslidervalue,
        final int sliderminimum, final int slidermaximum, final boolean debug) {
    final String SOURCE = "ChartHelper.updateDomainCrosshairForDomainSlider() ";
    final double dblDomainCrosshairXYPlot;

    if ((chartui.getChartPanel() != null) && (chartui.getChartPanel().getChart() != null)
            && (chartui.getChartPanel().getChart().getPlot() != null)) {
        final double dblDomainCrosshair;
        final double dblPositionFraction;
        final XYPlot plot;
        final ValueAxis domainAxis;
        final Range range;

        plot = (XYPlot) chartui.getChartPanel().getChart().getPlot();
        domainAxis = plot.getDomainAxis();
        range = domainAxis.getRange();

        if (movingindex == INDEX_LEFT) {
            // Trying to Move Left, but are we already at the Left Extent?
            if (movingslidervalue <= sliderminimum) {
                dblDomainCrosshair = sliderminimum;

                dblDomainCrosshairXYPlot = domainAxis.getLowerBound();

                FrameworkSingletons.LOGGER.debug(debug,
                        SOURCE + "At Left Extent, cannot move Left Thumb to the Left" + "  [crosshair.domain="
                                + dblDomainCrosshair + "] [crosshair.xyplot" + dblDomainCrosshairXYPlot + "]");
            }
            // It is Ok to move further Left than the current setting of domainstart,
            // but we musn't draw a crosshair
            else if (movingslidervalue < domainstart) {
                // Do not draw a crosshair, set to lower bound?
                dblDomainCrosshair = sliderminimum;

                dblDomainCrosshairXYPlot = domainAxis.getLowerBound();

                FrameworkSingletons.LOGGER.debug(debug,
                        SOURCE + "Moving Left Thumb to the Left beyond current DomainStart"
                                + "  [crosshair.domain=" + dblDomainCrosshair + "] [crosshair.xyplot"
                                + dblDomainCrosshairXYPlot + "]");
            } else {
                // Try to Move Right, the slider won't be able to move past the Right Thumb
                dblDomainCrosshair = movingslidervalue;

                dblPositionFraction = (double) (movingslidervalue - domainstart)
                        / (double) (domainend - domainstart);
                dblDomainCrosshairXYPlot = domainAxis.getLowerBound()
                        + (dblPositionFraction * range.getLength());

                FrameworkSingletons.LOGGER.debug(debug,
                        SOURCE + "Moving Left Thumb to the Right" + "  [crosshair.domain=" + dblDomainCrosshair
                                + "] [crosshair.xyplot" + dblDomainCrosshairXYPlot + "]");
            }
        } else if (movingindex == INDEX_RIGHT) {
            //  Trying to Move Right, but are we already at the Right Extent?
            if (movingslidervalue >= slidermaximum) {
                dblDomainCrosshair = slidermaximum;

                dblDomainCrosshairXYPlot = domainAxis.getLowerBound() + range.getLength();

                FrameworkSingletons.LOGGER.debug(debug,
                        SOURCE + "At Right Extent, cannot move Right Thumb to the Right"
                                + "  [crosshair.domain=" + dblDomainCrosshair + "] [crosshair.xyplot"
                                + dblDomainCrosshairXYPlot + "]");
            }
            // It is Ok to move further Right than the current setting of domainend
            // but we musn't draw a crosshair
            else if (movingslidervalue > domainend) {
                // Do not draw a crosshair, set to upper bound?
                dblDomainCrosshair = slidermaximum;

                dblDomainCrosshairXYPlot = domainAxis.getLowerBound() + range.getLength();

                FrameworkSingletons.LOGGER.debug(debug,
                        SOURCE + "Moving Right Thumb to the Right beyond current DomainEnd"
                                + "  [crosshair.domain=" + dblDomainCrosshair + "] [crosshair.xyplot"
                                + dblDomainCrosshairXYPlot + "]");
            } else {
                // Try to Move Left, the slider won't be able to move past the Left Thumb
                dblDomainCrosshair = movingslidervalue;

                dblPositionFraction = (double) (movingslidervalue - domainstart)
                        / (double) (domainend - domainstart);
                dblDomainCrosshairXYPlot = domainAxis.getLowerBound()
                        + (dblPositionFraction * range.getLength());

                FrameworkSingletons.LOGGER.debug(debug,
                        SOURCE + "Moving Right Thumb to the Left" + "  [crosshair.domain=" + dblDomainCrosshair
                                + "] [crosshair.xyplot" + dblDomainCrosshairXYPlot + "]");
            }
        } else {
            // Do nothing, an Error
            dblDomainCrosshair = sliderminimum;
            dblDomainCrosshairXYPlot = domainAxis.getLowerBound();

            FrameworkSingletons.LOGGER.debug(debug, SOURCE + "Invalid Thumb index" + "  [crosshair.domain="
                    + dblDomainCrosshair + "] [crosshair.xyplot" + dblDomainCrosshairXYPlot + "]");
        }

        chartui.setDomainCrosshair(dblDomainCrosshair);
        plot.setDomainCrosshairValue(dblDomainCrosshairXYPlot);
    } else {
        chartui.setDomainCrosshair(sliderminimum);
        dblDomainCrosshairXYPlot = Double.MIN_VALUE;

        FrameworkSingletons.LOGGER.debug(debug,
                SOURCE + "There is no Chart, so cannot update Domain Slider Crosshair" + "  [crosshair.domain="
                        + sliderminimum + "] [crosshair.xyplot" + dblDomainCrosshairXYPlot + "]");
    }

    return (dblDomainCrosshairXYPlot);
}

From source file:net.sf.mzmine.chartbasics.ChartLogicsFX.java

/**
 * Calculates the size of a chart for a given fixed plot width Domain and Range axes need to share
 * the same unit (e.g. mm)/*  w  ww  .  java  2s . c  om*/
 * 
 * @param chart
 * @param plotWidth
 * @return
 */
public static Dimension calcSizeForPlotWidth(ChartViewer myChart, double plotWidth, int iterations) {
    // ranges
    XYPlot plot = (XYPlot) myChart.getChart().getPlot();
    ValueAxis domainAxis = plot.getDomainAxis();
    Range x = domainAxis.getRange();
    ValueAxis rangeAxis = plot.getRangeAxis();
    Range y = rangeAxis.getRange();

    // plot height is fixed
    double plotHeight = plotWidth / x.getLength() * y.getLength();
    return calcSizeForPlotSize(myChart, plotWidth, plotHeight, iterations);
}

From source file:net.sf.mzmine.chartbasics.ChartLogics.java

/**
 * Calculates the size of a chart for a given fixed plot width Domain and Range axes need to share
 * the same unit (e.g. mm)//  w  w  w . j a  v  a2s.c o m
 * 
 * @param chart
 * @param plotWidth
 * @return
 */
public static Dimension calcSizeForPlotWidth(ChartPanel myChart, double plotWidth, int iterations) {
    // ranges
    XYPlot plot = (XYPlot) myChart.getChart().getPlot();
    ValueAxis domainAxis = plot.getDomainAxis();
    Range x = domainAxis.getRange();
    ValueAxis rangeAxis = plot.getRangeAxis();
    Range y = rangeAxis.getRange();

    // plot height is fixed
    double plotHeight = plotWidth / x.getLength() * y.getLength();
    return calcSizeForPlotSize(myChart, plotWidth, plotHeight, iterations);
}

From source file:net.sf.mzmine.chartbasics.ChartLogicsFX.java

/**
 * /*from   w  ww . j av a  2 s . c  o m*/
 * Domain and Range axes need to share the same unit (e.g. mm)
 * 
 * @param myChart
 * @return
 */
public static double calcWidthToHeight(ChartViewer myChart, double chartHeight) {
    makeChartResizable(myChart);

    myChart.getCanvas().draw();

    XYPlot plot = (XYPlot) myChart.getChart().getPlot();
    ChartRenderingInfo info = myChart.getRenderingInfo();
    Rectangle2D dataArea = info.getPlotInfo().getDataArea();
    Rectangle2D chartArea = info.getChartArea();

    // calc title space: will be added later to the right plot size
    double titleWidth = chartArea.getWidth() - dataArea.getWidth();
    double titleHeight = chartArea.getHeight() - dataArea.getHeight();

    // calc right plot size with axis dim.
    // real plot width is given by factor;
    double realPH = chartHeight - titleHeight;

    // ranges
    ValueAxis domainAxis = plot.getDomainAxis();
    org.jfree.data.Range x = domainAxis.getRange();
    ValueAxis rangeAxis = plot.getRangeAxis();
    org.jfree.data.Range y = rangeAxis.getRange();

    // real plot height can be calculated by
    double realPW = realPH / y.getLength() * x.getLength();

    double width = realPW + titleWidth;

    return width;
}

From source file:org.lmn.fc.frameworks.starbase.plugins.observatory.ui.tabs.charts.ChartUIHelper.java

/***********************************************************************************************
 * Draw the Chart Crosshair values on the XYPlot if possible.
 * Used by refreshChart().// w  w  w . j  a  va2s .  c o m
 * This should be followed by fireChartChanged() when all updates are complete.
 *
 * @param chartui
 * @param debug
 */

public static void drawChartCrosshairsOnXYPlot(final ChartUIComponentPlugin chartui, final boolean debug) {
    final String SOURCE = "ChartHelper.drawChartCrosshairsOnXYPlot() ";

    // RangeCrosshair
    if ((chartui != null) && (chartui.getRangeCrosshair() > ChartUIComponentPlugin.RANGE_MIN)
            && (chartui.getChartPanel() != null) && (chartui.getChartPanel().getChart() != null)
            && (chartui.getChartPanel().getChart().getXYPlot() != null)) {
        final XYPlot plot;
        final ValueAxis rangeAxis;
        final Range range;
        final double dblPositionFraction;
        final double dblRangeCrosshairXYPlot;

        plot = (XYPlot) chartui.getChartPanel().getChart().getPlot();
        rangeAxis = plot.getRangeAxis();
        range = rangeAxis.getRange();

        dblPositionFraction = (chartui.getRangeCrosshair() - ChartUIComponentPlugin.RANGE_MIN)
                / (double) (ChartUIComponentPlugin.RANGE_MAX - ChartUIComponentPlugin.RANGE_MIN);
        dblRangeCrosshairXYPlot = rangeAxis.getLowerBound() + (dblPositionFraction * range.getLength());

        FrameworkSingletons.LOGGER.debug(debug,
                SOURCE + "Draw Range Crosshair on XYPlot [crosshair.range=" + chartui.getRangeCrosshair()
                        + "] [crosshair.xyplot=" + dblRangeCrosshairXYPlot + "] [range.min="
                        + ChartUIComponentPlugin.RANGE_MIN + "] [range.max=" + ChartUIComponentPlugin.RANGE_MAX
                        + "]");

        plot.setRangeCrosshairValue(dblRangeCrosshairXYPlot);
    }

    // DomainCrosshair
    if ((chartui != null) && (chartui.getDomainCrosshair() > ChartUIComponentPlugin.DOMAIN_MIN)
            && (chartui.getChartPanel() != null) && (chartui.getChartPanel().getChart() != null)
            && (chartui.getChartPanel().getChart().getXYPlot() != null)) {
        final XYPlot plot;
        final ValueAxis domainAxis;
        final Range range;
        final double dblPositionFraction;
        final double dblDomainCrosshairXYPlot;

        plot = (XYPlot) chartui.getChartPanel().getChart().getPlot();
        domainAxis = plot.getDomainAxis();
        range = domainAxis.getRange();

        // ToDo WARNING! Needs to be the same as for the slider??
        dblPositionFraction = (chartui.getDomainCrosshair()
                - ChartUIComponentPlugin.OFFSET_CONTROL_COARSE_MINIMUM)
                / (double) (ChartUIComponentPlugin.OFFSET_CONTROL_COARSE_MAXIMUM
                        - ChartUIComponentPlugin.OFFSET_CONTROL_COARSE_MINIMUM);
        //            dblPositionFraction = (chartui.getDomainCrosshair() - ChartUIComponentPlugin.DOMAIN_MIN) / (double)(ChartUIComponentPlugin.DOMAIN_MAX - ChartUIComponentPlugin.DOMAIN_MIN);
        dblDomainCrosshairXYPlot = domainAxis.getLowerBound() + (dblPositionFraction * range.getLength());

        FrameworkSingletons.LOGGER.debug(debug,
                SOURCE + "Draw Domain Crosshair on XYPlot [crosshair.domain=" + chartui.getDomainCrosshair()
                        + "] [crosshair.xyplot=" + dblDomainCrosshairXYPlot + "] [domain.min="
                        + ChartUIComponentPlugin.OFFSET_CONTROL_COARSE_MINIMUM + "] [domain.max="
                        + ChartUIComponentPlugin.OFFSET_CONTROL_COARSE_MAXIMUM + "]");

        //            LOGGER.debug(debug,
        //                         SOURCE + "Draw Domain Crosshair on XYPlot [crosshair.domain=" + chartui.getDomainCrosshair()
        //                                + "] [crosshair.xyplot=" + dblDomainCrosshairXYPlot
        //                                + "] [domain.min=" + ChartUIComponentPlugin.DOMAIN_MIN
        //                                + "] [domain.max=" + ChartUIComponentPlugin.DOMAIN_MAX
        //                                + "]");
        //
        plot.setDomainCrosshairValue(dblDomainCrosshairXYPlot);
    }
}

From source file:net.sf.mzmine.chartbasics.ChartLogics.java

/**
 * /*from www  .j  a  v a2s .  co  m*/
 * Domain and Range axes need to share the same unit (e.g. mm)
 * 
 * @param myChart
 * @return
 */
public static double calcWidthToHeight(ChartPanel myChart, double chartHeight) {
    makeChartResizable(myChart);
    // paint on a ghost panel
    JPanel parent = (JPanel) myChart.getParent();
    JPanel p = new JPanel();
    p.removeAll();
    p.add(myChart, BorderLayout.CENTER);
    p.setBounds(myChart.getBounds());
    myChart.paintImmediately(myChart.getBounds());
    p.removeAll();
    parent.add(myChart);

    XYPlot plot = (XYPlot) myChart.getChart().getPlot();
    ChartRenderingInfo info = myChart.getChartRenderingInfo();
    Rectangle2D dataArea = info.getPlotInfo().getDataArea();
    Rectangle2D chartArea = info.getChartArea();

    // calc title space: will be added later to the right plot size
    double titleWidth = chartArea.getWidth() - dataArea.getWidth();
    double titleHeight = chartArea.getHeight() - dataArea.getHeight();

    // calc right plot size with axis dim.
    // real plot width is given by factor;
    double realPH = chartHeight - titleHeight;

    // ranges
    ValueAxis domainAxis = plot.getDomainAxis();
    org.jfree.data.Range x = domainAxis.getRange();
    ValueAxis rangeAxis = plot.getRangeAxis();
    org.jfree.data.Range y = rangeAxis.getRange();

    // real plot height can be calculated by
    double realPW = realPH / y.getLength() * x.getLength();

    double width = realPW + titleWidth;

    return width;
}

From source file:net.sf.mzmine.chartbasics.ChartLogicsFX.java

/**
 * Returns dimensions for limiting factor width or height
 * //  w w  w . j av  a2 s.co  m
 * @param myChart
 * @return
 */
public static Dimension calcMaxSize(ChartViewer myChart, double chartWidth, double chartHeight) {
    makeChartResizable(myChart);
    // paint on a ghost panel
    myChart.getCanvas().draw();

    XYPlot plot = (XYPlot) myChart.getChart().getPlot();
    ChartRenderingInfo info = myChart.getRenderingInfo();
    Rectangle2D dataArea = info.getPlotInfo().getDataArea();
    Rectangle2D chartArea = info.getChartArea();

    // calc title space: will be added later to the right plot size
    double titleWidth = chartArea.getWidth() - dataArea.getWidth();
    double titleHeight = chartArea.getHeight() - dataArea.getHeight();

    // calculatig width for max height

    // calc right plot size with axis dim.
    // real plot width is given by factor;
    double realPH = chartHeight - titleHeight;

    // ranges
    ValueAxis domainAxis = plot.getDomainAxis();
    org.jfree.data.Range x = domainAxis.getRange();
    ValueAxis rangeAxis = plot.getRangeAxis();
    org.jfree.data.Range y = rangeAxis.getRange();

    // real plot height can be calculated by
    double realPW = realPH / y.getLength() * x.getLength();

    double width = realPW + titleWidth;
    // if width is higher than given chartWidth then calc height for chartWidth
    if (width > chartWidth) {
        // calc right plot size with axis dim.
        // real plot width is given by factor;
        realPW = chartWidth - titleWidth;

        // real plot height can be calculated by
        realPH = realPW / x.getLength() * y.getLength();

        double height = realPH + titleHeight;
        // Return size
        return new Dimension((int) chartWidth, (int) height);
    } else {
        // Return size
        return new Dimension((int) width, (int) chartHeight);
    }
}

From source file:net.sf.mzmine.chartbasics.ChartLogics.java

/**
 * Returns dimensions for limiting factor width or height
 * /*from   ww w.j av a 2 s. co  m*/
 * @param myChart
 * @return
 */
public static Dimension calcMaxSize(ChartPanel myChart, double chartWidth, double chartHeight) {
    makeChartResizable(myChart);
    // paint on a ghost panel
    JPanel parent = (JPanel) myChart.getParent();
    JPanel p = new JPanel();
    p.removeAll();
    p.add(myChart, BorderLayout.CENTER);
    p.setBounds(myChart.getBounds());
    myChart.paintImmediately(myChart.getBounds());
    p.removeAll();
    parent.add(myChart);

    XYPlot plot = (XYPlot) myChart.getChart().getPlot();
    ChartRenderingInfo info = myChart.getChartRenderingInfo();
    Rectangle2D dataArea = info.getPlotInfo().getDataArea();
    Rectangle2D chartArea = info.getChartArea();

    // calc title space: will be added later to the right plot size
    double titleWidth = chartArea.getWidth() - dataArea.getWidth();
    double titleHeight = chartArea.getHeight() - dataArea.getHeight();

    // calculatig width for max height

    // calc right plot size with axis dim.
    // real plot width is given by factor;
    double realPH = chartHeight - titleHeight;

    // ranges
    ValueAxis domainAxis = plot.getDomainAxis();
    org.jfree.data.Range x = domainAxis.getRange();
    ValueAxis rangeAxis = plot.getRangeAxis();
    org.jfree.data.Range y = rangeAxis.getRange();

    // real plot height can be calculated by
    double realPW = realPH / y.getLength() * x.getLength();

    double width = realPW + titleWidth;
    // if width is higher than given chartWidth then calc height for chartWidth
    if (width > chartWidth) {
        // calc right plot size with axis dim.
        // real plot width is given by factor;
        realPW = chartWidth - titleWidth;

        // real plot height can be calculated by
        realPH = realPW / x.getLength() * y.getLength();

        double height = realPH + titleHeight;
        // Return size
        return new Dimension((int) chartWidth, (int) height);
    } else {
        // Return size
        return new Dimension((int) width, (int) chartHeight);
    }
}

From source file:net.sf.mzmine.chartbasics.ChartLogicsFX.java

/**
 * calculates the correct height with multiple iterations Domain and Range axes need to share the
 * same unit (e.g. mm)//from  w ww. jav  a 2  s.  c om
 * 
 * @param myChart
 * @param dataWidth width of data
 * @param axis for width calculation
 * @return
 */
public static double calcHeightToWidth(ChartViewer myChart, double chartWidth, double estimatedHeight,
        int iterations) {
    // if(myChart.getChartRenderingInfo()==null ||
    // myChart.getChartRenderingInfo().getChartArea()==null ||
    // myChart.getChartRenderingInfo().getChartArea().getWidth()==0)
    // result
    double height = estimatedHeight;
    double lastH = height;

    makeChartResizable(myChart);

    try {
        for (int i = 0; i < iterations; i++) {
            // paint on ghost panel with estimated height (if copy panel==true)
            myChart.getCanvas().setWidth((int) chartWidth);
            myChart.getCanvas().setHeight((int) estimatedHeight);
            myChart.getCanvas().draw();

            XYPlot plot = (XYPlot) myChart.getChart().getPlot();
            ChartRenderingInfo info = myChart.getRenderingInfo();
            Rectangle2D dataArea = info.getPlotInfo().getDataArea();
            Rectangle2D chartArea = info.getChartArea();

            // calc title space: will be added later to the right plot size
            double titleWidth = chartArea.getWidth() - dataArea.getWidth();
            double titleHeight = chartArea.getHeight() - dataArea.getHeight();

            // calc right plot size with axis dim.
            // real plot width is given by factor;
            double realPW = chartWidth - titleWidth;

            // ranges
            ValueAxis domainAxis = plot.getDomainAxis();
            org.jfree.data.Range x = domainAxis.getRange();
            ValueAxis rangeAxis = plot.getRangeAxis();
            org.jfree.data.Range y = rangeAxis.getRange();

            // real plot height can be calculated by
            double realPH = realPW / x.getLength() * y.getLength();

            // the real height
            height = realPH + titleHeight;

            // for next iteration
            estimatedHeight = height;
            if ((int) lastH == (int) height)
                break;
            else
                lastH = height;
        }
    } catch (Exception ex) {
        ex.printStackTrace();
    }

    return height;
}