Skip to main content
100%

Responding to Resize

✓ Published0🌍 Public
SShokoLocoMocco
Last edited Dec 23, 2020
Created on Dec 23, 2020

This example demonstrates how a D3.js v5 visualization can respond dynamically to browser resize events. An SVG element fills the viewport via CSS positioning, and a redraw function extracts the container’s current pixel dimensions using `clientWidth` and `clientHeight`. The code then sets the SVG’s `width` and `height` attributes accordingly and renders two green diagonal lines to form an X, with an event listener on `window` for the `resize` event triggering the redraw. The visualization uses a data join with `selectAll` and `enter` to update the lines.

AI-generated description
MIT Licensed

Similar vizzes