Skip to content

Fire plotly_afterplot after Promise.all callback #1342

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

Merged
merged 1 commit into from
Jan 31, 2017
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 2 additions & 7 deletions src/plot_api/plot_api.js
Original file line number Diff line number Diff line change
Expand Up @@ -337,12 +337,6 @@ Plotly.plot = function(gd, data, layout, config) {
Registry.getComponentMethod('updatemenus', 'draw')(gd);
}

function cleanUp() {
// now we're REALLY TRULY done plotting...
// so mark it as done and let other procedures call a replot
gd.emit('plotly_afterplot');
}

Lib.syncOrAsync([
Plots.previousPromises,
addFrames,
Expand All @@ -354,11 +348,12 @@ Plotly.plot = function(gd, data, layout, config) {
drawAxes,
drawData,
finalDraw
], gd, cleanUp);
], gd);

// even if everything we did was synchronous, return a promise
// so that the caller doesn't care which route we took
return Promise.all(gd._promises).then(function() {
gd.emit('plotly_afterplot');
return gd;
});
};
Expand Down
15 changes: 15 additions & 0 deletions test/jasmine/tests/plot_api_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,21 @@ describe('Test plot api', function() {
expect(gd._transitionData._frames[2].name).toEqual('frame3');
}).catch(fail).then(done);
});

it('should emit afterplot event after plotting is done', function(done) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test here fails on master.

I'm not exactly sure why though which might me related to #76

Consider:

var gd = document.getElementById('graph')

Plotly.plot(gd, [{}])

gd.on('plotly_afterplot', () => {})

I suspect that on master the Plotly.plot promise is resolved before gd.on('plotly_relayout, /* */) is set. By tucking gd.emit('plotly_afterplot') is the Promise.all callback the Plotly.plot promise is resolved after gd.on.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suspect that on master the Plotly.plot promise is resolved before gd.on('plotly_afterplot, /* */) is set.

exactly - in most cases the plotting itself is sync, so your fix here is spot on.

var afterPlot = false;

var promise = Plotly.plot(gd, [{ y: [2, 1, 2]}]);

gd.on('plotly_afterplot', function() {
afterPlot = true;
});

promise.then(function() {
expect(afterPlot).toBe(true);
})
.then(done);
});
});

describe('Plotly.relayout', function() {
Expand Down