Graphics Reference
In-Depth Information
.attr("height", height);
// some variables for layout assistance
var pad = 50;
var num = Math.sqrt(graph.nodes.length);
var scale = (width - pad * 2) / (num+1);
// draw the nodes
var node = svg.selectAll(".node")
.data(graph.nodes)
.enter().append("circle")
.attr("r", 15)
.attr("cx", function(d,i) { return scale * (i /
num) + pad; })
.attr("cy", function(d,i) { return scale * (i %
num) + pad; });
// draw the links
var link = svg.selectAll(".link")
.data(graph.links)
.enter().append("line")
.style("stroke","blue")
.attr("x1", function(d,i) { return scale *
(d.source / num)
+ pad;})
.attr("y1", function(d,i) { return scale *
(d.source % num)
+ pad; })
.attr("x2", function(d,i) { return scale *
(d.target / num)
+ pad;})
.attr("y2", function(d,i) { return scale *
(d.target % num)
+ pad; });
</script>
</body>
Search WWH ::




Custom Search