Skip to content
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
15 changes: 11 additions & 4 deletions spikeinterface_gui/probeview.py
Original file line number Diff line number Diff line change
Expand Up @@ -554,33 +554,38 @@ def _panel_refresh(self):
self.y_range.start = zoom_bounds[2]
self.y_range.end = zoom_bounds[3]

# Defer to avoid nested Bokeh callbacks
# pn.state.execute(_do_update, schedule=True)

def _panel_compute_unit_glyph_patches(self):
"""Compute glyph patches without modifying Bokeh models."""
current_alphas = self.glyphs_data_source.data['alpha']
current_sizes = self.glyphs_data_source.data['size']
current_line_colors = self.glyphs_data_source.data['line_color']
current_colors = self.glyphs_data_source.data['color']

alpha_patches = []
size_patches = []
line_color_patches = []
color_patches = []

if self.controller.main_settings['color_mode'] in ('color_by_visibility', 'color_only_visible'):
self.controller.refresh_colors()

for idx, unit_id in enumerate(self.controller.unit_ids):
color = self.get_unit_color(unit_id)
new_color = self.get_unit_color(unit_id)
is_visible = self.controller.get_unit_visibility(unit_id)

new_alpha = self.alpha_selected if is_visible else self.alpha_unselected
new_size = self.unit_marker_size_selected if is_visible else self.unit_marker_size_unselected
new_line_color = "black" if is_visible else color
new_line_color = "black" if is_visible else new_color

if current_alphas[idx] != new_alpha:
alpha_patches.append((idx, new_alpha))
if current_sizes[idx] != new_size:
size_patches.append((idx, new_size))
if current_line_colors[idx] != new_line_color:
line_color_patches.append((idx, new_line_color))
if current_colors[idx] != new_color:
color_patches.append((idx, new_color))

patch_dict = {}
if alpha_patches:
Expand All @@ -589,6 +594,8 @@ def _panel_compute_unit_glyph_patches(self):
patch_dict['size'] = size_patches
if line_color_patches:
patch_dict['line_color'] = line_color_patches
if color_patches:
patch_dict['color'] = color_patches

return patch_dict

Expand Down
22 changes: 13 additions & 9 deletions spikeinterface_gui/unitlistview.py
Original file line number Diff line number Diff line change
Expand Up @@ -682,15 +682,18 @@ def _do_update():
def _panel_refresh_colors(self):
import matplotlib.colors as mcolors

unit_ids_data = []
for unit_id in self.table.value.index.values:
unit_ids_data.append(
{
"id": str(unit_id),
"color": mcolors.to_hex(self.controller.get_unit_color(unit_id))
}
)
self.table.value.loc[:, "unit_id"] = unit_ids_data
if self.controller.main_settings['color_mode'] in ('color_by_visibility', 'color_only_visible'):
self.controller.refresh_colors()
# in this mode the color is dynamic based on visibility, so we need to refresh all colors
unit_ids_data = []
for unit_id in self.table.value.index.values:
unit_ids_data.append(
{
"id": str(unit_id),
"color": mcolors.to_hex(self.controller.get_unit_color(unit_id))
}
)
self.table.value.loc[:, "unit_id"] = unit_ids_data

def _panel_on_unit_color_changed(self):
# here we update the unit colors, since they are then fixed in the table
Expand All @@ -714,6 +717,7 @@ def _panel_on_only_selection(self):
selected_unit = self.table.selection[0]
unit_id = self.table.value.index.values[selected_unit]
self.controller.set_visible_unit_ids([unit_id])
self._panel_refresh_colors()
# update the visible column
df = self.table.value
df.loc[self.controller.unit_ids, "visible"] = self.controller.get_units_visibility_mask()
Expand Down