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
Kking-seo
Last edited Aug 28, 2019
Created on Aug 28, 2019

This example demonstrates a simple, responsive SVG visualization that adapts to the browser window's size. It draws two thick green lines forming an X across the entire viewport, illustrating how CSS-computed dimensions are used to redraw the graphic on window resizing. The D3 v5 code, using `d3.select`, extracts the container's `clientWidth` and `clientHeight` to update the SVG's `width` and `height` attributes, then repositions the line elements via the `merge` operation. A `window.addEventListener("resize")` handler triggers the `redraw` function whenever the window changes.

AI-generated description

Comments

Sign in to join the discussion.

MIT Licensed