Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle empty indicator when groupby is set #118

Merged
merged 3 commits into from
Jul 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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