From 3cbb60e4dedd6dc7ae875fd1483939fc3e2874e8 Mon Sep 17 00:00:00 2001 From: Rafal Bromirski Date: Fri, 8 Jun 2018 12:39:45 +0200 Subject: [PATCH 1/2] Plots.resize - additional check for gd.layout --- src/plots/plots.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/plots/plots.js b/src/plots/plots.js index 4d40ab31d20..381b005efeb 100644 --- a/src/plots/plots.js +++ b/src/plots/plots.js @@ -90,7 +90,7 @@ plots.resize = function(gd) { gd._redrawTimer = setTimeout(function() { // return if there is nothing to resize - if(gd.layout.width && gd.layout.height) { + if(gd.layout && gd.layout.width && gd.layout.height) { resolve(gd); return; } From 1d75ed1cb323025a0fa232d4edabf35bbe0b1cb1 Mon Sep 17 00:00:00 2001 From: Rafal Bromirski Date: Thu, 14 Jun 2018 14:51:02 +0200 Subject: [PATCH 2/2] Plots.resize - add test case --- src/plots/plots.js | 4 +-- test/jasmine/tests/plot_promise_test.js | 35 ++++++++++++++++++++++--- 2 files changed, 33 insertions(+), 6 deletions(-) diff --git a/src/plots/plots.js b/src/plots/plots.js index 381b005efeb..404e347ed6e 100644 --- a/src/plots/plots.js +++ b/src/plots/plots.js @@ -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 && 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; } diff --git a/test/jasmine/tests/plot_promise_test.js b/test/jasmine/tests/plot_promise_test.js index c8a0b38af49..57939eea702 100644 --- a/test/jasmine/tests/plot_promise_test.js +++ b/test/jasmine/tests/plot_promise_test.js @@ -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'; @@ -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) { @@ -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) { @@ -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() {