Skip to main content
100%

selection-multi and transition rollup

✓ Published0🌍 Public
11wheel
Last edited Jun 29, 2016
Created on Jun 29, 2016

This example demonstrates a D3.js animation that highlights the interplay between chained `.styles()` and `.transition()` methods on selected elements. Two `<h1>` headings are styled and animated in sequence: the first applies a red centered style, then transitions its color to steelblue over one second; the second starts invisible and fades in over another second after a delay. The visualization—essentially a minimal proof-of-concept—uses a custom bundling of d3-selection-multi and d3-transition to show how multi-property style and transition methods can be combined, with a note on the required prototype patching for transition chaining. The page renders text-only, with no charts or data, and relies on animation to demonstrate the effects.

AI-generated description

forked from D3 Custom Bundle II

styles after the transition wasn't working. I needed to modify node_modules/d3-selection-multi/index.js to update the transition prototype:

import {selection} from "d3-selection";
import selection_attrs from "./src/selection_attrs";
import selection_styles from "./src/selection_styles";
import selection_properties from "./src/selection_properties";

selection.prototype.attrs = selection_attrs;
selection.prototype.styles = selection_styles;
selection.prototype.properties = selection_properties;

if (selection.prototype.transition){
  selection.prototype.transition.attrs = selection_attrs;
  selection.prototype.transition.styles = selection_attrs;
  selection.prototype.transition.properties = selection_attrs;
}

This seems way too hacky since it there's an unspecified dependency on loading d3-transition before d3-selection-multi. I'm not sure if there should be a separate d3-selection-transition-multi module to handle this? Creating two modules for everything you'd like to stick onto selection.prototype seems like overkill.

To use attrs after a transition now, just add this to the top of your code:

d3.selection.prototype.transition.attrs = d3.selection.prototype.attrs
gpl-3.0 Licensed

Similar vizzes