Skip to content

Instantly share code, notes, and snippets.

@fabianthoma
Created June 16, 2013 15:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fabianthoma/5792402 to your computer and use it in GitHub Desktop.
Save fabianthoma/5792402 to your computer and use it in GitHub Desktop.
testing
{"description":"testing","endpoint":"","display":"svg","public":true,"require":[],"fileconfigs":{"inlet.js":{"default":true,"vim":false,"emacs":false,"fontSize":12}},"fullscreen":true,"play":true,"loop":true,"restart":true,"autoinit":true,"pause":true,"loop_type":"period","bv":false,"nclones":15,"clone_opacity":0.4,"duration":3000,"ease":"linear","dt":0.01}
var width = 960,
height = 500,
tau = 2 * Math.PI;
var arc = d3.svg.arc()
.innerRadius(30)
.outerRadius(50)
.startAngle(0);
var svg = d3.select("svg").append("svg")
.attr("width", width)
.attr("height", height)
.append("g")
.attr("transform", "translate(" + width / 2 + "," + height / 2 + ")")
// Add the background arc, from 0 to 100% (τ).
var background = svg.append("path")
.datum({endAngle: tau})
.style("fill", "#ddd")
.attr("d", arc);
// Add the foreground arc in orange, currently showing 12.7%.
var foreground = svg.append("path")
.datum({endAngle: 0.127 * tau})
.style("fill", "blue")
.attr("d", arc);
var label = svg.append("text")
.text('13%');
setInterval(function() {
var test = Math.random();
foreground.transition()
.duration(750)
.call(arcTween, test * tau);
//label.transition()
// .duration(750)
// .text(Math.round(test * 100) + '%');
}, 1500);
function arcTween(transition, newAngle) {
transition.attrTween("d", function(d) {
var interpolate = d3.interpolate(d.endAngle, newAngle);
return function(t) {
d.endAngle = interpolate(t);
return arc(d);
};
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment