Created
December 20, 2012 12:05
-
-
Save adriaanbaelus/4344931 to your computer and use it in GitHub Desktop.
Edge crossing with Reingold-Tilford
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
{ | |
"name": "Parent", | |
"children": [ | |
{ "name": "Child A" }, | |
{ "name": "Child B", | |
"children": [ | |
{ "name": "Grandchild 1" }, | |
{ "name": "Grandchild 2" }, | |
{ "name": "Grandchild 3" }, | |
{ "name": "Grandchild 4" }, | |
{ "name": "Grandchild 5" }, | |
{ "name": "Grandchild 6" }, | |
{ "name": "Grandchild 7" }, | |
{ "name": "Grandchild 8" } | |
]} | |
] | |
} |
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
<!DOCTYPE html> | |
<meta charset="utf-8"> | |
<link rel="stylesheet" href="style.css"> | |
<body> | |
<script src="http://d3js.org/d3.v3.min.js"></script> | |
<script> | |
var diameter = 960; | |
var tree = d3.layout.tree() | |
.size([360, (diameter - 150 - 100) / 2]) | |
.separation(function(a, b) { return (a.parent == b.parent ? 1 : 2) / a.depth; }); | |
var diagonal = d3.svg.diagonal.radial() | |
.projection(function(d) { return [d.y, d.x / 180 * Math.PI]; }); | |
var svg = d3.select("body").append("svg") | |
.attr("width", diameter) | |
.attr("height", diameter - 150) | |
.append("g") | |
.attr("transform", "translate(" + diameter / 2 + "," + (diameter - 150) / 2 + ")"); | |
d3.json("data.json", function(error, root) { | |
var nodes = tree.nodes(root), | |
links = tree.links(nodes); | |
var link = svg.selectAll(".link") | |
.data(links) | |
.enter().append("path") | |
.attr("class", "link") | |
.attr("d", diagonal); | |
var node = svg.selectAll(".node") | |
.data(nodes) | |
.enter().append("g") | |
.attr("class", "node") | |
.attr("transform", function(d) { return "rotate(" + (d.x - 90) + ")translate(" + d.y + ")"; }) | |
node.append("circle") | |
.attr("r", 4.5); | |
node.append("text") | |
.attr("dy", ".31em") | |
.attr("text-anchor", function(d) { return d.x < 180 ? "start" : "end"; }) | |
.attr("transform", function(d) { return d.x < 180 ? "translate(8)" : "rotate(180)translate(-8)"; }) | |
.text(function(d) { return d.name; }); | |
}); | |
d3.select(self.frameElement).style("height", diameter + "px"); | |
</script> | |
</body> |
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
.node circle { | |
fill: #fff; | |
stroke: steelblue; | |
stroke-width: 1.5px; | |
} | |
.node { | |
font: 10px sans-serif; | |
} | |
.link { | |
fill: none; | |
stroke: #ccc; | |
stroke-width: 1.5px; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment