FIX: Handle multiple plots in LegendHighlighter#403
Conversation
| renderers as values, or lists of renderers. | ||
| This function helps us assume we're always working with lists | ||
| """ | ||
| return obj if isinstance(obj, list) else [obj] |
There was a problem hiding this comment.
I briefly looked into the code for Legend to see if it made more sense to fix things there, but that did not appear to be the safe approach.
| def _reset_selects(self, plots): | ||
| """ Set all renderers to their default values. """ | ||
| for plot in sm.reduce(operator.add, plots.values()): | ||
| for plot in sum((_ensure_list(p) for p in plots.values()), []): |
There was a problem hiding this comment.
plots is the dictionary of the same name on the Legend instance. We need to anticipate values() being single renderers or lists of renderers.
There was a problem hiding this comment.
A better construct for concatenating list-likes is itertools.chain.from_iterable to the point where I sometimes alias that as concat.
|
@corranwebster The example code only covers the single plot case. I have a very similar change in some product code if you'd like to see something which exercises the multi-plot case. |
corranwebster
left a comment
There was a problem hiding this comment.
Basically OK - I would like to say that we should fix Legend but that would break lots of demo code and therefore by implication lots of user code that copies the pattern.
One nit on how to concatenate sequences.
| def _reset_selects(self, plots): | ||
| """ Set all renderers to their default values. """ | ||
| for plot in sm.reduce(operator.add, plots.values()): | ||
| for plot in sum((_ensure_list(p) for p in plots.values()), []): |
There was a problem hiding this comment.
A better construct for concatenating list-likes is itertools.chain.from_iterable to the point where I sometimes alias that as concat.
A Legend can have multiple plot renderers per name
120737a to
50f607f
Compare
|
Thanks for the feedback! |
|
Want to make sure I understand the fix. Before merging, selecting a name would show and hide only 1 of the renderers, am I guessing correctly? Mind adding details in the description of the issue? |
|
@jonathanrocher That's correct. If you have a plot with a legend where, for example, you have a single logical curve/plot which is broken into multiple segments, and thus multiple renderers, the |
FIX: Handle multiple plots in LegendHighlighter
A Legend can have multiple plot renderers per name.