An attempt to diagnose/fix this issue: d3/d3#2780
-
-
Save kwhitaker/87cefa0c596cffe51dab46369cf966f3 to your computer and use it in GitHub Desktop.
Wonky chrome animation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
license: gpl-3.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
apples | oranges | |
---|---|---|
77409 | 19670 | |
6248241 | 2304 | |
774522 | 155705 | |
17290 | 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<meta charset="utf-8"> | |
<style> | |
body { | |
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; | |
margin: auto; | |
position: relative; | |
width: 960px; | |
} | |
text { | |
font: 10px sans-serif; | |
} | |
form { | |
position: absolute; | |
right: 10px; | |
top: 10px; | |
} | |
#chart-wrap { | |
width: 460px; | |
height: 335px; | |
} | |
</style> | |
<form> | |
<label><input type="radio" name="dataset" value="apples" checked> Apples</label> | |
<label><input type="radio" name="dataset" value="oranges"> Oranges</label> | |
</form> | |
<div id="chart-wrap"></div> | |
<script src="//d3js.org/d3.v3.min.js"></script> | |
<script> | |
var elm = document.getElementById('chart-wrap') | |
var width = elm.offsetWidth, | |
height = elm.offsetHeight, | |
radius = Math.min(width, height) / 2; | |
var color = d3.scale.category20(); | |
var pie = d3.layout.pie() | |
.value(function(d) { return d.apples; }) | |
.sort(null); | |
var arc = d3.svg.arc() | |
.innerRadius(radius * .5) | |
.outerRadius(radius); | |
var svg = d3.select("body").append("svg") | |
.attr("width", width) | |
.attr("height", height) | |
.append("g") | |
.attr("transform", "translate(" + width / 2 + "," + height / 2 + ")"); | |
d3.tsv("data.tsv", type, function(error, data) { | |
if (error) throw error; | |
var path = svg.selectAll("path") | |
.data(pie(data)) | |
.enter().append("path") | |
.attr("fill", function(d, i) { return color(i); }) | |
.attr("d", arc) | |
.each(function(d) { this._current = d; }); // store the initial angles | |
d3.selectAll("input") | |
.on("change", change); | |
var timeout = setTimeout(function() { | |
d3.select("input[value=\"oranges\"]").property("checked", true).each(change); | |
}, 2000); | |
function change() { | |
var value = this.value; | |
clearTimeout(timeout); | |
pie.value(function(d) { return d[value]; }); // change the value function | |
path = path.data(pie); // compute the new angles | |
path.transition().duration(750).attrTween("d", arcTween); // redraw the arcs | |
} | |
}); | |
function type(d) { | |
d.apples = +d.apples; | |
d.oranges = +d.oranges; | |
return d; | |
} | |
// Store the displayed angles in _current. | |
// Then, interpolate from _current to the new angles. | |
// During the transition, _current is updated in-place by d3.interpolate. | |
function arcTween(a) { | |
var i = d3.interpolate(this._current, a); | |
this._current = i(0); | |
return function(t) { | |
return arc(i(t)); | |
}; | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment