Skip to content

Commit

Permalink
explicit check for hv.dim type
Browse files Browse the repository at this point in the history
  • Loading branch information
droumis committed Jul 22, 2024
1 parent 13c6d45 commit 1fca147
Showing 1 changed file with 14 additions and 15 deletions.
29 changes: 14 additions & 15 deletions holonote/app/panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import datetime as dt
from typing import TYPE_CHECKING, Any

import holoviews as hv
import panel as pn
import param
from packaging.version import Version
Expand Down Expand Up @@ -88,19 +89,17 @@ def _create_visible_widget(self):
style = self.annotator.style
self.colormap = {}
all_options = sorted(set(self.annotator.df[self.annotator.groupby].unique()))
if all_options:
if style.color is None:
self.colormap = dict(zip(all_options, _default_color))
elif isinstance(style.color, str):
self.colormap = dict(zip(all_options, [style.color] * len(all_options)))
else:
self.colormap = self.annotator.style.color.ops[0]["kwargs"]["categories"]
# assign default to any unspecified options
for option in all_options:
if option not in self.colormap:
self.colormap[option] = self.annotator.style.color.ops[0]["kwargs"][
"default"
]
# if all_options:
if style.color is None:
self.colormap = dict(zip(all_options, _default_color))
elif isinstance(style.color, str):
self.colormap = dict(zip(all_options, [style.color] * len(all_options)))
elif isinstance(style.color, hv.dim):
self.colormap = self.annotator.style.color.ops[0]["kwargs"]["categories"]
# assign default to any options whose color is unspecified by the user
for option in all_options:
if option not in self.colormap:
self.colormap[option] = self.annotator.style.color.ops[0]["kwargs"]["default"]

self._update_stylesheet()
options = sorted(self.colormap.keys())
Expand Down Expand Up @@ -149,7 +148,7 @@ def _update_visible_widget(self, event):
self.colormap = dict(zip(new_options, _default_color))
elif isinstance(style.color, str):
self.colormap[new_option] = style.color
else:
elif isinstance(style.color, hv.dim):
self.colormap[new_option] = style.color.ops[0]["kwargs"]["default"]
self._update_stylesheet()
self.visible_widget.stylesheets = [self.stylesheet]
Expand Down Expand Up @@ -178,7 +177,7 @@ def _update_visible_widget(self, event):
self.colormap = dict(zip(new_options, _default_color))
elif isinstance(style.color, str):
self.colormap[new_option] = style.color
else:
elif isinstance(style.color, hv.dim):
# if it's a new annot type but color dim had been specified by the user, it would already
# be in the colormap, so otherwise set the new anno type to the default color
self.colormap[new_option] = style.color.ops[0]["kwargs"]["default"]
Expand Down

0 comments on commit 1fca147

Please sign in to comment.