The ZoomPanModifier
Chart Android provides an inertial scrolling / panning behavior via the ZoomPanModifier, available out of the box.
Besides common features which are inherited from the ChartModifierBase class, the ZoomPanModifier allows to control its specific features via the following properties:
- setDirection(Direction2D direction) - allows to restrict zooming to the horizontal or vertical direction only if needed.
- setZoomExtentsY(boolean zoomExtentsY) - allows to to keep series' peeks always in viewport.
- setClipModeX(ClipMode clipModeX) - allows to specify the behavior when scrolling reaches data extents in X direction via the ClipMode enumeration.
There are several modes defined by the ClipMode enumeration:
- None - Means you can pan right off the edge of the data into uncharted space.
- StretchAtExtents - Causes a zooming (stretch) action when you reach the edge of the data.
- ClipAtMin - Forces the panning operation to stop suddenly at the minimum of the data, but expand at the maximum.
- ClipAtMax - Forces the panning operation to stop suddenly at the maximum of the data, but expand at the minimum.
- ClipAtExtents - Forces the panning operation to stop suddenly at the extents of the data.
There are two touch events defined by the GestureState enumeration, which can be used to get or set current interaction state of the surface:
- INTERACTED means surface has been interacted with touch, swipe or zoom events.
- NOT_INTERACTED means surface does not have any interactions or has been reset.
When using SciChartSurface with ChartModifiers inside a ScrollView, you can manage zoom and pan gestures by utilizing the isDisallowInterceptTouchEvent property. This allows you to control whether the ScrollView should intercept touch events or let the SciChartSurface handle them. Example can be found on GitHub
Adding a ZoomPanModifier to a Chart
Any Chart Modifier can be added to a SciChartSurface via the chartModifiers property and ZoomPanModifier is no difference:
// Assume a surface has been created and configured somewhere
// Create a Modifier
final ZoomPanModifier zoomPanModifier = new ZoomPanModifier();
zoomPanModifier.setDirection(Direction2D.XDirection);
zoomPanModifier.setClipModeX(ClipMode.StretchAtExtents);
zoomPanModifier.setClipModeY(ClipMode.None);
zoomPanModifier.setZoomExtentsY(true);
// Add the modifier to the surface
surface.getChartModifiers().add(zoomPanModifier);
Including/Excluding Axes from ZoomPanModifier
You can include or exclude specific axes from being affected by the ZoomPanModifier. This is done by using the includeXAxis or includeYAxis method.
Below is an example of including/excluding axes from ZoomPanModifier.
// Assume a zoomPanModifier has been created and configured somewhere
// To include/exclude an X axis in the zoomPanModifier (true = include, false = exclude)
zoomPanModifier.includeXAxis(xAxis, true);
zoomPanModifier.includeXAxis(xAxis, false);
// To include/exclude an Y axis from the zoomPanModifier (true = include, false = exclude)
zoomPanModifier.includeYAxis(yAxis, true);
zoomPanModifier.includeYAxis(yAxis, false);
// To include all X and Y axes to the zoomPanModifier
zoomPanModifier.includeAllAxes();
Note
To learn more about features available, please visit the Chart Modifier APIs article.