Skip to main content
100%

Responding to Resize

✓ Published1🌍 Public
AAdira4300
Last edited Apr 5, 2020
Created on Apr 5, 2020

This example demonstrates how a D3.js visualization can respond dynamically to browser window resizing. It shows a full-page SVG containing a large green X shape, where the X’s endpoints are recalculated to match the current viewport dimensions whenever the window is resized. The code uses `d3.select` to append an SVG element to a fixed-position chart container, then defines a `redraw` function that reads the container’s `clientWidth` and `clientHeight` properties to update the SVG’s `width` and `height` attributes. It binds the X’s line coordinates through D3’s data join pattern, and registers the `redraw` function as a listener for the browser’s `resize` event.

AI-generated description
MIT Licensed

Similar vizzes