"name": "Title 1", "size":1,
"name": "Title 1-1", "size":1,
{"name": "1-1-1", "size": 1},
{"name": "1-1-2", "size": 1},
{"name": "1-1-3", "size": 1},
{"name": "1-1-4", "size": 1}
"name": "Title 1-2", "size":1,
{"name": "1-2-1", "size": 1},
{"name": "1-2-2", "size": 1},
{"name": "1-2-3", "size": 1}
"name": "Title 1-3", "size":1,
{"name": "1-3-1", "size": 1}
x = d3.scale.linear().range([0, w]),
y = d3.scale.linear().range([0, h]),
color = d3.scale.category10(),
var treemap = d3.layout.treemap()
.value(function(d) { return d.size; });
var svg = d3.select("#body").append("div")
.style("width", w + "px")
.style("height", h + "px")
.attr("transform", "translate(.5,.5)");
var nodes = treemap.nodes(root)
.filter(function(d) { return !d.children; });
var cell = svg.selectAll("g")
.attr("transform", function(d) { return "translate(" + d.x + "," + d.y + ")"; })
.on("click", function(d) { return zoom(node == d.parent ? root : d.parent); });
.attr("width", function(d) { return d.dx - 1; })
.attr("height", function(d) { return d.dy - 1; })
.style("fill", function(d) { return color(d.parent.name); });
.attr("x", function(d) { return d.dx / 2; })
.attr("y", function(d) { return d.dy / 2; })
.attr("text-anchor", "middle")
.text(function(d) { return d.name; })
.style("opacity", function(d) { d.w = this.getComputedTextLength(); return d.dx > d.w ? 1 : 0; });
d3.select(window).on("click", function() { zoom(root); });
d3.select("select").on("change", function() {
treemap.value(this.value == "size" ? size : count).nodes(root);
var kx = w / d.dx, ky = h / d.dy;
x.domain([d.x, d.x + d.dx]);
y.domain([d.y, d.y + d.dy]);
var t = svg.selectAll("g.cell").transition()
.duration(d3.event.altKey ? 7500 : 750)
.attr("transform", function(d) { return "translate(" + x(d.x) + "," + y(d.y) + ")"; });
.attr("width", function(d) { return kx * d.dx - 1; })
.attr("height", function(d) { return ky * d.dy - 1; })
.attr("x", function(d) { return kx * d.dx / 2; })
.attr("y", function(d) { return ky * d.dy / 2; })
.style("opacity", function(d) { return kx * d.dx > d.w ? 1 : 0; });
d3.event.stopPropagation();