Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace overScaleMode with more flexible scaleMode #658

Merged
merged 4 commits into from Sep 1, 2022

Conversation

joshkel
Copy link
Contributor

@joshkel joshkel commented May 20, 2022

As described at #612, I'd like to allow both regular zooming (to zoom both axes via mouse wheel or pinch on the main chart area) and zooming a specific scale (to zoom only one axis via mouse wheel or pinch over the scale axis), but it seems that overScaleMode prevents regular zooming from working.

I would have expected that mode control regular zooming, while overScaleMode controls scale zooming in particular. For example ("scenario A"):

  • {mode: 'xy', overScaleMode: 'y'} would mean that zooming over the regular chart scales X and Y, and zooming over the Y axis scales Y.
  • {mode: 'x', overScaleMode: 'y'} would mean that zooming over the regular chart scales X, and zooming over the Y axis scales Y.
  • {mode: 'xy', overScaleMode: 'xy'} would mean that zooming over the regular chart scales X and Y, and zooming over the X or Y axis scales X or Y, respectively.

Instead, it appears that overScaleMode restricts and modifies mode ("scenario B"):

  • {mode: 'xy', overScaleMode: 'y'} would mean that zooming over the regular chart scales only X, and zooming over the Y axis scales Y.
  • {mode: 'x', overScaleMode: 'y'} is an invalid configuration.
  • {mode: 'xy', overScaleMode: 'xy'} would mean that zooming over the regular chart does nothing, and zooming over the X or Y axis scales X or Y, respectively.

This PR adds a new property, scaleMode, that behaves like scenario A. Since scenario A is strictly more flexible than scenario B, it deprecates overScaleMode.

There is a potential change in behavior with this PR: Previously, the pan function used chart.scales if overScaleMode was undefined, and it evaluated directionEnabled (which called mode if mode was a function). This meant that it could handle changes to the mode function's return value, and changes to what chart scales exist, even in the middle of a pan operation. Now, the list of scales to check is only evaluated when the pan operation starts.

src/plugin.js Outdated Show resolved Hide resolved
@kurkle kurkle merged commit 7ec113a into chartjs:master Sep 1, 2022
@joshkel joshkel deleted the over-scale-mode branch September 4, 2022 00:36
@kurkle kurkle mentioned this pull request Nov 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants