Skip to content

Instantly share code, notes, and snippets.

@nsonnad
Created July 2, 2013 07:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nsonnad/5907400 to your computer and use it in GitHub Desktop.
Save nsonnad/5907400 to your computer and use it in GitHub Desktop.
Multi-foci d3 force layout, based on data
force.on("tick", function(e) {
// Push nodes toward their designated focus.
var k = .1 * e.alpha;
nodes.forEach(function(o, i) {
o.y += (foci[o.id].y - o.y) * k;
o.x += (foci[o.id].x - o.x) * k;
});
vis.selectAll("circle.node")
.attr("cx", function(d) { return d.x; })
.attr("cy", function(d) { return d.y; });
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment