-
Notifications
You must be signed in to change notification settings - Fork 2
/
example1.html
66 lines (55 loc) · 1.33 KB
/
example1.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
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
<title>Point-along-path Interpolation</title>
<body>
<script type="text/javascript" src="http://mbostock.github.com/d3/d3.js?2.4.6"></script>
<style type="text/css">
path {
cursor: pointer;
fill: #eee;
stroke: #666;
stroke-width: 1.5px;
}
circle {
fill: steelblue;
stroke: white;
stroke-width: 1.5px;
}
</style>
<script type="text/javascript">
var w = 1260,
h = 800;
var svg = d3.select("body").append("svg:svg")
.attr("width", w)
.attr("height", h)
.append("svg:g")
.attr("transform", "translate(" + w / 2 + "," + h / 2 + ")");
var path = svg.append("svg:path")
.attr("d", d3.svg.arc()
.innerRadius(h / 4)
.outerRadius(h / 3)
.startAngle(0)
.endAngle(Math.PI));
var circle = svg.append("svg:circle")
.attr("r", 6.5)
.attr("transform", "translate(0," + -h / 3 + ")");
function transition() {
circle.transition()
.duration(5000)
.attrTween("transform", translateAlong(path.node()))
}
transition();
function translateAlong(path) {
var l = path.getTotalLength();
return function(d, i) {
return function(t) {
var p = path.getPointAtLength(t * l);
return "translate(" + p.x + "," + p.y + ")";
};
};
}
</script>
</body>
</html>