Example usage for org.jfree.chart ChartRenderingInfo getPlotInfo

List of usage examples for org.jfree.chart ChartRenderingInfo getPlotInfo

Introduction

In this page you can find the example usage for org.jfree.chart ChartRenderingInfo getPlotInfo.

Prototype

public PlotRenderingInfo getPlotInfo() 

Source Link

Document

Returns the rendering info for the chart's plot.

Usage

From source file:org.jax.bham.util.JFreeChartUtil.java

/**
 * Convert from a Java2D point to a graph point
 * @param java2DPoint/* w w w .j  a  va  2 s .  co m*/
 *          the java 2D point to convert
 * @param chartPanel
 *          the chart panel to convert
 * @return
 *          the point
 */
public static Point2D java2DPointToGraphPoint(Point2D java2DPoint, ChartPanel chartPanel) {
    JFreeChart chart = chartPanel.getChart();
    ChartRenderingInfo info = chartPanel.getChartRenderingInfo();
    Rectangle2D dataArea = info.getPlotInfo().getDataArea();
    XYPlot xyPlot = chart.getXYPlot();

    double graphX = xyPlot.getDomainAxis().java2DToValue(java2DPoint.getX(), dataArea,
            xyPlot.getDomainAxisEdge());
    double graphY = xyPlot.getRangeAxis().java2DToValue(java2DPoint.getY(), dataArea,
            xyPlot.getRangeAxisEdge());

    return new Point2D.Double(graphX, graphY);
}

From source file:org.jax.maanova.plot.PlotUtil.java

/**
 * Convert from graph coordinates to Java2D coordinates
 * @param plot/*from   w  w  w  .  j a  v a 2 s  .c o m*/
 *          the plot to use
 * @param renderingInfo
 *          the rendering info to use
 * @param graphX
 *          the graph X position to convert
 * @param graphY
 *          the graph Y position to convert
 * @return
 *          the point in Java2D coordinate space
 */
public static Point2D toJava2DCoordinates(XYPlot plot, ChartRenderingInfo renderingInfo, double graphX,
        double graphY) {
    final Rectangle2D dataArea = renderingInfo.getPlotInfo().getDataArea();

    final double java2DX = plot.getDomainAxis().valueToJava2D(graphX, dataArea, plot.getDomainAxisEdge());
    final double java2DY = plot.getRangeAxis().valueToJava2D(graphY, dataArea, plot.getRangeAxisEdge());

    return new Point2D.Double(java2DX, java2DY);
}

From source file:de.bund.bfr.knime.pmm.common.chart.ChartUtilities.java

public static PNGImageContent convertToPNGImageContent(JFreeChart chart, int width, int height) {
    try {//from  w ww  .  jav a 2 s.c o m
        BufferedImage img;

        if (chart != null) {
            ChartRenderingInfo info = new ChartRenderingInfo();

            img = chart.createBufferedImage(width, 5000, info);
            img = chart.createBufferedImage(width,
                    (int) (img.getHeight() - info.getPlotInfo().getDataArea().getHeight() + height));
        } else {
            img = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
        }

        return new PNGImageContent(org.jfree.chart.ChartUtilities.encodeAsPNG(img));
    } catch (IOException e) {
        e.printStackTrace();
    }

    return null;
}

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

/**
 * Subplot or main plot at point//from   w w  w. jav  a  2 s  . co m
 * 
 * @param chart
 * @param info
 * @param mouseX
 * @param mouseY
 * @return
 */
public static XYPlot findXYSubplot(JFreeChart chart, ChartRenderingInfo info, double mouseX, double mouseY) {
    int subplot = info.getPlotInfo().getSubplotIndex(new Point2D.Double(mouseX, mouseY));
    XYPlot plot = null;
    if (subplot != -1) {
        if (chart.getPlot() instanceof CombinedDomainXYPlot)
            plot = (XYPlot) ((CombinedDomainXYPlot) chart.getPlot()).getSubplots().get(subplot);
        else if (chart.getPlot() instanceof CombinedRangeXYPlot)
            plot = (XYPlot) ((CombinedRangeXYPlot) chart.getPlot()).getSubplots().get(subplot);
    }
    if (plot == null && chart.getPlot() instanceof XYPlot)
        plot = (XYPlot) chart.getPlot();
    return plot;
}

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

/**
 * Data width to pixel width on screen//w ww  . j a v a  2s  .c om
 * 
 * @param myChart
 * @param dataWidth width of data
 * @param axis for width calculation
 * @return
 */
public static double calcWidthOnScreen(ChartViewer myChart, double dataWidth, ValueAxis axis,
        RectangleEdge axisEdge) {
    XYPlot plot = (XYPlot) myChart.getChart().getPlot();
    ChartRenderingInfo info = myChart.getRenderingInfo();
    Rectangle2D dataArea = info.getPlotInfo().getDataArea();

    // width 2D
    return axis.lengthToJava2D(dataWidth, dataArea, axisEdge);
}

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

