diff --git a/jdaviz/app.py b/jdaviz/app.py index e06a26924d..2d491e1b78 100644 --- a/jdaviz/app.py +++ b/jdaviz/app.py @@ -139,6 +139,7 @@ def to_unit(self, data, cid, values, original_units, target_units): 'plugin-subset-select': 'components/plugin_subset_select.vue', 'plugin-viewer-select': 'components/plugin_viewer_select.vue', 'plugin-layer-select': 'components/plugin_layer_select.vue', + 'plugin-layer-select-tabs': 'components/plugin_layer_select_tabs.vue', 'plugin-editable-select': 'components/plugin_editable_select.vue', 'plugin-add-results': 'components/plugin_add_results.vue', 'plugin-auto-label': 'components/plugin_auto_label.vue', diff --git a/jdaviz/components/plugin_layer_select_tabs.vue b/jdaviz/components/plugin_layer_select_tabs.vue new file mode 100644 index 0000000000..eb2809862b --- /dev/null +++ b/jdaviz/components/plugin_layer_select_tabs.vue @@ -0,0 +1,20 @@ + + + diff --git a/jdaviz/configs/default/plugins/plot_options/plot_options.py b/jdaviz/configs/default/plugins/plot_options/plot_options.py index 0474113c03..9240dd0394 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'], @@ -929,3 +928,30 @@ 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) diff --git a/jdaviz/configs/default/plugins/plot_options/plot_options.vue b/jdaviz/configs/default/plugins/plot_options/plot_options.vue index 0f9778c8df..14dbbd5822 100644 --- a/jdaviz/configs/default/plugins/plot_options/plot_options.vue +++ b/jdaviz/configs/default/plugins/plot_options/plot_options.vue @@ -93,13 +93,12 @@ Layer options - Layer Visibility diff --git a/jdaviz/core/template_mixin.py b/jdaviz/core/template_mixin.py index e36d2d1951..6289e86703 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