Skip to content

Instantly share code, notes, and snippets.



Forked from mbostock/.block
Created Sep 25, 2015
What would you like to do?
Cluster Dendrogram

A dendrogram is a node-link diagram that places leaf nodes of the tree at the same depth. In this example, the classes (leaf nodes) are aligned on the right edge, with the packages (internal nodes) to the left. Data shows the Flare class hierarchy, courtesy Jeff Heer.

Compare to this radial layout.

<!DOCTYPE html>
<meta charset="utf-8">
.node circle {
fill: #fff;
stroke: steelblue;
stroke-width: 1.5px;
.node {
font: 10px sans-serif;
.link {
fill: none;
stroke: #ccc;
stroke-width: 1.5px;
<script src=""></script>
var width = 960,
height = 2200;
var cluster = d3.layout.cluster()
.size([height, width - 160]);
var diagonal = d3.svg.diagonal()
.projection(function(d) { return [d.y, d.x]; });
var svg ="body").append("svg")
.attr("width", width)
.attr("height", height)
.attr("transform", "translate(40,0)");
d3.json("/mbostock/raw/4063550/flare.json", function(error, root) {
if (error) throw error;
var nodes = cluster.nodes(root),
links = cluster.links(nodes);
var link = svg.selectAll(".link")
.attr("class", "link")
.attr("d", diagonal);
var node = svg.selectAll(".node")
.attr("class", "node")
.attr("transform", function(d) { return "translate(" + d.y + "," + d.x + ")"; })
.attr("r", 4.5);
.attr("dx", function(d) { return d.children ? -8 : 8; })
.attr("dy", 3)
.style("text-anchor", function(d) { return d.children ? "end" : "start"; })
.text(function(d) { return; });
});"height", height + "px");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment