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
DDy-Diana
Last edited Nov 7, 2020
Created on Nov 7, 2020

This example demonstrates how a D3 v5 visualization can adapt to browser window resizing by redrawing its SVG content to match the new dimensions. The code uses a CSS-positioned container to fill the viewport, then extracts the container’s `clientWidth` and `clientHeight` during a `redraw()` function. It sets the SVG element’s width and height attributes accordingly and updates a pair of green diagonal lines to form an X spanning the full chart area. A `window` resize event listener triggers the redraw on every size change, showing a minimal pattern for responsive D3 SVGs.

AI-generated description

Comments

Sign in to join the discussion.

MIT Licensed