-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
73 lines (62 loc) · 1.93 KB
/
index.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
73
<!DOCTYPE html>
<head>
<meta charset="utf-8">
<script src="http://d3js.org/d3.v3.min.js"></script>
<body>
<style>
body {
margin: auto;
width: 960px;
}
.node {
border: solid 1px white;
font: 10px sans-serif;
margin-top: 2px;
line-height: 12px;
overflow: hidden;
position: absolute;
text-indent: 2px;
}
</style>
</head>
<script>
function flatten(lost_data) {
for (var i = 0; i < lost_data.children.length; i++) {
for (var j = 0; j < lost_data.children[i].children.length; j++) {
lost_data += lost_data.children[i].children[j].count
}
}
return lost_data
}
var margin = {top: 40, right: 10, bottom: 10, left: 10},
width = 960
height = 600
var color = d3.scale.ordinal()
.range(["#a49ac1", "#465002", "#3a1cbc", "#cfb2a2", "#22e4ee", "#c8a249", "#f4e71d", "#f2253b", "#5f6df9", "#59897d", "#d3e4c7", "#9faafb", "#8e3646", "#14b293", "#b0dfc4", "#b27f41", "#86eeed", "#bb8f84", "#71b6e1", "#b96ca7", "#dc6a4b", "#686083", "#d0eab1"]);
var treemap = d3.layout.treemap()
.size([width, height])
.sticky(true)
.value(function(d) { return d.count; });
var div = d3.select("body").append("div")
.style("position", "relative")
.style("left", margin.left + "px")
.style("top", margin.top + "px");
d3.json("lostandfound.json", function(root) {
window.lost_data = root;
var node = div.datum(root).selectAll(".node")
.data(treemap.nodes)
.enter().append("div")
.attr("class", "node")
.call(position)
.style("background", function(d) { return d.children ? color(d.category) : null; })
.text(function(d) { return d.item; });
});
function position() {
this.style("left", function(d) { return d.x + "px"; })
.style("top", function(d) { return d.y + "px"; })
.style("width", function(d) { return d.dx - 1 + "px"; })
.style("height", function(d) { return d.dy - 1 + "px"; });
}
</script>
</body>
</html>