Created
January 12, 2012 15:38
-
-
Save alper/1601164 to your computer and use it in GitHub Desktop.
D3 onload
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
window.onload = function() { | |
console.log('Loaded..'); | |
var w = 960; | |
var h = 2200; | |
var cluster = d3.layout.cluster() | |
.size([h, w - 160]) | |
var diagonal = d3.svg.diagonal() | |
.projection(function(d) { return [d.y, d.x]; }); | |
var vis = d3.select("#viz").append("svg") | |
.attr("width", w) | |
.attr("height", h) | |
.append("g") | |
.attr("tranform", "translate(40, 0)"); | |
d3.json("tree.json", function(json) { | |
console.log(json); | |
var nodes = cluster.nodes(json); | |
console.log(nodes); | |
console.log(cluster.links(nodes)); | |
var link = vis.selectAll("path.link") | |
.data(cluster.links(nodes)) | |
.enter().append("path") | |
.attr("class", "link") | |
.attr("d", diagonal); | |
var node = vis.selectAll("g.node") | |
.data(nodes) | |
.enter().append("g") | |
.attr("class", "node") | |
.attr("transform", function(d) { return "translate(" + d.y + "," + d.x + ")"; }) | |
node.append("circle") | |
.attr("r", 4.5); | |
node.append("text") | |
.attr("dx", function(d) { return d.children ? -8 : 8; }) | |
.attr("dy", 3) | |
.attr("text-anchor", function(d) { return d.children ? "end":"start"; }) | |
.text(function(d) { return d.name; }); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment