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

Don't show all elements if nothing is selected by visibile #133

Merged
merged 6 commits into from
Sep 13, 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
2 changes: 1 addition & 1 deletion holonote/annotate/annotator.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ class Annotator(AnnotatorInterface):

groupby = param.Selector(default=None, doc="Groupby dimension", allow_refs=True)
visible = param.ListSelector(
default=[], doc="Visible dimensions, needs groupby enabled", allow_refs=True
default=None, doc="Visible dimensions, needs groupby enabled", allow_refs=True
)
style = param.ClassSelector(default=Style(), class_=Style, doc="Style parameters")

Expand Down
10 changes: 8 additions & 2 deletions holonote/annotate/display.py
Original file line number Diff line number Diff line change
Expand Up @@ -537,8 +537,14 @@ def static_indicators(self, **events):
msg = f"{self.region_format} not implemented"
raise NotImplementedError(msg)

if len(indicator.data) == 0:
return hv.NdOverlay({0: self._make_empty_element()})
if len(indicator.data) == 0 or (
self.annotator.groupby
and self.annotator.visible is not None
and not len(self.annotator.visible)
):
el = self._make_empty_element()
el_opts = getattr(hv.opts, type(el).__name__)(**_default_opts)
return hv.NdOverlay({0: el}).opts(el_opts)

if self.annotator.groupby and self.annotator.visible:
indicator = indicator.get(self.annotator.visible)
Expand Down
12 changes: 10 additions & 2 deletions holonote/tests/test_annotators_element.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def test_set_regions_range1d(annotator_range1d) -> None:
expected = [None, None]
assert output == expected

output = next(get_indicator_data(annotator, hv.Rectangles))
output = next(get_indicator_data(annotator, hv.VSpans))
output1 = output.iloc[0][["start[TIME]", "end[TIME]"]].tolist()
expected1 = [-0.25, 0.25]
assert output1 == expected1
Expand Down Expand Up @@ -115,7 +115,7 @@ def test_set_regions_multiple(multiple_annotators):
expected = [None, None]
assert output == expected

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


def test_groupby_visible_empty(cat_annotator):
cat_annotator.groupby = "category"
cat_annotator.visible = []
iter_indicator = get_indicator(cat_annotator, hv.Curve)
indicator = next(iter_indicator)
assert indicator.data.shape == (0, 2)


def test_groupby_with_overlay_from_empty_annotator(annotator_range2d, capsys):
# Test for https://github.com/holoviz/holonote/issues/119
annotator = annotator_range2d
Expand Down
2 changes: 1 addition & 1 deletion holonote/tests/test_annotators_style.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def compare_style(cat_annotator):


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


Expand Down
5 changes: 4 additions & 1 deletion holonote/tests/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ def get_editor_data(annotator, element_type, kdims=None):

def get_indicator(annotator, element_type, kdims=None):
si = _get_display(annotator, kdims).indicators().last
yield from si.data.values()
if element_type:
yield from (s for s in si.data.values() if isinstance(s, element_type))
else:
yield from si.data.values()


def get_indicator_data(annotator, element_type, kdims=None):
Expand Down
2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ filterwarnings = [
"ignore:datetime.datetime.utcfromtimestamp():DeprecationWarning:dateutil.tz.tz", # https://github.com/dateutil/dateutil/pull/1285
# 2024-01
"ignore:\\s+Pyarrow will become a required dependency of pandas", # Will fix itself
# 2024-09
"ignore:The (non_)?interactive_bk attribute was deprecated in Matplotlib 3.9", # OK - Only happening in debug mode
]

[tool.ruff]
Expand Down