Skip to main content
🌍 Public

Share visualization

Send this visualization to others.

Responding to Resize

Public visualization

Responding to Resize

0 stars0🌍 Public
Ssetom
Last edited Dec 12, 2019
Created on Dec 12, 2019

This example demonstrates a full-window SVG chart that automatically redraws itself whenever the browser window is resized. The code uses CSS fixed positioning to make a container div fill the viewport, then reads its `clientWidth` and `clientHeight` properties inside a `redraw()` function. It sets the SVG’s `width` and `height` attributes accordingly and renders two diagonal green lines forming an X, using the data-join pattern with `svg.selectAll("line").data()` and the `merge()` method. A global `resize` event listener triggers the redraw on every window size change.

AI-generated description

Comments

Sign in to join the discussion.

MIT Licensed