Skip to content

Added optional modifier keys #382

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

Merged
merged 2 commits into from
Mar 11, 2021
Merged

Conversation

BarryPSmith
Copy link
Contributor

@BarryPSmith BarryPSmith commented Sep 7, 2020

Often the chart captures scroll events in an undesired way, so this PR makes it possible to set an optional wheelModifierKey that must be pressed to activate mouse wheel zoom.

A modifierKey can also be set for pan. By default this is only checked when the input comes via mouse, but can be set for touch and other inputs with requireModifierNonMouse: true

zoom.onWheelModifierKeyFailed is fired when a zoom does not occur because the modifier key is not present (e.g. to allow the consumer to display "Press ctrl to zoom"). A similar pan.onModifierKeyFailed is also available.

Although not necessarily the requested fix, it will help with the following issues:
#377, #370, #335, #308 (Actually I see the collaborators offer to accept PRs on this issue there). Not looking any further...

Relationship to other pull requests:
Might be incompatible with #380.
A more flexible version of #368

@BarryPSmith
Copy link
Contributor Author

@jledentu I see on issue #308 you suggest the name modifierKey for both the pan and zoom modifiers. I have used 'wheelModifierKey' for the zoom key in this PR because it only affects wheel zoom, but it would be an easy change to have them both 'modifierKey'.

@benmccann
Copy link
Collaborator

benmccann commented Nov 21, 2020

I think a better way to handle this might be a generic function that let's you filter whether the zoom occurs as proposed in #329. That would allow you to handle more use cases

Or maybe you can actually handle this case already today with an external listener that enables the plugin when the modifier key is pressed and disables the plugin when the modifier key is released and all we need is an example of doing that

@NicolasGoeddel
Copy link

Okay, why the heck do you delete comments?

@benmccann
Copy link
Collaborator

The comments are meant for code review. If you want to express interest you can simply leave a thumbs up on the PR

@kurkle
Copy link
Member

kurkle commented Mar 9, 2021

@BarryPSmith would you be up to rebasing this?

@BarryPSmith
Copy link
Contributor Author

@benmccann I think that this and #329 are intended to solve different problems. I do not see any parameters in that PR related to keys or the type of input that is causing the zoom or pan event.

Or maybe you can actually handle this case already today with an external listener that enables the plugin when the modifier key is pressed and disables the plugin when the modifier key is released and all we need is an example of doing that

Perhaps I overestimate the complexity of the situation. I would be interested to see the robust example.

@kurkle Is there interest in merging this then? What else needs to be done for this to be merged?

@kurkle
Copy link
Member

kurkle commented Mar 10, 2021

@BarryPSmith yes, I think something like this is needed. I'm not sure there is a use case for the non-mouse modifier, that we meght want to leave out - unless there is a use case. Maybe some nits, I did not do a full review yet.

@BarryPSmith
Copy link
Contributor Author

It looks like enough has changed that it'll be easier to rewrite the PR. That's the impression I get looking at the conflict files that rebase has generated. At least it's a fairly simple set of changes to the functional code.

I'll throw away the zoom tests, given the modified test/utils.js has migrated into a different repo.

At least the weather is bad here so I have time.

@kurkle
Copy link
Member

kurkle commented Mar 10, 2021

some lint issues, npm run lint should reveal them locally.

@BarryPSmith
Copy link
Contributor Author

Test coverage decrease: In order to test the new code one must be able to send mouse events with keys attached. That is not possible with the current test framework - util.js of chartjs-test-utils must be updated. See test/util.js of d5cb18f

@kurkle
Copy link
Member

kurkle commented Mar 10, 2021

Test coverage decrease: In order to test the new code one must be able to send mouse events with keys attached. That is not possible with the current test framework - util.js of chartjs-test-utils must be updated. See test/util.js of d5cb18f

Ok, I'll take a look at the tests later. I think it needs to be a WheelEvent for the delta stuff.

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.

Overall looks good. I'm not sure about the event names, is there some reasoning that I missed?

@kurkle kurkle merged commit e6658c9 into chartjs:master Mar 11, 2021
@kurkle
Copy link
Member

kurkle commented Mar 11, 2021

Thanks @BarryPSmith

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.

Panning does not work with draggable-date plugin
4 participants