Skip to content

Commit 5fb7cd1

Browse files
committed
cache initial autosize vals -> use them on relayout
- so that relayout(gd, 'width', null) reset the graph to its initial width
1 parent 4c14251 commit 5fb7cd1

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

src/plot_api/plot_api.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -1821,10 +1821,12 @@ function _relayout(gd, aobj) {
18211821
// op and has no flag.
18221822
undoit[ai] = (pleaf === 'reverse') ? vi : p.get();
18231823

1824-
// tweak width / height update value when null such that
1825-
// new dimensions are honored in Plots.supplyDefaults
1824+
// Setting width or height to null must reset the graph's width / height
1825+
// back to its initial value as computed during the first pass in Plots.plotAutoSize.
1826+
//
1827+
// To do so, we must manually set them back here using the _initialAutoSize cache.
18261828
if(['width', 'height'].indexOf(ai) !== -1 && vi === null) {
1827-
vi = 'initial';
1829+
gd._fullLayout[ai] = gd._initialAutoSize[ai];
18281830
}
18291831
// check autorange vs range
18301832
else if(pleafPlus.match(/^[xyz]axis[0-9]*\.range(\[[0|1]\])?$/)) {

src/plots/plots.js

+7
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)