Skip to content

Commit

Permalink
Handle empty indicator when groupby is set (#118)
Browse files Browse the repository at this point in the history
  • Loading branch information
droumis authored Jul 2, 2024
1 parent 96c5997 commit 36f5602
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
3 changes: 3 additions & 0 deletions holonote/annotate/display.py
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,9 @@ def static_indicators(self, **events):
highlighters = {opt: self._selected_dim_expr(v[0], v[1]) for opt, v in highlight.items()}
indicator = indicator.opts(*self.style.indicator(**highlighters))

if len(indicator.data) == 0:
return hv.NdOverlay({0: self._make_empty_element()})

return indicator.overlay() if self.annotator.groupby else hv.NdOverlay({0: indicator})

def _selected_dim_expr(self, selected_value, non_selected_value) -> hv.dim:
Expand Down
19 changes: 19 additions & 0 deletions holonote/tests/test_annotators_element.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,25 @@ def test_groupby_visible(cat_annotator):
next(iter_indicator)


def test_groupby_with_overlay_from_empty_annotator(annotator_range2d, capsys):
# Test for https://github.com/holoviz/holonote/issues/119
annotator = annotator_range2d
annotator.groupby = "description"
bounds = (-1, -1, 1, 1)
data = np.array([[0, 1], [1, 0]])
img = hv.Image(data, kdims=["x", "y"], bounds=bounds)

plot = annotator * img
hv.render(plot)

annotator.set_regions(x=(-0.15, 0.15), y=(-0.25, 0.25))
annotator.add_annotation(description="Test")

captured = capsys.readouterr()
bad_output = "AssertionError: DynamicMap must only contain one type of object, not both Overlay and NdOverlay."
assert bad_output not in captured.out


def test_multiply_overlay(annotator_range1d):
el1 = hv.Curve([], kdims=["TIME"])
el2 = hv.Curve([], kdims=["TIME"])
Expand Down

0 comments on commit 36f5602

Please sign in to comment.