Skip to content

Commit 1ef43ae

Browse files
authored
Merge pull request #6758 from plotly/automargin-multi-line-title
handle multi-line text in title automargin
2 parents 9e3a7d4 + eea8484 commit 1ef43ae

5 files changed

+43
-0
lines changed

draftlogs/6758_fix.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- Fix handling multi-line text in title `automargin` [[#6758](https://github.com/plotly/plotly.js/pull/6758)]

src/plot_api/subroutines.js

+13
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,19 @@ exports.drawMainTitle = function(gd) {
430430
'text-anchor': textAnchor,
431431
dy: getMainTitleDyAdj(title.yanchor)
432432
}).call(svgTextUtils.positionText, x, y);
433+
434+
var extraLines = (title.text.match(svgTextUtils.BR_TAG_ALL) || []).length;
435+
if(extraLines) {
436+
var delta = alignmentConstants.LINE_SPACING * extraLines + alignmentConstants.MID_SHIFT;
437+
if(title.y === 0) {
438+
delta = -delta;
439+
}
440+
441+
titleObj.selectAll('.line').each(function() {
442+
var newDy = +(this.getAttribute('dy')).slice(0, -2) - delta + 'em';
443+
this.setAttribute('dy', newDy);
444+
});
445+
}
433446
}
434447
}
435448
};
Loading
Loading
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"data": [
3+
{
4+
"showlegend": false,
5+
"type": "scatter",
6+
"x": [
7+
1,
8+
2,
9+
3
10+
],
11+
"y": [
12+
4,
13+
5,
14+
6
15+
]
16+
}],
17+
"layout": {
18+
"height": 300,
19+
"width": 400,
20+
"margin": {"t":0, "b": 0, "l": 0, "r": 0},
21+
"title": {
22+
"automargin": true,
23+
"text": "Paper<br>Multi-line",
24+
"pad": {"t": 15, "b": 10},
25+
"yref": "paper",
26+
"y": 0
27+
}
28+
}
29+
}

0 commit comments

Comments
 (0)