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

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

Introduction

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

Prototype

public RectangleEdge getDomainAxisEdge() 

Source Link

Document

Returns the edge for the primary domain axis (taking into account the plot's orientation).

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  . c o  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: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.  java2  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:net.sf.maltcms.chromaui.charts.tools.ChartTools.java

/**
 *
 * @param plot//from  w  ww.ja  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 w w  w .  j a va  2 s.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  . ja  va 2 s . c o  m
    }
}

From source file:com.rapidminer.gui.new_plotter.engine.jfreechart.MultiAxesCrosshairOverlay.java

@Override
public void paintOverlay(Graphics2D g2, ChartPanel chartPanel) {
    Shape savedClip = g2.getClip();
    Rectangle2D dataArea = chartPanel.getScreenDataArea();
    g2.clip(dataArea);/*from   w  w w .  j  a  v a 2 s . c o m*/
    JFreeChart chart = chartPanel.getChart();
    XYPlot plot = (XYPlot) chart.getPlot();
    ValueAxis xAxis = plot.getDomainAxis();
    RectangleEdge xAxisEdge = plot.getDomainAxisEdge();
    Iterator iterator = this.getDomainCrosshairs().iterator();
    while (iterator.hasNext()) {
        Crosshair ch = (Crosshair) iterator.next();
        if (ch.isVisible()) {
            double x = ch.getValue();
            double xx = xAxis.valueToJava2D(x, dataArea, xAxisEdge);
            if (plot.getOrientation() == PlotOrientation.VERTICAL) {
                drawVerticalCrosshair(g2, dataArea, xx, ch);
            } else {
                drawHorizontalCrosshair(g2, dataArea, xx, ch);
            }
        }
    }

    int rangeAxisIdx = 0;
    for (ArrayList<Crosshair> crosshairsForRange : rangeCrosshairs) {
        ValueAxis yAxis = plot.getRangeAxis(rangeAxisIdx);
        RectangleEdge yAxisEdge = plot.getRangeAxisEdge(rangeAxisIdx);
        iterator = crosshairsForRange.iterator();
        while (iterator.hasNext()) {
            Crosshair ch = (Crosshair) iterator.next();
            if (ch.isVisible()) {
                double y = ch.getValue();
                double yy = yAxis.valueToJava2D(y, dataArea, yAxisEdge);
                if (plot.getOrientation() == PlotOrientation.VERTICAL) {
                    drawHorizontalCrosshair(g2, dataArea, yy, ch);
                } else {
                    drawVerticalCrosshair(g2, dataArea, yy, ch);
                }
            }
        }
        g2.setClip(savedClip);
        ++rangeAxisIdx;
    }
}

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  w w  .  j av  a  2  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:org.jfree.chart.demo.MouseListenerDemo4.java

public void chartMouseClicked(ChartMouseEvent chartmouseevent) {
    int i = chartmouseevent.getTrigger().getX();
    int j = chartmouseevent.getTrigger().getY();
    System.out.println("x = " + i + ", y = " + j);
    Point2D point2d = chartPanel.translateScreenToJava2D(new Point(i, j));
    XYPlot xyplot = (XYPlot) chart.getPlot();
    ChartRenderingInfo chartrenderinginfo = chartPanel.getChartRenderingInfo();
    java.awt.geom.Rectangle2D rectangle2d = chartrenderinginfo.getPlotInfo().getDataArea();
    ValueAxis valueaxis = xyplot.getDomainAxis();
    org.jfree.ui.RectangleEdge rectangleedge = xyplot.getDomainAxisEdge();
    ValueAxis valueaxis1 = xyplot.getRangeAxis();
    org.jfree.ui.RectangleEdge rectangleedge1 = xyplot.getRangeAxisEdge();
    double d = valueaxis.java2DToValue(point2d.getX(), rectangle2d, rectangleedge);
    double d1 = valueaxis1.java2DToValue(point2d.getY(), rectangle2d, rectangleedge1);
    System.out.println("Chart: x = " + d + ", y = " + d1);
}

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

/**
 *
 * @param g2//from   ww  w.j  a v  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);
    }
}