Skip to content

Commit 33bbbef

Browse files
committed
Apply review comments
1 parent a3462d2 commit 33bbbef

File tree

3 files changed

+17
-25
lines changed

3 files changed

+17
-25
lines changed

src/plot_api/plot_api.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ function _doPlot(gd, data, layout, config) {
277277

278278
subroutines.drawMarginPushers(gd);
279279
Axes.allowAutoMargin(gd);
280-
Plots.allowAutoMargin(gd, 'title.automargin');
280+
if(gd._fullLayout.title.text && gd._fullLayout.title.automargin) Plots.allowAutoMargin(gd, 'title.automargin');
281281

282282
// TODO can this be moved elsewhere?
283283
if(fullLayout._has('pie')) {

src/plot_api/subroutines.js

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ exports.drawMainTitle = function(gd) {
406406
var dy = getMainTitleDy(fullLayout);
407407
var y = getMainTitleY(fullLayout, dy);
408408

409-
if(title.automargin) {
409+
if(title.text && title.automargin) {
410410
applyTitleAutoMargin(gd, y);
411411
}
412412

@@ -442,23 +442,15 @@ function isOutsideContainer(gd, title, position, y) {
442442
// 'auto' is not supported for either title.y or title.yanchor when automargin=true
443443
function setDflts(title) {
444444
if(title.automargin && title.yref === 'paper') {
445-
title.y = title.y === 0 ? title.y : 1;
445+
title.y = title.y === 0 ? 0 : 1;
446446
if(title.yanchor === 'auto') {
447-
if(title.y === 0) {
448-
title.yanchor = 'top';
449-
} else {
450-
title.yanchor = 'bottom';
451-
}
447+
title.yanchor = title.y === 0 ? 'top' : 'bottom';
452448
}
453449
}
454450
if(title.automargin && title.yref === 'container') {
455-
title.y = title.y === 'auto' ? 1 : title.y;
451+
if(title.y === 'auto') title.y = 1;
456452
if(title.yanchor === 'auto') {
457-
if(title.y < 0.5) {
458-
title.yanchor = 'bottom';
459-
} else {
460-
title.yanchor = 'top';
461-
}
453+
title.yanchor = title.y < 0.5 ? 'bottom' : 'top';
462454
}
463455
}
464456
}

src/plots/plots.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1981,15 +1981,15 @@ plots.doAutoMargin = function(gd) {
19811981

19821982
var gs = fullLayout._size;
19831983
var margin = fullLayout.margin;
1984-
var reservedMargins = {'t': 0, 'b': 0, 'l': 0, 'r': 0};
1984+
var reservedMargins = {t: 0, b: 0, l: 0, r: 0};
19851985
var oldMargins = Lib.extendFlat({}, gs);
19861986

1987-
// We're assuming that each entry only pushes the margin out on one side
19881987
var margins = gd._fullLayout._reservedMargin;
19891988
for(var key in margins) {
1990-
var side = Object.keys(margins[key])[0];
1991-
var val = Object.values(margins[key])[0];
1992-
reservedMargins[side] += val;
1989+
for(var side in margins[key]) {
1990+
var val = margins[key][side];
1991+
reservedMargins[side] = Math.max(reservedMargins[side], val);
1992+
}
19931993
}
19941994
// adjust margins for outside components
19951995
// fullLayout.margin is the requested margin,
@@ -2026,16 +2026,16 @@ plots.doAutoMargin = function(gd) {
20262026
var pl = pushleft.size;
20272027
var fb = pushbottom.val;
20282028
var pb = pushbottom.size;
2029-
var nonReservedWidth = width - reservedMargins.r - reservedMargins.l;
2030-
var nonReservedHeight = height - reservedMargins.t - reservedMargins.b;
2029+
var availableWidth = width - reservedMargins.r - reservedMargins.l;
2030+
var availableHeight = height - reservedMargins.t - reservedMargins.b;
20312031

20322032
for(var k2 in pushMargin) {
20332033
if(isNumeric(pl) && pushMargin[k2].r) {
20342034
var fr = pushMargin[k2].r.val;
20352035
var pr = pushMargin[k2].r.size;
20362036
if(fr > fl) {
2037-
var newL = (pl * fr + (pr - nonReservedWidth) * fl) / (fr - fl);
2038-
var newR = (pr * (1 - fl) + (pl - nonReservedWidth) * (1 - fr)) / (fr - fl);
2037+
var newL = (pl * fr + (pr - availableWidth) * fl) / (fr - fl);
2038+
var newR = (pr * (1 - fl) + (pl - availableWidth) * (1 - fr)) / (fr - fl);
20392039
if(newL + newR > ml + mr) {
20402040
ml = newL;
20412041
mr = newR;
@@ -2047,8 +2047,8 @@ plots.doAutoMargin = function(gd) {
20472047
var ft = pushMargin[k2].t.val;
20482048
var pt = pushMargin[k2].t.size;
20492049
if(ft > fb) {
2050-
var newB = (pb * ft + (pt - nonReservedHeight) * fb) / (ft - fb);
2051-
var newT = (pt * (1 - fb) + (pb - nonReservedHeight) * (1 - ft)) / (ft - fb);
2050+
var newB = (pb * ft + (pt - availableHeight) * fb) / (ft - fb);
2051+
var newT = (pt * (1 - fb) + (pb - availableHeight) * (1 - ft)) / (ft - fb);
20522052
if(newB + newT > mb + mt) {
20532053
mb = newB;
20542054
mt = newT;

0 commit comments

Comments
 (0)