Skip to main content
100%

Transition to Default

✓ Published0🌍 Public
Mmbostock
Last edited Feb 9, 2016
Created on Oct 22, 2015

A single circle cycles through random HCL colors as an inline style, then transitions back to its default fill. Every 2.5 seconds, d3.hcl assigns a new fill, followed by a 2-second transition. The transition’s fill function temporarily removes the inline style, reads the computed default from the stylesheet, restores the original color, and returns the default, so the circle fades back to dark gray. This illustrates a workaround for d3.v3’s transition.style behavior, which lacks built-in null handling. The example uses SVG rendering with D3’s selection and transition methods.

AI-generated description

This example demonstrates how to transition back to a default style value after setting an inline style. Inside transition.style, temporarily remove the style to retrieve its default value; then restore the style before starting the transition.

In a future version of D3 (see related issue), transition.style(name, null) will probably do this for you automatically, rather than its current behavior of immediately removing the specified style at the start of the transition.

gpl-3.0 Licensed

Similar vizzes