Skip to main content
🌍 Public

Share visualization

Send this visualization to others.

Responding to Resize

Public visualization

Viewing a saved revision (read-only)

4b60128afd684ecba1114e2c9e0602a5

Responding to Resize

0 stars0🌍 Public
EEd Link III
Last edited Oct 24, 2019
Created on Oct 23, 2019

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