Skip to main content
100%

Responding to Resize

✓ Published1🌍 Public
Ggonghewan
Last edited Jan 17, 2020
Created on Jan 17, 2020

This example demonstrates how a visualization can respond to browser window resizing by redrawing an SVG to match its container’s updated dimensions. It shows a green X spanning the full width and height of the viewport, with thick, semi-transparent strokes. The code uses `d3.select` to create an SVG element and a `redraw()` function that reads `clientWidth` and `clientHeight` from the chart’s `<div>`, then sets the SVG’s `width` and `height` attributes accordingly. A `window.addEventListener("resize", redraw)` triggers the redraw on every resize event, while `selection.enter().merge()` updates the two `<line>` elements’ coordinates.

AI-generated description
MIT Licensed

Similar vizzes