From a34ebc82ebddccc68996043b1477e56cf57706f0 Mon Sep 17 00:00:00 2001 From: Kyle Conroy Date: Wed, 13 Sep 2023 13:27:03 -0400 Subject: [PATCH 01/24] POC: plugin API hints demo --- jdaviz/components/plugin_add_results.vue | 17 +++++++++++++---- jdaviz/components/plugin_dataset_select.vue | 11 +++++++++-- jdaviz/components/tray_plugin.vue | 5 +++++ .../gaussian_smooth/gaussian_smooth.vue | 18 +++++++++++++++++- jdaviz/core/template_mixin.py | 1 + jdaviz/core/user_api.py | 2 +- 6 files changed, 46 insertions(+), 8 deletions(-) diff --git a/jdaviz/components/plugin_add_results.vue b/jdaviz/components/plugin_add_results.vue index 9d576b17ee..61fd4378fe 100644 --- a/jdaviz/components/plugin_add_results.vue +++ b/jdaviz/components/plugin_add_results.vue @@ -8,8 +8,9 @@ :auto="label_auto" @update:auto="$emit('update:label_auto', $event)" :invalid_msg="label_invalid_msg" - :label="label_label ? label_label : 'Output Data Label'" + :label="show_api_hints && label_api_hint ? label_api_hint : label_label ? label_label : 'Output Data Label'" :hint="label_hint ? label_hint : 'Label for the resulting data item.'" + :class="show_api_hints ? 'api_hint' : null" >
@@ -77,6 +78,14 @@ {{action_label}}{{label_overwrite ? ' (Overwrite)' : ''}} + + {{action_api_hint}} +
@@ -89,8 +98,8 @@ diff --git a/jdaviz/components/plugin_dataset_select.vue b/jdaviz/components/plugin_dataset_select.vue index e0e73635dd..c39368075a 100644 --- a/jdaviz/components/plugin_dataset_select.vue +++ b/jdaviz/components/plugin_dataset_select.vue @@ -7,13 +7,14 @@ :items="items" v-model="selected" @change="$emit('update:selected', $event)" - :label="label ? label : 'Data'" + :label="show_api_hints && api_hint ? api_hint : (label ? label : 'Data')" :hint="hint ? hint : 'Select data.'" :rules="rules ? rules : []" :multiple="multiselect" :chips="multiselect" item-text="label" item-value="label" + :class="show_api_hint ? 'api_hint' : null" persistent-hint > diff --git a/jdaviz/components/tray_plugin.vue b/jdaviz/components/tray_plugin.vue index e5f2a95c53..16c177129a 100644 --- a/jdaviz/components/tray_plugin.vue +++ b/jdaviz/components/tray_plugin.vue @@ -108,4 +108,9 @@ module.exports = { margin-top: 2px !important; margin-bottom: 2px !important; } + + .api_hint :is(.v-select__slot, .v-text-field__slot) > label.v-label { + color: orange !important; + font-family: monospace; + } diff --git a/jdaviz/configs/default/plugins/gaussian_smooth/gaussian_smooth.vue b/jdaviz/configs/default/plugins/gaussian_smooth/gaussian_smooth.vue index 08353c7c30..48aa37f1e3 100644 --- a/jdaviz/configs/default/plugins/gaussian_smooth/gaussian_smooth.vue +++ b/jdaviz/configs/default/plugins/gaussian_smooth/gaussian_smooth.vue @@ -5,6 +5,16 @@ :popout_button="popout_button" :scroll_to.sync="scroll_to"> + + + plg = {{config}}.plugins['Gaussian Smooth'] + + diff --git a/jdaviz/core/template_mixin.py b/jdaviz/core/template_mixin.py index bf196988ba..843693b27e 100644 --- a/jdaviz/core/template_mixin.py +++ b/jdaviz/core/template_mixin.py @@ -402,6 +402,7 @@ class PluginTemplateMixin(TemplateMixin): is_active = Bool(False).tag(sync=True) # noqa read-only: whether the previews should be shown according to plugin_opened and keep_active scroll_to = Bool(False).tag(sync=True) # noqa once set to True, vue will scroll to the element and reset to False spinner = Bool(False).tag(sync=True) # noqa use along-side @with_spinner() and + show_api_hints = Bool(False).tag(sync=True) previews_temp_disabled = Bool(False).tag(sync=True) # noqa use along-side @with_temp_disable() and previews_last_time = Float(0).tag(sync=True) supports_auto_update = Bool(False).tag(sync=True) # noqa whether this plugin supports auto-updating plugin results (requires __call__ method) diff --git a/jdaviz/core/user_api.py b/jdaviz/core/user_api.py index c54cc29399..39c0573978 100644 --- a/jdaviz/core/user_api.py +++ b/jdaviz/core/user_api.py @@ -128,7 +128,7 @@ class PluginUserApi(UserApiWrapper): help(plugin_object.show) """ def __init__(self, plugin, expose=[], readonly=[], excl_from_dict=[]): - expose = list(set(list(expose) + ['open_in_tray', 'close_in_tray', 'show'])) + expose = list(set(list(expose) + ['open_in_tray', 'close_in_tray', 'show', 'show_api_hints'])) if plugin.uses_active_status: expose += ['keep_active', 'as_active'] self._deprecation_msg = None From d646b99809a59901fb470c04d2321e2510b7e777 Mon Sep 17 00:00:00 2001 From: Kyle Conroy Date: Tue, 31 Oct 2023 11:54:41 -0400 Subject: [PATCH 02/24] store plugin state in metadata "history" --- .../default/plugins/gaussian_smooth/gaussian_smooth.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/jdaviz/configs/default/plugins/gaussian_smooth/gaussian_smooth.py b/jdaviz/configs/default/plugins/gaussian_smooth/gaussian_smooth.py index edf226d5c7..3e033c5235 100644 --- a/jdaviz/configs/default/plugins/gaussian_smooth/gaussian_smooth.py +++ b/jdaviz/configs/default/plugins/gaussian_smooth/gaussian_smooth.py @@ -156,6 +156,8 @@ def smooth(self, add_data=True): spec : `~specutils.Spectrum1D` The smoothed spectrum or data cube """ + plugin_state = self.user_api.to_dict() + if self.mode_selected == 'Spatial': if self.config != 'cubeviz': raise NotImplementedError("spatial smoothing only supported for Cubeviz") @@ -171,6 +173,10 @@ def smooth(self, add_data=True): else: results = self.spectral_smooth() + if '_jdaviz_history' not in results.meta.keys(): + results.meta['_jdaviz_history'] = [] + results.meta['_jdaviz_history'] += [plugin_state] + if add_data: # add data to the collection/viewer self.add_results.add_results_from_plugin(results) From 187f3648049532cece7943412e337eeb5e40dab8 Mon Sep 17 00:00:00 2001 From: Kyle Conroy Date: Tue, 31 Oct 2023 12:04:22 -0400 Subject: [PATCH 03/24] button to toggle API hints (only hooked up for gaussian smooth for now) --- jdaviz/components/plugin_dataset_select.vue | 2 +- jdaviz/components/tray_plugin.vue | 9 +++++++-- .../default/plugins/gaussian_smooth/gaussian_smooth.vue | 1 + 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/jdaviz/components/plugin_dataset_select.vue b/jdaviz/components/plugin_dataset_select.vue index c39368075a..9b239c7137 100644 --- a/jdaviz/components/plugin_dataset_select.vue +++ b/jdaviz/components/plugin_dataset_select.vue @@ -14,7 +14,7 @@ :chips="multiselect" item-text="label" item-value="label" - :class="show_api_hint ? 'api_hint' : null" + :class="show_api_hints ? 'api_hint' : null" persistent-hint >