From f25c11093dceb0fb6a2179301af4e63479bc0e13 Mon Sep 17 00:00:00 2001 From: Philipp Rudiger Date: Tue, 8 Oct 2019 22:09:29 +0200 Subject: [PATCH] Further fixes --- holoviews/plotting/bokeh/chart.py | 2 +- holoviews/plotting/bokeh/element.py | 22 ++++++++++++++----- holoviews/plotting/bokeh/path.py | 2 +- holoviews/plotting/bokeh/stats.py | 2 +- .../tests/plotting/bokeh/testpathplot.py | 3 ++- 5 files changed, 22 insertions(+), 9 deletions(-) diff --git a/holoviews/plotting/bokeh/chart.py b/holoviews/plotting/bokeh/chart.py index 8d0d85bffa..4db84693b9 100644 --- a/holoviews/plotting/bokeh/chart.py +++ b/holoviews/plotting/bokeh/chart.py @@ -917,7 +917,7 @@ def _add_color_data(self, ds, ranges, style, cdim, data, mapping, factors, color legend_prop = 'legend_field' if bokeh_version >= '1.3.5' else 'legend' if ('color' in cmapping and self.show_legend and isinstance(cmapper, CategoricalColorMapper)): - mapping[legend_prop] = {'field': cdim.name} + mapping[legend_prop] = cdim.name if not (self.stacked or self.stack_index) and ds.ndims > 1: cmapping.pop(legend_prop, None) diff --git a/holoviews/plotting/bokeh/element.py b/holoviews/plotting/bokeh/element.py index 13aa743534..1b9b4aa0c9 100644 --- a/holoviews/plotting/bokeh/element.py +++ b/holoviews/plotting/bokeh/element.py @@ -1049,7 +1049,7 @@ def _apply_transforms(self, element, data, ranges, style, group=None): field = k if categorical and getattr(self, 'show_legend', False): legend_prop = 'legend_field' if bokeh_version >= '1.3.5' else 'legend' - new_style[legend_prop] = {'field': field} + new_style[legend_prop] = field key = {'field': field, 'transform': cmapper} new_style[k] = key @@ -1127,8 +1127,11 @@ def _update_glyph(self, renderer, properties, mapping, glyph, source, data): allowed_properties = glyph.properties() properties = mpl_to_bokeh(properties) merged = dict(properties, **mapping) - legend_prop = 'legend_label' if bokeh_version >= '1.3.5' else 'legend' - legend = merged.pop(legend_prop, None) + legend_props = ('legend_field', 'legend_label') if bokeh_version >= '1.3.5' else ('legend',) + for lp in legend_props: + legend = merged.pop(lp, None) + if legend is not None: + break columns = list(source.data.keys()) glyph_updates = [] for glyph_type in ('', 'selection_', 'nonselection_', 'hover_', 'muted_'): @@ -1170,7 +1173,16 @@ def _update_glyph(self, renderer, properties, mapping, glyph, source, data): for leg in self.state.legend: for item in leg.items: if renderer in item.renderers: - item.label = legend if isinstance(legend, dict) else {'value': legend} + if isinstance(legend, dict): + label = legend + elif lp != 'legend': + prop = 'value' if 'label' in lp else 'field' + label = {prop: legend} + elif isinstance(item.label, dict): + label = {list(item.label)[0]: legend} + else: + label = {'value': legend} + item.label = label for glyph, update in glyph_updates: glyph.update(**update) @@ -1758,7 +1770,7 @@ def _get_color_data(self, element, ranges, style, name='color', factors=None, co data[field] = cdata if factors is not None and self.show_legend: legend_prop = 'legend_field' if bokeh_version >= '1.3.5' else 'legend' - mapping[legend_prop] = {'field': field} + mapping[legend_prop] = field mapping[name] = {'field': field, 'transform': mapper} return data, mapping diff --git a/holoviews/plotting/bokeh/path.py b/holoviews/plotting/bokeh/path.py index a1ec68bc97..c7b4e4188f 100644 --- a/holoviews/plotting/bokeh/path.py +++ b/holoviews/plotting/bokeh/path.py @@ -245,7 +245,7 @@ def get_data(self, element, ranges, style): mapping[self._color_style] = {'field': dim_name, 'transform': cmapper} if self.show_legend: legend_prop = 'legend_field' if bokeh_version >= '1.3.5' else 'legend' - mapping[legend_prop] = {'field': dim_name} + mapping[legend_prop] = dim_name return data, mapping, style def _init_glyph(self, plot, mapping, properties): diff --git a/holoviews/plotting/bokeh/stats.py b/holoviews/plotting/bokeh/stats.py index 9633972177..9c99f5ff94 100644 --- a/holoviews/plotting/bokeh/stats.py +++ b/holoviews/plotting/bokeh/stats.py @@ -288,7 +288,7 @@ def get_data(self, element, ranges, style): if self.show_legend: legend_prop = 'legend_field' if bokeh_version >= '1.3.5' else 'legend' - vbar_map[legend_prop] = {'field': cdim.name} + vbar_map[legend_prop] = cdim.name return data, mapping, style diff --git a/holoviews/tests/plotting/bokeh/testpathplot.py b/holoviews/tests/plotting/bokeh/testpathplot.py index 96a4615bfa..761691d637 100644 --- a/holoviews/tests/plotting/bokeh/testpathplot.py +++ b/holoviews/tests/plotting/bokeh/testpathplot.py @@ -181,7 +181,8 @@ def test_path_continuously_varying_color_legend(self): path = Path(data, vdims="cat").opts(color="cat", cmap=dict(zip(levels, colors)), line_width=4, show_legend=True) plot = bokeh_renderer.get_plot(path) item = plot.state.legend[0].items[0] - self.assertEqual(item.label, 'color_str__') + legend = {'field': 'color_str__'} + self.assertEqual(item.label, legend) self.assertEqual(item.renderers, [plot.handles['glyph_renderer']])