Skip to main content
100%

Responding to Resize

✓ Published1🌍 Public
Llinlala
Last edited Dec 9, 2019
Created on Dec 9, 2019

This example demonstrates how a D3.js visualization can dynamically respond to browser window resizing. It fills the entire viewport with an SVG element, then draws two green diagonal lines forming an X, with the intersection point shifting as the dimensions change. The code uses a custom `redraw` function that reads the container’s `clientWidth` and `clientHeight` to update the SVG’s width and height attributes, binding new coordinate data to the lines via a data join. A `window` resize event listener triggers `redraw` each time the viewport size changes.

AI-generated description
MIT Licensed

Similar vizzes