Skip to content

Commit

Permalink
Add real legend_cols support for Bokeh (#5669)
Browse files Browse the repository at this point in the history
  • Loading branch information
hoxbro authored Apr 17, 2023
1 parent eba8156 commit 028c1da
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions holoviews/plotting/bokeh/element.py
Original file line number Diff line number Diff line change
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
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

0 comments on commit 028c1da

Please sign in to comment.