Skip to content

Commit d5595d7

Browse files
committed
add 1px tolerence in Plots.didMarginChange
... to avoid potential infinite loops when rounding errors make auto-margins fail to converge. See report (that @etpinard was never able to reproduce) in #3561 (comment)
1 parent 7ca62a0 commit d5595d7

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

src/plots/plots.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -1911,7 +1911,9 @@ plots.didMarginChange = function(margin0, margin1) {
19111911
var k = marginKeys[i];
19121912
var m0 = margin0[k];
19131913
var m1 = margin1[k];
1914-
if(!isNumeric(m0) || Math.abs(m1 - m0) > 0) {
1914+
// use 1px tolerance in case we old/new differ only
1915+
// by rounding errors, which can lead to infinite loops
1916+
if(!isNumeric(m0) || Math.abs(m1 - m0) > 1) {
19151917
return true;
19161918
}
19171919
}

test/jasmine/tests/plots_test.js

+13
Original file line numberDiff line numberDiff line change
@@ -988,6 +988,19 @@ describe('Test Plots', function() {
988988
plotCallCnt: 1
989989
});
990990
})
991+
.then(function() {
992+
gd._fullLayout._pushmargin.legend.r.size += 1;
993+
return Plots.doAutoMargin(gd);
994+
})
995+
.then(function() {
996+
// see https://github.com/plotly/plotly.js/issues/3561#issuecomment-485953778
997+
// for more info
998+
_assert('after doAutoMargin() with bigger margins under tolerance', {
999+
r: r0 + 3,
1000+
w: w0 - 3,
1001+
plotCallCnt: 0
1002+
});
1003+
})
9911004
.catch(failTest)
9921005
.then(done);
9931006
});

0 commit comments

Comments
 (0)