Example usage for org.jfree.chart.plot XYPlot getRangeAxisEdge

List of usage examples for org.jfree.chart.plot XYPlot getRangeAxisEdge

Introduction

In this page you can find the example usage for org.jfree.chart.plot XYPlot getRangeAxisEdge.

Prototype

public RectangleEdge getRangeAxisEdge() 

Source Link

Document

Returns the edge for the primary range axis.

Usage

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

/**
 * Convert from a Java2D point to a graph point
 * @param java2DPoint//from   ww  w .  ja v a  2 s  .  com
 *          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:inflor.core.utils.ChartUtils.java

public static Point2D getPlotCoordinates(MouseEvent e, FCSChartPanel panel) {
    Point2D p = panel.translateScreenToJava2D(e.getPoint());
    Rectangle2D plotArea = panel.getScreenDataArea();
    XYPlot plot = panel.getChart().getXYPlot();
    double x = plot.getDomainAxis().java2DToValue(p.getX(), plotArea, plot.getDomainAxisEdge());
    double y = plot.getRangeAxis().java2DToValue(p.getY(), plotArea, plot.getRangeAxisEdge());
    return new Point2D.Double(x, y);
}

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

/**
 * Convert from graph coordinates to Java2D coordinates
 * @param plot//  w ww.j a  v a 2s  .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:net.sf.maltcms.chromaui.charts.tools.ChartTools.java

/**
 *
 * @param plot//from www  .  j  a va 2 s.  c o m
 * @param screenPoint
 * @param screenDataArea
 * @return
 */
public static Point translatePointToImageCoord(XYPlot plot, final Point screenPoint,
        final Rectangle2D screenDataArea) {
    final ValueAxis da = plot.getDomainAxis();
    final ValueAxis ra = plot.getRangeAxis();

    final double x = da.java2DToValue(screenPoint.getX(), screenDataArea, plot.getDomainAxisEdge());
    final double y = ra.java2DToValue(screenPoint.getY(), screenDataArea, plot.getRangeAxisEdge());

    Logger.getLogger(ChartTools.class.getName()).log(Level.INFO, "{0} - {1}", new Object[] { x, y });

    if (x > 0 && y > 0) {
        return new Point((int) x, (int) y);
    }

    //        final double axisXperc = (x - plot.getDomainAxis().getLowerBound())
    //                / (plot.getDomainAxis().getUpperBound() - plot.getDomainAxis().getLowerBound());
    //        final double axisYperc = (y - plot.getRangeAxis().getLowerBound())
    //                / (plot.getRangeAxis().getUpperBound() - plot.getRangeAxis().getLowerBound());
    //
    //        System.out.println(axisXperc + " - " + axisYperc);
    //        final int newX = (int) (axisXperc * this.imageWidth);
    //        final int newY = (int) (axisYperc * this.imageHeight);
    return null;
}

From source file:net.sf.maltcms.common.charts.api.overlay.AbstractChartOverlay.java

/**
 *
 * @param chartPanel//from  ww  w  . j  a va  2s. c o m
 * @param x1
 * @param y1
 * @return
 */
public static AffineTransform getModelToViewTransformXY(ChartPanel chartPanel, double x1, double y1) {
    double zoomX = chartPanel.getScaleX();
    double zoomY = chartPanel.getScaleY();
    Insets insets = chartPanel.getInsets();
    AffineTransform at = getTranslateInstance(insets.left, insets.top);
    at.concatenate(getScaleInstance(zoomX, zoomY));
    Plot plot = chartPanel.getChart().getPlot();
    if (plot instanceof XYPlot) {
        XYPlot xyp = (XYPlot) plot;
        RectangleEdge xAxisLocation = xyp.getDomainAxisEdge();
        RectangleEdge yAxisLocation = xyp.getRangeAxisEdge();
        PlotOrientation orientation = xyp.getOrientation();
        Rectangle2D dataArea = chartPanel.getChartRenderingInfo().getPlotInfo().getDataArea();
        double transX = xyp.getDomainAxis().valueToJava2D(x1, dataArea, xAxisLocation);
        double transY = xyp.getRangeAxis().valueToJava2D(y1, dataArea, yAxisLocation);
        if (orientation == PlotOrientation.HORIZONTAL) {
            double tmp = transX;
            transX = transY;
            transY = tmp;
        }
        at.concatenate(getTranslateInstance(transX, transY));
        return at;
    }
    throw new IllegalArgumentException("Unsupported plot type: " + plot.getClass());
}

From source file:com.sciaps.listener.JFreeChartMouseListener.java

@Override
public void chartMouseClicked(ChartMouseEvent cme) {

    if (cme.getTrigger().isControlDown()) {

        Point2D p = cme.getTrigger().getPoint();
        Rectangle2D plotArea = chartPanel_.getScreenDataArea();
        XYPlot plot = (XYPlot) jFreeChart_.getPlot();
        double chartX = plot.getDomainAxis().java2DToValue(p.getX(), plotArea, plot.getDomainAxisEdge());
        double chartY = plot.getRangeAxis().java2DToValue(p.getY(), plotArea, plot.getRangeAxisEdge());

        if (callback_ != null) {
            callback_.jFreeChartOnClicked(chartX, chartY);
        }/*from  w  w  w . j av a2s  .  com*/
    }
}

From source file:MouseEventListener.java

