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() { initialize.call(force, 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.