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
TTrey Billing
Last edited Aug 22, 2019
Created on Aug 22, 2019

This example demonstrates how a D3.js visualization can adapt to browser window resizing. It uses the CSS `position: fixed` to make the chart container fill the viewport, then extracts the container’s `clientWidth` and `clientHeight` to set the SVG’s width and height attributes on each resize event. A green X is drawn using SVG `<line>` elements and the `selection.merge()` method, with both lines re-rendered to span the full dimensions. The code relies on `d3.select` and the `window.addEventListener("resize", redraw)` API to trigger updates.

AI-generated description

Comments

Sign in to join the discussion.

MIT Licensed