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

Add a modifierKey for drag-to-zoom #556

Conversation

Sean-Stellingwerff
Copy link

This PR adds the modifierKey option to zoom.drag, in a similar fashion to how it works for panning and wheel zooming.

Note: by some hilarious coincidence it looks like @kurkle had the exact same idea today and beat me by 4 hours to add this 😂 I noticed that I had a couple of changes not included in his PR, so I've decided to add my MR as well. I'm perfectly fine with either PR getting merged: I care more about the feature being there than getting my code merged 😉.

@kurkle
Copy link
Member

kurkle commented Jun 30, 2021

Filename Size Change
dist/chartjs-plugin-zoom.esm.js 7.46 kB +106 B (+1%)
dist/chartjs-plugin-zoom.js 7.71 kB +108 B (+1%)
dist/chartjs-plugin-zoom.min.js 4.49 kB +67 B (+2%)

Copy link
Member

@kurkle kurkle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left a couple of comments.

The other pr is about half the size, but we are still talking about couple of bytes. I ofc prefer the way I did it :)
However, its easier to get this merged as I don't need to request a review from another maintainer.

I also noticed that pan.enabled can be false and a modifierKey in there would still prevent drag-to-zoom. I changed that in the other pr.

for (const key of ['ctrl', 'alt', 'shift', 'meta']) {
for (const pressed of [true, false]) {
let chart, scaleX, scaleY;
it(`should ${pressed ? 'not ' : ''}change ${pressed ? 'without' : 'with'} key ${key}`, async function() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The 'not'/'' and 'without'/'with' are reversed

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whoops, good catch, thanks!

const modifierKey = panOptions.modifierKey;
const requireModifier = modifierKey && (event.pointerType === 'mouse');
if (!state.panning && requireModifier && !event.srcEvent[modifierKey + 'Key']) {
if (!state.panning && blockedByPanModifierKey(panOptions, event) || blockedByDragModifierKey(zoomOptions, event)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the !state.panning check is needed for both conditions; once panning is started, it should not change to drag-zoom if that modifier key is pressed while still panning.

@Sean-Stellingwerff
Copy link
Author

Thanks for the feedback @kurkle!

I would just go with your PR. It's the cleaner of the two, it's smaller and at least for me there's no immediate rush to get it merged.

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.

2 participants