All examples By author By category About

cool-Blue

d3 Force directed graph with node size transitions - CSS transitions

d3 Force directed graph with node size transitions - CSS transitions


Key points

  1. Gravity, and charge set to 0, friction set to 1
  2. Schedule the transition on the radius in the timer callback
  3. Create a dynamic radius on the data (d.rt) and, in the tick callback, update it with the current DOM element radius to synchronise with the transition
  4. Use the dynamic radius for calculating collisions
  5. Use the dynamic radius to adjust the line x0 and x1 in the tick callback
  6. Use a transform on the nodes (g element) to decouple text and line positioning from node position, adjust the transform x and y, only in the tick callback
  7. Using CSS transitions on circle radius and getComputedStyle or r.animVal.value to track it

Cross-browser version without CSS transitions


Issues

Only works in chrome!