source: Dev/trunk/d3/examples/pie/pie-transition.html @ 76

Last change on this file since 76 was 76, checked in by fpvanagthoven, 14 years ago

d3

File size: 1.5 KB
Line 
1<!DOCTYPE html>
2<html>
3  <head>
4    <title>Pie Chart</title>
5    <script type="text/javascript" src="../../d3.js"></script>
6    <script type="text/javascript" src="../../d3.layout.js"></script>
7    <style type="text/css">
8
9body {
10  font: 10px sans-serif;
11}
12
13    </style>
14  </head>
15  <body>
16    <script type="text/javascript">
17
18var w = 400,
19    h = 400,
20    r = Math.min(w, h) / 2,
21    data = d3.range(10).map(Math.random),
22    color = d3.scale.category20(),
23    arc = d3.svg.arc().outerRadius(r),
24    donut = d3.layout.pie();
25
26var vis = d3.select("body")
27  .append("svg:svg")
28    .data([data.sort(d3.descending)])
29    .attr("width", w)
30    .attr("height", h);
31
32var arcs = vis.selectAll("g.arc")
33    .data(donut)
34  .enter().append("svg:g")
35    .attr("class", "arc")
36    .attr("transform", "translate(" + r + "," + r + ")");
37
38var paths = arcs.append("svg:path")
39    .attr("fill", function(d, i) { return color(i); });
40
41paths.transition()
42    .ease("bounce")
43    .duration(2000)
44    .attrTween("d", tweenPie);
45
46paths.transition()
47    .ease("elastic")
48    .delay(function(d, i) { return 2000 + i * 50; })
49    .duration(750)
50    .attrTween("d", tweenDonut);
51
52function tweenPie(b) {
53  b.innerRadius = 0;
54  var i = d3.interpolate({startAngle: 0, endAngle: 0}, b);
55  return function(t) {
56    return arc(i(t));
57  };
58}
59
60function tweenDonut(b) {
61  b.innerRadius = r * .6;
62  var i = d3.interpolate({innerRadius: 0}, b);
63  return function(t) {
64    return arc(i(t));
65  };
66}
67
68    </script>
69  </body>
70</html>
Note: See TracBrowser for help on using the repository browser.