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
Export zoomRect and make it more configurable (#659)
* Implement zoomRect functions
Normal zooming supports customizing zoom behavior using zoomFunctions, but the drag-to-zoom functionality that's implemented by zoomRect bypasses zoomFunctions and calls updateRange correctly.
I have a custom scale implementation that relies on zoomFunctions, so trying to enable drag-to-zoom causes problems. (Specifically, I'm breaking up the axis into viewports so that I can stack multiple series within this chart - somewhat like this example. The scales for the individual portions of the chart shouldn't be directly zoomed, because their layout is managed by a separate, controlling scale, so their zoomFunctions are no-ops.)
Zooming by rectangle appears to be a distinctly different interface than zooming by percentage and focal point, so it seems reasonable to add a zoomRectFunctions to let scales customize that behavior and cover this use case.
* Expose zoomRect; remove incorrect TypeScript type definitions
To go with adding stronger zoomRect functionality, it makes sense to expose the `zoomRect` function directly.
The TypeScript type definitions said that standalone functions like `zoom` were exported, but these don't actually exist. Fix that.
* Restore incorrectly deleted type definitions
And properly export zoomRect.
* Further update comments
* Restore type tests
* Fix type
Copy file name to clipboardExpand all lines: docs/guide/developers.md
+8-3Lines changed: 8 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -44,7 +44,7 @@ Returns whether the chart has been zoomed or panned - i.e. whether the initial s
44
44
45
45
## Custom Scales
46
46
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.
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`, `zoomRectFunctions`, and `panFunctions` members. These objects are indexed by scale types (scales' `id` members) and give optional handlers for zoom and pan functionality.
48
48
49
49
```js
50
50
import {Scale} from'chart.js';
@@ -57,17 +57,22 @@ MyScale.id = 'myScale';
57
57
MyScale.defaults= defaultConfigObject;
58
58
59
59
zoomPlugin.zoomFunctions.myScale= (scale, zoom, center, limits) =>false;
60
+
zoomPlugin.zoomRectFunctions.myScale= (scale, from, to, limits) =>false;
// zoomRectFunctions can normally be omitted, since zooming by specific pixel
63
+
// coordinates rarely needs special handling.
61
64
```
62
65
63
-
The zoom and pan functions take the following arguments:
66
+
The zoom, zoomRect, and pan functions take the following arguments:
64
67
65
68
| Name | Type | For | Description
66
69
| ---- | ---- | --- | ----------
67
70
| `scale` | `Scale` | Zoom, Pan | The custom scale instance (usually derived from `Chart.Scale`)
68
71
| `zoom` | `number` | Zoom | The zoom fraction; 1.0 is unzoomed, 0.5 means zoomed in to 50% of the original area, etc.
69
72
| `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.
73
+
| `from` | `number` | ZoomRect | Pixel coordinate of the start of the zoomRect operation.
74
+
| `to` | `number` | ZoomRect | Pixel coordinate of the end of the zoomRect operation.
70
75
| `delta` | `number` | Pan | Pixel amount to pan by
71
76
| `limits` | [Limits](./options#limits) | Zoom, Pan | Zoom and pan limits (from chart options)
72
77
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).
78
+
For examples, see chartjs-plugin-zoom's [default zoomFunctions, zoomRectFunctions, 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