Skip to content

Plots.resize - additional check for gd.layout #2710

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 2 commits into from
Jun 18, 2018
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
4 changes: 2 additions & 2 deletions src/plots/plots.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ plots.resize = function(gd) {
if(gd._redrawTimer) clearTimeout(gd._redrawTimer);

gd._redrawTimer = setTimeout(function() {
// return if there is nothing to resize
if(gd.layout.width && gd.layout.height) {
// return if there is nothing to resize or is hidden
if(!gd.layout || (gd.layout.width && gd.layout.height) || isHidden(gd)) {
resolve(gd);
return;
}
Expand Down
35 changes: 31 additions & 4 deletions test/jasmine/tests/plot_promise_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ var Plotly = require('@lib/index');
var Events = require('@src/lib/events');
var createGraphDiv = require('../assets/create_graph_div');
var destroyGraphDiv = require('../assets/destroy_graph_div');

var failTest = require('../assets/fail_test');

describe('Plotly.___ methods', function() {
'use strict';
Expand Down Expand Up @@ -468,7 +468,9 @@ describe('Plotly.___ methods', function() {
expect(gd).toBeDefined();
expect(typeof gd).toBe('object');
expect(gd.layout).toBeDefined();
}).then(done);
})
.catch(failTest)
.then(done);
});

it('should return a rejected promise if gd is hidden', function(done) {
Expand All @@ -478,7 +480,9 @@ describe('Plotly.___ methods', function() {
}, function(err) {
expect(err).toBeDefined();
expect(err.message).toBe('Resize must be passed a displayed plot div element.');
}).then(done);
})
.catch(failTest)
.then(done);
});

it('should return a rejected promise if gd is detached from the DOM', function(done) {
Expand All @@ -488,7 +492,30 @@ describe('Plotly.___ methods', function() {
}, function(err) {
expect(err).toBeDefined();
expect(err.message).toBe('Resize must be passed a displayed plot div element.');
}).then(done);
})
.catch(failTest)
.then(done);
});

it('should return a resolved promise if plot has been purged and there is nothing to resize', function(done) {
var resizePromise = Plotly.Plots.resize(initialDiv);

Plotly.purge(initialDiv);
destroyGraphDiv();

resizePromise
.catch(failTest)
.then(done);
});

it('should return a resolved promise if plot has been hidden and gd is hidden', function(done) {
var resizePromise = Plotly.Plots.resize(initialDiv);

initialDiv.style.display = 'none';

resizePromise
.catch(failTest)
.then(done);
});

it('errors before even generating a promise if gd is not defined', function() {
Expand Down