From 766ca24717d8a76f820ebc63d2f52b0088b4a523 Mon Sep 17 00:00:00 2001 From: Kyle Conroy Date: Wed, 14 Aug 2024 12:10:59 -0400 Subject: [PATCH 1/3] update method called by zoom callbacks to include logic to skip callback when histogram is not set to follow zoom-limits --- jdaviz/configs/default/plugins/plot_options/plot_options.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/jdaviz/configs/default/plugins/plot_options/plot_options.py b/jdaviz/configs/default/plugins/plot_options/plot_options.py index e205cd83ee..967de6d5af 100644 --- a/jdaviz/configs/default/plugins/plot_options/plot_options.py +++ b/jdaviz/configs/default/plugins/plot_options/plot_options.py @@ -568,7 +568,7 @@ def state_attr_for_line_visible(state): state_filter=is_image) self.stretch_histogram = Plot(self, name='stretch_hist', viewer_type='histogram', - update_callback=self._update_stretch_histogram) + update_callback=self._request_update_stretch_histogram) # Add the stretch bounds tool to the default Plot viewer. self.stretch_histogram.tools_nested.append(["jdaviz:stretch_bounds"]) self.stretch_histogram._initialize_toolbar(["jdaviz:stretch_bounds"]) @@ -938,7 +938,7 @@ def _update_stretch_histogram(self, msg={}): or not self.stretch_hist_zoom_limits): vs = viewer.state for attr in ('x_min', 'x_max', 'y_min', 'y_max'): - vs.add_callback(attr, self._update_stretch_histogram) + vs.add_callback(attr, self._request_update_stretch_histogram) if isinstance(msg, dict) and msg.get('name') == 'viewer_selected': viewer_label_old = msg.get('old') if isinstance(viewer_label_old, list): @@ -947,7 +947,7 @@ def _update_stretch_histogram(self, msg={}): if viewer_label_old in self.app._viewer_store: vs_old = self.app.get_viewer(viewer_label_old).state for attr in ('x_min', 'x_max', 'y_min', 'y_max'): - vs_old.remove_callback(attr, self._update_stretch_histogram) + vs_old.remove_callback(attr, self._request_update_stretch_histogram) if not len(self.layer.selected_obj): # skip further updates if no data are available: From 9575c716df30866772765356ad2cd640894b2491 Mon Sep 17 00:00:00 2001 From: Kyle Conroy Date: Wed, 14 Aug 2024 13:57:20 -0400 Subject: [PATCH 2/3] changelog entry --- CHANGES.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGES.rst b/CHANGES.rst index ee87712bb6..cfd40b3949 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -221,6 +221,8 @@ Other Changes and Additions Bug Fixes --------- +- Stretch histogram in zoom limits no longer attempts unnecessary updates when zoom limits are changed. [#3151] + Cubeviz ^^^^^^^ From ecf3886d12b288fcff0fce2250727dc9f6e9bb70 Mon Sep 17 00:00:00 2001 From: Kyle Conroy Date: Wed, 14 Aug 2024 14:10:37 -0400 Subject: [PATCH 3/3] zoom-limits handled independently instead of relying on empty msg --- .../plugins/plot_options/plot_options.py | 26 ++++++++----------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/jdaviz/configs/default/plugins/plot_options/plot_options.py b/jdaviz/configs/default/plugins/plot_options/plot_options.py index 967de6d5af..9c092bafb1 100644 --- a/jdaviz/configs/default/plugins/plot_options/plot_options.py +++ b/jdaviz/configs/default/plugins/plot_options/plot_options.py @@ -568,7 +568,7 @@ def state_attr_for_line_visible(state): state_filter=is_image) self.stretch_histogram = Plot(self, name='stretch_hist', viewer_type='histogram', - update_callback=self._request_update_stretch_histogram) + update_callback=self._update_stretch_histogram) # Add the stretch bounds tool to the default Plot viewer. self.stretch_histogram.tools_nested.append(["jdaviz:stretch_bounds"]) self.stretch_histogram._initialize_toolbar(["jdaviz:stretch_bounds"]) @@ -895,23 +895,19 @@ def _request_update_stretch_histogram(self, msg={}): # plugin hasn't been fully initialized yet return - if not isinstance(msg, dict): # pragma: no cover - # then this is from the limits callbacks - # IMPORTANT: this assumes the only non-observe callback to this method comes - # from state callbacks from zoom limits. - if not self.stretch_hist_zoom_limits: - # there isn't anything to update, let's not waste resources - return - # override msg as an empty dict so that the rest of the logic doesn't have to check - # its type - msg = {} - # NOTE: this method is separate from _update_stretch_histogram so that # _update_stretch_histogram can be called manually (or from the # update_callback on the Plot object itself) without going through - # the skip_if_no_updates_since_last_active check + # the skip_if_no_updates_since_last_active check (and can therefore + # be executed even if the plugin is not active) self._update_stretch_histogram(msg) + def _zoom_limits_update_stretch_histogram(self, msg={}): + if not self.stretch_hist_zoom_limits: + # there isn't anything to update, let's not waste resources + return + self._update_stretch_histogram() + @with_spinner('stretch_hist_spinner') def _update_stretch_histogram(self, msg={}): if not self.stretch_function_sync.get('in_subscribed_states'): # pragma: no cover @@ -938,7 +934,7 @@ def _update_stretch_histogram(self, msg={}): or not self.stretch_hist_zoom_limits): vs = viewer.state for attr in ('x_min', 'x_max', 'y_min', 'y_max'): - vs.add_callback(attr, self._request_update_stretch_histogram) + vs.add_callback(attr, self._zoom_limits_update_stretch_histogram) if isinstance(msg, dict) and msg.get('name') == 'viewer_selected': viewer_label_old = msg.get('old') if isinstance(viewer_label_old, list): @@ -947,7 +943,7 @@ def _update_stretch_histogram(self, msg={}): if viewer_label_old in self.app._viewer_store: vs_old = self.app.get_viewer(viewer_label_old).state for attr in ('x_min', 'x_max', 'y_min', 'y_max'): - vs_old.remove_callback(attr, self._request_update_stretch_histogram) + vs_old.remove_callback(attr, self._zoom_limits_update_stretch_histogram) if not len(self.layer.selected_obj): # skip further updates if no data are available: