/** 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!
Requested by @gforman44 with some suggested code:
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!