Skip to content

Promise from resize #262

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
Feb 17, 2016
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
8 changes: 5 additions & 3 deletions src/plots/plots.js
Original file line number Diff line number Diff line change
Expand Up @@ -233,9 +233,11 @@ plots.redrawText = function(gd) {

// resize plot about the container size
plots.resize = function(gd) {
if (!gd || d3.select(gd).style('display') === 'none') return;
return new Promise(function(resolve, reject) {

return new Promise(function(resolve) {
if (!gd || d3.select(gd).style('display') === 'none'){
reject(new Error('Resize must be passed a plot div element.'));
}

if (gd._redrawTimer) clearTimeout(gd._redrawTimer);

Expand All @@ -249,7 +251,7 @@ plots.resize = function(gd) {

Plotly.relayout(gd, { autosize: true });
gd.changed = oldchanged;
resolve();
resolve(gd);
}
}, 100);
});
Expand Down
27 changes: 27 additions & 0 deletions test/jasmine/tests/plot_promise_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -464,4 +464,31 @@ describe('Plotly.___ methods', function() {
});
});

describe('Plotly.Plots.resize promise', function() {
var initialDiv;

beforeEach(function(done) {
var data = [{ x: [1,2,3], y: [4,5,6] }];

initialDiv = createGraphDiv();

Plotly.plot(initialDiv, data, {}).then(done);
});

it('should return a resolved promise of the gd', function(done) {
Plotly.Plots.resize(initialDiv).then(function(gd) {
expect(gd).toBeDefined();
expect(typeof gd).toBe('object');
expect(gd.layout).toBeDefined();
}).then(done);
});

it('should return a rejected promise with no argument', function(done) {
Plotly.Plots.resize().then(null, function(err) {
expect(err).toBeDefined();
expect(err.message).toBe('Resize must be passed a plot div element.');
}).then(done);
});
});

});