Horizontal legend layouts with long series names become vertical
See original GitHub issueRepro cases: http://codepen.io/anon/pen/RGozGE
I’ve encountered an odd behavior on horizontal legends with long series names. If the series names are relatively short, setting layout.legend.orientation
to 'h'
does indeed produce a reasonably laid out horizontal legend where each line of the legend is filled with as many series as possible (first example in the codepen). If, however, a series has a very long name, each series is placed on its own row in the legend (effectively becoming a vertical legend), even though there’s clearly room for series with shorter names to be placed on the same rows (second example in the codepen). I think the more logical behavior should be something like this, where the series are packed into rows as closely as their names allow.
I’m happy to make a PR to improve this (it should just involve fiddling with the logic near legend/draw.js:603). Should the current behavior be preserved via a new legend attribute whose default is the current behavior and has an option for the new behavior, or is the current behavior never reasonable and should be replaced?
CC to @markwatabe who originally discussed this issue with me and helped with the proposed solution.
Issue Analytics
- State:
- Created 7 years ago
- Reactions:6
- Comments:13 (9 by maintainers)
Top GitHub Comments
This issue has been tagged with
NEEDS SPON$OR
A community PR for this feature would certainly be welcome, but our experience is deeper features like this are difficult to complete without the Plotly maintainers leading the effort.
Sponsorship range: $5k-$10k
What Sponsorship includes:
Please include the link to this issue when contacting us to discuss.
The simplest workaround to avoid this problem is to
slice(0, maxLengthForLegend)
the trace’s name (maxLengthForLegend
between 20 and 30 seem to work well and allow the trace name to be recognized).