Skip to content

Commit

Permalink
allow separate clear behavior between tables
Browse files Browse the repository at this point in the history
  • Loading branch information
kecnry committed Feb 4, 2025
1 parent 238643b commit 85e2bc6
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 38 deletions.
6 changes: 3 additions & 3 deletions jdaviz/components/plugin_table.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template>
<div class="plugin-table-component">
<div class="plugin-table-component" v-if="show_if_empty || items.length">
<v-row style="margin: 0px 0px -8px 0px !important">
<div class="row-select">
<v-select
Expand Down Expand Up @@ -56,11 +56,11 @@
></v-data-table>
</v-row>

<v-row v-if="clear_table" justify="end">
<v-row v-if="clear_table && items.length" justify="end">
<plugin-action-button
:results_isolated_to_plugin="true"
@click="clear_table"
>Clear Table
>{{ clear_btn_lbl }}
</plugin-action-button>
</v-row>
</div>
Expand Down
58 changes: 30 additions & 28 deletions jdaviz/configs/imviz/plugins/catalogs/catalogs.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,36 @@ def __init__(self, *args, **kwargs):
self.table.item_key = 'id'
self.table.show_rowselect = True

def clear_table_callback():
# gets the current viewer
viewer = self.viewer.selected_obj

# resetting values
self.results_available = False
self.number_of_results = 0

if self._marker_name in self.app.data_collection.labels:
# all markers are removed from the viewer
viewer.remove_markers(marker_name=self._marker_name)

elif self.results_available:
from jdaviz.utils import layer_is_table_data

# markers still there, just hidden
for lyr in viewer.layers:
if layer_is_table_data(lyr.layer) and lyr.layer.label == self._marker_name:
lyr.visible = False

self.table._clear_callback = clear_table_callback

self.table_selected = Table(self, name='table_selected')
self.table_selected.clear_btn_lbl = 'Clear Selection'
self.table_selected.show_if_empty = False

def clear_selected_table_callback():
self.table.select_none()

self.table_selected._clear_callback = clear_selected_table_callback
self.table_selected_widget = 'IPY_MODEL_'+self.table_selected.model_id

self.docs_description = "Queries an area encompassed by the viewer using\
Expand Down Expand Up @@ -362,7 +391,7 @@ def _on_is_active_changed(self, *args):
def _table_selection_changed(self, msg):
selected_rows = self.table.selected_rows

self.table_selected.clear_table()
self.table_selected._clear_table()
for selected_row in selected_rows:
self.table_selected.add_item(selected_row)

Expand Down Expand Up @@ -446,30 +475,3 @@ def import_catalog(self, catalog):
def vue_do_search(self, *args, **kwargs):
# calls self.search() which handles all of the searching logic
self.search()

def clear_table(self, hide_only=True):
# gets the current viewer
viewer = self.viewer.selected_obj

if not hide_only:
super().clear_table()

if not hide_only and self._marker_name in self.app.data_collection.labels:
# resetting values
self.results_available = False
self.number_of_results = 0

# all markers are removed from the viewer
viewer.remove_markers(marker_name=self._marker_name)

elif self.results_available:
from jdaviz.utils import layer_is_table_data

# resetting values
self.results_available = False
self.number_of_results = 0

# markers still there, just hidden
for lyr in viewer.layers:
if layer_is_table_data(lyr.layer) and lyr.layer.label == self._marker_name:
lyr.visible = False
22 changes: 15 additions & 7 deletions jdaviz/core/template_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -4741,11 +4741,16 @@ class Table(PluginSubcomponent):
item_key = Unicode().tag(sync=True) # Unique field to identify row for selection
selected_rows = List().tag(sync=True) # List of selected rows

show_if_empty = Bool(True).tag(sync=True)
clear_btn_lbl = Unicode('Clear Table').tag(sync=True)

def __init__(self, plugin, name='table', selected_rows_changed_callback=None,
clear_callback=None,
*args, **kwargs):
self._qtable = None
self._table_name = name
self._selected_rows_changed_callback = selected_rows_changed_callback
self._clear_callback = clear_callback
super().__init__(plugin, 'Table', *args, **kwargs)

plugin.session.hub.broadcast(PluginTableAddedMessage(sender=self))
Expand Down Expand Up @@ -4860,16 +4865,21 @@ def float_precision(column, item):
def __len__(self):
return len(self.items)

def clear_table(self):
"""
Clear all entries/markers from the current table.
"""
def _clear_table(self):
self.items = []
self.selected_rows = []
self.selected_indices = []
self._qtable = None
self._plugin.session.hub.broadcast(PluginTableModifiedMessage(sender=self))

def clear_table(self):
"""
Clear all entries/markers from the current table.
"""
self._clear_table()
if self._clear_callback is not None:
self._clear_callback()

def select_rows(self, rows):
"""
Select rows from the current table by index, indices, or slice.
Expand Down Expand Up @@ -4910,9 +4920,7 @@ def select_none(self):
self.selected_rows = []

def vue_clear_table(self, data=None):
# if the plugin (or via the TableMixin) has its own clear_table implementation,
# call that, otherwise call the one defined here
getattr(self._plugin, 'clear_table', self.clear_table)()
self.clear_table()

def export_table(self, filename=None, overwrite=False):
"""
Expand Down

0 comments on commit 85e2bc6

Please sign in to comment.