chartjs / chartjs/chartjs-plugin-zoom
Inconsistent behavior when using limits and new data points
- Dominant language
- JavaScript
- Stars
- 623
- Forks
- 331
- Avg merge
- 7h 5m
- Merged PRs (30d)
- 7
Description
Let's say that you have a chart with limits min/max = 'original', so that panning/zooming never exceeds the range of data points.
Then new data points arrive. (Like another day of data points with time x-axis, and we drop the oldest day of data points.)
1. In the initial chart display--or after a `resetZoom()`--when the new data points arrive, they get displayed.
2. But if you're zoomed and/or panned, and new data points arrive, then you cannot visit the new data points (by zooming out or panning over); the original range of data points is set in stone due to `storeOriginalScaleLimits()`.
A partial workaround for zooming out is to call `resetZoom()` once you've zoomed all the way out:
```
onZoomComplete: ({chart}) => {
if( !this.is_resetting_zoom && chart.getZoomLevel() == 1 ) {
this.is_resetting_zoom = true;
chart.resetZoom();
this.is_resetting_zoom = false;
}
}
```
No workaround for when you're zoomed in or panning.
I know you could update limits min/max with the range of the new data (like in #649), as it arrives, but that information may not be available, and not as convenient.
Contributor guide
Research direction
Reproduce the issue with limits min/max set to 'original', then add new data while the chart is reset, zoomed, and panned. Start by tracing storeOriginalScaleLimits() and the zoom/pan limit handling; done means newly arrived points remain reachable without requiring resetZoom() or manually updating limits.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- chart.js, javascript
- Domain
- frontend, web-dev
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100