🌍 Public
Viewing a saved revision (read-only)
753ab95cd17d4d1190b4f9ab6356accc
Responding to Resize
This example demonstrates how a D3.js v5 visualization can respond to browser window resizing by redrawing its content to match the computed CSS size of its container. The SVG element’s width and height are dynamically updated using `chartDiv.clientWidth` and `clientHeight`, and two diagonal lines are drawn to form an X shape as a visual confirmation of the new dimensions. The code uses D3 selections with `selectAll`, `enter`, and `merge` to update the line elements, and a `window` `resize` event listener triggers the redraw function. The container is fixed to fill the viewport via CSS.
AI-generated description