public class ChartZoomManager extends Object
start()
and disabled via stop()
. The normal usage is to create a
StackPane with two children, an XYChart type and a Rectangle. The Rectangle should start out
invisible and have mouseTransparent set to true. If it has a stroke, it should be of INSIDE
type to be pixel perfect.
You can also use JFXChartUtil.setupZooming(XYChart)
for a default solution.
Six types of zooming are supported. All are enabled by default. The drag zooming can be disabled
with the setMouseFilter(javafx.event.EventHandler<? super javafx.scene.input.MouseEvent>)
set to a mouse filter that allows nothing. Mouse wheel zooming
can be disabled via the setMouseWheelZoomAllowed(boolean)
method.
<StackPane fx:id="chartPane" alignment="CENTER"> <LineChart fx:id="chart" animated="false" legendVisible="false"> <xAxis> <NumberAxis animated="false" side="BOTTOM" /> </xAxis> <yAxis> <NumberAxis animated="false" side="LEFT" /> </yAxis> </LineChart> <Rectangle fx:id="selectRect" fill="DODGERBLUE" height="0.0" mouseTransparent="true" opacity="0.3" stroke="#002966" strokeType="INSIDE" strokeWidth="3.0" width="0.0" x="0.0" y="0.0" StackPane.alignment="TOP_LEFT" /> </StackPane>Example Java code in bound controller class:
ChartZoomManager zoomManager = new ChartZoomManager( chartPane, selectRect, chart ); zoomManager.start();
Type | Property and Description |
---|---|
javafx.beans.property.BooleanProperty |
mouseWheelZoomAllowed
If true, allow zooming via mouse wheel.
|
javafx.beans.property.BooleanProperty |
zoomAnimated
If true, animates the zoom.
|
javafx.beans.property.DoubleProperty |
zoomDurationMillis
Returns the number of milliseconds the zoom animation takes.
|
Modifier and Type | Field and Description |
---|---|
static javafx.event.EventHandler<javafx.scene.input.MouseEvent> |
DEFAULT_FILTER
The default mouse filter for the
ChartZoomManager filters events unless only primary
mouse button (usually left) is depressed. |
Constructor and Description |
---|
ChartZoomManager(javafx.scene.layout.Pane chartPane,
javafx.scene.shape.Rectangle selectRect,
javafx.scene.chart.XYChart<?,?> chart)
Construct a new ChartZoomManager.
|
Modifier and Type | Method and Description |
---|---|
javafx.event.EventHandler<? super javafx.scene.input.MouseEvent> |
getMouseFilter()
Returns the mouse filter.
|
double |
getZoomDurationMillis()
Returns the number of milliseconds the zoom animation takes.
|
boolean |
isMouseWheelZoomAllowed()
If true, allow zooming via mouse wheel.
|
boolean |
isZoomAnimated()
If true, animates the zoom.
|
javafx.beans.property.BooleanProperty |
mouseWheelZoomAllowedProperty()
If true, allow zooming via mouse wheel.
|
void |
setMouseFilter(javafx.event.EventHandler<? super javafx.scene.input.MouseEvent> mouseFilter)
Sets the mouse filter for starting the zoom action.
|
void |
setMouseWheelZoomAllowed(boolean allowed)
If true, allow zooming via mouse wheel.
|
void |
setZoomAnimated(boolean zoomAnimated)
If true, animates the zoom.
|
void |
setZoomDurationMillis(double zoomDurationMillis)
Sets the number of milliseconds the zoom animation takes.
|
void |
start()
Start managing zoom management by adding event handlers and bindings as appropriate.
|
void |
stop()
Stop managing zoom management by removing all event handlers and bindings, and hiding the
rectangle.
|
javafx.beans.property.BooleanProperty |
zoomAnimatedProperty()
If true, animates the zoom.
|
javafx.beans.property.DoubleProperty |
zoomDurationMillisProperty()
Returns the number of milliseconds the zoom animation takes.
|
public static final javafx.event.EventHandler<javafx.scene.input.MouseEvent> DEFAULT_FILTER
ChartZoomManager
filters events unless only primary
mouse button (usually left) is depressed.public ChartZoomManager(javafx.scene.layout.Pane chartPane, javafx.scene.shape.Rectangle selectRect, javafx.scene.chart.XYChart<?,?> chart)
ChartZoomManager
documentation for normal usage.chartPane
- A Pane which is the ancestor of all argumentsselectRect
- A Rectangle whose layoutX/Y makes it line up with the chartchart
- Chart to manage, where both X and Y axis are a ValueAxis
.public boolean isZoomAnimated()
public javafx.beans.property.BooleanProperty zoomAnimatedProperty()
public void setZoomAnimated(boolean zoomAnimated)
public double getZoomDurationMillis()
public javafx.beans.property.DoubleProperty zoomDurationMillisProperty()
public void setZoomDurationMillis(double zoomDurationMillis)
public boolean isMouseWheelZoomAllowed()
public javafx.beans.property.BooleanProperty mouseWheelZoomAllowedProperty()
public void setMouseWheelZoomAllowed(boolean allowed)
public javafx.event.EventHandler<? super javafx.scene.input.MouseEvent> getMouseFilter()
setMouseFilter(EventHandler)
public void setMouseFilter(javafx.event.EventHandler<? super javafx.scene.input.MouseEvent> mouseFilter)
Event.consume()
, then the event is ignored. If the filter is null, all events are
passed through. The default filter is DEFAULT_FILTER
.public void start()
public void stop()
Copyright © 2013 Jason Winnebeck. All Rights Reserved.