/**
 * Subplot or main plot at point/*from   w  ww  . j  ava 2 s .  c  o m*/
 * 
 * @param chart
 * @param info
 * @param mouseX
 * @param mouseY
 * @return
 */
public static XYPlot findXYSubplot(JFreeChart chart, ChartRenderingInfo info, double mouseX, double mouseY) {
    int subplot = info.getPlotInfo().getSubplotIndex(new Point2D.Double(mouseX, mouseY));
    XYPlot plot = null;
    if (subplot != -1) {
        if (chart.getPlot() instanceof CombinedDomainXYPlot)
            plot = (XYPlot) ((CombinedDomainXYPlot) chart.getPlot()).getSubplots().get(subplot);
        else if (chart.getPlot() instanceof CombinedRangeXYPlot)
            plot = (XYPlot) ((CombinedRangeXYPlot) chart.getPlot()).getSubplots().get(subplot);
    }

    if (plot == null && chart.getPlot() instanceof XYPlot)
        plot = (XYPlot) chart.getPlot();

    return plot;
}

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

/**
 * Data width to pixel width on screen/*  ww  w .j a  v a 2  s  .  c  o m*/
 * 
 * @param myChart
 * @param dataWidth width of data
 * @param axis for width calculation
 * @return
 */
public static double calcWidthOnScreen(ChartPanel myChart, double dataWidth, ValueAxis axis,
        RectangleEdge axisEdge) {
    XYPlot plot = (XYPlot) myChart.getChart().getPlot();
    ChartRenderingInfo info = myChart.getChartRenderingInfo();
    Rectangle2D dataArea = info.getPlotInfo().getDataArea();

    double width2D = axis.lengthToJava2D(dataWidth, dataArea, axisEdge);

    return width2D;
}

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

/**
 * /*from  w  ww  . j a v 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:net.sf.mzmine.chartbasics.ChartLogicsFX.java

/**
 * Translates mouse coordinates to chart coordinates (xy-axis)
 * //ww  w .j  a  v a  2  s.  c o  m
 * @param myChart
 * @param mouseX
 * @param mouseY
 * @return Range as chart coordinates (never null)
 */
public static Point2D mouseXYToPlotXY(ChartViewer myChart, int mouseX, int mouseY) {
    XYPlot plot = null;
    // find plot as parent of axis
    ChartEntity entity = findChartEntity(myChart.getCanvas(), mouseX, mouseY);
    if (entity instanceof AxisEntity) {
        Axis a = ((AxisEntity) entity).getAxis();
        if (a.getPlot() instanceof XYPlot)
            plot = (XYPlot) a.getPlot();
    }

    ChartRenderingInfo info = myChart.getRenderingInfo();
    int subplot = info.getPlotInfo().getSubplotIndex(new Point2D.Double(mouseX, mouseY));
    Rectangle2D dataArea = info.getPlotInfo().getDataArea();
    if (subplot != -1)
        dataArea = info.getPlotInfo().getSubplotInfo(subplot).getDataArea();

    // find subplot or plot
    if (plot == null)
        plot = findXYSubplot(myChart.getChart(), info, mouseX, mouseY);

    // coordinates
    double cx = 0;
    double cy = 0;
    if (plot != null) {
        // find axis
        ValueAxis domainAxis = plot.getDomainAxis();
        ValueAxis rangeAxis = plot.getRangeAxis();
        RectangleEdge domainAxisEdge = plot.getDomainAxisEdge();
        RectangleEdge rangeAxisEdge = plot.getRangeAxisEdge();
        // parent?
        if (domainAxis == null && plot.getParent() != null && plot.getParent() instanceof XYPlot) {
            XYPlot pp = ((XYPlot) plot.getParent());
            domainAxis = pp.getDomainAxis();
            domainAxisEdge = pp.getDomainAxisEdge();
        }
        if (rangeAxis == null && plot.getParent() != null && plot.getParent() instanceof XYPlot) {
            XYPlot pp = ((XYPlot) plot.getParent());
            rangeAxis = pp.getRangeAxis();
            rangeAxisEdge = pp.getRangeAxisEdge();
        }

        if (domainAxis != null)
            cx = domainAxis.java2DToValue(mouseX, dataArea, domainAxisEdge);
        if (rangeAxis != null)
            cy = rangeAxis.java2DToValue(mouseY, dataArea, rangeAxisEdge);
    }
    return new Point2D.Double(cx, cy);
}

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

/**
 * Returns dimensions for limiting factor width or height
 * // w  ww .j  a  v a  2s  .c o  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);
    }
}