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
SSimon Fei
Last edited Nov 2, 2019
Created on Nov 2, 2019

This example demonstrates a responsive SVG visualization that adapts to its container’s size. It uses CSS to make a chart div fill the viewport, then extracts the computed `clientWidth` and `clientHeight` in a `redraw` function to dynamically set the SVG’s width and height attributes. The code draws two green crossed lines, creating an X, with a thick semi-transparent stroke. A window `resize` event listener triggers `redraw` whenever the browser dimensions change, ensuring the visualization always matches the available space. The implementation relies on D3 v5’s `select` and data-join methods for updating the lines.

AI-generated description

Comments

Sign in to join the discussion.

MIT Licensed