v4.0 - d3.zoom() prevents binding events on the SVG or it's elements
See original GitHub issueAfter changing to the new v4.0 D3, seems like using d3.zoom()
blocks other events somehow, like:
Calling this:
svg.call(d3.zoom()
.scaleExtent([1, 40])
.translateExtent([[-100, -100], [width + 90, height + 100]])
.on("zoom", zoomed));
And then this:
document.querySelector('svg').addEventListener('mouseup', function(){ alert(1) })
Won’t alert anything.
Demo page
Issue Analytics
- State:
- Created 7 years ago
- Comments:12 (4 by maintainers)
Top Results From Across the Web
d3.zoom() prevents binding some events except on the Window
The zoom adds a pan event, mousedown starts a pan (i.e. zoom start ) and mouseup ends a pan (i.e. zoom end )....
Read more >D3 v4 Brush and Zoom on the same element (without mouse ...
Essentially it amounts to creating an SVG rect to specifically handle the zoom events. You can leave your brush behavior attached to an...
Read more >4. Events, Interactivity, and Animation - D3 for the Impatient ...
When working with SVG, you can supply any element (as a Node ), and the function will calculate the coordinates relative to the...
Read more >D3.js Tutorial: Mouse Events Handling - OctoPerf
Learn how to handle mouse events using D3.js to manipulate SVG graphics. d3.datum() and d3.mouse() explained via code and live examples.
Read more >Simplest way to add zoom/pan on d3.js (version 3 and 4)
You just need to create a g element as first child of the SVG element and connect d3.behavior.zoom() behavior. var svg = d3.select("body") ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I came across this too, and have just played around a little. I was a bit confused by @mbostock’s comment regarding the
d3.event.stopPropagation()
because I couldn’t seem to see that working.If however you go a little further, you can prevent the zoom kicking in when clicking on say a circle, by ensuring that you stopPropagation of the
mousedown
, preventing thezoom
from ever triggering.using DOM:
Sorry, but no. I expect you can achieve your desired result without modifying the zoom implementation, but I don’t have time right now to make a more specific example for you other than the ones I have already linked (and are linked from the README).
If you want to allow the zoom gesture but still listen to a mouseup handled by the zoom behavior then again I recommend listening to the zoom behavior’s end event so that you can do something on the end of a zoom gesture (or specifically mouseup by looking at d3.event.sourceEvent).
Alternatively I expect you could still intercede on the mouseup event by using a capturing listener (passing true as the third argument to selection.on). You might need to listen to the window rather than the specific element you want to receive the mouseup, though, since capturing events bubble the other way.
Anyhow, I am afraid this is all the help I can provide. If you want further assistance please try Stack Overflow tag d3.js or the d3-js Google group. I am currently on vacation.