Skip to content

Instantly share code, notes, and snippets.

@dhoboy
Last active August 29, 2015 14:17
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 dhoboy/2f6ec590e3efca4c65d3 to your computer and use it in GitHub Desktop.
Save dhoboy/2f6ec590e3efca4c65d3 to your computer and use it in GitHub Desktop.
Gately Radial Tree

Re-working Gately Tree as a Radial Tree. I like this data better as a tree, rather than a radial tree. The radial needed to be spaced out so much to accommodate long labels. Adapted Gately Tree to radial according to this Mike Bostock Block.

<!DOCTYPE html>
<meta charset="utf-8">
<style>
.node circle {
fill: #fff;
stroke: steelblue;
stroke-width: 1.5px;
}
.node {
font: 10px sans-serif;
}
.link {
fill: none;
stroke: #ccc;
stroke-width: 1.5px;
}
</style>
<body>
<script src="http://d3js.org/d3.v3.js"></script>
<script>
var diameter = 1100,
padding = {top: 250, side: 400};
var tree = d3.layout.tree()
.size([360, diameter / 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 + padding.side)
.attr("height", diameter + padding.top)
.append("g")
.attr("transform", "translate(700, 500)");
d3.json("/d/914d024adf10bface11a/gately.json", function(error, data) {
var nodes = tree.nodes(data),
links = tree.links(nodes);
var link = svg.selectAll("path.link")
.data(links)
.enter()
.append("path")
.attr("class", "link")
.attr("d", diagonal);
var nodes = svg.selectAll("g.node")
.data(nodes);
// enter
nodes.enter()
.append("g")
.attr("class", "node")
.attr("transform", function(d){ return "rotate(" + (d.x - 90) + ")translate(" + d.y + ")"; })
// update
nodes.append("circle")
.attr("r", 4.5);
nodes.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 + padding.top) + "px").style("width", (diameter + padding.side) + "px");
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment