Skip to content

Allow style editing of graph legend labels #7063

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
notwopr opened this issue Feb 2, 2023 · 2 comments
Open

Allow style editing of graph legend labels #7063

notwopr opened this issue Feb 2, 2023 · 2 comments
Labels
feature something new P3 backlog

Comments

@notwopr
Copy link

notwopr commented Feb 2, 2023

Thanks so much for your interest in Dash!

The feature has already been tangentially discussed here: https://community.plotly.com/t/scatter-plot-how-to-wrap-legends-text-when-legend-text-is-too-long/4767/7

Is your feature request related to a problem? Please describe.
I have traces that have very long names. It's problematic because the legend text does not word wrap and so it squishes the graph.
Here's an example: https://postimg.cc/VSq0bQXW

Describe the solution you'd like
Please allow for more stylistic control over legend text, particularly allowing for textoverflow control, like word wrap, hidden+ellipsis, hover tooltip etc.

Describe alternatives you've considered
I had to resorted to displaying a hashmap to translate the long text into a shorter signature.

Additional context
I've had it where the text is really long that the actual graph is completely unreadable.

@ned2
Copy link

ned2 commented Feb 5, 2023

Enhancements around the legend formatting would likely be added to plotly.js rather than Dash.

It looks like there's already a few couple of related issues on this topic over there.

One thing you could do as a workaround is truncate the name of the trace in the underlying figure. This is where trace names are sourced from for building the legend. It's possible the field is used elsewhere, which means it would be truncated to there. Luckily the default hover text does not seem to be affected.

import plotly.express

df = px.data.gapminder()
df = df[df["continent"]=="Europe"]
fig = px.line(df, x="year", y="lifeExp", color='country')

max_len = 15
for trace in fig.data:
    if len(trace.name) > max_len:
        trace.name = f"{trace.name[:max_len]}..."

@notwopr
Copy link
Author

notwopr commented Feb 24, 2023

Thank you that makes sense it is for plotly and not dash. Thank you for the references. I'll look into it.

@gvwilson gvwilson self-assigned this Jul 24, 2024
@gvwilson gvwilson transferred this issue from plotly/dash Jul 24, 2024
@gvwilson gvwilson removed their assignment Aug 2, 2024
@gvwilson gvwilson added feature something new P3 backlog labels Aug 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature something new P3 backlog
Projects
None yet
Development

No branches or pull requests

3 participants