Skip to main content
100%

Responding to Resize

✓ Published0🌍 Public
LLorenzo Furno
Last edited Dec 29, 2019
Created on Dec 29, 2019

This example demonstrates how a D3.js visualization can respond dynamically to browser window resizing by redrawing an SVG element to match its container’s current dimensions. The code uses `clientWidth` and `clientHeight` to extract the CSS-computed size of the chart div, then updates the SVG’s `width` and `height` attributes accordingly. It renders two green diagonal lines forming an X, with a thick stroke and partial opacity, to visually confirm the resizing behavior. The `window.addEventListener('resize', ...)` triggers the `redraw` function on every viewport change.

AI-generated description
MIT Licensed

Similar vizzes