Skip to content

Commit b8942ee

Browse files
committed
improved subtitle automargin positioning
1 parent 47a5b82 commit b8942ee

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

src/components/titles/index.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -411,5 +411,7 @@ function draw(gd, titleClass, options) {
411411
}
412412

413413
module.exports = {
414-
draw: draw
414+
draw: draw,
415+
SUBTITLE_PADDING_EM: SUBTITLE_PADDING_EM,
416+
SUBTITLE_PADDING_MATHJAX_EM: SUBTITLE_PADDING_MATHJAX_EM,
415417
};

src/plot_api/subroutines.js

+15
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,21 @@ exports.drawMainTitle = function(gd) {
445445
this.setAttribute('dy', newDy);
446446
});
447447
}
448+
449+
// If there is a subtitle
450+
var subtitleObj = d3.selectAll('.gtitle-subtitle');
451+
if(subtitleObj.node()) {
452+
// Get bottom edge of title bounding box
453+
var titleBB = titleObj.node().getBBox();
454+
var titleBottom = titleBB.y + titleBB.height;
455+
var subtitleY = titleBottom + Titles.SUBTITLE_PADDING_EM * title.subtitle.font.size;
456+
subtitleObj.attr({
457+
x: x,
458+
y: subtitleY,
459+
'text-anchor': textAnchor,
460+
dy: getMainTitleDyAdj(title.yanchor)
461+
}).call(svgTextUtils.positionText, x, subtitleY);
462+
}
448463
}
449464
}
450465
};

0 commit comments

Comments
 (0)