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

1
AAdira4300
Last edited Apr 5, 2020
Created on Apr 5, 2020

This example demonstrates how a D3.js visualization can respond dynamically to browser window resizing. It shows a full-page SVG containing a large green X shape, where the X’s endpoints are recalculated to match the current viewport dimensions whenever the window is resized. The code uses `d3.select` to append an SVG element to a fixed-position chart container, then defines a `redraw` function that reads the container’s `clientWidth` and `clientHeight` properties to update the SVG’s `width` and `height` attributes. It binds the X’s line coordinates through D3’s data join pattern, and registers the `redraw` function as a listener for the browser’s `resize` event.

AI-generated description

Comments

Sign in to join the discussion.

MIT Licensed