Skip to main content
100%

D3.js: Panning with mouse wheel

✓ Published0🌍 Public
Aahmohamed
Last edited Feb 20, 2015
Created on Feb 20, 2015

A D3.js v3 example remaps the mouse wheel to pan a scatterplot of 2,000 normally distributed points instead of zooming. The visualization renders circles as SVG elements inside a group that responds to wheel events. The code uses `d3.behavior.zoom` for the initial zoom setup, then overrides the `wheel.zoom` event with a custom `pan` function. This function reads `d3.event.wheelDeltaX` and `wheelDeltaY`, adds them to the current translation from `d3.transform`, and updates the group’s `transform` attribute, while stopping propagation to prevent default zoom behavior.

AI-generated description

This example demonstrate how to remap D3 events. MouseWheel event is used to pan the chart in x and y directions. This example was created as an answer to this SO question (Refer to it for detailed explanation).

Similar vizzes