Skip to content

Instantly share code, notes, and snippets.

@lancepantz
Created March 21, 2012 00:07
Show Gist options
  • Save lancepantz/2142810 to your computer and use it in GitHub Desktop.
Save lancepantz/2142810 to your computer and use it in GitHub Desktop.
d3.json(uri, function(json) {
var myData = data();
force
.nodes(myData.nodes)
.links(myData.links)
.start();
var link = svg.selectAll("line.link")
.data(force.links())
.enter().append("line")
.attr("class", "link")
.style("stroke-width", function(d) { return Math.sqrt(d.value); });
var node = svg.selectAll("circle.node")
.data(force.nodes())
.enter().append("circle")
.attr("class", "node")
.attr("r", nodeSize)
.attr("cx", width / 2)
.attr("cy", height / 2)
.call(force.drag);
var text = svg.selectAll("text.text")
.data(force.nodes())
.enter().append("text")
.attr("class", "label")
.text(function(d) { return d.id; });
force.on("tick", function() {
link
.attr("x1", function(d) { return d.source.x; })
.attr("y1", function(d) { return d.source.y; })
.attr("x2", function(d) { return d.target.x; })
.attr("y2", function(d) { return d.target.y; });
node
.attr("cx", function(d) { return d.x; })
.attr("cy", function(d) { return d.y; });
text
.attr("x", function(d) { return d.x; })
.attr("y", function(d) { return d.y; })
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment