Skip to content

Commit

Permalink
data-menu: show add data list for empty viewers (spacetelescope#3272)
Browse files Browse the repository at this point in the history
* show list of data to add for empty viewer rather than opening data menu
* improved menu hints to find load data button
* clear viewer icon when viewer is deleted ensures that callbacks to icons being updated will be retriggered when/if viewer recreated
  • Loading branch information
kecnry authored Nov 13, 2024
1 parent 4a43a8c commit 01553da
Show file tree
Hide file tree
Showing 7 changed files with 238 additions and 186 deletions.
2 changes: 1 addition & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
New Features
------------

* New design for viewer legend. [#3220, #3254, #3263, #3264]
* New design for viewer legend. [#3220, #3254, #3263, #3264, #3272]

Cubeviz
^^^^^^^
Expand Down
6 changes: 5 additions & 1 deletion jdaviz/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ def to_unit(self, data, cid, values, original_units, target_units):
'plugin-color-picker': 'components/plugin_color_picker.vue',
'plugin-input-header': 'components/plugin_input_header.vue',
'glue-state-sync-wrapper': 'components/glue_state_sync_wrapper.vue',
'data-menu-add-data': 'components/data_menu_add_data.vue',
'data-menu-add': 'components/data_menu_add.vue',
'data-menu-remove': 'components/data_menu_remove.vue',
'data-menu-subset-edit': 'components/data_menu_subset_edit.vue'}

Expand Down Expand Up @@ -2134,6 +2134,10 @@ def remove(stack_items):
if cid in self._viewer_store:
del self._viewer_store[cid]

# clear from the viewer icons dictionary
if cid in self.state.viewer_icons:
del self.state.viewer_icons[cid]

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

def vue_data_item_unload(self, event):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@
>
<v-btn
icon
:class="loaded_n_data > 0 ? 'invert-if-dark' : 'invert-if-dark pulse'"
v-bind="attrs"
v-on="on"
>
<v-icon class="invert-if-dark">mdi-plus</v-icon>
<v-icon>mdi-plus</v-icon>
</v-btn>
</j-tooltip>
</template>
Expand Down Expand Up @@ -61,6 +62,6 @@

<script>
module.exports = {
props: ['dataset_items', 'subset_tools'],
props: ['dataset_items', 'subset_tools', 'loaded_n_data'],
};
</script>
2 changes: 1 addition & 1 deletion jdaviz/components/viewer_data_select.vue
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ module.exports = {
return {
// default to passed values, whenever value or uncertainty are changed
// updateTruncatedValues will overwrite the displayed values
data_menu_open: this.$props.viewer.open_data_menu_if_empty && Object.keys(this.$props.viewer.selected_data_items).length == 0 && this.$props.data_items.length > 0,
data_menu_open: false,
multi_select: multi_select,
showExtraItems: Object.keys(this.$props.viewer.selected_data_items).length == 0,
valueTrunc: this.value,
Expand Down
22 changes: 11 additions & 11 deletions jdaviz/configs/default/plugins/data_menu/data_menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ class DataMenu(TemplateMixin, LayerSelectMixin, DatasetSelectMixin):

dm_layer_selected = List().tag(sync=True)

loaded_n_data = Integer(0).tag(sync=True)
selected_n_layers = Integer(0).tag(sync=True)
selected_n_data = Integer(0).tag(sync=True)
selected_n_subsets = Integer(0).tag(sync=True)
Expand Down Expand Up @@ -135,12 +136,6 @@ def user_api(self):
def existing_subset_labels(self):
return [sg.label for sg in self.app.data_collection.subset_groups]

@observe('layer_items')
def _update_data_not_in_viewer(self, msg):
# changing the layers in the viewer needs to trigger an update to dataset_items
# through the set filters
self.dataset._on_data_changed()

def _set_viewer_id(self):
# viewer_ids are not populated on the viewer at init, so we'll keep checking and set
# these the first time that they are available
Expand Down Expand Up @@ -180,7 +175,7 @@ def _dm_layer_selected_changed(self, event={}):
# not possible from UI interaction, but instead caused by a selected
# layer being removed (deleting a selected subset, etc). We want
# to update dm_layer_selected in order to preserve layer.selected
self._update_dm_layer_selected(event)
self._layers_changed(event)
return
with self.during_select_sync():
# map index in dm_layer_selected (inverse order of layer_items)
Expand All @@ -190,7 +185,7 @@ def _dm_layer_selected_changed(self, event={}):
for i in self.dm_layer_selected]

@observe('layer_selected', 'layer_items')
def _update_dm_layer_selected(self, event={}):
def _layers_changed(self, event={}):
if not hasattr(self, 'layer') or not self.layer.multiselect: # pragma: no cover
return
if not self._during_select_sync:
Expand All @@ -200,13 +195,18 @@ def _update_dm_layer_selected(self, event={}):
self.dm_layer_selected = [layer_labels.index(label) for label in self.layer.selected
if label in layer_labels]

subset_labels = self.existing_subset_labels

if event.get('name') == 'layer_items':
# don't need to make the updates below unless the selection has been changed
# changing the layers in the viewer needs to trigger an update to dataset_items
# through the set filters
self.dataset._on_data_changed()
self.loaded_n_data = len([lyr for lyr in self.layer.choices
if lyr not in subset_labels])
return

# update internal counts and tooltips
self.selected_n_layers = len(self.layer.selected)
subset_labels = self.existing_subset_labels
self.selected_n_subsets = len([lyr for lyr in self.layer.selected if lyr in subset_labels])
self.selected_n_data = self.selected_n_layers - self.selected_n_subsets

Expand All @@ -229,7 +229,7 @@ def _update_dm_layer_selected(self, event={}):
# with an update
self.info_enabled = False
self.info_tooltip = ''
if self.layer_items[self.dm_layer_selected[0]].get('from_plugin', False):
elif self.layer_items[self.dm_layer_selected[0]].get('from_plugin', False):
self.info_enabled = False
self.info_tooltip = 'Selected data layer is a plugin product and does not have metadata' # noqa
else:
Expand Down
Loading

0 comments on commit 01553da

Please sign in to comment.