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
TTheRedUnicorn
Last edited Jul 18, 2019
Created on Jul 18, 2019

This example demonstrates a chart that responds to browser resizing by redrawing its content to match the available space. It shows a large green X drawn across the entire viewport, with the SVG dimensions updating dynamically as the window changes. The code uses the D3 v5 library to bind an SVG element to a fixed-position container, then recalculates the width and height from the container's `clientWidth` and `clientHeight` properties on every resize event. A `redraw()` function defines two diagonal lines and updates their endpoints via D3's selection-merging API, while a window listener triggers the redraw.

AI-generated description

Comments

Sign in to join the discussion.

MIT Licensed