Skip to content

Commit

Permalink
Merge pull request #6923 from plotly/fix6922-treemap-centered-multili…
Browse files Browse the repository at this point in the history
…ne-headers

Fix centering multi-line headers for `treemap` traces
  • Loading branch information
archmoj committed Mar 15, 2024
2 parents 39bd75f + c5455f0 commit 49efb52
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 2 deletions.
1 change: 1 addition & 0 deletions draftlogs/6923_fix.md
@@ -0,0 +1 @@
- Fix centering multi-line headers for treemap traces [[#6923](https://github.com/plotly/plotly.js/pull/6923)]
8 changes: 6 additions & 2 deletions src/traces/treemap/draw_descendants.js
Expand Up @@ -184,9 +184,13 @@ module.exports = function drawDescendants(gd, cd, entry, slices, opts) {

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

sliceText.text(pt._text || ' ') // use one space character instead of a blank string to avoid jumps during transition

var text = pt._text || ' '; // use one space character instead of a blank string to avoid jumps during transition
var singleLineHeader = isHeader && text.indexOf('<br>') === -1;

sliceText.text(text)
.classed('slicetext', true)
.attr('text-anchor', hasRight ? 'end' : (hasLeft || isHeader) ? 'start' : 'middle')
.attr('text-anchor', hasRight ? 'end' : (hasLeft || singleLineHeader) ? 'start' : 'middle')
.call(Drawing.font, font)
.call(svgTextUtils.convertToTspans, gd);

Expand Down
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
41 changes: 41 additions & 0 deletions test/image/mocks/zz-treemap_multi-line_headers.json
@@ -0,0 +1,41 @@
{
"data": [
{
"labels": [
"parent2",
"parent1<br>Long text on second line",
"item2",
"item1"
],
"name": "",
"parents": [
"",
"",
"parent2",
"parent1<br>Long text on second line"
],
"values": [
0,
0,
200,
500
],
"type": "treemap",
"textposition": "middle center",
"texttemplate": "<b>%{label}</b>",
"textfont": {
"size": 20
}
}
],
"layout": {
"margin": {
"t": 50,
"b": 10,
"l": 10,
"r": 10
},
"height": 200,
"width": 500
}
}

0 comments on commit 49efb52

Please sign in to comment.