Skip to content

Releases: d3/d3-timer

v1.0.3

26 Aug 20:38
Compare
Choose a tag to compare
  • Fix for invalid timestamp argument in requestAnimationFrame in RStudio (#16).

v1.0.2

02 Aug 21:27
Compare
Choose a tag to compare
  • Add module entry point to package.json.

v1.0.1

30 Jun 14:33
Compare
Choose a tag to compare

v1.0.0

14 Jun 22:22
Compare
Choose a tag to compare
  • First stable release.

Changes since D3 3.x

In D3 3.x, the only way to stop a timer was for its callback to return true. For example, this timer stops after one second:

d3.timer(function(elapsed) {
  console.log(elapsed);
  return elapsed >= 1000;
});

In 4.0, use timer.stop instead:

var t = d3.timer(function(elapsed) {
  console.log(elapsed);
  if (elapsed >= 1000) {
    t.stop();
  }
});

The primary benefit of timer.stop is that timers are not required to self-terminate: they can be stopped externally, allowing for the immediate and synchronous disposal of associated resources, and the separation of concerns. The above is equivalent to:

var t = d3.timer(function(elapsed) {
  console.log(elapsed);
});

d3.timeout(function() {
  t.stop();
}, 1000);

This improvement extends to d3-transition: now when a transition is interrupted, its resources are immediately freed rather than having to wait for transition to start.

4.0 also introduces a new timer.restart method for restarting timers, for replacing the callback of a running timer, or for changing its delay or reference time. Unlike timer.stop followed by d3.timer, timer.restart maintains the invocation priority of an existing timer: it guarantees that the order of invocation of active timers remains the same. The d3.timer.flush method has been renamed to d3.timerFlush.

Some usage patterns in D3 3.x could cause the browser to hang when a background page returned to the foreground. For example, the following code schedules a transition every second:

setInterval(function() {
  d3.selectAll("div").transition().call(someAnimation); // BAD
}, 1000);

If such code runs in the background for hours, thousands of queued transitions will try to run simultaneously when the page is foregrounded. D3 4.0 avoids this hang by freezing time in the background: when a page is in the background, time does not advance, and so no queue of timers accumulates to run when the page returns to the foreground. Use d3.timer instead of transitions to schedule a long-running animation, or use d3.timeout and d3.interval in place of setTimeout and setInterval to prevent transitions from being queued in the background:

d3.interval(function() {
  d3.selectAll("div").transition().call(someAnimation); // GOOD
}, 1000);

By freezing time in the background, timers are effectively “unaware” of being backgrounded. It’s like nothing happened! 4.0 also now uses high-precision time (performance.now) where available; the current time is available as d3.now.

See CHANGES for all D3 changes since 3.x.

v0.5.1

10 Jun 14:08
Compare
Choose a tag to compare

v0.5.0

08 Jun 00:20
Compare
Choose a tag to compare
  • Export to the global d3 in vanilla environments (d3/d3#2840).

v0.4.4

13 May 20:11
Compare
Choose a tag to compare
  • Fix current time on iOS 8 (#12).

v0.4.3

29 Apr 18:22
Compare
Choose a tag to compare

v0.4.2

29 Apr 16:11
Compare
Choose a tag to compare

v0.4.1

22 Feb 00:08
Compare
Choose a tag to compare