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
HHouseoftruth
Last edited Apr 26, 2020
Created on Apr 26, 2020

This example demonstrates how to create a visualization that automatically responds to changes in the browser window size. The code uses CSS to position a chart container that fills the entire viewport, then extracts the container’s computed width and height via `clientWidth` and `clientHeight` in a `redraw` function. An SVG element is resized to match these dimensions, and two green lines are drawn across the space to form an X, verifying that the size updates correctly. A `window` resize event listener triggers the `redraw` function whenever the viewport changes. The example uses D3 v5 with SVG rendering.

AI-generated description

Comments

Sign in to join the discussion.

MIT Licensed