Fork of Responding to Resize
✓ Published0🌍 Public
This example demonstrates how a D3.js visualization can automatically respond to browser window resizing. It draws two thick blue diagonal lines—an X shape—across a full-screen SVG element. The code uses CSS positioning to make the chart container fill the viewport, then extracts the container’s `clientWidth` and `clientHeight` properties within a `redraw` function. This function sets the SVG’s dimensions and updates the line coordinates accordingly. The visualization listens for window resize events and calls `redraw` each time, ensuring the X always spans the entire display area. The data for the lines is defined as an array of coordinate pairs.
AI-generated descriptionMIT Licensed