From 38e30b8411219abc807224ee4625fbdbe4e3d8d3 Mon Sep 17 00:00:00 2001 From: Demetris Roumis Date: Thu, 27 Jun 2024 15:13:38 -0700 Subject: [PATCH 1/2] Handle empty indicator data --- holonote/annotate/display.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/holonote/annotate/display.py b/holonote/annotate/display.py index d707d86..9ceadab 100644 --- a/holonote/annotate/display.py +++ b/holonote/annotate/display.py @@ -519,6 +519,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: From 5fcdf26fa9007a48a3a281b7427ea7bf98773c1a Mon Sep 17 00:00:00 2001 From: Demetris Roumis Date: Tue, 2 Jul 2024 12:07:29 -0500 Subject: [PATCH 2/2] test for when anno is empty, groupby field, and anno overlaid --- holonote/tests/test_annotators_element.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/holonote/tests/test_annotators_element.py b/holonote/tests/test_annotators_element.py index e30f022..32fd244 100644 --- a/holonote/tests/test_annotators_element.py +++ b/holonote/tests/test_annotators_element.py @@ -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"])