Skip to main content
100%

Responding to Resize

✓ Published0🌍 Public
TTouha Zohair
Last edited May 7, 2020
Created on May 7, 2020

This example demonstrates a dynamic SVG visualization that adjusts its output to match the browser window’s current dimensions. The code extracts the container’s `clientWidth` and `clientHeight`, then uses D3 v5’s `.attr` method to resize the SVG element while redrawing two diagonal lines that form a crosshair. The `redraw` function is invoked initially and again through a `window.addEventListener` listener, which triggers a recalculated layout whenever the viewport changes. The visualization uses D3’s selection and merging API to update the lines efficiently.

AI-generated description
MIT Licensed

Similar vizzes