Skip to content

Commit 49efb52

Browse files
authored
Merge pull request #6923 from plotly/fix6922-treemap-centered-multiline-headers
Fix centering multi-line headers for `treemap` traces
2 parents 39bd75f + c5455f0 commit 49efb52

File tree

4 files changed

+48
-2
lines changed

4 files changed

+48
-2
lines changed

draftlogs/6923_fix.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- Fix centering multi-line headers for treemap traces [[#6923](https://github.com/plotly/plotly.js/pull/6923)]

src/traces/treemap/draw_descendants.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -184,9 +184,13 @@ module.exports = function drawDescendants(gd, cd, entry, slices, opts) {
184184

185185
var font = Lib.ensureUniformFontSize(gd, helpers.determineTextFont(trace, pt, fullLayout.font));
186186

187-
sliceText.text(pt._text || ' ') // use one space character instead of a blank string to avoid jumps during transition
187+
188+
var text = pt._text || ' '; // use one space character instead of a blank string to avoid jumps during transition
189+
var singleLineHeader = isHeader && text.indexOf('<br>') === -1;
190+
191+
sliceText.text(text)
188192
.classed('slicetext', true)
189-
.attr('text-anchor', hasRight ? 'end' : (hasLeft || isHeader) ? 'start' : 'middle')
193+
.attr('text-anchor', hasRight ? 'end' : (hasLeft || singleLineHeader) ? 'start' : 'middle')
190194
.call(Drawing.font, font)
191195
.call(svgTextUtils.convertToTspans, gd);
192196

Loading
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
{
2+
"data": [
3+
{
4+
"labels": [
5+
"parent2",
6+
"parent1<br>Long text on second line",
7+
"item2",
8+
"item1"
9+
],
10+
"name": "",
11+
"parents": [
12+
"",
13+
"",
14+
"parent2",
15+
"parent1<br>Long text on second line"
16+
],
17+
"values": [
18+
0,
19+
0,
20+
200,
21+
500
22+
],
23+
"type": "treemap",
24+
"textposition": "middle center",
25+
"texttemplate": "<b>%{label}</b>",
26+
"textfont": {
27+
"size": 20
28+
}
29+
}
30+
],
31+
"layout": {
32+
"margin": {
33+
"t": 50,
34+
"b": 10,
35+
"l": 10,
36+
"r": 10
37+
},
38+
"height": 200,
39+
"width": 500
40+
}
41+
}

0 commit comments

Comments
 (0)