block by mbostock b1f0ee970299756bc12d60aedf53c13b

Isolating Forces

Full Screen

This example demonstrates how to patch force.initialize such that a force applies only to a subset of nodes in a simulation.

function isolate(force, filter) {
  var initialize = force.initialize;
  force.initialize = function() {, nodes.filter(filter)); };
  return force;

Another way of having forces only apply to some nodes is to set the force strength to zero for those nodes by using a custom strength accessor (e.g., x.x). But if you have lots of isolated forces and lots of nodes, it is faster to isolate the force to a subset of nodes than to set the strength to zero for unaffected nodes.