You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Horizontal legend items not visible when many legend items #769
Was pointed out in #766 that scrolling not intended for layout.legend.orientation = 'h'. Example workaround is to use legend groups.
This is not a great solution, however, as it means clicking the legend group hides/shows ALL traces in the group (see jsfiddle).
Proposing that plotly.js implement something similar to ggplot2 which automatically wraps additional legend items on horizontal legend orientation. Especially on mobile portrait orientation, this allows the graph data to take up the entire width of the screen and push the legend below the graph which is much preferable in my view.
changed the title [-]Horizontal legend items not visible when many items[/-][+]Horizontal legend items not visible when many legend items[/+]on Jul 22, 2016
@etpinard I did notice that but decided it's probably more complicated than it's worth. Personally, I don't have any problems with the items not appearing in columns and I think that the legend groups workaround would still be possible if a user really wanted the lined-up columns.
I did notice that but decided it's probably more complicated than it's worth
Yeah. I agree. Your solution sounds like a solid fallback for extra-wide legends. If ever some users want a more fine-grained legend layout, we could always add support for something like:
This PR is an improvement over the current behaviour. I think there is a low hanging fruit that could be implemented in another PR. With this PR, a multiline horizontal legend would look like this:
One easy way to align the traces in a grid would be to iterate over all the traces to compute the maximum width, and use this width for all the traces.
@etpinard I've made a change to the pull request per @n-riesco suggestions about aligning traces in a grid. I agree that it looks much better and it was simpler to do than I originally thought.
I understand that customizing the grid is probably more complicated than its worth. But something I noticed is that when more than one row appear, the x-positioning of the legend is lost. So if you have one row, you can center the legend with xanchor: center, x:0.5. Once you have 2 rows, it just defaults to far left and any of the xanchor, x options don't do anything.
All I did in second screenshot was make the plot narrower.
I did notice that but decided it's probably more complicated than it's worth
Yeah. I agree. Your solution sounds like a solid fallback for extra-wide legends. If ever some users want a more fine-grained legend layout, we could always add support for something like:
I realize I am pretty late for this conversation, but that suggestion sounds fantastic. The problem with using legend groups to align/group the legends is that this also makes them visible/invisible together when you toggle-click the trace name in the legend. More than ones, I have wanted to group similar legends together, though be able to make them invisible seperatly.
Activity
[-]Horizontal legend items not visible when many items[/-][+]Horizontal legend items not visible when many legend items[/+]etpinard commentedon Jul 22, 2016
Thanks.
Might fix plotly#769 - added check for pushing past plot margin and s…
psalmody commentedon Jul 22, 2016
@etpinard Can you review this PR on my fork? I think it should resolves this issue. psalmody#1
etpinard commentedon Jul 22, 2016
@psalmody I think that should do it.
One possible imperfection I see here:
is that the items on the second line don't line up with the items above them - unlike in the ggplot example you posted. Was that on purpose?
psalmody commentedon Jul 22, 2016
@etpinard I did notice that but decided it's probably more complicated than it's worth. Personally, I don't have any problems with the items not appearing in columns and I think that the legend groups workaround would still be possible if a user really wanted the lined-up columns.
etpinard commentedon Jul 22, 2016
Yeah. I agree. Your solution sounds like a solid fallback for extra-wide legends. If ever some users want a more fine-grained legend layout, we could always add support for something like:
down the road.
@n-riesco what do you think?
n-riesco commentedon Jul 22, 2016
I'm unable to test this until Monday.
Does toggling traces work in this PR?
psalmody commentedon Jul 22, 2016
If by toggle you mean hide/show the trace by clicking the legend item, yes.
n-riesco commentedon Jul 26, 2016
@etpinard , @mdtusz I think this PR is ready for review.
This PR is an improvement over the current behaviour. I think there is a low hanging fruit that could be implemented in another PR. With this PR, a multiline horizontal legend would look like this:
One easy way to align the traces in a grid would be to iterate over all the traces to compute the maximum width, and use this width for all the traces.
psalmody commentedon Jul 26, 2016
@etpinard I've made a change to the pull request per @n-riesco suggestions about aligning traces in a grid. I agree that it looks much better and it was simpler to do than I originally thought.
psalmody commentedon Jul 27, 2016
Sorry but new to this process. @etpinard or @mdtusz should I send a PR back to plotly/plotly.js from my fork?
mdtusz commentedon Jul 27, 2016
Yep! Open a PR with your fork and we'll take a look at it!
psalmody commentedon Jul 27, 2016
@etpinard @mdtusz See #786
yniknafs commentedon Apr 20, 2018
@psalmody @etpinard
I understand that customizing the grid is probably more complicated than its worth. But something I noticed is that when more than one row appear, the x-positioning of the legend is lost. So if you have one row, you can center the legend with xanchor: center, x:0.5. Once you have 2 rows, it just defaults to far left and any of the xanchor, x options don't do anything.
All I did in second screenshot was make the plot narrower.
psalmody commentedon Apr 20, 2018
@yniknafs It's a great idea. Not sure I personally have the time to modify the code though... :(
viggotw commentedon Sep 11, 2019
I realize I am pretty late for this conversation, but that suggestion sounds fantastic. The problem with using legend groups to align/group the legends is that this also makes them visible/invisible together when you toggle-click the trace name in the legend. More than ones, I have wanted to group similar legends together, though be able to make them invisible seperatly.
adibiasio commentedon Jun 15, 2020
Any updates on this?