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

Skip to content

Commit a814965

Browse files
committed
add checks for maxSpace to be valid and non-zero
1 parent f3ab980 commit a814965

File tree

1 file changed

+29
-20
lines changed

1 file changed

+29
-20
lines changed

src/plots/plots.js

Lines changed: 29 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1888,37 +1888,41 @@ plots.autoMargin = function(gd, id, o) {
18881888
var fullLayout = gd._fullLayout;
18891889
var width = fullLayout.width;
18901890
var height = fullLayout.height;
1891+
var margin = fullLayout.margin;
18911892

18921893
var maxSpaceW = Math.max(0, width - MIN_FINAL_WIDTH);
18931894
var maxSpaceH = Math.max(0, height - MIN_FINAL_HEIGHT);
18941895

18951896
var pushMargin = fullLayout._pushmargin;
18961897
var pushMarginIds = fullLayout._pushmarginIds;
18971898

1898-
if(fullLayout.margin.autoexpand !== false) {
1899+
if(margin.autoexpand !== false) {
18991900
if(!o) {
19001901
delete pushMargin[id];
19011902
delete pushMarginIds[id];
19021903
} else {
19031904
var pad = o.pad;
19041905
if(pad === undefined) {
1905-
var margin = fullLayout.margin;
19061906
// if no explicit pad is given, use 12px unless there's a
19071907
// specified margin that's smaller than that
19081908
pad = Math.min(12, margin.l, margin.r, margin.t, margin.b);
19091909
}
19101910

19111911
// if the item is too big, just give it enough automargin to
19121912
// make sure you can still grab it and bring it back
1913-
var rW = (o.l + o.r) / maxSpaceW;
1914-
if(rW > 1) {
1915-
o.l /= rW;
1916-
o.r /= rW;
1913+
if(maxSpaceW) {
1914+
var rW = (o.l + o.r) / maxSpaceW;
1915+
if(rW > 1) {
1916+
o.l /= rW;
1917+
o.r /= rW;
1918+
}
19171919
}
1918-
var rH = (o.t + o.b) / maxSpaceH;
1919-
if(rH > 1) {
1920-
o.t /= rH;
1921-
o.b /= rH;
1920+
if(maxSpaceH) {
1921+
var rH = (o.t + o.b) / maxSpaceH;
1922+
if(rH > 1) {
1923+
o.t /= rH;
1924+
o.b /= rH;
1925+
}
19221926
}
19231927

19241928
var xl = o.xl !== undefined ? o.xl : o.x;
@@ -1945,8 +1949,6 @@ plots.doAutoMargin = function(gd) {
19451949
var fullLayout = gd._fullLayout;
19461950
var width = fullLayout.width;
19471951
var height = fullLayout.height;
1948-
var maxSpaceW = Math.max(0, width - MIN_FINAL_WIDTH);
1949-
var maxSpaceH = Math.max(0, height - MIN_FINAL_HEIGHT);
19501952

19511953
if(!fullLayout._size) fullLayout._size = {};
19521954
initMargins(fullLayout);
@@ -2019,16 +2021,23 @@ plots.doAutoMargin = function(gd) {
20192021
}
20202022
}
20212023

2022-
var rW = (ml + mr) / maxSpaceW;
2023-
if(rW > 1) {
2024-
ml /= rW;
2025-
mr /= rW;
2024+
var maxSpaceW = Math.max(0, width - MIN_FINAL_WIDTH);
2025+
var maxSpaceH = Math.max(0, height - MIN_FINAL_HEIGHT);
2026+
2027+
if(maxSpaceW) {
2028+
var rW = (ml + mr) / maxSpaceW;
2029+
if(rW > 1) {
2030+
ml /= rW;
2031+
mr /= rW;
2032+
}
20262033
}
20272034

2028-
var rH = (mb + mt) / maxSpaceH;
2029-
if(rH > 1) {
2030-
mb /= rH;
2031-
mt /= rH;
2035+
if(maxSpaceH) {
2036+
var rH = (mb + mt) / maxSpaceH;
2037+
if(rH > 1) {
2038+
mb /= rH;
2039+
mt /= rH;
2040+
}
20322041
}
20332042

20342043
gs.l = Math.round(ml);

0 commit comments

Comments
 (0)