Skip to content

Commit

Permalink
Add get_display
Browse files Browse the repository at this point in the history
  • Loading branch information
hoxbro committed Oct 24, 2023
1 parent e50a8ba commit 33ca984
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions holonote/annotate/annotator.py
Original file line number Diff line number Diff line change
Expand Up @@ -690,7 +690,7 @@ def __init__(self, spec: dict, **params):
The spec argument must be an element or a dictionary of kdim dtypes
"""

self._elements = {}
self._displays = {}

super().__init__(
spec if isinstance(spec, dict) else self._infer_kdim_dtypes(spec),
Expand All @@ -712,28 +712,31 @@ def _create_annotation_element(self, element_key: tuple[str, ...]) -> Annotation
raise ValueError(msg)
return AnnotationDisplay(self, kdims=list(element_key))

def get_element(self, kdims: tuple[str, ...] | str) -> AnnotationDisplay:
element_key = (kdims,) if isinstance(kdims, str) else tuple(map(str, kdims))
if element_key not in self._elements:
self._elements[element_key] = self._create_annotation_element(element_key)
return self._elements[element_key]
def get_element(self, *kdims: str | hv.Dimension) -> hv.DynamicMap:
return self.get_display(*kdims).element

def get_display(self, *kdims: str | hv.Dimension) -> AnnotationDisplay:
element_key = tuple(map(str, kdims))
if element_key not in self._displays:
self._displays[element_key] = self._create_annotation_element(element_key)
return self._displays[element_key]

def __mul__(self, other: hv.Element) -> hv.Overlay:
return other * self.get_element(other.kdims).element
return other * self.get_element(*other.kdims)

def __rmul__(self, other: hv.Element) -> hv.Overlay:
return self.__mul__(other)

def refresh(self, clear=False) -> None:
for v in self._elements.values():
for v in self._displays.values():
hv.streams.Stream.trigger([v._annotation_count_stream])
if clear:
v.clear_indicated_region()
v.show_region()

def set_annotation_table(self, annotation_table):
self.select_by_index()
for v in self._elements.values():
for v in self._displays.values():
v.select_by_index()
self.clear_regions()
super().set_annotation_table(annotation_table)
Expand Down Expand Up @@ -770,7 +773,7 @@ def delete_annotations(self, *indices):
def select_by_index(self, *inds):
"Set the selection state by the indices i.e. primary key values"

for v in self._elements.values():
for v in self._displays.values():
if not v.selection_enabled:
inds = ()

Expand Down Expand Up @@ -799,7 +802,7 @@ def selection_enabled(self) -> bool:

@selection_enabled.setter
def selection_enabled(self, enabled: bool) -> None:
for v in self._elements.values():
for v in self._displays.values():
v.selection_enabled = enabled

if not enabled:
Expand All @@ -811,5 +814,5 @@ def editable_enabled(self) -> bool:

@editable_enabled.setter
def editable_enabled(self, enabled: bool) -> None:
for v in self._elements.values():
for v in self._displays.values():
v.editable_enabled = enabled

0 comments on commit 33ca984

Please sign in to comment.