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

Activating zoom after first click #370

Closed
flaushi opened this issue Jun 25, 2020 · 1 comment · Fixed by #486
Closed

Activating zoom after first click #370

flaushi opened this issue Jun 25, 2020 · 1 comment · Fixed by #486

Comments

@flaushi
Copy link

flaushi commented Jun 25, 2020

Is it possible to activate the zoom plugin only after the user clicks the canvas?

I have embedded several graphs in a long page, which has to be scrolled. It happens often that the cursor scrolls over the canvas (unintentionally), and then the next scroll event (mouse wheel) is eaten by the chart (instead of the main document).

I am afraid to destroy the mouse events if just intercepting

$('#canvas').on('click', () => {
    chart.options.plugins.zoom.zoom.enabled = true; 
    chart.update();
});

Once zooming and panning is enabled, the click event is needed by the plugin, right?
Related issue: #335

@cederlof
Copy link

cederlof commented Oct 7, 2020

#382 didn't do it for me, I landed on the code provided in OP's post. I also added tabindex="0" to the canvas so I could catch the blur-event for disabling zoom upon clicking outside of the chart.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants