Skip to main content
100%

Responding to Resize

✓ Published0🌍 Public
Mmi-desai
Last edited Nov 9, 2019
Created on Nov 9, 2019

This example demonstrates how a D3.js visualization can respond dynamically to browser resizing. It shows a green X shape drawn with SVG lines that maintains its position relative to the viewport as the window changes dimensions. The code uses a `window.addEventListener("resize", redraw)` callback, which queries the container’s `clientWidth` and `clientHeight` properties to update the SVG’s `width` and `height` attributes. The `redraw()` function re-binds the line data and updates the `x1`, `y1`, `x2`, and `y2` attributes via `merge()`. The chart container is styled with fixed CSS positioning to fill the entire page.

AI-generated description
MIT Licensed

Similar vizzes