Zoom vs. Click
✓ Published0🌍 Public
Mmbostock
Last edited May 31, 2016
Created on Mar 2, 2016
This example distinguishes a mouse click from a zoom gesture (pan or wheel) using `d3.event.defaultPrevented`. Randomly placed colored circles render in SVG with `d3.behavior.zoom` for pan and zoom, while a background `rect` listens for click events; clicking it briefly flashes black before returning to white, but panning or zooming suppresses that flash. The code uses D3 v3’s `d3.event.defaultPrevented`, `d3.scale.category10`, and `d3.range` to generate the data.
AI-generated descriptionThis example demonstrates how to disambiguate a click from a zoom gesture using d3.event.defaultPrevented. Click and drag to pan, mousewheel to zoom, or click the background to briefly highlight it.
gpl-3.0 Licensed