Skip to content

Commit

Permalink
Fixes and improvements for CompositeElementPlot (#2140)
Browse files Browse the repository at this point in the history
  • Loading branch information
philippjfr committed Nov 22, 2017
1 parent bc7c083 commit f5e8512
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
4 changes: 2 additions & 2 deletions holoviews/plotting/bokeh/chart.py
Original file line number Diff line number Diff line change
Expand Up @@ -1068,12 +1068,12 @@ def get_data(self, element, ranges, style):
data = {
bar_glyph+'_1': r1_data, bar_glyph+'_2': r2_data, 'segment_1': s1_data,
'segment_2': s2_data, 'rect_1': w1_data, 'rect_2': w2_data,
'circle': out_data
'circle_1': out_data
}
mapping = {
bar_glyph+'_1': vbar_map, bar_glyph+'_2': vbar2_map, 'segment_1': seg_map,
'segment_2': seg_map, 'rect_1': whisk_map, 'rect_2': whisk_map,
'circle': out_map
'circle_1': out_map
}

# Cast data to arrays to take advantage of base64 encoding
Expand Down
18 changes: 14 additions & 4 deletions holoviews/plotting/bokeh/element.py
Original file line number Diff line number Diff line change
Expand Up @@ -668,7 +668,8 @@ def _glyph_properties(self, plot, element, source, ranges, style):
self.overlay_dims.items()])
else:
legend = element.label
properties['legend'] = value(legend)
if legend:
properties['legend'] = value(legend)
return properties

def _update_glyph(self, renderer, properties, mapping, glyph):
Expand Down Expand Up @@ -921,9 +922,12 @@ class CompositeElementPlot(ElementPlot):
drawing of multiple glyphs.
"""

# Mapping between glyph name and style groups
# Mapping between style groups and glyph names
_style_groups = {}

# Defines the order in which glyphs are drawn, defined by glyph name
_draw_order = []

def _init_glyphs(self, plot, element, ranges, source):
# Get data and initialize data source
style = self.style[self.cyclic_index]
Expand Down Expand Up @@ -983,7 +987,13 @@ def _update_glyphs(self, element, ranges):
style = self.style[self.cyclic_index]
data, mapping, style = self.get_data(element, ranges, style)

for key in sorted(dict(mapping, **data)):
# Order glyphs by supplied draw order
keys = sorted(dict(mapping, **data))
def order_fn(glyph):
matches = [item for item in self._draw_order if glyph.startswith(item)]
if matches: return self._draw_order.index(matches[0])
return 1e6+keys.index(glyph)
for key in sorted(keys, key=order_fn):
gdata = data.get(key)
source = self.handles[key+'_source']
glyph = self.handles.get(key+'_glyph')
Expand All @@ -1003,7 +1013,7 @@ def _init_glyph(self, plot, mapping, properties, key):
Returns a Bokeh glyph object.
"""
properties = mpl_to_bokeh(properties)
plot_method = key.split('_')[0]
plot_method = '_'.join(key.split('_')[:-1])
renderer = getattr(plot, plot_method)(**dict(properties, **mapping))
return renderer, renderer.glyph

Expand Down

0 comments on commit f5e8512

Please sign in to comment.