Skip to content

Commit

Permalink
Further fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
philippjfr committed Oct 8, 2019
1 parent 7520c46 commit f25c110
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 9 deletions.
2 changes: 1 addition & 1 deletion holoviews/plotting/bokeh/chart.py
Expand Up @@ -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)
Expand Down
22 changes: 17 additions & 5 deletions holoviews/plotting/bokeh/element.py
Expand Up @@ -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

Expand Down Expand Up @@ -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_'):
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion holoviews/plotting/bokeh/path.py
Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion holoviews/plotting/bokeh/stats.py
Expand Up @@ -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

Expand Down
3 changes: 2 additions & 1 deletion holoviews/tests/plotting/bokeh/testpathplot.py
Expand Up @@ -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']])


Expand Down

0 comments on commit f25c110

Please sign in to comment.