Skip to main content
100%

Responding to Resize

✓ Published0🌍 Public
Xxhoumba
Last edited Mar 12, 2020
Created on Mar 12, 2020

This example demonstrates a D3.js visualization that dynamically resizes an SVG graphic to match its container’s dimensions. The page’s CSS fixes the chart div to fill the viewport, and the `redraw` function reads `clientWidth` and `clientHeight` to update the SVG’s width and height attributes. It then draws two green, semi-transparent diagonal lines forming an X, whose endpoints are recalculated on every resize. The code uses the browser’s `resize` event listener to invoke `redraw`, alongside D3’s data join for efficient line updates.

AI-generated description
MIT Licensed

Similar vizzes