Skip to content
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

Add real legend_cols support for Bokeh #5669

Merged
merged 1 commit into from Apr 17, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
22 changes: 14 additions & 8 deletions holoviews/plotting/bokeh/element.py
Expand Up @@ -2174,8 +2174,8 @@ def _init_glyph(self, plot, mapping, properties):

class LegendPlot(ElementPlot):

legend_cols = param.Integer(default=False, doc="""
Whether to lay out the legend as columns.""")
legend_cols = param.Integer(default=0, bounds=(0, None), doc="""
Number of columns for legend.""")

legend_labels = param.Dict(default=None, doc="""
Label overrides.""")
Expand Down Expand Up @@ -2218,12 +2218,16 @@ def _process_legend(self, plot=None):
or not self.show_legend):
legend.items[:] = []
else:
plot.legend.orientation = 'horizontal' if self.legend_cols else 'vertical'
if bokeh3 and self.legend_cols:
plot.legend.nrows = self.legend_cols
philippjfr marked this conversation as resolved.
Show resolved Hide resolved
else:
plot.legend.orientation = 'horizontal' if self.legend_cols else 'vertical'

pos = self.legend_position
if pos in self.legend_specs:
plot.legend[:] = []
legend.location = self.legend_offset
if pos in ['top', 'bottom']:
if pos in ['top', 'bottom'] and not self.legend_cols:
plot.legend.orientation = 'horizontal'
plot.add_layout(legend, self.legend_specs[pos])
else:
Expand Down Expand Up @@ -2311,17 +2315,19 @@ def _process_legend(self, overlay):
options[k] = v

pos = self.legend_position
orientation = 'horizontal' if self.legend_cols else 'vertical'
if pos in ['top', 'bottom']:
orientation = 'horizontal'
options['orientation'] = orientation
if not bokeh3:
options['orientation'] = 'horizontal' if self.legend_cols else 'vertical'
if pos in ['top', 'bottom'] and not self.legend_cols:
options['orientation'] = 'horizontal'

if overlay is not None and overlay.kdims:
title = ', '.join([d.label for d in overlay.kdims])
options['title'] = title

options.update(self._fontsize('legend', 'label_text_font_size'))
options.update(self._fontsize('legend_title', 'title_text_font_size'))
if bokeh3 and self.legend_cols:
options.update({"ncols": self.legend_cols})
legend.update(**options)

if pos in self.legend_specs:
Expand Down