-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathpack_bubble.html
59 lines (45 loc) · 1.39 KB
/
pack_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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<script src="https://d3js.org/d3.v3.js"></script>
<title>Learn D3</title>
</head>
<body>
<script>
var width = 1000;
var height = 800;
var container = d3.select("body")
.append("svg")
.attr("width",width)
.attr("height",height)
.append("g")
.attr("transform","translate(50,50)");
var pack = d3.layout.pack()
.size([width,height - 50])
.padding(10);
d3.json("data2.json", function(data) {
var nodes = pack.nodes(data);
var node = container.selectAll(".node")
.data(nodes)
.enter()
.append("g")
.attr("class","node")
.attr("transform",function (d) {return"translate("+d.x+","+d.y+")";});
node.append("circle")
.attr("r", function (d) { return d.r;
})
.attr("fill",function (d) { return d.children ? "white" : "blue"
})
.attr("opacity",0.25)
.attr("stroke",function (d) { return d.children ? "white" : "yellow"
})
.attr("stroke-width","2");
node.append("text")
.text(function (d) { return d.children ? "" : d.name
})
}
)
</script>
</body>
</html>