You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add chart method for getting initial scale bounds (#585)
* Add chart method for getting initial scale bounds
* Add types for initial scale bounds function
* Always return a {min, max} object, even if the scale is not found
Co-authored-by: Jukka Kurkela <[email protected]>
* Add `isZoomedOrPanned` API
* Add documentation for using the imperative API
* Fix type and documentation tests
Co-authored-by: Jonathan Frere <[email protected]>
Co-authored-by: Jukka Kurkela <[email protected]>
Copy file name to clipboardExpand all lines: docs/guide/developers.md
+45-1Lines changed: 45 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,5 +1,49 @@
1
1
# Developers
2
2
3
+
## Imperative Zoom/Pan API
4
+
5
+
Alongside user-driven interactions, it is also possible to imperatively interact with the chart, either to manually zoom into a selected region, or to get information about the current zoom status.
Pans the current chart by the specified amount in one or more axes. The value of `delta` can be a number, in which case all axes are panned by the same amount, or it can be an `{x, y}` object to pan different amounts in the horizontal and vertical directions. The value of `scales` is a list of scale objects that should be panned - by default, all scales of the chart will be panned. The value of `mode` should be one of the Chart.js [animation modes](https://www.chartjs.org/docs/latest/configuration/animations.html#default-transitions).
10
+
11
+
### `chart.zoom(zoomLevel, mode = 'none'): void`
12
+
13
+
Zooms the current chart by the specified amount in one more axes. The value of `zoomLevel` can be a number, in which case all axes are zoomed by the same amount, or it can be an `{x, y}` object to zoom different amounts in the horizontal and vertical directions. The value of `mode` should be one of the Chart.js [animation modes](https://www.chartjs.org/docs/latest/configuration/animations.html#default-transitions).
Zooms the specified scale to the range given by `newRange`. This is an object in the form `{min, max}` and represents the new bounds of that scale. The value of `mode` should be one of the Chart.js [animation modes](https://www.chartjs.org/docs/latest/configuration/animations.html#default-transitions).
18
+
19
+
### `chart.resetZoom(mode = 'none'): void`
20
+
21
+
Resets the current chart bounds to the defaults that were used before any zooming or panning occurred. The value of `mode` should be one of the Chart.js [animation modes](https://www.chartjs.org/docs/latest/configuration/animations.html#default-transitions).
22
+
23
+
### `chart.getZoomLevel(): number`
24
+
25
+
Returns the current zoom level. If this is the same as the chart's initial scales, the value returned will be `1.0`. Otherwise, the value will be less than one if the chart has been zoomed out, and more than one if it has been zoomed in. If different axes have been zoomed by different amounts, the returned value will be the zoom level of the most zoomed out axis if any have been zoomed out, otherwise it will be the zoom level of the most zoomed-in axis.
26
+
27
+
If the chart has been panned but not zoomed, this method will still return `1.0`.
Returns the initial scale bounds of each scale before any zooming or panning took place. This is returned in the format of an object, e.g.
32
+
33
+
```json
34
+
{
35
+
x: {min: 0, max: 100},
36
+
y1: {min: 50, max: 80},
37
+
y2: {min: 0.1, max: 0.8}
38
+
}
39
+
```
40
+
41
+
### `chart.isZoomedOrPanned(): boolean`
42
+
43
+
Returns whether the chart has been zoomed or panned - i.e. whether the initial scale of any axis is different to the one used currently.
44
+
45
+
## Custom Scales
46
+
3
47
You can extend chartjs-plugin-zoom with support for [custom scales](https://www.chartjs.org/docs/latest/developers/axes.html) by using the zoom plugin's `zoomFunctions` and `panFunctions` members. These objects are indexed by scale types (scales' `id` members) and give optional handlers for zoom and pan functionality.
4
48
5
49
```js
@@ -23,7 +67,7 @@ The zoom and pan functions take the following arguments:
23
67
| `scale` | `Scale` | Zoom, Pan | The custom scale instance (usually derived from `Chart.Scale`)
24
68
| `zoom` | `number` | Zoom | The zoom fraction; 1.0 is unzoomed, 0.5 means zoomed in to 50% of the original area, etc.
25
69
| `center` | `{x, y}` | Zoom | Pixel coordinates of the center of the zoom operation. `{x: 0, y: 0}` is the upper left corner of the chart's canvas.
26
-
| `pan` | `number` | Pan | Pixel amount to pan by
70
+
| `delta` | `number` | Pan | Pixel amount to pan by
27
71
| `limits` | [Limits](./options#limits) | Zoom, Pan | Zoom and pan limits (from chart options)
28
72
29
73
For examples, see chartjs-plugin-zoom's [default zoomFunctions and panFunctions handling for standard Chart.js axes](https://github.com/chartjs/chartjs-plugin-zoom/blob/v1.0.1/src/scale.types.js#L128).
0 commit comments