Skip to content

Instantly share code, notes, and snippets.

@recursionbane
Forked from mbostock/.block
Last active February 27, 2017 16:31
Show Gist options
  • Save recursionbane/2057fe21345e02b901c6a1598f621513 to your computer and use it in GitHub Desktop.
Save recursionbane/2057fe21345e02b901c6a1598f621513 to your computer and use it in GitHub Desktop.
Radial Dendrogram for blocks and experiments
license: gpl-3.0
border: no
height: 900
id value
my__prc
my__prc.blockA
my__prc.blockA.ipo1234_run1
my__prc.blockA.ipo1234_run1.setup 1
my__prc.blockA.ipo1234_run1.prep 2
my__prc.blockA.ipo1234_run1.plan 3
my__prc.blockA.ipo1234_run1.place 4
my__prc.blockA.ipo1234_run1.cts 5
my__prc.blockA.ipo1234_run1.postcts 6
my__prc.blockA.ipo1234_run1.route 7
my__prc.blockA.ipo1234_run1.postroute 8
my__prc.blockA.ipo1234_run1.fill 9
my__prc.blockA.ipo1234_run2
my__prc.blockA.ipo1234_run2.setup 1
my__prc.blockA.ipo1234_run2.prep 2
my__prc.blockA.ipo1234_run2.plan 3
my__prc.blockA.ipo1234_run2.place 4
my__prc.blockA.ipo1234_run2.cts 5
my__prc.blockA.ipo1234_run2.route 6
my__prc.blockA.ipo1234_run2.postroute 7
my__prc.blockA.ipo1234_run2.fill 8
my__prc.blockB
my__prc.blockB.ipo1234_run1
my__prc.blockB.ipo1234_run1.setup 1
my__prc.blockB.ipo1234_run1.prep 2
my__prc.blockB.ipo1234_run1.plan 3
my__prc.blockB.ipo1234_run1.place 4
my__prc.blockB.ipo1234_run1.cts 5
my__prc.blockB.ipo1234_run1.postcts 6
my__prc.blockB.ipo1234_run1.route 7
my__prc.blockB.ipo1234_run1.postroute 8
my__prc.blockB.ipo1234_run1.fill 9
my__prc.blockB.ipo1234_run2
my__prc.blockB.ipo1234_run2.setup 1
my__prc.blockB.ipo1234_run2.prep 2
my__prc.blockB.ipo1234_run2.plan 3
my__prc.blockB.ipo1234_run2.place 4
my__prc.blockB.ipo1234_run2.cts 5
my__prc.blockB.ipo1234_run2.route 6
my__prc.blockB.ipo1234_run2.postroute 7
my__prc.blockB.ipo1234_run2.fill 8
<!DOCTYPE html>
<meta charset="utf-8">
<style>
.node circle {
fill: #999;
}
.node text {
font: 10px sans-serif;
}
.node--internal circle {
fill: #555;
}
.node--internal text {
text-shadow: 0 1px 0 #fff, 0 -1px 0 #fff, 1px 0 0 #fff, -1px 0 0 #fff;
}
.link {
fill: none;
stroke: #555;
stroke-opacity: 0.4;
stroke-width: 1.5px;
}
</style>
<svg width="960" height="900"></svg>
<script src="//d3js.org/d3.v4.min.js"></script>
<script>
var svg = d3.select("svg"),
width = +svg.attr("width"),
height = +svg.attr("height"),
g = svg.append("g").attr("transform", "translate(" + width / 2 + "," + (height / 2 + 20) + ")");
var stratify = d3.stratify()
.parentId(function(d) { return d.id.substring(0, d.id.lastIndexOf(".")); });
var cluster = d3.cluster()
.size([360, width / 2 - 120]);
d3.csv("flare.csv", function(error, data) {
if (error) throw error;
var root = stratify(data)
.sort(function(a, b) { return a.height - b.height || a.id.localeCompare(b.id); });
cluster(root);
var link = g.selectAll(".link")
.data(root.descendants().slice(1))
.enter().append("path")
.attr("class", "link")
.attr("d", function(d) {
return "M" + project(d.x, d.y)
+ "C" + project(d.x, (d.y + d.parent.y) / 2)
+ " " + project(d.parent.x, (d.y + d.parent.y) / 2)
+ " " + project(d.parent.x, d.parent.y);
});
var node = g.selectAll(".node")
.data(root.descendants())
.enter().append("g")
.attr("class", function(d) { return "node" + (d.children ? " node--internal" : " node--leaf"); })
.attr("transform", function(d) { return "translate(" + project(d.x, d.y) + ")"; });
node.append("circle")
.attr("r", 2.5);
node.append("text")
.attr("dy", "0.31em")
.attr("x", function(d) { return d.x < 180 === !d.children ? 6 : -6; })
.style("text-anchor", function(d) { return d.x < 180 === !d.children ? "start" : "end"; })
.attr("transform", function(d) { return "rotate(" + (d.x < 180 ? d.x - 90 : d.x + 90) + ")"; })
.text(function(d) { return d.id.substring(d.id.lastIndexOf(".") + 1); });
});
function project(x, y) {
var angle = (x - 90) / 180 * Math.PI, radius = y;
return [radius * Math.cos(angle), radius * Math.sin(angle)];
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment