Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix unnecessary stretch histogram updates #3151

Merged
merged 3 commits into from
Aug 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
^^^^^^^

Expand Down
24 changes: 10 additions & 14 deletions jdaviz/configs/default/plugins/plot_options/plot_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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._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):
Expand All @@ -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._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:
Expand Down