Skip to content

Commit 5206b49

Browse files
authored
Merge pull request #1342 from plotly/afterplot
Fire plotly_afterplot after Promise.all callback
2 parents 5b86f99 + 8cea3fd commit 5206b49

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

src/plot_api/plot_api.js

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -337,12 +337,6 @@ Plotly.plot = function(gd, data, layout, config) {
337337
Registry.getComponentMethod('updatemenus', 'draw')(gd);
338338
}
339339

340-
function cleanUp() {
341-
// now we're REALLY TRULY done plotting...
342-
// so mark it as done and let other procedures call a replot
343-
gd.emit('plotly_afterplot');
344-
}
345-
346340
Lib.syncOrAsync([
347341
Plots.previousPromises,
348342
addFrames,
@@ -354,11 +348,12 @@ Plotly.plot = function(gd, data, layout, config) {
354348
drawAxes,
355349
drawData,
356350
finalDraw
357-
], gd, cleanUp);
351+
], gd);
358352

359353
// even if everything we did was synchronous, return a promise
360354
// so that the caller doesn't care which route we took
361355
return Promise.all(gd._promises).then(function() {
356+
gd.emit('plotly_afterplot');
362357
return gd;
363358
});
364359
};

test/jasmine/tests/plot_api_test.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,21 @@ describe('Test plot api', function() {
8484
expect(gd._transitionData._frames[2].name).toEqual('frame3');
8585
}).catch(fail).then(done);
8686
});
87+
88+
it('should emit afterplot event after plotting is done', function(done) {
89+
var afterPlot = false;
90+
91+
var promise = Plotly.plot(gd, [{ y: [2, 1, 2]}]);
92+
93+
gd.on('plotly_afterplot', function() {
94+
afterPlot = true;
95+
});
96+
97+
promise.then(function() {
98+
expect(afterPlot).toBe(true);
99+
})
100+
.then(done);
101+
});
87102
});
88103

89104
describe('Plotly.relayout', function() {

0 commit comments

Comments
 (0)