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
{{ message }}
Repository navigation
Zoom reset for scales built with suggestedMin and suggestedMax #801
Trying to summarize as much as possible, we have the following use case:
A chart with two 'y' scales - both scales are created using the 'suggestedMin' and 'suggestedMax' properties
Starts to zoom in
Hides the scale and datasets of one of the 'y' scales - this is done via the native legend plugin of chartjs
Resets zoom (this.chart.resetZoom()) - zoom is reset
Observing the onZoomComplete callback, the previously hidden scale now has a 'min'=0 and 'max'=1
- The expectation would be that the scale would have the initial values
If the chart scales are build using the 'min' and 'max' properties instead of the 'suggestedMin' and 'suggestedMax' (point 1), then the expectation is correctly met.
After resetZoom() is called, the visible chart zoom is correctly reset. Then, we onZoomComplete is called. In that callback, we get the zoomLevel by calling chart.getZoomLevel() to update our app state.
I tried to reproduce this with v3.0.0 and could not: two y scales with suggestedMin / suggestedMax, zoom in, hide the dataset of one scale (and the scale), resetZoom(). In onZoomComplete the hidden scale had its suggested range again and getZoomLevel() returned 1, both with mode: 'x' and mode: 'xy'.
Two changes that are on their way may also bear on this: #1008 keeps the range a reset refers to in step with the data, including datasets being hidden, and #1010 makes getZoomLevel() count only the scales that are zoomed.
If it still happens for you with 3.0.0, a reproduction (CodePen or similar) would help a lot.
Activity
kurkle commentedon Nov 17, 2024
Might be the same root cause with #798
jwedel commentedon Feb 13, 2025
We have the exact same scenario as described.
After resetZoom() is called, the visible chart zoom is correctly reset. Then, we
onZoomCompleteis called. In that callback, we get the zoomLevel by callingchart.getZoomLevel()to update our app state.Instead of the expected
1, we get e.g.25.kurkle commentedon Nov 21, 2026
I tried to reproduce this with v3.0.0 and could not: two y scales with
suggestedMin/suggestedMax, zoom in, hide the dataset of one scale (and the scale),resetZoom(). InonZoomCompletethe hidden scale had its suggested range again andgetZoomLevel()returned 1, both withmode: 'x'andmode: 'xy'.Two changes that are on their way may also bear on this: #1008 keeps the range a reset refers to in step with the data, including datasets being hidden, and #1010 makes
getZoomLevel()count only the scales that are zoomed.If it still happens for you with 3.0.0, a reproduction (CodePen or similar) would help a lot.