Skip to content

Commit 565f942

Browse files
committed
adjust large margins instead of dropping them
1 parent 670d238 commit 565f942

8 files changed

+32
-20
lines changed

src/plots/plots.js

+28-16
Original file line numberDiff line numberDiff line change
@@ -1864,6 +1864,9 @@ function initMargins(fullLayout) {
18641864
if(!fullLayout._pushmarginIds) fullLayout._pushmarginIds = {};
18651865
}
18661866

1867+
var minFinalWidth = 64; // could possibly be exposed as layout.margin.minfinalwidth
1868+
var minFinalHeight = 64; // could possibly be exposed as layout.margin.minfinalheight
1869+
18671870
/**
18681871
* autoMargin: called by components that may need to expand the margins to
18691872
* be rendered on-plot.
@@ -1881,12 +1884,10 @@ function initMargins(fullLayout) {
18811884
*/
18821885
plots.autoMargin = function(gd, id, o) {
18831886
var fullLayout = gd._fullLayout;
1884-
var minFinalWidth = Math.max(0, fullLayout.width -
1885-
64 // TODO: could be exposed as layout.margin.minfinalwidth
1886-
);
1887-
var minFinalHeight = Math.max(0, fullLayout.height -
1888-
64 // TODO: could be exposed as layout.margin.minfinalheight
1889-
);
1887+
var width = fullLayout.width;
1888+
var height = fullLayout.height;
1889+
var maxSpaceW = Math.max(0, width - minFinalWidth);
1890+
var maxSpaceH = Math.max(0, height - minFinalHeight);
18901891

18911892
var pushMargin = fullLayout._pushmargin;
18921893
var pushMarginIds = fullLayout._pushmarginIds;
@@ -1906,15 +1907,13 @@ plots.autoMargin = function(gd, id, o) {
19061907

19071908
// if the item is too big, just give it enough automargin to
19081909
// make sure you can still grab it and bring it back
1909-
var rW = (o.l + o.r) / minFinalWidth;
1910+
var rW = (o.l + o.r) / maxSpaceW;
19101911
if(rW > 1) {
1911-
Lib.log('Margin push', id, 'is too big in x, adjusting');
19121912
o.l /= rW;
19131913
o.r /= rW;
19141914
}
1915-
var rH = (o.t + o.b) / minFinalHeight;
1915+
var rH = (o.t + o.b) / maxSpaceH;
19161916
if(rH > 1) {
1917-
Lib.log('Margin push', id, 'is too big in y, adjusting');
19181917
o.t /= rH;
19191918
o.b /= rH;
19201919
}
@@ -1941,6 +1940,11 @@ plots.autoMargin = function(gd, id, o) {
19411940

19421941
plots.doAutoMargin = function(gd) {
19431942
var fullLayout = gd._fullLayout;
1943+
var width = fullLayout.width;
1944+
var height = fullLayout.height;
1945+
var maxSpaceW = Math.max(0, width - minFinalWidth);
1946+
var maxSpaceH = Math.max(0, height - minFinalHeight);
1947+
19441948
if(!fullLayout._size) fullLayout._size = {};
19451949
initMargins(fullLayout);
19461950

@@ -1955,8 +1959,6 @@ plots.doAutoMargin = function(gd) {
19551959
var mr = margin.r;
19561960
var mt = margin.t;
19571961
var mb = margin.b;
1958-
var width = fullLayout.width;
1959-
var height = fullLayout.height;
19601962
var pushMargin = fullLayout._pushmargin;
19611963
var pushMarginIds = fullLayout._pushmarginIds;
19621964

@@ -1988,11 +1990,10 @@ plots.doAutoMargin = function(gd) {
19881990
if(isNumeric(pl) && pushMargin[k2].r) {
19891991
var fr = pushMargin[k2].r.val;
19901992
var pr = pushMargin[k2].r.size;
1991-
19921993
if(fr > fl) {
19931994
var newL = (pl * fr + (pr - width) * fl) / (fr - fl);
19941995
var newR = (pr * (1 - fl) + (pl - width) * (1 - fr)) / (fr - fl);
1995-
if(newL >= 0 && newR >= 0 && width - (newL + newR) > 0 && newL + newR > ml + mr) {
1996+
if(newL + newR > ml + mr) {
19961997
ml = newL;
19971998
mr = newR;
19981999
}
@@ -2002,11 +2003,10 @@ plots.doAutoMargin = function(gd) {
20022003
if(isNumeric(pb) && pushMargin[k2].t) {
20032004
var ft = pushMargin[k2].t.val;
20042005
var pt = pushMargin[k2].t.size;
2005-
20062006
if(ft > fb) {
20072007
var newB = (pb * ft + (pt - height) * fb) / (ft - fb);
20082008
var newT = (pt * (1 - fb) + (pb - height) * (1 - ft)) / (ft - fb);
2009-
if(newB >= 0 && newT >= 0 && height - (newT + newB) > 0 && newB + newT > mb + mt) {
2009+
if(newB + newT > mb + mt) {
20102010
mb = newB;
20112011
mt = newT;
20122012
}
@@ -2016,6 +2016,18 @@ plots.doAutoMargin = function(gd) {
20162016
}
20172017
}
20182018

2019+
var rW = (ml + mr) / maxSpaceW;
2020+
if(rW > 1) {
2021+
ml /= rW;
2022+
mr /= rW;
2023+
}
2024+
2025+
var rH = (mb + mt) / maxSpaceH;
2026+
if(rH > 1) {
2027+
mb /= rH;
2028+
mt /= rH;
2029+
}
2030+
20192031
gs.l = Math.round(ml);
20202032
gs.r = Math.round(mr);
20212033
gs.t = Math.round(mt);
Loading
Loading
354 Bytes
Loading
670 Bytes
Loading

test/jasmine/tests/axes_test.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -3856,7 +3856,7 @@ describe('Test axes', function() {
38563856
.then(function() { return Plotly.relayout(gd, 'height', 100); })
38573857
.then(function() {
38583858
_assert('after relayout to *small* height', {
3859-
bottomLowerBound: 30,
3859+
bottomLowerBound: 15,
38603860
totalHeight: 100
38613861
});
38623862
})
@@ -3896,7 +3896,7 @@ describe('Test axes', function() {
38963896
.then(function() { return Plotly.relayout(gd, 'width', 100); })
38973897
.then(function() {
38983898
_assert('after relayout to *small* width', {
3899-
leftLowerBound: 30,
3899+
leftLowerBound: 15,
39003900
totalWidth: 100
39013901
});
39023902
})

test/jasmine/tests/indicator_test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ describe('Indicator plot', function() {
171171
return Plotly.relayout(gd, {width: 200, height: 200});
172172
})
173173
.then(function() {
174-
checkNumbersScale(0.2, 'should scale down');
174+
checkNumbersScale(0.4794007490636704, 'should scale down');
175175
return Plotly.relayout(gd, {width: 400, height: 400});
176176
})
177177
.then(function() {

test/jasmine/tests/legend_scroll_test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ describe('The legend', function() {
405405
expect(countLegendClipPaths(gd)).toBe(1);
406406

407407
// clippath resized to new height less than new plot height
408-
expect(+legendHeight).toBe(getPlotHeight(gd));
408+
expect(+legendHeight).toBeGreaterThan(getPlotHeight(gd));
409409
expect(+legendHeight).toBeLessThan(+origLegendHeight);
410410

411411
done();

0 commit comments

Comments
 (0)