Skip to main content
100%

Responding to Resize

✓ Published0🌍 Public
VVijay2051
Last edited Jul 8, 2019
Created on Jul 8, 2019

This example demonstrates how a visualization can dynamically respond to browser window resizing. It shows a green X shape that stretches and scales to fill the entire viewport, using an SVG canvas. The code uses CSS to size a chart container and then extracts its computed dimensions via `clientWidth` and `clientHeight`. A `redraw` function updates the SVG’s width and height attributes and redraws two intersecting lines. A window `resize` event listener triggers this function, ensuring the graphic always matches the current viewport size. It uses D3.js v5 for SVG element creation and manipulation.

AI-generated description
MIT Licensed

Similar vizzes