-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathtreemap.html
executable file
·72 lines (59 loc) · 2.04 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
70
71
72
<html>
<head>
<meta charset="utf-8">
<title>Treemap</title>
</head>
<style>
.nodeRect {
stroke: white;
stroke-width: 2px;
}
.nodeName {
fill: white;
font-size: 12px;
font-family: simsun;
}
</style>
<body>
<script src="http://d3js.org/d3.v3.min.js" charset="utf-8"></script>
<script>
var width = 1900,
height = 1000;
var svg = d3.select("body").append("svg")
.attr("width", width)
.attr("height", height);
var treemap = d3.layout.treemap()
.size([width, height])
.value(function (d) { return d.value; });
d3.json("Data/Data.json", function (error, root) {
var nodes = treemap.nodes(root);
var links = treemap.links(nodes);
console.log(nodes);
console.log(links);
var color = d3.scale.category10();
var groups = svg.selectAll("g")
.data(nodes.filter(function (d) { return !d.children; }))
.enter()
.append("g");
var rects = groups.append("rect")
.attr("class", "nodeRect")
.attr("x", function (d) { return d.x; })
.attr("y", function (d) { return d.y; })
.attr("width", function (d) { return d.dx; })
.attr("height", function (d) { return d.dy; })
.style("fill", function (d, i) { return color(d.parent.name); });
var texts = groups.append("title")
.attr("class", "nodeName")
.attr("x", function (d) { return d.x; })
.attr("y", function (d) { return d.y; })
.attr("dx", "0.5em")
.attr("dy", "1.5em")
.text(function (d) {
if (d.value > 10000) {
return d.name + " " + d.value;
}
});
});
</script>
</body>
</html>