Skip to main content
100%

Responding to Resize

✓ Published0🌍 Public
LLI
Last edited Aug 17, 2019
Created on Aug 17, 2019

This example demonstrates how a D3.js SVG visualization can adapt to browser window resizing, drawing a green X composed of two thick lines that span the full width and height of the container. It shows the size extraction and redrawing process in action. The code uses a `redraw` function that reads the dynamic `clientWidth` and `clientHeight` properties of the chart’s div, then updates the SVG’s `width` and `height` attributes accordingly via D3 selections and merges. A native `window.addEventListener("resize", redraw)` triggers the redraw on every viewport change, while CSS fixed positioning ensures the container fills the page.

AI-generated description
MIT Licensed

Similar vizzes