🌍 Public
Viewing a saved revision (read-only)
4b60128afd684ecba1114e2c9e0602a5
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