Skip to content

Commit

Permalink
sort data-menu by z-order
Browse files Browse the repository at this point in the history
  • Loading branch information
kecnry committed Nov 15, 2024
1 parent 9443cfa commit 99dcebb
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
6 changes: 3 additions & 3 deletions jdaviz/configs/default/plugins/data_menu/data_menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ def __init__(self, viewer, *args, **kwargs):
self.layer.remove_filter('filter_is_root')
self.layer.add_filter(is_not_wcs_only)
self.layer.multiselect = True
self.layer.sort_by = 'zorder'
self.layer._default_mode = 'empty'

# we'll use a modified version of the dataset mixin to have a filtered
Expand Down Expand Up @@ -218,8 +219,7 @@ def _dm_layer_selected_changed(self, event={}):
with self.during_select_sync():
# map index in dm_layer_selected (inverse order of layer_items)
# to set self.layer.selected
length = len(self.layer_items)
self.layer.selected = [self.layer_items[length-1-i]['label']
self.layer.selected = [self.layer_items[i]['label']
for i in self.dm_layer_selected]

@observe('layer_selected', 'layer_items')
Expand All @@ -229,7 +229,7 @@ def _layers_changed(self, event={}):
if not self._during_select_sync:
with self.during_select_sync():
# map list of strings in self.layer.selected to indices in dm_layer_selected
layer_labels = [layer['label'] for layer in self.layer_items][::-1]
layer_labels = [layer['label'] for layer in self.layer_items]
self.dm_layer_selected = [layer_labels.index(label) for label in self.layer.selected
if label in layer_labels]

Expand Down
4 changes: 2 additions & 2 deletions jdaviz/configs/default/plugins/data_menu/data_menu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
<span class="invert-if-dark" style="margin-left: 30px; margin-right: 36px; line-height: 28px">{{viewer_reference || viewer_id}}</span>
</div>

<div v-for="item in layer_items.slice().reverse()" class="viewer-label">
<div v-for="item in layer_items" class="viewer-label">
<div v-if="item.visible">
<span style="float: right">
<j-layer-viewer-icon-stylized
Expand Down Expand Up @@ -142,7 +142,7 @@
dense
>
<div>
<v-list-item v-for="item in layer_items.slice().reverse()">
<v-list-item v-for="item in layer_items">
<v-list-item-icon>
<j-layer-viewer-icon-stylized
:label="item.label"
Expand Down
10 changes: 5 additions & 5 deletions jdaviz/configs/default/tests/test_data_menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,15 +128,15 @@ def test_data_menu_remove_subset(specviz_helper, spectrum1d):
6100 * spectrum1d.spectral_axis.unit),
combination_mode='new')

assert dm.layer.choices == ['test', 'test2', 'Subset 1', 'Subset 2']
assert dm.layer.choices == ['Subset 2', 'Subset 1', 'test2', 'test']
dm.layer.selected = ['Subset 1']
dm.remove_from_viewer()

# subset visibility is set to false, but still appears in menu (unlike removing data)
assert dm.layer.choices == ['test', 'test2', 'Subset 1', 'Subset 2']
assert dm._obj.layer_items[2]['label'] == 'Subset 1'
assert dm.layer.choices == ['Subset 2', 'Subset 1', 'test2', 'test']
assert dm._obj.layer_items[1]['label'] == 'Subset 1'
# TODO: sometimes appearing as mixed right now, known bug
assert dm._obj.layer_items[2]['visible'] is not True
assert dm._obj.layer_items[1]['visible'] is not True

# selection should not have changed by removing subset from viewer
assert dm.layer.selected == ['Subset 1']
Expand Down Expand Up @@ -178,7 +178,7 @@ def test_data_menu_view_info(specviz_helper, spectrum1d):
6300 * spectrum1d.spectral_axis.unit),
combination_mode='new')

assert dm.layer.choices == ['test', 'test2', 'Subset 1', 'Subset 2']
assert dm.layer.choices == ['Subset 2', 'Subset 1', 'test2', 'test']

dm.layer.selected = ["test2"]
dm.view_info()
Expand Down

0 comments on commit 99dcebb

Please sign in to comment.