Skip to main content
Public

Share visualization

Loading preview…

Fork of 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

Fork of Responding to Resize

0
Hhafiz9977
Last edited Dec 23, 2020
Created on Dec 23, 2020

This example demonstrates how a D3.js visualization can automatically respond to browser window resizing. It draws two thick blue diagonal lines—an X shape—across a full-screen SVG element. The code uses CSS positioning to make the chart container fill the viewport, then extracts the container’s `clientWidth` and `clientHeight` properties within a `redraw` function. This function sets the SVG’s dimensions and updates the line coordinates accordingly. The visualization listens for window resize events and calls `redraw` each time, ensuring the X always spans the entire display area. The data for the lines is defined as an array of coordinate pairs.

AI-generated description

Comments

Sign in to join the discussion.

MIT Licensed