From fdb0a2a0830370533684cebbba4a733e8dd768fe Mon Sep 17 00:00:00 2001 From: Alessandro Burato Date: Fri, 12 Feb 2016 17:17:37 +0100 Subject: [PATCH 1/2] Plots.resize returns a Promise As the resize operation will modify the size of the plot only after a timeout, if you call resize and then immediately do something based on the current plot size, you'll get the "old" size. This fixes it. --- src/plots/plots.js | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/src/plots/plots.js b/src/plots/plots.js index 595296de3d7..e9feb8dd238 100644 --- a/src/plots/plots.js +++ b/src/plots/plots.js @@ -232,23 +232,27 @@ plots.redrawText = function(gd) { }; // resize plot about the container size -plots.resize = function(gd) { - if(!gd || d3.select(gd).style('display') === 'none') return; +plots.resize = function (gd) { + if (!gd || d3.select(gd).style('display') === 'none') return; - if(gd._redrawTimer) clearTimeout(gd._redrawTimer); + return new Promise(function (resolve) { + + if (gd._redrawTimer) clearTimeout(gd._redrawTimer); - gd._redrawTimer = setTimeout(function() { - if((gd._fullLayout || {}).autosize) { - // autosizing doesn't count as a change that needs saving - var oldchanged = gd.changed; + gd._redrawTimer = setTimeout(function () { + if ((gd._fullLayout || {}).autosize) { + // autosizing doesn't count as a change that needs saving + var oldchanged = gd.changed; - // nor should it be included in the undo queue - gd.autoplay = true; + // nor should it be included in the undo queue + gd.autoplay = true; - Plotly.relayout(gd, {autosize: true}); - gd.changed = oldchanged; - } - }, 100); + Plotly.relayout(gd, { autosize: true }); + gd.changed = oldchanged; + resolve(); + } + }, 100); + }); }; From c336dae81804b447ac099143c2ae54441efd73f4 Mon Sep 17 00:00:00 2001 From: Alessandro Burato Date: Mon, 15 Feb 2016 20:06:17 +0100 Subject: [PATCH 2/2] un-linted --- src/plots/plots.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/plots/plots.js b/src/plots/plots.js index e9feb8dd238..4b5e632463e 100644 --- a/src/plots/plots.js +++ b/src/plots/plots.js @@ -232,14 +232,14 @@ plots.redrawText = function(gd) { }; // resize plot about the container size -plots.resize = function (gd) { +plots.resize = function(gd) { if (!gd || d3.select(gd).style('display') === 'none') return; - return new Promise(function (resolve) { - + return new Promise(function(resolve) { + if (gd._redrawTimer) clearTimeout(gd._redrawTimer); - gd._redrawTimer = setTimeout(function () { + gd._redrawTimer = setTimeout(function() { if ((gd._fullLayout || {}).autosize) { // autosizing doesn't count as a change that needs saving var oldchanged = gd.changed;