-
Notifications
You must be signed in to change notification settings - Fork 0
/
treemap.html
69 lines (53 loc) · 1.56 KB
/
treemap.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<!DOCTYPE html ">
<html lang="en">
<head>
<meta charset="utf-8">
<title>
TreeMap Layout example
</title>
<script src="http://d3js.org/d3.v3.min.js"></script>
</script>
<style type="text/css">
</style>
</head>
<body>
<script type="text/javascript">
var w = 800;
var h = 600;
var margin = {top:5, bottom:5, left:5, right: 5};
var width = w - margin.left - margin.right;
var height = h - margin.top - margin.bottom;
var svg = d3.select("body").append("svg")
.attr({width:w, height:h});
var chart = svg.append("g")
.attr("transform","translate("+margin.left + "," + margin.top+ ")");
var treemap = d3.layout.treemap()
.size([width, height])
.round(true)
.value(function(d){return +d.size;})
.mode("squarify")
.padding(2);
var color = d3.scale.category20c();
d3.json("http://www.cs.middlebury.edu/~candrews/classes/infovis/data/infovis_dir.json", function (dataset) {
var treeNodes = treemap.nodes(dataset);
var nodes = chart.selectAll(".node")
.data(treeNodes)
.enter()
.append("rect")
.attr({
class:"node",
x: function(d){return d.x;},
y: function(d){return d.y;},
width: function(d){return d.dx;},
height: function(d){return d.dy;},
})
.style("stroke", "white")
.style("fill", function(d){
return d.children? "grey":color(d.name.slice(d.name.length-3));
});
var labels = nodes.append("title")
.text(function(d){return d.name;});
});
</script>
</body>
</html>