Skip to main content
Public

Share visualization

Loading preview…

Responding to Resize

vizhub.com

Shared links may look like this on X, LinkedIn, Slack, and Discord.

Before sharing, review the publishing checklist.

Choose how to deliver this visualization

LinkedIn caption

LinkedIn may not keep text supplied by the share sheet. Copy the caption and paste it into the post if needed. You can tag the VizHub company page when posting.

More options

Embed on a websiteCopy iframe embed code
Download & exportPNG, HTML, source ZIP

Responding to Resize

0
Mmkarachi
Last edited Apr 26, 2020
Created on Apr 26, 2020

This example demonstrates how a D3.js visualization can respond dynamically to browser resizing. It uses CSS positioning to make the chart container fill the viewport, then queries its `clientWidth` and `clientHeight` properties on each resize event to update the SVG’s `width` and `height` attributes. The visualization redraws a large green X composed of two SVG `<line>` elements, using the `merge` method for efficient updates. The code relies on the `window.addEventListener("resize", redraw)` API to trigger the redraw function whenever the window dimensions change.

AI-generated description

Comments

Sign in to join the discussion.

MIT Licensed