Search in sources :

Example 1 with Pannable

use of org.jfree.chart.plot.Pannable in project n2a by frothga.

the class ChartPanelDrag method mousePressed.

@Override
public void mousePressed(MouseEvent e) {
    if (chart == null)
        return;
    org.jfree.chart.plot.Plot plot = chart.getPlot();
    if (e.getButton() == MouseEvent.BUTTON1) {
        // can we pan this plot?
        if (plot instanceof Pannable) {
            Pannable pannable = (Pannable) plot;
            if (pannable.isDomainPannable() || pannable.isRangePannable()) {
                Rectangle2D screenDataArea = getScreenDataArea(e.getX(), e.getY());
                if (screenDataArea != null && screenDataArea.contains(e.getPoint())) {
                    panW = screenDataArea.getWidth();
                    panH = screenDataArea.getHeight();
                    panLast = e.getPoint();
                    setCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR));
                }
            }
        }
    } else if (zoomRectangle == null) {
        Rectangle2D screenDataArea = getScreenDataArea(e.getX(), e.getY());
        if (screenDataArea != null)
            zoomPoint = getPointInRectangle(e.getX(), e.getY(), screenDataArea);
        else
            zoomPoint = null;
        if (e.isPopupTrigger() && popup != null)
            displayPopupMenu(e.getX(), e.getY());
    }
}
Also used : Pannable(org.jfree.chart.plot.Pannable) Rectangle2D(java.awt.geom.Rectangle2D)

Example 2 with Pannable

use of org.jfree.chart.plot.Pannable in project jfreechart-fx by jfree.

the class PanHandlerFX method handleMouseDragged.

/**
 * Handles a mouse dragged event by calculating the distance panned and
 * updating the axes accordingly.
 *
 * @param canvas  the JavaFX canvas ({@code null} not permitted).
 * @param e  the mouse event ({@code null} not permitted).
 */
@Override
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);
}
Also used : Pannable(org.jfree.chart.plot.Pannable) PlotRenderingInfo(org.jfree.chart.plot.PlotRenderingInfo) Point2D(java.awt.geom.Point2D) JFreeChart(org.jfree.chart.JFreeChart)

Example 3 with Pannable

use of org.jfree.chart.plot.Pannable in project jfreechart-fx by jfree.

the class PanHandlerFX method handleMousePressed.

/**
 * Handles a mouse pressed event by recording the initial mouse pointer
 * location.
 *
 * @param canvas  the JavaFX canvas ({@code null} not permitted).
 * @param e  the mouse event ({@code null} not permitted).
 */
@Override
public void handleMousePressed(ChartCanvas canvas, MouseEvent e) {
    Plot plot = canvas.getChart().getPlot();
    if (!(plot instanceof Pannable)) {
        canvas.clearLiveHandler();
        return;
    }
    Pannable pannable = (Pannable) plot;
    if (pannable.isDomainPannable() || pannable.isRangePannable()) {
        Point2D point = new Point2D.Double(e.getX(), e.getY());
        Rectangle2D dataArea = canvas.findDataArea(point);
        if (dataArea != null && dataArea.contains(point)) {
            this.panW = dataArea.getWidth();
            this.panH = dataArea.getHeight();
            this.panLast = point;
            canvas.setCursor(javafx.scene.Cursor.MOVE);
        }
    }
// the actual panning occurs later in the mouseDragged() method
}
Also used : Pannable(org.jfree.chart.plot.Pannable) Point2D(java.awt.geom.Point2D) Plot(org.jfree.chart.plot.Plot) Rectangle2D(java.awt.geom.Rectangle2D)

Aggregations

Pannable (org.jfree.chart.plot.Pannable)3 Point2D (java.awt.geom.Point2D)2 Rectangle2D (java.awt.geom.Rectangle2D)2 JFreeChart (org.jfree.chart.JFreeChart)1 Plot (org.jfree.chart.plot.Plot)1 PlotRenderingInfo (org.jfree.chart.plot.PlotRenderingInfo)1