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
VVijay2051
Last edited Jul 8, 2019
Created on Jul 8, 2019

This example demonstrates how a visualization can dynamically respond to browser window resizing. It shows a green X shape that stretches and scales to fill the entire viewport, using an SVG canvas. The code uses CSS to size a chart container and then extracts its computed dimensions via `clientWidth` and `clientHeight`. A `redraw` function updates the SVG’s width and height attributes and redraws two intersecting lines. A window `resize` event listener triggers this function, ensuring the graphic always matches the current viewport size. It uses D3.js v5 for SVG element creation and manipulation.

AI-generated description

Comments

Sign in to join the discussion.

MIT Licensed