BrU32

JS Data Vis SRC Demo SRC

Nov 27th, 2016
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <meta charset="utf-8">
  3. <body bgcolor="grey">
  4. <svg width="960" height="500"></svg>
  5. <script src="//d3js.org/d3.v4.min.js"></script>
  6. <script>
  7. var tau = 2 * Math.PI;
  8. var arc = d3.arc()
  9. .innerRadius(180)
  10. .outerRadius(240)
  11. .startAngle(0);
  12.  
  13. var svg = d3.select("svg"),
  14. width = +svg.attr("width"),
  15. height = +svg.attr("height"),
  16. g = svg.append("g").attr("transform", "translate(" + width / 2 + "," + height / 2 + ")");
  17. var background = g.append("path")
  18. .datum({endAngle: tau})
  19. .style("fill", "#000")
  20. .attr("d", arc);
  21. var foreground = g.append("path")
  22. .datum({endAngle: 0.127 * tau})
  23. .style("fill", "red")
  24. .attr("d", arc);
  25. d3.interval(function() {
  26. foreground.transition()
  27. .duration(750)
  28. .attrTween("d", arcTween(Math.random() * tau));
  29. }, 100);
  30.  
  31. function arcTween(newAngle) {
  32.  
  33. return function(d) {
  34.  
  35. var interpolate = d3.interpolate(d.endAngle, newAngle);
  36.  
  37. return function(t) {
  38.  
  39. d.endAngle = interpolate(t);
  40.  
  41. return arc(d);
  42. };
  43. };
  44. }
  45. </script>
Advertisement
Add Comment
Please, Sign In to add comment