Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 08069a4

Browse files
committed
try an even better fix
1 parent 8396018 commit 08069a4

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

src/plot_api/plot_api.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1822,13 +1822,11 @@ function _relayout(gd, aobj) {
18221822
undoit[ai] = (pleaf === 'reverse') ? vi : p.get();
18231823

18241824
// Setting width or height to null must reset the graph's width / height
1825-
// back to its initial value as listed in attribute declaration.
1825+
// back to its initial value as computed during the first pass in Plots.plotAutoSize.
18261826
//
1827-
// We must manually set them back here, because we can't rely on
1828-
// Plots.plotAutoSize as it falls back to computing width / height values
1829-
// from the DOM which can have been changed by other relayout calls.
1827+
// To do so, we must manually set them back here using the _initialAutoSize cache.
18301828
if(['width', 'height'].indexOf(ai) !== -1 && vi === null) {
1831-
gd._fullLayout[ai] = Plots.layoutAttributes[ai].dflt;
1829+
gd._fullLayout[ai] = gd._initialAutoSize[ai];
18321830
}
18331831
// check autorange vs range
18341832
else if(pleafPlus.match(/^[xyz]axis[0-9]*\.range(\[[0|1]\])?$/)) {

src/plots/plots.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -998,6 +998,12 @@ plots.plotAutoSize = function plotAutoSize(gd, layout, fullLayout) {
998998
if(heightHasChanged) fullLayout.height = newHeight;
999999
}
10001000

1001+
// cache initial autosize value, used in relayout when
1002+
// width or height values are set to null
1003+
if(!gd._initialAutoSize) {
1004+
gd._initialAutoSize = { width: newWidth, height: newHeight };
1005+
}
1006+
10011007
plots.sanitizeMargins(fullLayout);
10021008
};
10031009

@@ -1117,6 +1123,7 @@ plots.purge = function(gd) {
11171123
delete gd._lastHoverTime;
11181124
delete gd._transitionData;
11191125
delete gd._transitioning;
1126+
delete gd._initialAutoSize;
11201127

11211128
// remove all event listeners
11221129
if(gd.removeAllListeners) gd.removeAllListeners();

0 commit comments

Comments
 (0)