holoviz / holonote

Tools to create, edit, and persist annotated regions for HoloViews
https://holonote.holoviz.org
BSD 3-Clause "New" or "Revised" License
23 stars 2 forks source link

Cannot disable visibility of all groups #132

Closed droumis closed 2 months ago

droumis commented 2 months ago

holonote v0.2.1rc0

Software Version Info ```plaintext Python : 3.11.9 | packaged by conda-forge | (main, Apr 19 2024, 18:34:54) [Clang 16.0.6 ] Operating system : macOS-13.5.2-arm64-arm-64bit Panel comms : default holoviews : 1.19.1 bokeh : 3.4.2 colorcet : 3.1.0 cudf : - cupy : - dask : 2024.8.1 dask-expr : 1.1.11 datashader : 0.16.3 geoviews : - hvplot : 0.10.0 ibis-framework : - IPython : 8.26.0 ipywidgets-bokeh : - jupyter-bokeh : - jupyterlab : 4.2.5 matplotlib : 3.9.2 networkx : - notebook : 6.5.7 numba : 0.60.0 numpy : 1.26.4 pandas : 2.2.2 panel : 1.4.5 param : 2.1.1 pillow : 10.4.0 plotly : - pyarrow : 17.0.0 pyviz-comms : 3.0.3 scikit-image : - scipy : 1.14.1 spatialpandas : - streamz : - tsdownsample : 0.1.3 xarray : 2024.7.0 ```

Description of expected behavior and the observed behavior

You cannot disable the visibility of all groups via the visibility widget.

Complete, minimal, self-contained example code that reproduces the issue

import pandas as pd
from holonote.annotate import Annotator 
from holonote.app import PanelWidgets
import panel as pn; pn.extension('tabulator')
import holoviews as hv; hv.extension('bokeh')
from holonote.annotate.connector import SQLiteDB

data = {
    'type': ['A', 'B'],
    'start': range(2),
    'end': [i + .5 for i in range(2)]
}
annotations_df = pd.DataFrame(data)
annotator = Annotator({"x": float,}, fields=["type"],
                      connector=SQLiteDB(filename=':memory:'))
annotator.define_annotations(annotations_df, x=("start", "end"))
annotator.groupby = "type"
annotator_widgets = PanelWidgets(annotator)
pn.Row(annotator_widgets, annotator * hv.Curve([]).opts(xlim=(-1,3))).servable()

Stack traceback and/or browser JavaScript console output

Screenshots or screencasts of the bug in action

https://github.com/user-attachments/assets/ba0c76c5-0075-412a-8595-2e748504d49f

hoxbro commented 2 months ago

Maybe this could be an if statement which needs to distinguish between an empty list and None.

hoxbro commented 2 months ago

Looks like this change will fix the problem:

diff --git a/holonote/annotate/display.py b/holonote/annotate/display.py
index d926843..6494ec4 100644
--- a/holonote/annotate/display.py
+++ b/holonote/annotate/display.py
@@ -537,8 +537,8 @@ class AnnotationDisplay(param.Parameterized):
             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 not self.annotator.visible:
+            return hv.NdOverlay({0: self._make_empty_element()}).opts(show_legend=False)

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