Skip to content

Commit

Permalink
Viewer multiselect mixed state working
Browse files Browse the repository at this point in the history
  • Loading branch information
javerbukh committed Nov 14, 2023
1 parent 6483a01 commit 3c31e18
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 27 deletions.
27 changes: 0 additions & 27 deletions jdaviz/configs/default/plugins/plot_options/plot_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -928,30 +928,3 @@ def _viewer_is_image_viewer(self):

return isinstance(self.viewer.selected_obj, (ImvizImageView, CubevizImageView,
MosvizImageView, MosvizProfile2DView))

@observe('line_color_value', 'image_color_value')
def color_change_event(self, event):
# Do not run when Plot Options is being instantiated
if event['old'] is None:
return
layer_names = [x['label'] for x in self.layer_items]

if isinstance(self.layer_selected, list):
layers_select = self.layer_selected
else:
layers_select = [self.layer_selected]
for layer_select in layers_select:
self.layer_items[layer_names.index(layer_select)]['color'] = event['new']
self.send_state('layer_items')

@observe('layer_selected')
def layer_selected_change_event(self, event):
if event is None or event['old'] is None:
return
print("layer", self.layer_items, self.layer.items)

@observe('viewer_selected')
def viewer_selected_change_event(self, event):
if event is None or event['old'] is None:
return
print("viewer", self.layer_items, self.layer.items)
10 changes: 10 additions & 0 deletions jdaviz/core/template_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -1247,6 +1247,8 @@ def __init__(self, plugin, items, selected, viewer,
self.add_observe(viewer, self._on_viewer_changed)
self._on_layers_changed()

self.callbacks_list = []

def _get_viewer(self, viewer):
# newer will likely be the viewer name in most cases, but viewer id in the case
# of additional viewers in imviz.
Expand Down Expand Up @@ -1274,6 +1276,14 @@ def _on_viewer_changed(self, msg=None):
if new != old:
self._clear_cache()
self._on_layers_changed()
added_viewers = list(set(new) - set(old))
removed_viewers = list(set(old) - set(new))
for old_viewer in removed_viewers:
for layer in self._get_viewer(old_viewer).state.layers:
layer.remove_callback('color', self._on_layers_changed)
for new_viewer in added_viewers:
for layer in self._get_viewer(new_viewer).state.layers:
layer.add_callback('color', self._on_layers_changed)

@observe('filters')
def _on_layers_changed(self, msg=None):
Expand Down

0 comments on commit 3c31e18

Please sign in to comment.