Example usage for org.jfree.chart.plot Pannable panRangeAxes

List of usage examples for org.jfree.chart.plot Pannable panRangeAxes

Introduction

In this page you can find the example usage for org.jfree.chart.plot Pannable panRangeAxes.

Prototype

public void panRangeAxes(double percent, PlotRenderingInfo info, Point2D source);

Source Link

Document

Pans the range axes by the specified percentage.

Usage

From source file:de.hs.mannheim.modUro.controller.diagram.fx.interaction.PanHandlerFX.java

/**
 * Handles a mouse dragged event by calculating the distance panned and
 * updating the axes accordingly.//from   w ww . j a  va 2  s . c  o  m
 * 
 * @param canvas  the JavaFX canvas (<code>null</code> not permitted).
 * @param e  the mouse event (<code>null</code> not permitted).
 */
public void handleMouseDragged(ChartCanvas canvas, MouseEvent e) {
    if (this.panLast == null) {
        //handle panning if we have a start point else unregister
        canvas.clearLiveHandler();
        return;
    }

    JFreeChart chart = canvas.getChart();
    double dx = e.getX() - this.panLast.getX();
    double dy = e.getY() - this.panLast.getY();
    if (dx == 0.0 && dy == 0.0) {
        return;
    }
    double wPercent = -dx / this.panW;
    double hPercent = dy / this.panH;
    boolean old = chart.getPlot().isNotify();
    chart.getPlot().setNotify(false);
    Pannable p = (Pannable) chart.getPlot();
    PlotRenderingInfo info = canvas.getRenderingInfo().getPlotInfo();
    if (p.getOrientation().isVertical()) {
        p.panDomainAxes(wPercent, info, this.panLast);
        p.panRangeAxes(hPercent, info, this.panLast);
    } else {
        p.panDomainAxes(hPercent, info, this.panLast);
        p.panRangeAxes(wPercent, info, this.panLast);
    }
    this.panLast = new Point2D.Double(e.getX(), e.getY());
    chart.getPlot().setNotify(old);
}

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

@Override
public void mouseDragged(MouseEvent e) {
    // when not allowed to zoom / select, return
    if (blockSelectionOrZoom) {
        return;/*from  w  ww .  j  a v a2  s.c  o  m*/
    }
    // if the popup menu has already been triggered, then ignore dragging...
    if (getChartFieldValueByName("popup") != null
            && ((JPopupMenu) getChartFieldValueByName("popup")).isShowing()) {
        return;
    }

    // handle panning if we have a start point
    if (getChartFieldValueByName("panLast") != null) {
        double dx = e.getX() - ((Point) getChartFieldValueByName("panLast")).getX();
        double dy = e.getY() - ((Point) getChartFieldValueByName("panLast")).getY();
        if (dx == 0.0 && dy == 0.0) {
            return;
        }
        double wPercent = -dx / ((Double) getChartFieldValueByName("panW"));
        double hPercent = dy / ((Double) getChartFieldValueByName("panH"));
        boolean old = getChart().getPlot().isNotify();
        getChart().getPlot().setNotify(false);
        Pannable p = (Pannable) getChart().getPlot();
        if (p.getOrientation() == PlotOrientation.VERTICAL) {
            p.panDomainAxes(wPercent, getChartRenderingInfo().getPlotInfo(),
                    (Point) getChartFieldValueByName("panLast"));
            p.panRangeAxes(hPercent, getChartRenderingInfo().getPlotInfo(),
                    (Point) getChartFieldValueByName("panLast"));
        } else {
            p.panDomainAxes(hPercent, getChartRenderingInfo().getPlotInfo(),
                    (Point) getChartFieldValueByName("panLast"));
            p.panRangeAxes(wPercent, getChartRenderingInfo().getPlotInfo(),
                    (Point) getChartFieldValueByName("panLast"));
        }
        setChartFieldValue((getChartFieldByName("panLast")), e.getPoint());
        getChart().getPlot().setNotify(old);
        return;
    }

    // if no initial zoom point was set, ignore dragging...
    if (getChartFieldValueByName("zoomPoint") == null) {
        return;
    }
    Graphics2D g2 = (Graphics2D) getGraphics();

    // erase the previous zoom rectangle (if any). We only need to do
    // this is we are using XOR mode, which we do when we're not using
    // the buffer (if there is a buffer, then at the end of this method we
    // just trigger a repaint)
    if (!(Boolean) getChartFieldValueByName("useBuffer")) {
        drawZoomRectangle(g2, true);
    }

    boolean hZoom = false;
    boolean vZoom = false;
    if ((PlotOrientation) getChartFieldValueByName("orientation") == PlotOrientation.HORIZONTAL) {
        hZoom = (Boolean) getChartFieldValueByName("rangeZoomable");
        vZoom = (Boolean) getChartFieldValueByName("domainZoomable");
    } else {
        hZoom = (Boolean) getChartFieldValueByName("domainZoomable");
        vZoom = (Boolean) getChartFieldValueByName("rangeZoomable");
    }
    Point2D zoomPoint = (Point2D) getChartFieldValueByName("zoomPoint");
    Rectangle2D scaledDataArea = getScreenDataArea((int) zoomPoint.getX(), (int) zoomPoint.getY());
    if (hZoom && vZoom) {
        // selected rectangle shouldn't extend outside the data area...
        double xmax = Math.min(e.getX(), scaledDataArea.getMaxX());
        double ymax = Math.min(e.getY(), scaledDataArea.getMaxY());
        setChartFieldValue(getChartFieldByName("zoomRectangle"), new Rectangle2D.Double(zoomPoint.getX(),
                zoomPoint.getY(), xmax - zoomPoint.getX(), ymax - zoomPoint.getY()));
    } else if (hZoom) {
        double xmax = Math.min(e.getX(), scaledDataArea.getMaxX());
        setChartFieldValue(getChartFieldByName("zoomRectangle"), new Rectangle2D.Double(zoomPoint.getX(),
                scaledDataArea.getMinY(), xmax - zoomPoint.getX(), scaledDataArea.getHeight()));
    } else if (vZoom) {
        double ymax = Math.min(e.getY(), scaledDataArea.getMaxY());
        setChartFieldValue(getChartFieldByName("zoomRectangle"),
                new Rectangle2D.Double(scaledDataArea.getMinX(), zoomPoint.getY(), scaledDataArea.getWidth(),
                        ymax - zoomPoint.getY()));
    }

    // Draw the new zoom rectangle...
    if ((Boolean) getChartFieldValueByName("useBuffer")) {
        repaint();
    } else {
        // with no buffer, we use XOR to draw the rectangle "over" the
        // chart...
        drawZoomRectangle(g2, true);
    }
    g2.dispose();

}