Skip to main content
Public

Share visualization

Loading preview…

Dealing with Timers

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

Dealing with Timers

1
CCurran Kelleher
Last edited Aug 12, 2024
Created on Jul 29, 2024
Forked from Clickable Circles

This visualization demonstrates how to manage timers for blinking effects in interactive data visualizations. It renders a set of colored circles using D3.js, where clicking a circle highlights it and triggers a blinking animation through alternating stroke colors. The code uses D3’s selection API with `select` and `join` for efficient SVG updates, and manages a timer via `setTimeout` within the main function. A cleanup function is returned to clear the timeout, ensuring proper handling during hot reloads, similar to React’s `useEffect` cleanup pattern.

AI-generated description

Click on a circle to see it highlight and blink!

This example is about dealing with timers, such as the one related to the blinking of the circle. It shows how you can return a "cleanup function" from main, which will be invoked whenever the app is hot reloaded. This is similar to the cleanup function returned from the useEffect callback in React.

For examples of this in various frameworks, see d3-rosetta

Comments

Sign in to join the discussion.

MIT Licensed