Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Defer first tick to end of timer frame. #1576

Merged
merged 4 commits into from Oct 10, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 7 additions & 11 deletions d3.js
Expand Up @@ -2071,13 +2071,6 @@ d3 = function() {
d3_timer_mark();
d3_timer_sweep();
};
function d3_timer_replace(callback, delay, then) {
var n = arguments.length;
if (n < 2) delay = 0;
if (n < 3) then = Date.now();
d3_timer_active.callback = callback;
d3_timer_active.time = then + delay;
}
function d3_timer_mark() {
var now = Date.now();
d3_timer_active = d3_timer_queueHead;
Expand Down Expand Up @@ -8111,9 +8104,10 @@ d3 = function() {
};
++lock.count;
d3.timer(function(elapsed) {
var d = node.__data__, ease = transition.ease, delay = transition.delay, duration = transition.duration, tweened = [];
var d = node.__data__, ease = transition.ease, delay = transition.delay, duration = transition.duration, timer = d3_timer_active, tweened = [];
timer.time = delay + time;
if (delay <= elapsed) return start(elapsed - delay);
d3_timer_replace(start, delay, time);
timer.callback = start;
function start(elapsed) {
if (lock.active > id) return stop();
lock.active = id;
Expand All @@ -8123,8 +8117,10 @@ d3 = function() {
tweened.push(value);
}
});
if (tick(elapsed || 1)) return 1;
d3_timer_replace(tick, delay, time);
d3.timer(function() {
timer.callback = tick(elapsed || 1) ? d3_true : tick;
return 1;
}, 0, time);
}
function tick(elapsed) {
if (lock.active !== id) return stop();
Expand Down
10 changes: 5 additions & 5 deletions d3.min.js

Large diffs are not rendered by default.

8 changes: 0 additions & 8 deletions src/event/timer.js
Expand Up @@ -48,14 +48,6 @@ d3.timer.flush = function() {
d3_timer_sweep();
};

function d3_timer_replace(callback, delay, then) {
var n = arguments.length;
if (n < 2) delay = 0;
if (n < 3) then = Date.now();
d3_timer_active.callback = callback;
d3_timer_active.time = then + delay;
}

function d3_timer_mark() {
var now = Date.now();
d3_timer_active = d3_timer_queueHead;
Expand Down
11 changes: 8 additions & 3 deletions src/transition/transition.js
@@ -1,5 +1,6 @@
import "../arrays/map";
import "../core/subclass";
import "../core/true";
import "../event/dispatch";
import "../event/timer";
import "../interpolate/ease";
Expand Down Expand Up @@ -67,10 +68,12 @@ function d3_transitionNode(node, i, id, inherit) {
ease = transition.ease,
delay = transition.delay,
duration = transition.duration,
timer = d3_timer_active,
tweened = [];

timer.time = delay + time;
if (delay <= elapsed) return start(elapsed - delay);
d3_timer_replace(start, delay, time);
timer.callback = start;

function start(elapsed) {
if (lock.active > id) return stop();
Expand All @@ -83,8 +86,10 @@ function d3_transitionNode(node, i, id, inherit) {
}
});

if (tick(elapsed || 1)) return 1;
d3_timer_replace(tick, delay, time);
d3.timer(function() { // defer to end of current frame
timer.callback = tick(elapsed || 1) ? d3_true : tick;
return 1;
}, 0, time);
}

function tick(elapsed) {
Expand Down
12 changes: 5 additions & 7 deletions test/transition/transition-test-transition.js
Expand Up @@ -27,13 +27,11 @@ module.exports = {
"while transitioning": {
topic: function(t1) {
var callback = this.callback;
var t2 = t1.transition().tween("custom", function() {
return function(t) {
if (callback) {
callback(null, t2);
callback = null;
}
};
var t2 = t1.transition().each("start", function() {
if (callback) {
callback(null, t2);
callback = null;
}
});
},
"increments the lock's reference count": function(t2) {
Expand Down