Skip to content

Commit

Permalink
subcoordinate_y: reverse the renderers by default (#6194)
Browse files Browse the repository at this point in the history
  • Loading branch information
maximlt authored Apr 16, 2024
1 parent 372eb6c commit 1568bdd
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
20 changes: 16 additions & 4 deletions holoviews/plotting/bokeh/element.py
Original file line number Diff line number Diff line change
Expand Up @@ -2201,7 +2201,6 @@ def _init_glyph(self, plot, mapping, properties, key):
return renderer, renderer.glyph



class ColorbarPlot(ElementPlot):
"""
ColorbarPlot provides methods to create colormappers and colorbar
Expand Down Expand Up @@ -2617,7 +2616,6 @@ def _process_legend(self, plot=None):
r.muted = self.legend_muted



class AnnotationPlot:
"""
Mix-in plotting subclass for AnnotationPlots which do not have a legend.
Expand Down Expand Up @@ -2782,7 +2780,6 @@ def _process_legend(self, overlay):
for r in item.renderers:
r.muted = self.legend_muted or r.muted


def _init_tools(self, element, callbacks=None):
"""
Processes the list of tools to be supplied to the plot.
Expand Down Expand Up @@ -2825,7 +2822,6 @@ def _init_tools(self, element, callbacks=None):
self.handles['hover_tools'] = hover_tools
return init_tools


def _merge_tools(self, subplot):
"""
Merges tools on the overlay with those on the subplots.
Expand Down Expand Up @@ -2923,6 +2919,7 @@ def initialize_plot(self, ranges=None, plot=None, plots=None):
self._update_ranges(element, ranges)

panels = []
subcoord_y_glyph_renderers = []
for key, subplot in self.subplots.items():
frame = None
if self.tabs:
Expand All @@ -2941,6 +2938,21 @@ def initialize_plot(self, ranges=None, plot=None, plots=None):
title = get_tab_title(key, frame, self.hmap.last)
panels.append(TabPanel(child=child, title=title))
self._merge_tools(subplot)
if getattr(subplot, "subcoordinate_y", False) and (
glyph_renderer := subplot.handles.get("glyph_renderer")
):
subcoord_y_glyph_renderers.append(glyph_renderer)

if self.subcoordinate_y:
# Reverse the subcoord-y renderers only.
reversed_renderers = subcoord_y_glyph_renderers[::-1]
reordered = []
for item in plot.renderers:
if item not in subcoord_y_glyph_renderers:
reordered.append(item)
else:
reordered.append(reversed_renderers.pop(0))
plot.renderers = reordered

if self.tabs:
self.handles['plot'] = Tabs(
Expand Down
11 changes: 11 additions & 0 deletions holoviews/tests/plotting/bokeh/test_subcoordy.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,17 @@ def test_bool_base(self):
assert plot.state.yaxis.ticker.ticks == [0, 1]
assert plot.state.yaxis.major_label_overrides == {0: 'Data 0', 1: 'Data 1'}

def test_renderers_reversed(self):
overlay = Overlay([Curve(range(10), label=f'Data {i}').opts(subcoordinate_y=True) for i in range(2)])
overlay = VSpan(0, 1, label='back') * overlay * VSpan(2, 3, label='front')
plot = bokeh_renderer.get_plot(overlay)
renderers = plot.handles['plot'].renderers
assert (renderers[0].left, renderers[0].right) == (0, 1)
# Only the subcoord-y renderers are reversed by default.
assert renderers[1].name == 'Data 1'
assert renderers[2].name == 'Data 0'
assert (renderers[3].left, renderers[3].right) == (2, 3)

def test_bool_scale(self):
test_data = [
(0.5, (-0.25, 0.25), (0.75, 1.25), (-0.25, 1.25)),
Expand Down

0 comments on commit 1568bdd

Please sign in to comment.