🌍 Public
Viewing a saved revision (read-only)
3541bf04b4794ed9aa1efd5fd2d65a64
Responding to Resize
This example demonstrates how a D3.js visualization can respond dynamically to browser resizing. A green X-shaped pair of lines fills the entire viewport, with the SVG’s width and height attributes continuously updated based on the container’s client dimensions. The code uses a CSS fixed-position div to define the chart area, then directly sets the SVG dimensions via `clientWidth` and `clientHeight` within a `redraw` function. A `window.addEventListener("resize", redraw)` triggers the update, while D3’s data join (`selectAll`, `enter`, `merge`) efficiently redraws the line elements with updated coordinates and stroke properties.
AI-generated description