Created
January 13, 2015 15:05
-
-
Save rbu/6cda4f71909d0f5e4f11 to your computer and use it in GitHub Desktop.
d3 bug report
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> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/1.11.2/jquery.js"></script> | |
<script src="//cdnjs.cloudflare.com/ajax/libs/d3/3.5.3/d3.js"></script> | |
<script> | |
$(function() { | |
window.svgs = []; | |
window.embeds = []; | |
var second = 1000; | |
function empty() { | |
$(".playground").empty(); | |
} | |
function removeFirst() { | |
/* | |
// @D3 Workaround: | |
// This piece of code makes it less like that the problem occurs | |
// does not reliably prevent it. There is still a race condition between | |
// element DOM removal and d3.timer.stop() actually running (at which point | |
// the DOM node can already be inaccessible) | |
function stopAnimationOnSvg(svg) { | |
svg.select('#logo').interrupt().transition(); | |
d3.timer.flush(); | |
} | |
stopAnimationOnSvg(window.svgs[0]); | |
*/ | |
$(".playground").children().first().remove(); | |
} | |
function render() { | |
var embed = document.createElement("embed") | |
embed.className = 'gauge-svg' | |
embed.setAttribute("src", "gauge.svg") | |
embed.setAttribute("type", "image/svg+xml") | |
embed = $(embed); | |
$(".playground").append(embed); | |
embed[0].onload = function() { | |
didLoadSvg(embed); | |
}; | |
} | |
function didLoadSvg(embed) { | |
var svg = d3.select(embed[0].getSVGDocument()); | |
svgs.push(svg); | |
// @D3: Workaround commenting this in keeps a reference and does not trigger the bug | |
//embeds.push(embed[0]); | |
svg.select('#logo') | |
.transition() | |
.duration(5*second) | |
.attr('transform', function(d, i) { | |
return "translate(100,100) rotate (180) scale(2)"; | |
}); | |
} | |
var startLoading = new Date(); | |
function clock() { | |
now = new Date(); | |
difference = (now - startLoading) / 1000; | |
$('.clock').text(difference); | |
} | |
window.clockInterval = setInterval(clock, 10); | |
window.onerror = function(e) { | |
clearInterval(window.clockInterval); | |
$('.clock').append("... got Exception: " + e + '. ') | |
} | |
setTimeout(render, 0) | |
setTimeout(removeFirst, 1*second) | |
// @D3: Comment in this line to see that future animations also do not run | |
// setTimeout(render, 4000) | |
}); | |
</script> | |
</head> | |
<body> | |
<div class="clock"></div> | |
<div class="playground"></div> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment