Skip to content

Commit 0a53856

Browse files
authored
Don't show all elements if nothing is selected by visibile (#133)
1 parent eb9dbf4 commit 0a53856

File tree

6 files changed

+26
-7
lines changed

6 files changed

+26
-7
lines changed

holonote/annotate/annotator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ class Annotator(AnnotatorInterface):
321321

322322
groupby = param.Selector(default=None, doc="Groupby dimension", allow_refs=True)
323323
visible = param.ListSelector(
324-
default=[], doc="Visible dimensions, needs groupby enabled", allow_refs=True
324+
default=None, doc="Visible dimensions, needs groupby enabled", allow_refs=True
325325
)
326326
style = param.ClassSelector(default=Style(), class_=Style, doc="Style parameters")
327327

holonote/annotate/display.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -537,8 +537,14 @@ def static_indicators(self, **events):
537537
msg = f"{self.region_format} not implemented"
538538
raise NotImplementedError(msg)
539539

540-
if len(indicator.data) == 0:
541-
return hv.NdOverlay({0: self._make_empty_element()})
540+
if len(indicator.data) == 0 or (
541+
self.annotator.groupby
542+
and self.annotator.visible is not None
543+
and not len(self.annotator.visible)
544+
):
545+
el = self._make_empty_element()
546+
el_opts = getattr(hv.opts, type(el).__name__)(**_default_opts)
547+
return hv.NdOverlay({0: el}).opts(el_opts)
542548

543549
if self.annotator.groupby and self.annotator.visible:
544550
indicator = indicator.get(self.annotator.visible)

holonote/tests/test_annotators_element.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def test_set_regions_range1d(annotator_range1d) -> None:
3737
expected = [None, None]
3838
assert output == expected
3939

40-
output = next(get_indicator_data(annotator, hv.Rectangles))
40+
output = next(get_indicator_data(annotator, hv.VSpans))
4141
output1 = output.iloc[0][["start[TIME]", "end[TIME]"]].tolist()
4242
expected1 = [-0.25, 0.25]
4343
assert output1 == expected1
@@ -115,7 +115,7 @@ def test_set_regions_multiple(multiple_annotators):
115115
expected = [None, None]
116116
assert output == expected
117117

118-
output = next(get_indicator_data(annotator, hv.Rectangles, "TIME"))
118+
output = next(get_indicator_data(annotator, hv.VSpans, "TIME"))
119119
output1 = output.iloc[0][["start[TIME]", "end[TIME]"]].tolist()
120120
expected1 = [-0.25, 0.25]
121121
assert output1 == expected1
@@ -251,6 +251,14 @@ def test_groupby_visible(cat_annotator):
251251
next(iter_indicator)
252252

253253

254+
def test_groupby_visible_empty(cat_annotator):
255+
cat_annotator.groupby = "category"
256+
cat_annotator.visible = []
257+
iter_indicator = get_indicator(cat_annotator, hv.Curve)
258+
indicator = next(iter_indicator)
259+
assert indicator.data.shape == (0, 2)
260+
261+
254262
def test_groupby_with_overlay_from_empty_annotator(annotator_range2d, capsys):
255263
# Test for https://github.com/holoviz/holonote/issues/119
256264
annotator = annotator_range2d

holonote/tests/test_annotators_style.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def compare_style(cat_annotator):
3838

3939

4040
def get_selected_indicator_data(annotator) -> pd.Series:
41-
df = pd.concat([i.data for i in get_indicator(annotator, hv.VLines)])
41+
df = pd.concat([i.data for i in get_indicator(annotator, None)])
4242
return df["__selected__"]
4343

4444

holonote/tests/util.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,10 @@ def get_editor_data(annotator, element_type, kdims=None):
2626

2727
def get_indicator(annotator, element_type, kdims=None):
2828
si = _get_display(annotator, kdims).indicators().last
29-
yield from si.data.values()
29+
if element_type:
30+
yield from (s for s in si.data.values() if isinstance(s, element_type))
31+
else:
32+
yield from si.data.values()
3033

3134

3235
def get_indicator_data(annotator, element_type, kdims=None):

pyproject.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ filterwarnings = [
4848
"ignore:datetime.datetime.utcfromtimestamp():DeprecationWarning:dateutil.tz.tz", # https://github.com/dateutil/dateutil/pull/1285
4949
# 2024-01
5050
"ignore:\\s+Pyarrow will become a required dependency of pandas", # Will fix itself
51+
# 2024-09
52+
"ignore:The (non_)?interactive_bk attribute was deprecated in Matplotlib 3.9", # OK - Only happening in debug mode
5153
]
5254

5355
[tool.ruff]

0 commit comments

Comments
 (0)