question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Treemap label wrapping not working

See original GitHub issue

I’m submitting a…


[ ] Regression (a behavior that used to work and stopped working in a new release)
[x] Bug report  
[ ] Performance issue
[ ] Feature request
[ ] Documentation issue or request
[ ] Other... Please describe:

Current behavior

When the treemap label is longer than it’s rect, it doesn’t wrap and instead just disappears.

Expected behavior

Labels wrap nicely.

Minimal reproduction of the problem with instructions

I’ve checked the current shape of the wrapText function here and while looping over the words, in lines 33 and 38 it always adds the word width to the sum. It then compares sumWidth to container width in line 52 and if we need wrapping, it’s obviously longer, so it returns null. Since wrapText is used in different charts as well and I’ve just started using reaviz, I’m probably not the person to fix it so I don’t cause any regressions.

const simpleData: ChartShallowDataShape[] = [
    {
      key: "Very long text, make it as long as necessary or shrink the treemap width so it's longer than the rect's width.",
      data: 1,
    },
    ]
    
     return <TreeMap
      height={400}
      data={simpleData}
      margins={20}
      series={
        <TreeMapSeries  />
      }
    />

Environment


Libs:
    "react": "17.0.2",
    "reaviz": "13.1.3"
Others:

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
amcdnlcommented, Oct 11, 2022

@puripant - We would welcome any contributions!

0reactions
puripantcommented, Oct 11, 2022

Hi, I am new to this repo but would like to contribute, especially to this issue. I looked into wrapText.tsx and found a few things that made it not working for treemap. For example, the sum of word widths (plus spaces) was not the same as running calculateDimensions() on the whole sentence, probably due to kerning and such. paddingX had no default value and could be undefined and etc. I edited wrapText() as follows.

for (const word of words) {
  nextText = curText === "" ? word : `${curText} ${word}`;
  nextWidth = calculateDimensions(nextText, fontFamily, fontSize).width;
  
  if (nextWidth <= width - (paddingX ? 2*paddingX : 0)) {
    curText = nextText;
    currWidth = nextWidth;
  } else {
    rows.push(curText);
    maxWidth = Math.max(maxWidth, currWidth);
    curText = word;
    currWidth = calculateDimensions(curText, fontFamily, fontSize).width;
  }
}
rows.push(curText);
maxHeight = rows.length * size.height;

I also wrote a treemap example with long text labels in the Storybook to test it. wrapText() was used in two other charts: bubble chart and Venn diagram. I checked their examples with long label texts and they worked fine as well.

If this sounds okay, I can create a pull request.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Text wrap for TreeMap label · Issue #377 · plouc/nivo - GitHub
It seems like TreeMap's label property can only render strings as opposed to html entities, and adding "\n" to the strings doesn't break ......
Read more >
Treemap: data label wrapping - Highcharts official support forum
1.3 - the label no longer wraps by default due to the css styling on the span that highcharts places around the customised...
Read more >
How can I get treemap datalabels to wrap consistently?
Sometimes they wrap, sometimes highcharts truncates them with ellipses (but it really seems like it could wrap them instead).
Read more >
word wrap on treemap visual - Microsoft Power BI Community
Solved! Go to Solution. Labels: Labels: General Comment.
Read more >
Label hiding instead of label wrapping - Tableau Community
I've got a couple of treemaps, where both wrapped and unwrapped label setting seems to be causing problems. Below in the image see...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found