Skip to content

Commit

Permalink
Backport PR spacetelescope#3151: fix unnecessary stretch histogram up…
Browse files Browse the repository at this point in the history
…dates
  • Loading branch information
kecnry authored and meeseeksmachine committed Aug 14, 2024
1 parent 4e95a02 commit 76503d3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 14 deletions.
2 changes: 2 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
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 @@ -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
Expand All @@ -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):
Expand All @@ -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:
Expand Down

0 comments on commit 76503d3

Please sign in to comment.