diff --git a/CHANGES.rst b/CHANGES.rst index bb6e4292f8..4cbe4ea9eb 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -4,6 +4,8 @@ Bug Fixes --------- +- Stretch histogram in zoom limits no longer attempts unnecessary updates when zoom limits are changed. [#3151] + Cubeviz ^^^^^^^ diff --git a/jdaviz/configs/default/plugins/plot_options/plot_options.py b/jdaviz/configs/default/plugins/plot_options/plot_options.py index 18ccc4ecaa..c7cdf8745f 100644 --- a/jdaviz/configs/default/plugins/plot_options/plot_options.py +++ b/jdaviz/configs/default/plugins/plot_options/plot_options.py @@ -898,23 +898,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 @@ -941,7 +937,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._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): @@ -950,7 +946,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._zoom_limits_update_stretch_histogram) if not len(self.layer.selected_obj): # skip further updates if no data are available: