Class Zoomer


  • public class Zoomer
    extends ChartPlugin
    Zoom capabilities along X, Y or both axis. For every zoom-in operation the current X and Y range is remembered and restored upon following zoom-out operation.
    • zoom-in - triggered on MOUSE_PRESSED event that is accepted by zoom-in filter. It shows a zooming rectangle determining the zoom window once mouse button is released.
    • zoom-out - triggered on MOUSE_CLICKED event that is accepted by zoom-out filter. It restores the previous ranges on both axis.
    • zoom-origin - triggered on MOUSE_CLICKED event that is accepted by zoom-origin filter. It restores the initial ranges on both axis as it was at the moment of the first zoom-in operation.

    CSS class name of the zoom rectangle: "chart-zoom-rect".

    Author:
    Grzegorz Kruk, rstein - adapted to XYChartPane, corrected some features (mouse zoom events outside canvas, auto-ranging on zoom-out, scrolling, toolbar)
    • Field Detail

      • ZOOMER_OMIT_AXIS

        public static final java.lang.String ZOOMER_OMIT_AXIS
        See Also:
        Constant Field Values
      • STYLE_CLASS_ZOOM_RECT

        public static final java.lang.String STYLE_CLASS_ZOOM_RECT
        See Also:
        Constant Field Values
      • DEFAULT_MOUSE_FILTER

        public static final java.util.function.Predicate<javafx.scene.input.MouseEvent> DEFAULT_MOUSE_FILTER
        Default pan mouse filter passing on left mouse button with control key down.
      • defaultZoomInMouseFilter

        public final java.util.function.Predicate<javafx.scene.input.MouseEvent> defaultZoomInMouseFilter
        Default zoom-in mouse filter passing on left mouse button (only).
      • defaultZoomOutMouseFilter

        public final java.util.function.Predicate<javafx.scene.input.MouseEvent> defaultZoomOutMouseFilter
        Default zoom-out mouse filter passing on right mouse button (only).
      • defaultZoomOriginFilter

        public final java.util.function.Predicate<javafx.scene.input.MouseEvent> defaultZoomOriginFilter
        Default zoom-origin mouse filter passing on right mouse button with control key down.
      • defaultScrollFilter

        public final java.util.function.Predicate<javafx.scene.input.ScrollEvent> defaultScrollFilter
        Default zoom scroll filter with control key down.
    • Constructor Detail

      • Zoomer

        public Zoomer()
        Creates a new instance of Zoomer with animation disabled and with zoomMode initialized to AxisMode.XY.
      • Zoomer

        public Zoomer​(AxisMode zoomMode)
        Creates a new instance of Zoomer with animation disabled.
        Parameters:
        zoomMode - initial value of zoomMode property
      • Zoomer

        public Zoomer​(AxisMode zoomMode,
                      boolean animated)
        Creates a new instance of Zoomer.
        Parameters:
        zoomMode - initial value of axisMode property
        animated - initial value of animated property
      • Zoomer

        public Zoomer​(boolean animated)
        Creates a new instance of Zoomer with zoomMode initialized to AxisMode.XY.
        Parameters:
        animated - initial value of animated property
    • Method Detail

      • animatedProperty

        public final javafx.beans.property.BooleanProperty animatedProperty()
        When true zooming will be animated. By default it's false.
        Returns:
        the animated property
        See Also:
        zoomDurationProperty()
      • autoZoomEnabledProperty

        public final javafx.beans.property.BooleanProperty autoZoomEnabledProperty()
        When true auto-zooming feature is being enabled, ie. more horizontal drags do x-zoom only, more vertical drags do y-zoom only, and xy-zoom otherwise
        Returns:
        the autoZoom property
      • autoZoomThresholdProperty

        public javafx.beans.property.IntegerProperty autoZoomThresholdProperty()
      • axisModeProperty

        public final javafx.beans.property.ObjectProperty<AxisMode> axisModeProperty()
        The mode defining axis along which the zoom can be performed. By default initialised to AxisMode.XY.
        Returns:
        the axis mode property
      • clear

        public void clear()
        Clears the stack of zoom windows saved during zoom-in operations.
      • clear

        public void clear​(Axis axis)
        Clears the stack of zoom states saved during zoom-in operations for a specific given axis.
        Parameters:
        axis - axis zoom history that shall be removed
      • dragCursorProperty

        public final javafx.beans.property.ObjectProperty<javafx.scene.Cursor> dragCursorProperty()
        Mouse cursor to be used during drag operation.
        Returns:
        the mouse cursor property
      • getAutoZoomThreshold

        public int getAutoZoomThreshold()
      • getDragCursor

        public final javafx.scene.Cursor getDragCursor()
        Returns the value of the dragCursorProperty()
        Returns:
        the current cursor
      • getRangeSlider

        public org.controlsfx.control.RangeSlider getRangeSlider()
      • getZoomCursor

        public final javafx.scene.Cursor getZoomCursor()
        Returns the value of the zoomCursorProperty()
        Returns:
        the current cursor
      • getZoomDuration

        public final javafx.util.Duration getZoomDuration()
        Returns the value of the zoomDurationProperty().
        Returns:
        the current zoom duration
      • getZoomInMouseFilter

        public java.util.function.Predicate<javafx.scene.input.MouseEvent> getZoomInMouseFilter()
        Returns zoom-in mouse event filter.
        Returns:
        zoom-in mouse event filter
        See Also:
        setZoomInMouseFilter(Predicate)
      • getZoomInteractorBar

        public javafx.scene.layout.HBox getZoomInteractorBar()
      • getZoomOriginMouseFilter

        public java.util.function.Predicate<javafx.scene.input.MouseEvent> getZoomOriginMouseFilter()
        Returns zoom-origin mouse filter.
        Returns:
        zoom-origin mouse filter
        See Also:
        setZoomOriginMouseFilter(Predicate)
      • getZoomOutMouseFilter

        public java.util.function.Predicate<javafx.scene.input.MouseEvent> getZoomOutMouseFilter()
        Returns zoom-out mouse filter.
        Returns:
        zoom-out mouse filter
        See Also:
        setZoomOutMouseFilter(Predicate)
      • getZoomScrollFilter

        public java.util.function.Predicate<javafx.scene.input.ScrollEvent> getZoomScrollFilter()
        Returns zoom-scroll filter.
        Returns:
        predicate of filter
      • isAutoZoomEnabled

        public final boolean isAutoZoomEnabled()
        Returns:
        true if auto-zooming feature is being enabled, ie. more horizontal drags do x-zoom only, more vertical drags do y-zoom only, and xy-zoom otherwise
      • isPannerEnabled

        public final boolean isPannerEnabled()
      • isSliderVisible

        public final boolean isSliderVisible()
        Returns the value of the sliderVisibleProperty().
        Returns:
        true if horizontal range slider is shown
      • isUpdateTickUnit

        public final boolean isUpdateTickUnit()
        Returns the value of the animatedProperty().
        Returns:
        true if zoom is animated, false otherwise
        See Also:
        getZoomDuration()
      • omitAxisZoomList

        public final javafx.collections.ObservableList<Axis> omitAxisZoomList()
        Returns:
        list of axes that shall be ignored when performing zoom-in or outs
      • pannerEnabledProperty

        public final javafx.beans.property.BooleanProperty pannerEnabledProperty()
        When true pressing the middle mouse button and dragging pans the plot
        Returns:
        the pannerEnabled property
      • setAutoZoomEnabled

        public final void setAutoZoomEnabled​(boolean state)
        Sets the value of the autoZoomEnabledProperty().
        Parameters:
        state - if true auto-zooming feature is being enabled, ie. more horizontal drags do x-zoom only, more vertical drags do y-zoom only, and xy-zoom otherwise
      • setAutoZoomThreshold

        public void setAutoZoomThreshold​(int value)
      • setAxisMode

        public final void setAxisMode​(AxisMode mode)
        Sets the value of the axisModeProperty().
        Parameters:
        mode - the mode to be used
      • setDragCursor

        public final void setDragCursor​(javafx.scene.Cursor cursor)
        Sets value of the dragCursorProperty().
        Parameters:
        cursor - the cursor to be used by the plugin
      • setPannerEnabled

        public final void setPannerEnabled​(boolean state)
        Sets the value of the pannerEnabledProperty().
        Parameters:
        state - if true the panner (middle mouse button is enabled
      • setSliderVisible

        public final void setSliderVisible​(boolean state)
        Sets the value of the sliderVisibleProperty().
        Parameters:
        state - if true the horizontal range slider is shown
      • setZoomCursor

        public final void setZoomCursor​(javafx.scene.Cursor cursor)
        Sets value of the zoomCursorProperty().
        Parameters:
        cursor - the cursor to be used by the plugin
      • setZoomDuration

        public final void setZoomDuration​(javafx.util.Duration duration)
        Sets the value of the zoomDurationProperty().
        Parameters:
        duration - duration of the zoom
      • setZoomInMouseFilter

        public void setZoomInMouseFilter​(java.util.function.Predicate<javafx.scene.input.MouseEvent> zoomInMouseFilter)
        Sets filter on DRAG_DETECTED events that should start zoom-in operation.
        Parameters:
        zoomInMouseFilter - the filter to accept zoom-in mouse event. If null then any DRAG_DETECTED event will start zoom-in operation. By default it's set to defaultZoomInMouseFilter.
        See Also:
        getZoomInMouseFilter()
      • setZoomOriginMouseFilter

        public void setZoomOriginMouseFilter​(java.util.function.Predicate<javafx.scene.input.MouseEvent> zoomOriginMouseFilter)
        Sets filter on MOUSE_CLICKED events that should trigger zoom-origin operation.
        Parameters:
        zoomOriginMouseFilter - the filter to accept zoom-origin mouse event. If null then any MOUSE_CLICKED event will start zoom-origin operation. By default it's set to defaultZoomOriginFilter.
        See Also:
        getZoomOriginMouseFilter()
      • setZoomOutMouseFilter

        public void setZoomOutMouseFilter​(java.util.function.Predicate<javafx.scene.input.MouseEvent> zoomOutMouseFilter)
        Sets filter on MOUSE_CLICKED events that should trigger zoom-out operation.
        Parameters:
        zoomOutMouseFilter - the filter to accept zoom-out mouse event. If null then any MOUSE_CLICKED event will start zoom-out operation. By default it's set to defaultZoomOutMouseFilter.
        See Also:
        getZoomOutMouseFilter()
      • setZoomScrollFilter

        public void setZoomScrollFilter​(java.util.function.Predicate<javafx.scene.input.ScrollEvent> zoomScrollFilter)
        Sets filter on MOUSE_CLICKED events that should trigger zoom-origin operation.
        Parameters:
        zoomScrollFilter - filter
      • sliderVisibleProperty

        public final javafx.beans.property.BooleanProperty sliderVisibleProperty()
        When true an additional horizontal range slider is shown in a HiddeSidesPane at the bottom. By default it's true.
        Returns:
        the sliderVisible property
        See Also:
        getRangeSlider()
      • updateTickUnitProperty

        public final javafx.beans.property.BooleanProperty updateTickUnitProperty()
        When true zooming will be animated. By default it's false.
        Returns:
        the animated property
        See Also:
        zoomDurationProperty()
      • zoomCursorProperty

        public final javafx.beans.property.ObjectProperty<javafx.scene.Cursor> zoomCursorProperty()
        Mouse cursor to be used during zoom operation.
        Returns:
        the mouse cursor property
      • zoomDurationProperty

        public final javafx.beans.property.ObjectProperty<javafx.util.Duration> zoomDurationProperty()
        Duration of the animated zoom (in and out). Used only when animatedProperty() is set to true. By default initialised to 500ms.
        Returns:
        the zoom duration property
      • zoomOrigin

        public boolean zoomOrigin()
      • hasBoundedRange

        protected static boolean hasBoundedRange​(Axis axis)
      • isOmitZoom

        public static boolean isOmitZoom​(Axis axis)
        Parameters:
        axis - the axis to be modified
        Returns:
        true if axis is zoomable, false otherwise
      • setOmitZoom

        public static void setOmitZoom​(Axis axis,
                                       boolean state)
        Parameters:
        axis - the axis to be modified
        state - true: axis is not taken into account when zooming