-
Notifications
You must be signed in to change notification settings - Fork 117
/
07_transition.html
executable file
·105 lines (97 loc) · 1.52 KB
/
07_transition.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>D3: Transitions</title>
<script type="text/javascript" src="d3.js"></script>
<style type="text/css">
body {
background-color: gray;
}
svg {
background-color: white;
}
</style>
</head>
<body>
<script type="text/javascript">
//Width and height
var w = 500;
var h = 100;
var dataset = [
{
x: 5,
y: 20,
r: 10
},
{
x: 480,
y: 90,
r: 20
},
{
x: 250,
y: 50,
r: 15
},
{
x: 100,
y: 33,
r: 7
},
{
x: 330,
y: 95,
r: 18
},
{
x: 410,
y: 12,
r: 19
},
{
x: 475,
y: 44,
r: 25
},
{
x: 25,
y: 67,
r: 12
},
{
x: 85,
y: 21,
r: 5
},
{
x: 220,
y: 88,
r: 3
}
];
//Create SVG element
var svg = d3.select("body")
.append("svg")
.attr("width", w)
.attr("height", h);
svg.selectAll("circle")
.data(dataset)
.enter()
.append("circle")
.attr("cx", function(d) {
return d.x;
})
.attr("cy", h)
.attr("r", 1)
.transition()
.duration(2000)
.attr("cy", function(d) {
return d.y;
})
.attr("r", function(d) {
return d.r;
});
</script>
</body>
</html>