Search in sources :

Example 1 with Zoomable

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

the class ScrollHandlerFX method handleScroll.

@Override
public void handleScroll(ChartCanvas canvas, ScrollEvent e) {
    JFreeChart chart = canvas.getChart();
    Plot plot = chart.getPlot();
    if (plot instanceof Zoomable) {
        Zoomable zoomable = (Zoomable) plot;
        handleZoomable(canvas, zoomable, e);
    } else if (plot instanceof PiePlot) {
        PiePlot pp = (PiePlot) plot;
        pp.handleMouseWheelRotation((int) e.getDeltaY());
    }
}
Also used : Plot(org.jfree.chart.plot.Plot) PiePlot(org.jfree.chart.plot.PiePlot) Zoomable(org.jfree.chart.plot.Zoomable) PiePlot(org.jfree.chart.plot.PiePlot) JFreeChart(org.jfree.chart.JFreeChart)

Example 2 with Zoomable

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

the class ZoomHandlerFX method handleMouseReleased.

@Override
public void handleMouseReleased(ChartCanvas canvas, MouseEvent e) {
    Plot p = canvas.getChart().getPlot();
    if (!(p instanceof Zoomable)) {
        return;
    }
    boolean hZoom, vZoom;
    Zoomable z = (Zoomable) p;
    if (z.getOrientation().isHorizontal()) {
        hZoom = z.isRangeZoomable();
        vZoom = z.isDomainZoomable();
    } else {
        hZoom = z.isDomainZoomable();
        vZoom = z.isRangeZoomable();
    }
    boolean zoomTrigger1 = hZoom && Math.abs(e.getX() - this.startPoint.getX()) >= 10;
    boolean zoomTrigger2 = vZoom && Math.abs(e.getY() - this.startPoint.getY()) >= 10;
    if (zoomTrigger1 || zoomTrigger2) {
        Point2D endPoint = new Point2D.Double(e.getX(), e.getY());
        PlotRenderingInfo pri = canvas.getRenderingInfo().getPlotInfo();
        if ((hZoom && (e.getX() < this.startPoint.getX())) || (vZoom && (e.getY() < this.startPoint.getY()))) {
            boolean saved = p.isNotify();
            p.setNotify(false);
            z.zoomDomainAxes(0, pri, endPoint);
            z.zoomRangeAxes(0, pri, endPoint);
            p.setNotify(saved);
        } else {
            double x = this.startPoint.getX();
            double y = this.startPoint.getY();
            double w = e.getX() - x;
            double h = e.getY() - y;
            Rectangle2D dataArea = canvas.findDataArea(this.startPoint);
            double maxX = dataArea.getMaxX();
            double maxY = dataArea.getMaxY();
            // otherwise both are true
            if (!vZoom) {
                y = dataArea.getMinY();
                w = Math.min(w, maxX - this.startPoint.getX());
                h = dataArea.getHeight();
            } else if (!hZoom) {
                x = dataArea.getMinX();
                w = dataArea.getWidth();
                h = Math.min(h, maxY - this.startPoint.getY());
            } else {
                w = Math.min(w, maxX - this.startPoint.getX());
                h = Math.min(h, maxY - this.startPoint.getY());
            }
            Rectangle2D zoomArea = new Rectangle2D.Double(x, y, w, h);
            boolean saved = p.isNotify();
            p.setNotify(false);
            double pw0 = percentW(x, dataArea);
            double pw1 = percentW(x + w, dataArea);
            double ph0 = percentH(y, dataArea);
            double ph1 = percentH(y + h, dataArea);
            PlotRenderingInfo info = this.viewer.getRenderingInfo().getPlotInfo();
            if (z.getOrientation().isVertical()) {
                z.zoomDomainAxes(pw0, pw1, info, endPoint);
                z.zoomRangeAxes(1 - ph1, 1 - ph0, info, endPoint);
            } else {
                z.zoomRangeAxes(pw0, pw1, info, endPoint);
                z.zoomDomainAxes(1 - ph1, 1 - ph0, info, endPoint);
            }
            p.setNotify(saved);
        }
    }
    this.viewer.hideZoomRectangle();
    this.startPoint = null;
    canvas.clearLiveHandler();
}
Also used : Point2D(java.awt.geom.Point2D) PlotRenderingInfo(org.jfree.chart.plot.PlotRenderingInfo) Plot(org.jfree.chart.plot.Plot) Rectangle2D(java.awt.geom.Rectangle2D) Zoomable(org.jfree.chart.plot.Zoomable)

Example 3 with Zoomable

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

the class ZoomHandlerFX method handleMouseDragged.

/**
 * Handles a mouse dragged event by updating the zoom rectangle displayed
 * in the ChartViewer.
 *
 * @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.startPoint == null) {
        // no initial zoom rectangle exists but the handler is set
        // as life handler unregister
        canvas.clearLiveHandler();
        return;
    }
    boolean hZoom, vZoom;
    Plot p = canvas.getChart().getPlot();
    if (!(p instanceof Zoomable)) {
        return;
    }
    Zoomable z = (Zoomable) p;
    if (z.getOrientation().isHorizontal()) {
        hZoom = z.isRangeZoomable();
        vZoom = z.isDomainZoomable();
    } else {
        hZoom = z.isDomainZoomable();
        vZoom = z.isRangeZoomable();
    }
    Rectangle2D dataArea = canvas.findDataArea(this.startPoint);
    double x = this.startPoint.getX();
    double y = this.startPoint.getY();
    double w = 0;
    double h = 0;
    if (hZoom && vZoom) {
        // selected rectangle shouldn't extend outside the data area...
        double xmax = Math.min(e.getX(), dataArea.getMaxX());
        double ymax = Math.min(e.getY(), dataArea.getMaxY());
        w = xmax - this.startPoint.getX();
        h = ymax - this.startPoint.getY();
    } else if (hZoom) {
        double xmax = Math.min(e.getX(), dataArea.getMaxX());
        y = dataArea.getMinY();
        w = xmax - this.startPoint.getX();
        h = dataArea.getHeight();
    } else if (vZoom) {
        double ymax = Math.min(e.getY(), dataArea.getMaxY());
        x = dataArea.getMinX();
        w = dataArea.getWidth();
        h = ymax - this.startPoint.getY();
    }
    this.viewer.showZoomRectangle(x, y, w, h);
}
Also used : Plot(org.jfree.chart.plot.Plot) Rectangle2D(java.awt.geom.Rectangle2D) Zoomable(org.jfree.chart.plot.Zoomable)

Aggregations

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