Skip to content

Commit fdb0a2a

Browse files
author
Alessandro Burato
committed
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.
1 parent 7f785d5 commit fdb0a2a

File tree

1 file changed

+17
-13
lines changed

1 file changed

+17
-13
lines changed

src/plots/plots.js

+17-13
Original file line numberDiff line numberDiff line change
@@ -232,23 +232,27 @@ plots.redrawText = function(gd) {
232232
};
233233

234234
// resize plot about the container size
235-
plots.resize = function(gd) {
236-
if(!gd || d3.select(gd).style('display') === 'none') return;
235+
plots.resize = function (gd) {
236+
if (!gd || d3.select(gd).style('display') === 'none') return;
237237

238-
if(gd._redrawTimer) clearTimeout(gd._redrawTimer);
238+
return new Promise(function (resolve) {
239+
240+
if (gd._redrawTimer) clearTimeout(gd._redrawTimer);
239241

240-
gd._redrawTimer = setTimeout(function() {
241-
if((gd._fullLayout || {}).autosize) {
242-
// autosizing doesn't count as a change that needs saving
243-
var oldchanged = gd.changed;
242+
gd._redrawTimer = setTimeout(function () {
243+
if ((gd._fullLayout || {}).autosize) {
244+
// autosizing doesn't count as a change that needs saving
245+
var oldchanged = gd.changed;
244246

245-
// nor should it be included in the undo queue
246-
gd.autoplay = true;
247+
// nor should it be included in the undo queue
248+
gd.autoplay = true;
247249

248-
Plotly.relayout(gd, {autosize: true});
249-
gd.changed = oldchanged;
250-
}
251-
}, 100);
250+
Plotly.relayout(gd, { autosize: true });
251+
gd.changed = oldchanged;
252+
resolve();
253+
}
254+
}, 100);
255+
});
252256
};
253257

254258

0 commit comments

Comments
 (0)