From ddeb60c4fe68acef131dcde4257397f4d96b3b94 Mon Sep 17 00:00:00 2001 From: Jesse Averbukh Date: Mon, 13 Nov 2023 15:21:54 -0500 Subject: [PATCH] Move logic to LayerSelect --- .../components/plugin_layer_select_tabs.vue | 7 +++- .../plugins/plot_options/plot_options.py | 37 ++++++++++--------- jdaviz/core/template_mixin.py | 29 +++++++++++++-- 3 files changed, 49 insertions(+), 24 deletions(-) diff --git a/jdaviz/components/plugin_layer_select_tabs.vue b/jdaviz/components/plugin_layer_select_tabs.vue index 90bfb269df..eb2809862b 100644 --- a/jdaviz/components/plugin_layer_select_tabs.vue +++ b/jdaviz/components/plugin_layer_select_tabs.vue @@ -2,16 +2,19 @@
- {{ item.icon }} + {{ item.icon }} + + {{ selected }} +
diff --git a/jdaviz/configs/default/plugins/plot_options/plot_options.py b/jdaviz/configs/default/plugins/plot_options/plot_options.py index 0707a5676b..7b7674c25c 100644 --- a/jdaviz/configs/default/plugins/plot_options/plot_options.py +++ b/jdaviz/configs/default/plugins/plot_options/plot_options.py @@ -330,7 +330,6 @@ def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.viewer = ViewerSelect(self, 'viewer_items', 'viewer_selected', 'multiselect') self.layer = LayerSelect(self, 'layer_items', 'layer_selected', 'viewer_selected', 'multiselect') # noqa - self.swatches_palette = [ ['#FF0000', '#AA0000', '#550000'], ['#FFD300', '#AAAA00', '#555500'], @@ -880,24 +879,26 @@ def _viewer_is_image_viewer(self): @observe('line_color_value', 'image_color_value') def color_change_event(self, event): # Do not run when Plot Options is being instantiated - if not event['old']: + if event['old'] is None: return - # self.layer_items_tabs = self.layer_items - print(event['name'], event['old'], event['new']) - print(event['owner'].layer_items) - print(event.keys()) - print(self.layer_items) - print(self.layer_selected) layer_names = [x['label'] for x in self.layer_items] - print('BEFORE IF') - if len(layer_names) > 0 and self.layer_selected in layer_names: - print("1") - # if hasattr(self.layer_items[layer_names.index(self.layer_selected)], 'image_color_value'): - print(layer_names, self.layer_selected, layer_names.index(self.layer_selected), - layer_names.index(self.layer_selected)) - print(self.layer_items[layer_names.index(self.layer_selected)]['color']) - self.layer_items[layer_names.index(self.layer_selected)]['color'] = event['new'] - print(self.layer_items[layer_names.index(self.layer_selected)]['color']) - self.send_state('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) diff --git a/jdaviz/core/template_mixin.py b/jdaviz/core/template_mixin.py index 0ebc5e67af..9e5ebe46bb 100644 --- a/jdaviz/core/template_mixin.py +++ b/jdaviz/core/template_mixin.py @@ -1255,10 +1255,12 @@ def _get_viewer(self, viewer): except TypeError: return self.app.get_viewer_by_id(viewer) - def _layer_to_dict(self, layer): + def _layer_to_dict(self, layer, label_to_color=None, label_mixed_color=None): d = {"label": layer.layer.label, "color": layer.state.color, - "icon": self.app.state.layer_icons.get(layer.layer.label)} + "icon": self.app.state.layer_icons.get(layer.layer.label), + "visible": layer.state.bitmap_visible, + "mixed_color": False if not label_mixed_color else label_mixed_color[layer.layer.label]} return d def _on_viewer_changed(self, msg=None): @@ -1287,10 +1289,29 @@ def _on_layers_changed(self, msg=None): # same name in different viewers will be randomly assigned within plot_options # based on which was found _first. layer_labels = [layer.layer.label for layer in layers] + print("LayerSelect", layer_labels) + print("unique return", np.unique(layer_labels, return_index=True)) _, inds = np.unique(layer_labels, return_index=True) - layers = [layers[i] for i in inds] + layers_unique = [layers[i] for i in inds] + label_to_color = {} + label_mixed_color = {} + for layer in layers: + label = layer.layer.label + color = layer.state.color + # label_to_color tracks all colors per layer label + if label not in label_to_color: + label_to_color[label] = [color] + label_mixed_color[label] = False + else: + # If the color is not yet present, then layers + # with this label have mixed color + if color not in label_to_color[label]: + label_mixed_color[label] = True + label_to_color[label] += [color] + + self.items = manual_items + [self._layer_to_dict(layer, label_to_color, label_mixed_color) + for layer in layers_unique] - self.items = manual_items + [self._layer_to_dict(layer) for layer in layers] self._apply_default_selection() @cached_property