Skip to content

Commit

Permalink
Merge branch 'delete3' of https://github.com/duytnguyendtn/jdaviz int…
Browse files Browse the repository at this point in the history
…o duytnguyendtn-delete3
  • Loading branch information
rosteen committed Aug 30, 2023
2 parents 9ff42f6 + 0215be7 commit a09830e
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 16 deletions.
3 changes: 3 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,9 @@ New Features

- Support for Scatter plots/markers in plot options. [#2193]

- Allow user-loaded data to be removed from the app (in specviz and imviz)
so long as it is not the only user-loaded data [#2211]

Cubeviz
^^^^^^^

Expand Down
4 changes: 4 additions & 0 deletions jdaviz/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -1968,6 +1968,10 @@ def set_data_visibility(self, viewer_reference, data_label, visible=True, replac
viewer.on_limits_change() # Trigger compass redraw

def vue_data_item_remove(self, event):
# Hack for disappearing subsets. Temporarily add the data back to the viewer to
# transfer ownership of subsets
self.add_data_to_viewer(event['viewer_id'], event['item_name'])

self.data_collection.remove(self.data_collection[event['item_name']])

def vue_close_snackbar_message(self, event):
Expand Down
2 changes: 1 addition & 1 deletion jdaviz/components/tooltip.vue
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ const tooltips = {
'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-data-delete': 'Remove data entry across entire app',
'viewer-data-delete': 'Remove data entry across entire app (might affect existing subsets)',
'table-prev': 'Select previous row in table',
'table-next': 'Select next row in table',
Expand Down
6 changes: 6 additions & 0 deletions jdaviz/components/viewer_data_select.vue
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
:icon="layer_icons[item.name]"
:viewer="viewer"
:multi_select="multi_select"
:n_data_entries="nDataEntries"
@data-item-visibility="$emit('data-item-visibility', $event)"
@data-item-unload="$emit('data-item-unload', $event)"
@data-item-remove="$emit('data-item-remove', $event)"
Expand Down Expand Up @@ -79,6 +80,7 @@
:icon="layer_icons[item.name]"
:viewer="viewer"
:multi_select="multi_select"
:n_data_entries="nDataEntries"
@data-item-visibility="$emit('data-item-visibility', $event)"
@data-item-remove="$emit('data-item-remove', $event)"
></j-viewer-data-select-item>
Expand Down Expand Up @@ -216,6 +218,10 @@ module.exports = {
extraDataItems() {
return this.$props.data_items.filter((item) => this.itemIsVisible(item, true))
},
nDataEntries() {
// return number of data entries in the entire plugin that were NOT created by a plugin
return this.$props.data_items.filter((item) => item.meta.Plugin === undefined).length
},
}
};
</script>
27 changes: 13 additions & 14 deletions jdaviz/components/viewer_data_select_item.vue
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
<j-tooltip tipid='viewer-data-delete'>
<v-btn
icon
@click="$emit('data-item-remove', {item_name: item.name})"
@click="$emit('data-item-remove', {item_name: item.name, viewer_id: viewer.id})"
><v-icon>mdi-delete</v-icon></v-btn>
</j-tooltip>
</div>
Expand All @@ -60,7 +60,7 @@
<script>
module.exports = {
props: ['item', 'icon', 'multi_select', 'viewer'],
props: ['item', 'icon', 'multi_select', 'viewer', 'n_data_entries'],
methods: {
selectClicked() {
prevVisibleState = this.visibleState
Expand Down Expand Up @@ -114,14 +114,15 @@ module.exports = {
// forbid unloading the original reference cube
// this logic might need to be generalized if supporting custom data labels
// per-cube or renaming data labels
const extension = this.itemNameExtension
if (this.$props.viewer.reference === 'flux-viewer') {
return this.$props.item.name.indexOf('[FLUX]') === -1
return ['SCI', 'FLUX'].indexOf(extension) !== -1
} else if (this.$props.viewer.reference === 'uncert-viewer') {
return this.$props.item.name.indexOf('[IVAR]') === -1
return ['IVAR', 'ERR'].indexOf(extension) !== -1
} else if (this.$props.viewer.reference === 'mask-viewer') {
return this.$props.item.name.indexOf('[MASK]') === -1
return ['MASK', 'DQ'].indexOf(extension) !== -1
} else if (this.$props.viewer.reference === 'spectrum-viewer') {
return this.$props.item.name.indexOf('[FLUX]') === -1
return ['SCI', 'FLUX'].indexOf(extension) !== -1
}
} else if (this.$props.viewer.config === 'specviz2d') {
if (this.$props.viewer.reference === 'spectrum-2d-viewer') {
Expand All @@ -133,14 +134,12 @@ module.exports = {
return true
},
isDeletable() {
// only allow deleting products from plugins. We might want to allow some non-plugin
// data to also be deleted in the future, but would probably need more advanced logic
// to ensure essential data isn't removed that would break the app.
if (this.$props.item.meta.Plugin === undefined) {
return false
}
// for any exceptions not above, enable deleting
return !this.isSelected
isLastDataset = (this.$props.n_data_entries <= 1)
notSelected = !this.isSelected
isMosviz = this.$props.viewer.config === 'mosviz'
isCubeviz = this.$props.viewer.config === 'cubeviz'
isPluginData = !(this.$props.item.meta.Plugin === undefined)
return notSelected && (isPluginData || (!isLastDataset && !isMosviz && !isCubeviz))
},
selectTipId() {
if (this.multi_select) {
Expand Down
3 changes: 2 additions & 1 deletion jdaviz/configs/cubeviz/plugins/tests/test_data_selection.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ def test_data_selection(cubeviz_helper, spectrum1d_cube, tmpdir):
assert len(fv.layers) == 2
assert len([layer for layer in fv.layers if layer.visible]) == 2

app.vue_data_item_remove({'item_name': app.state.data_items[1]['name']})
app.vue_data_item_remove({'item_name': app.state.data_items[1]['name'],
'viewer_id': 'cubeviz-0'})

assert len(fv.layers) == 1

0 comments on commit a09830e

Please sign in to comment.