Skip to content

Commit

Permalink
data-menu: remove/deprecate old data menu (#3281)
Browse files Browse the repository at this point in the history
* replace old data-menu with new data-menu
* fix icon for layers beyond "Z"
* remove tests for old data-menu
* update tests
* docs updates
* support disabling layer multiselect from API
* (temporary) ability to open data-menu from old button
  • Loading branch information
kecnry authored Jan 7, 2025
1 parent 4afb979 commit 19ddfac
Show file tree
Hide file tree
Showing 27 changed files with 152 additions and 833 deletions.
2 changes: 2 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ New Features

- Added API for renaming subsets to Subset Tools plugin. [#3356]

- Viewer data-menus are now found in the legend on the right of the viewer. [#3281]

Cubeviz
^^^^^^^

Expand Down
24 changes: 9 additions & 15 deletions docs/imviz/displayimages.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,18 @@ Right-click will open a dropdown with access to different options for each butto
Selecting a Data Set
====================

Data can be selected and de-selected in each viewer's data menu, opened by clicking the
|icon-viewer-data-select| button in the top left of the viewer. Here, you can click a
checkbox to the left of the listed data to make the data visible (checked) or invisible
(unchecked). The datasets available in each viewer are filtered
Data can be selected and de-selected in each viewer's data menu, opened by clicking on
the legend in the top right of the viewer. Here, all the data and subset layers are listed
and their visibility can be toggled with the "eye" icon on the right.

To add an additional data layer or interactively create a new subset, click the "+" icon in
the top right of the data menu. The datasets available in each viewer are filtered
to include only compatible data, so you may not see all loaded data in the menu for
every viewer. For example, 1D spectra will not be available in the image viewers.

In addition to selecting and de-selecting data to toggle its visibility in the viewer, you
can also unload the data from the viewer completely by clicking the ``X`` to the right of the
data label. Any data that still exists in Imviz but has been unloaded from the viewer
is listed in a separate section that is hidden by default but can can be expanded by clicking
on the section header:

.. image:: img/imviz_removed_data.png

This section can be hidden by clicking the section header again. Unloaded data will be available
to re-load into the viewer (by clicking the ``+`` icon) or remove permanently from the app (by
clicking the trashcan icon).
Clicking on the rows in the data menu selects entries for further actions available in the
bottom bar of the data menu. Here you can modify selected subsets, view metadata or subset
details, or remove layers from either the viewer or the entire application instance.

.. warning::
Deleting the first image that was loaded into Imviz may be slow, as deleting this image
Expand Down
Binary file removed docs/imviz/img/imviz_removed_data.png
Binary file not shown.
17 changes: 7 additions & 10 deletions docs/specviz/displaying.rst
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,16 @@ for each button.
Selecting/Showing Data Sets
===========================

Data can be selected and de-selected in each viewer's data menu, opened by clicking the
|icon-viewer-data-select| button in the top left of the viewer. Here, you can click a
checkbox next to the listed data to make the data visible (checked) or invisible (unchecked).
Data layers can be toggled in each viewer's data menu, opened by clicking the
legend in the top right of the viewer. Here, you can click the "eye" icon
next to the listed data to toggle that layer's visibility.

.. image:: img/data_tab.png

In addition to toggling the visibility of a data layer, the data can be unloaded from a viewer
by clicking the ``X`` button on the right. Data unloaded from the viewer will also be excluded
Data can be unloaded from a viewer by clicking on the data row
and selecting "Remove from viewer" in the delete submenu on the
bottom bar of the data menu. Data unloaded from the viewer will also be excluded
as options from dataset dropdown menus in the various plugins. Unloaded data will be available
to re-load into the viewer (by clicking the ``+`` icon) or remove permanently from the app (by
clicking the trashcan icon) from an expandable section in the data menu:
to re-load into the viewer (by clicking the ``+`` icon in the top right of the data menu).

.. image:: img/specviz_remove_data.png

.. _specviz_cursor_info:

Expand Down
Binary file removed docs/specviz/img/data_tab.png
Binary file not shown.
Binary file removed docs/specviz/img/specviz_remove_data.png
Binary file not shown.
2 changes: 1 addition & 1 deletion docs/specviz2d/displaying.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Displaying Spectra
******************

Specviz2D consists of a 2D spectrum viewer and a 1D spectrum viewer, with linked x-axes. Each
viewer window contains a toolbar, including a data menu.
viewer window contains a toolbar, legend, and data menu.

.. seealso::

Expand Down
64 changes: 3 additions & 61 deletions jdaviz/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,6 @@ def to_unit(self, data, cid, values, original_units, target_units):
custom_components = {'j-tooltip': 'components/tooltip.vue',
'j-external-link': 'components/external_link.vue',
'j-docs-link': 'components/docs_link.vue',
'j-viewer-data-select': 'components/viewer_data_select.vue',
'j-viewer-data-select-item': 'components/viewer_data_select_item.vue',
'j-layer-viewer-icon': 'components/layer_viewer_icon.vue',
'j-layer-viewer-icon-stylized': 'components/layer_viewer_icon_stylized.vue',
'j-tray-plugin': 'components/tray_plugin.vue',
Expand Down Expand Up @@ -446,15 +444,13 @@ def _update_live_plugin_results(self, trigger_data_lbl=None, trigger_subset=None
self.hub.broadcast(SnackbarMessage(
f"Auto-update for {plugin_inputs['add_results']['label']} failed: {e}",
sender=self, color="error"))
# TODO: should we delete the entry (but then any plot options, etc, are lost)
# self.vue_data_item_remove({'item_name': data.label})

def _remove_live_plugin_results(self, trigger_data_lbl=None, trigger_subset=None):
for data, plugin_inputs in self._iter_live_plugin_results(trigger_data_lbl, trigger_subset):
self.hub.broadcast(SnackbarMessage(
f"Removing {data.label} due to deletion of {trigger_subset.label if trigger_subset is not None else trigger_data_lbl}", # noqa
sender=self, color="warning"))
self.vue_data_item_remove({'item_name': data.label})
self.data_item_remove(data.label)

def _on_add_data_message(self, msg):
self._on_layers_changed(msg)
Expand Down Expand Up @@ -1702,12 +1698,6 @@ def remove_data_from_viewer(self, viewer_reference, data_label):
sender=self)
self.hub.broadcast(remove_data_message)

# update data menu entry
selected_items = viewer_item['selected_data_items']
data_id = self._data_id_from_label(data_label)
if data_id in selected_items:
_ = selected_items.pop(data_id)

def _data_id_from_label(self, label):
"""
Retrieve the data item given the Glue ``DataCollection`` data label.
Expand Down Expand Up @@ -2267,19 +2257,6 @@ def remove(stack_items):

self.hub.broadcast(ViewerRemovedMessage(cid, sender=self))

def vue_data_item_unload(self, event):
"""
Callback for selection events in the front-end data list when clicking to unload an entry
from the viewer.
"""
data_label = self._get_data_item_by_id(event['item_id'])['name']
self.remove_data_from_viewer(event['id'], data_label)

def vue_data_item_visibility(self, event):
self.set_data_visibility(event['id'],
self._get_data_item_by_id(event['item_id'])['name'],
visible=event['visible'], replace=event.get('replace', False))

def vue_change_reference_data(self, event):
self._change_reference_data(
self._get_data_item_by_id(event['item_id'])['name'],
Expand Down Expand Up @@ -2367,7 +2344,7 @@ def set_data_visibility(self, viewer_reference, data_label, visible=True, replac
# if Data has children, update their visibilities to match Data:
available_plugins = [tray_item['name'] for tray_item in self.state.tray_items]
for child in assoc_children:
if child not in viewer.data_labels_loaded:
if child not in viewer.data_menu.data_labels_loaded:
self.add_data_to_viewer(viewer.reference, child, visible=visible)

if 'g-data-quality' in available_plugins and visible:
Expand All @@ -2389,29 +2366,6 @@ def set_data_visibility(self, viewer_reference, data_label, visible=True, replac
else:
layer.visible = visible

# update data menu - selected_data_items should be READ ONLY, not modified by the user/UI.
# must update the visibility of `data_label` and its children:
selected_items = viewer_item['selected_data_items']
update_data_labels = [data_label] + assoc_children
for update_data_label in update_data_labels:
data_id = self._data_id_from_label(update_data_label)

if replace and update_data_label == data_label:
for id in selected_items:
if id != data_id:
selected_items[id] = 'hidden'

selected_items[data_id] = 'visible' if visible else 'hidden'

# remove WCS-only data from selected items, add to wcs_only_layers:
for layer in viewer.layers:
layer_is_wcs_only = getattr(layer.layer, 'meta', {}).get(_wcs_only_label, False)
if layer.layer.data.label == data_label and layer_is_wcs_only:
layer.visible = False
if data_label not in viewer.state.wcs_only_layers:
viewer.state.wcs_only_layers.append(data_label)
selected_items.pop(data_id)

# Sets the plot axes labels to be the units of the most recently
# active data.
viewer_data_labels = [layer.layer.label for layer in viewer.layers]
Expand All @@ -2421,9 +2375,7 @@ def set_data_visibility(self, viewer_reference, data_label, visible=True, replac
if self.config == 'imviz':
viewer.on_limits_change() # Trigger compass redraw

def vue_data_item_remove(self, event):

data_label = event['item_name']
def data_item_remove(self, data_label):
data = self.data_collection[data_label]
orientation_plugin = self._jdaviz_helper.plugins.get("Orientation")
if orientation_plugin is not None and orientation_plugin.align_by == "WCS":
Expand Down Expand Up @@ -2672,8 +2624,6 @@ def _create_viewer_item(self, viewer, vid=None, name=None, reference=None,
sender=self)
)

wcs_only_layers = getattr(viewer.state, 'wcs_only_layers', [])

reference_data = getattr(viewer.state, 'reference_data', None)
reference_data_label = getattr(reference_data, 'label', None)
linked_by_wcs = getattr(viewer.state, 'linked_by_wcs', False)
Expand All @@ -2684,17 +2634,13 @@ def _create_viewer_item(self, viewer, vid=None, name=None, reference=None,
'widget': "IPY_MODEL_" + viewer.figure_widget.model_id,
'toolbar': "IPY_MODEL_" + viewer.toolbar.model_id if viewer.toolbar else '', # noqa
'data_menu': 'IPY_MODEL_' + viewer._data_menu.model_id if hasattr(viewer, '_data_menu') else '', # noqa
# TODO: remove unused entries after old data menu deprecation period
'selected_data_items': {}, # noqa data_id: visibility state (visible, hidden, mixed), READ-ONLY
'wcs_only_layers': wcs_only_layers,
'reference_data_label': reference_data_label,
'canvas_angle': 0, # canvas rotation clockwise rotation angle in deg
'canvas_flip_horizontal': False, # canvas rotation horizontal flip
'config': self.config, # give viewer access to app config/layout
'collapse': True,
'reference': reference or name or vid,
'linked_by_wcs': linked_by_wcs,
'open_data_menu_if_empty': open_data_menu_if_empty # noqa open menu on init if viewer is empty
}

def _on_new_viewer(self, msg, vid=None, name=None, add_layers_to_viewer=False,
Expand Down Expand Up @@ -2748,10 +2694,6 @@ def _on_new_viewer(self, msg, vid=None, name=None, add_layers_to_viewer=False,
linked_by_wcs = False
viewer.state.linked_by_wcs = linked_by_wcs

if linked_by_wcs:
from jdaviz.configs.imviz.helper import get_wcs_only_layer_labels
viewer.state.wcs_only_layers = get_wcs_only_layer_labels(self)

if msg.x_attr is not None:
x = msg.data.id[msg.x_attr]
viewer.state.x_att = x
Expand Down
7 changes: 1 addition & 6 deletions jdaviz/components/plugin_dataset_select.vue
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,7 @@
<script>
module.exports = {
props: ['items', 'selected', 'label', 'hint', 'rules', 'show_if_single_entry', 'multiselect',
'api_hint', 'api_hints_enabled'],
methods: {
isWCSOnlyLayer(item) {
const wcsOnly = Object.keys(this.$props.viewer.wcs_only_layers).includes(item.name)
return wcsOnly
},
'api_hint', 'api_hints_enabled']
}
};
</script>
Expand Down
9 changes: 0 additions & 9 deletions jdaviz/components/tooltip.vue
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,6 @@ const tooltips = {
'viewer-toolbar-figure-save': 'Save figure',
'viewer-toolbar-menu': 'Adjust display: contrast, bias, stretch',
'viewer-toolbar-more': 'More options...',
'viewer-data-select-enabled': 'Allow multiple entries (click to enable replace)',
'viewer-data-radio-enabled': 'Replace current entry (click to enable multi-select)',
'viewer-data-select': 'Toggle visibility of all layers associated with this data entry',
'viewer-data-radio': 'Switch visibility to layers associated with this data entry',
'viewer-data-enable': 'Load data entry into this viewer',
'viewer-data-disable': 'Disable data within this viewer (will be hidden and unavailable from plugins until re-enabled)',
'viewer-wcs-delete': 'Remove orientation option across entire app',
'viewer-data-delete': 'Remove data entry across entire app (might affect existing subsets)',
'viewer-data-nowcs': 'Data does not have WCS, cannot add unless link type changed to pixel',
'table-prev': 'Select previous row in table',
'table-next': 'Select next row in table',
Expand Down
Loading

0 comments on commit 19ddfac

Please sign in to comment.