@Override
public void chartMouseMoved(ChartMouseEvent arg0) {
    Double chartX;//from w  ww. j  a  v a  2 s  . c  om
    Double chartT;

    XYPlot plot = (XYPlot) chartPanel.getChart().getPlot();
    chartX = plot.getRangeAxis().java2DToValue(
            chartPanel.translateScreenToJava2D(arg0.getTrigger().getPoint()).getY(),
            chartPanel.getScreenDataArea(), plot.getRangeAxisEdge());
    chartT = plot.getDomainAxis().java2DToValue(
            chartPanel.translateScreenToJava2D(arg0.getTrigger().getPoint()).getX(),
            chartPanel.getScreenDataArea(), plot.getDomainAxisEdge());

    //simuladorGUI.actualizarPosicionCursor(chartX, chartT);

}

From source file:org.jfree.chart.demo.ScatterPlotDemo3.java

/**
 * Callback method for receiving notification of a mouse click on a chart.
 *
 * @param event  information about the event.
 *//*from  w ww.  jav  a2  s. c om*/
public void chartMouseClicked(ChartMouseEvent event) {
    int x = event.getTrigger().getX();
    int y = event.getTrigger().getY();

    // the following translation takes account of the fact that the chart image may 
    // have been scaled up or down to fit the panel...
    Point2D p = chartPanel.translateScreenToJava2D(new Point(x, y));

    // now convert the Java2D coordinate to axis coordinates...
    XYPlot plot = chartPanel.getChart().getXYPlot();
    Rectangle2D dataArea = chartPanel.getChartRenderingInfo().getPlotInfo().getDataArea();
    double xx = plot.getDomainAxis().java2DToValue(p.getX(), dataArea, plot.getDomainAxisEdge());
    double yy = plot.getRangeAxis().java2DToValue(p.getY(), dataArea, plot.getRangeAxisEdge());

    // just for fun, lets convert the axis coordinates back to component coordinates...
    double xxx = plot.getDomainAxis().valueToJava2D(xx, dataArea, plot.getDomainAxisEdge());
    double yyy = plot.getRangeAxis().valueToJava2D(yy, dataArea, plot.getRangeAxisEdge());

    Point2D p2 = chartPanel.translateJava2DToScreen(new Point2D.Double(xxx, yyy));
    System.out
            .println("Mouse coordinates are (" + x + ", " + y + "), in data space = (" + xx + ", " + yy + ").");
    System.out.println("--> (" + p2.getX() + ", " + p2.getY() + ")");
}

From source file:com.vgi.mafscaling.MafChartPanel.java

public void mousePressed(MouseEvent e) {
    Insets insets = chartPanel.getInsets();
    int x = (int) ((e.getX() - insets.left) / chartPanel.getScaleX());
    int y = (int) ((e.getY() - insets.top) / chartPanel.getScaleY());
    ChartEntity entity = chartPanel.getChartRenderingInfo().getEntityCollection().getEntity(x, y);
    if (entity == null || !(entity instanceof XYItemEntity))
        return;/*  w w  w  . ja va  2 s .  co m*/
    IsMovable = true;
    chartPanel.setCursor(new Cursor(Cursor.HAND_CURSOR));
    xyItemEntity = (XYItemEntity) entity;
    XYPlot plot = chartPanel.getChart().getXYPlot();
    Rectangle2D dataArea = chartPanel.getChartRenderingInfo().getPlotInfo().getDataArea();
    Point2D p = chartPanel.translateScreenToJava2D(e.getPoint());
    initialMovePointY = plot.getRangeAxis().java2DToValue(p.getY(), dataArea, plot.getRangeAxisEdge());
}

From source file:net.sf.maltcms.chromaui.charts.overlay.Peak1DHeatmapOverlay.java

/**
 *
 * @param g2//  w ww. j  av a 2 s.c o m
 * @param chartPanel
 */
@Override
public void paintOverlay(Graphics2D g2, ChartPanel chartPanel) {
    if (isVisible()) {
        Shape savedClip = g2.getClip();
        Rectangle2D dataArea = chartPanel.getScreenDataArea();
        g2.clip(dataArea);
        JFreeChart chart = chartPanel.getChart();
        XYPlot plot = (XYPlot) chart.getPlot();
        ValueAxis xAxis = plot.getDomainAxis();
        RectangleEdge xAxisEdge = plot.getDomainAxisEdge();
        ValueAxis yAxis = plot.getRangeAxis();
        RectangleEdge yAxisEdge = plot.getRangeAxisEdge();
        Color c = g2.getColor();
        Color fillColor = peakAnnotations.getColor();
        if (fillColor == null || fillColor.equals(Color.WHITE)
                || fillColor.equals(new Color(255, 255, 255, 0))) {
            Logger.getLogger(getClass().getName())
                    .info("Peak annotation color was null or white, using color from treatment group!");
            fillColor = peakAnnotations.getChromatogram().getTreatmentGroup().getColor();
        }
        g2.setColor(ChartCustomizer.withAlpha(fillColor, 0.5f));
        for (IPeakAnnotationDescriptor descr : peakAnnotations.getMembers()) {
            double x = descr.getApexTime();
            double xx = xAxis.valueToJava2D(x, dataArea, xAxisEdge);
            double width = xAxis.valueToJava2D(1, dataArea, xAxisEdge);
            double mzRange = (descr.getMassValues()[descr.getMassValues().length - 1]
                    - descr.getMassValues()[0]);
            double y = mzRange / 2.0d;
            double yy = yAxis.valueToJava2D(y, dataArea, yAxisEdge);
            double height = yAxis.valueToJava2D(mzRange, dataArea, yAxisEdge);
            AffineTransform at = AffineTransform.getTranslateInstance(xx, yy);
            at.concatenate(AffineTransform.getTranslateInstance(-x, -y));
            Rectangle2D.Double r = new Rectangle2D.Double(xx - (width / 2.0d), yy, width, height);
            g2.fill(at.createTransformedShape(r));
        }
        g2.setColor(c);
        g2.setClip(savedClip);
    }
}