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
TTouha Zohair
Last edited May 7, 2020
Created on May 7, 2020

This example demonstrates a dynamic SVG visualization that adjusts its output to match the browser window’s current dimensions. The code extracts the container’s `clientWidth` and `clientHeight`, then uses D3 v5’s `.attr` method to resize the SVG element while redrawing two diagonal lines that form a crosshair. The `redraw` function is invoked initially and again through a `window.addEventListener` listener, which triggers a recalculated layout whenever the viewport changes. The visualization uses D3’s selection and merging API to update the lines efficiently.

AI-generated description

Comments

Sign in to join the discussion.

MIT Licensed