Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
575 views
in Technique[技术] by (71.8m points)

treemap - Using plotly.graph_objects, is there way to trim or wrap the label text inside of each box when the box is too small?

If you look here: https://plotly.com/python/treemaps/#nested-layers-in-treemap, looking at the image: enter image description here

Note the tiny text in the second small block. You can hardly see it because the text is "Blackcurrant-like", and it's too big to fit.

None of the current options proposed in the documentation are sufficient.

Proposed solution 1: Force the font size to be bigger, hide if it won't fit.

By adding this line:

    fig.update_layout(uniformtext=dict(minsize=11, mode='hide'))

It hides labels that don't fit:

enter image description here

And that's not very good. I want to be able to see the text.

Proposed solution 2: Force the font size to be bigger, force show if it won't fit.

    fig.update_layout(uniformtext=dict(minsize=11, mode='show'))

enter image description here

That solves the problem in the text hiding, but now it draws outside of the box, which is not good.

What I would like is for the text to wrap. If that's not possible, then I would like it to trim (possibly with ellipses). I can't figure out a way to do either with this library. So my first question is, is it possible?

Proposed solution 3: Trim text ahead of time.

If I knew ahead of time that the text won't fit, I could trim it. But how do I know that, and how can I tell by how much I can trim it? I suppose, since the the size of the box is indirectly related to the value we pass it, we can make a guess as to which boxes are going to be too small for the text we pass in. But how? I don't even know the shame of the box. Below it's a tall rectangle. There's no way for me to guess that.
If there was an event I can hook on where the UI calls me back before rending the text, giving me the dimensions of the square, allowing me to change the text, I might have a chance.

Any suggestions?

Seems silly to have all that space in the box that I can't populate. I'm assuming there's some technical reason why the text can't wrap since that would have been the most obvious solution.

question from:https://stackoverflow.com/questions/65942714/using-plotly-graph-objects-is-there-way-to-trim-or-wrap-the-label-text-inside-o

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...