-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbubble.html
108 lines (87 loc) · 2.75 KB
/
bubble.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
<!DOCTYPE html>
<meta charset="utf-8">
<style>
text {
font: 10px sans-serif;
text-anchor: middle;
}
</style>
<svg width="960" height="960">
</svg>
<script src="js/d3.v4.min.js"></script>
<script src="js/d3.tip.v0.6.3.js"></script>
<script>
var country = window.location.search.slice(window.location.search.lastIndexOf("?")+1).split("=")[1];
// ÆøÅݳöÏÖµÄʱ¼ä¼ä¸ô
var appear_interval = 200;
var svg = d3.select("svg"),
width = +svg.attr("width");
var format = d3.format(",d");
var color = d3.scaleOrdinal(d3.schemeCategory20c);
var pack = d3.pack()
.size([width, width])
.padding(1.5);
var node = null;
var tooltip = d3.select("body")
.append("div")
.style("position", "absolute")
.style("z-index", "10")
.style("visibility", "hidden")
.style("color", "white")
.style("padding", "8px")
.style("background-color", "rgba(0, 0, 0, 0.75)")
.style("border-radius", "6px")
.style("font", "12px sans-serif")
.text("tooltip");
d3.csv("preprocessing/"+country+".csv",
function(d) {
d.value = +d.value;
if (d.value) return d;
},
function(error, classes) {
if (error) throw error;
var root = d3.hierarchy({children: classes})
.sum(function(d) { return d.value; })
.each(function(d) {
if (id = d.data.id) {
var id, i = id.lastIndexOf(".");
d.id = id;
d.package = id.slice(0, i);
d.class = id.slice(i + 1);
}
});
var node = svg.selectAll(".node")
.data(pack(root).leaves())
.enter().append("g")
.attr("class", "node")
.attr("transform", function(d) { return "translate(" + d.x + "," + d.y + ")"; });
node.append("circle")
.attr("id", function(d) { return d.id; })
.attr("r", 1)
.style("fill","white")
.transition()
.duration(1000)
.delay(function(d,i){ return i * appear_interval })
.attr("r", function(d) { return d.r; })
.style("fill", function(d) { return color(d.package); })
//.on("mouseover", tip.show)
//.on("mouseout", tip.hide);
node.append("clipPath")
.attr("id", function(d) { return "clip-" + d.id; })
.append("use")
.attr("xlink:href", function(d) { return "#" + d.id; });
node.append("text")
.attr("clip-path", function(d) { return "url(#clip-" + d.id + ")"; })
.style("font-size", function(d) {return Math.min(d.r * 0.3, (2 * d.r - 6) / this.getComputedTextLength() * 2) + "px";})
.selectAll("tspan")
.data(function(d) {
return d.class.split(/(?=[A-Z][^A-Z])/g);
})
.enter().append("tspan")
.attr("x", 0)
.attr("y", function(d, i, nodes) { return 23 + (i - nodes.length / 2 - 0.5) * 20; })
.text(function(d) { return d; });
node.append("title")
.text(function(d) { return d.id + "\n" + format(d.value); });
});
</script>