Skip to main content
100%

Responding to Resize

✓ Published0🌍 Public
JJosé
Last edited Jul 18, 2020
Created on Jul 18, 2020

This example demonstrates how a D3.js v5 SVG visualization can respond to browser resizing. The chart container fills the page using CSS, and the `redraw()` function extracts its `clientWidth` and `clientHeight` to set the SVG’s dimensions. It then draws a dynamic X shape—two green lines with 100-pixel stroke width—that always spans the full viewport. A `window` resize event listener triggers `redraw()` on every size change, ensuring the visualization stays responsive without recalculating scales. The rendering relies on SVG elements and direct attribute updates.

AI-generated description
MIT Licensed

Similar vizzes