Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

data-menu: show add data list for empty viewers #3272

Merged
merged 4 commits into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
2 changes: 1 addition & 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
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 @@

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 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 @@
# 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)

Check warning on line 178 in jdaviz/configs/default/plugins/data_menu/data_menu.py

View check run for this annotation

Codecov / codecov/patch

jdaviz/configs/default/plugins/data_menu/data_menu.py#L178

Added line #L178 was not covered by tests
return
with self.during_select_sync():
# map index in dm_layer_selected (inverse order of layer_items)
Expand All @@ -190,7 +185,7 @@
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 @@
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 @@
# 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