Extend onZoom and onPan callbacks for syncing multiple charts #933
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Purpose
onZoom and onPan callbacks now return additional data that is useful for syncing multiple charts.
Changes
onZoom
returns the amount it zoomed.onPan
returns the delta it panned.These values can be used to zoom/pan other charts by the same amount.
The values are basically piped through from the function args, so there is no additional computation.
As charts may only zoom/pan certain axis, the amount/delta returned will only set the values that were actually applied.
pan()
receives a new PanTrigger parameter.It can be used in the spirit of ZoomTrigger to distinguish between "api" and user interactions.
This is required to pan other charts when the user pans, but not trigger a loop through the subsequent programmatic calls to pan().
Example
Background
So far there is no good way to sync zoom and pan across multiple charts that I could come up with or have found during my research.
The only approach I found was this from 2019:
#238 (comment)
The changes I propose solve the issue of syncing multiple charts in a simple way while not breaking anything.
I think it would be a good addition to the library that could help many others.