Reputation: 940
This is a common timing function in d3 examples:
d3.timer(function() {
var angle = (Date.now() - start) * speed,
transform = function(d) {
return "rotate(" + angle / d.radius + ")";};
lightsweep.select(".lightsweep").attr("transform", transform);
});
The "lightsweep" is specific to me. The d.radius is pulled from the data object bound to the "lightsweep" object and used to rotate an svg group. This code works for me, but I would like to run it intermittently; say, run it for 1 second, then wait for 10 seconds before running it again. How can I do that?
Note: I do not want to use setInterval or setTimeout. The d3 timer has some amazing attributes and is better than those functions. But the d3.timer requires a return true
to cancel it. I imagine that might be a callback function but I am not able to think of it.
Thanks for any help.
Upvotes: 2
Views: 7231
Reputation: 2635
Yes the d3.timer - which uses requestAnimationFrame internally on browsers that support it - has nice properties like as pausing when the window/tab is not in the foreground. But in his tutorial code, Mike Bostock (d3 author) uses setInterval to cover this use case, so unfortunately that might be your best option.
Upvotes: 2