-
Notifications
You must be signed in to change notification settings - Fork 0
/
bubbleExample.html
70 lines (65 loc) · 2.4 KB
/
bubbleExample.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
<html>
<head>
<script src = "d3.min.js"></script>
</head>
<body>
<script type="text/javascript">
var familyData = {
"name": "Maria",
"value": 80,
"children": [
{"name": "Cathy",
"value": 53,
"children":
[
{"name":"Yvette", "value": 35, children: [
{"name": "Aliyah", "value": 13},
{"name": "Hannah", "value": 10}
]
},
{"name": "Patty", "value": 25},
{"name": "Gavin", "value": 11}
]
},
{"name": "Ana",
"value": 50,
"children":
[
{"name": "Perry", "value": 29},
{"name": "Dani", "value": 26, children:[
{"name": "Patches", "value": 15},
{"name": "Scrabble", "value": 7},
{"name": "Rook", "value": 7},
{"name": "Bitey", "value": 3}
]
},
{"name": "Stevie", "value": 21}
]
}
]
};
var width = 800,
height = 600,
svgContainer = 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);
var nodes = pack.nodes(familyData);
var node = svgContainer.selectAll('.node')
.data(nodes)
.enter()
.append('g')
.attr('transform', function(d) { return 'translate(' + d.x + ',' + d.y + ')';});
var nodeCircles = node.append('circle')
.attr('r', function (d) { return d.r;})
.attr('fill', function (d) { return d.children ? 'white' : 'blue';})
.attr('opacity', 0.2);
var names = node.append('text')
.text(function (d) { return d.children ? "" : d.name;});
</script>
</body>
</html>