Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Utility method to reset zoom on double click #9

Closed
gillius opened this issue May 12, 2016 · 0 comments
Closed

Utility method to reset zoom on double click #9

gillius opened this issue May 12, 2016 · 0 comments

Comments

@gillius
Copy link
Owner

gillius commented May 12, 2016

Requested by @gforman44 with some suggested code:

/** Add double-click for auto-ranging.  If user double-clicks the x-axis, only that axis will be reset.  Likewise for y-axis
 */
public static void addDoubleClickAutoRange(final ScatterChart<?, ?> sc) {
    sc.addEventHandler(MouseEvent.MOUSE_CLICKED, ev -> {
        if (ev.getClickCount() == 2) {
            resetRange(sc, ev);
            ev.consume();
        }
    });
}
/** Reset AutoRanging for one or both axes, depending on where user clicked.  
 * x-axis only?  y-axis only?  chart --> both. 
 */
public static void resetRange(final ScatterChart<?, ?> sc, MouseEvent ev) {
    XYChartInfo i = new XYChartInfo(sc);
    if (!i.getXAxisArea().contains(ev.getX(), ev.getY())) sc.getYAxis().setAutoRanging(true);
    if (!i.getYAxisArea().contains(ev.getX(), ev.getY())) sc.getXAxis().setAutoRanging(true);
}

I will add similar functionality but use XYChart type and anonymous classes instead of Lambdas since jfxutils supports Java 7. Thanks for the code suggestions @gforman44!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant