Skip to main content
100%

Zoom Transitions

✓ Published0🌍 Public
AAjayyy
Last edited May 13, 2019
Created on Jul 20, 2018

A phyllotaxis layout of a thousand black circles on a canvas randomly selects a red target point every 2.5 seconds, smoothly zooming to center it using the `d3.zoom` API and `transition()` call. The animation uses a custom `zoomed` handler that translates and scales the context, leveraging `d3-zoom`’s transform interpolation. Rendering is done via the Canvas 2D context.

AI-generated description

This example demonstrates smooth zoom transitions using d3-zoom. Every 2.5 seconds, a point is randomly selected, and the transform to position the selected point at the center of the viewport is computed:

function transform() {
  return d3.zoomIdentity
      .translate(width / 2, height / 2)
      .scale(8)
      .translate(-point[0], -point[1]);
}

Then, transition.call is used to invoke zoom.transform with the new transform, initiating a smooth zoom transition from the current transform.

forked from <a href='http://bl.ocks.org/mbostock/'>mbostock</a>'s block: <a href='http://bl.ocks.org/mbostock/b783fbb2e673561d214e09c7fb5cedee'>Zoom Transitions</a>

gpl-3.0 Licensed

Similar vizzes