Skip to content

Commit aec44c6

Browse files
committed
Animation cleanup
1 parent b4a553b commit aec44c6

File tree

4 files changed

+28
-14
lines changed

4 files changed

+28
-14
lines changed

src/plot_api/plot_api.js

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2540,15 +2540,18 @@ Plotly.transition = function(gd, data, layout, traceIndices, transitionConfig) {
25402540

25412541
Plots.supplyDefaults(gd);
25422542

2543+
// TODO: Add logic that computes animatedTraces to avoid unnecessary work while
2544+
// still handling things like box plots that are interrelated.
25432545
// doCalcdata(gd, animatedTraces);
2546+
25442547
doCalcdata(gd);
25452548

25462549
ErrorBars.calc(gd);
25472550
}
25482551

25492552
var restyleList = [];
25502553
var completionTimeout = null;
2551-
var completion = null;
2554+
var resolveTransitionCallback = null;
25522555

25532556
function executeTransitions() {
25542557
var j;
@@ -2567,22 +2570,25 @@ Plotly.transition = function(gd, data, layout, traceIndices, transitionConfig) {
25672570
}
25682571

25692572
return new Promise(function(resolve) {
2570-
completion = resolve;
2573+
resolveTransitionCallback = resolve;
25712574
completionTimeout = setTimeout(resolve, transitionConfig.duration);
25722575
});
25732576
}
25742577

25752578
function interruptPreviousTransitions() {
2576-
var ret;
2579+
var ret, interrupt;
25772580
clearTimeout(completionTimeout);
25782581

2579-
if(completion) {
2580-
completion();
2582+
if(resolveTransitionCallback) {
2583+
resolveTransitionCallback();
2584+
}
2585+
2586+
while(gd._frameData._layoutInterrupts.length) {
2587+
(gd._frameData._layoutInterrupts.pop())();
25812588
}
25822589

2583-
if(gd._animationInterrupt) {
2584-
ret = gd._animationInterrupt();
2585-
gd._animationInterrupt = null;
2590+
while(gd._frameData._styleInterrupts.length) {
2591+
(gd._frameData._styleInterrupts.pop())();
25862592
}
25872593
return ret;
25882594
}

src/plots/cartesian/transition_axes.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,12 +229,12 @@ module.exports = function transitionAxes(gd, newLayout, transitionConfig) {
229229
return new Promise(function(resolve, reject) {
230230
var t1, t2, raf;
231231

232-
gd._animationInterrupt = function() {
232+
gd._frameData._layoutInterrupts.push(function() {
233233
reject();
234234
cancelAnimationFrame(raf);
235235
raf = null;
236236
transitionTail();
237-
};
237+
});
238238

239239
function doFrame() {
240240
t2 = Date.now();

src/plots/plots.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -561,6 +561,14 @@ plots.supplyDefaults = function(gd) {
561561
if(!gd._frameData._counter) {
562562
gd._frameData._counter = 0;
563563
}
564+
565+
if(!gd._frameData._layoutInterrupts) {
566+
gd._frameData._layoutInterrupts = [];
567+
}
568+
569+
if(!gd._frameData._styleInterrupts) {
570+
gd._frameData._styleInterrupts = [];
571+
}
564572
};
565573

566574
// helper function to be bound to fullLayout to check

test/image/mocks/animation.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
}
4040
}
4141
}, {
42-
"name": 'frame0',
42+
"name": "frame0",
4343
"data": [
4444
{"y": [0.5, 1.5, 7.5]},
4545
{"y": [4.25, 2.25, 3.05]}
@@ -48,7 +48,7 @@
4848
"traceIndices": [0, 1],
4949
"layout": { }
5050
}, {
51-
"name": 'frame1',
51+
"name": "frame1",
5252
"data": [
5353
{"y": [2.1, 1, 7]},
5454
{"y": [4.5, 2.5, 3.1]}
@@ -57,7 +57,7 @@
5757
"traceIndices": [0, 1],
5858
"layout": { }
5959
}, {
60-
"name": 'frame2',
60+
"name": "frame2",
6161
"data": [
6262
{"y": [3.5, 0.5, 6]},
6363
{"y": [5.7, 2.7, 3.9]}
@@ -66,7 +66,7 @@
6666
"traceIndices": [0, 1],
6767
"layout": { }
6868
}, {
69-
"name": 'frame3',
69+
"name": "frame3",
7070
"data": [
7171
{"y": [5.1, 0.25, 5]},
7272
{"y": [7, 2.9, 6]}

0 commit comments

Comments
 (0)