Skip to content

Commit

Permalink
Merge pull request glue-viz#472 from astrofrog/explicit-frb-updates
Browse files Browse the repository at this point in the history
Try and improve responsiveness when debounced isn't really needed
  • Loading branch information
astrofrog authored Oct 31, 2024
2 parents dc834e8 + dd84dbf commit 44e7df6
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
13 changes: 11 additions & 2 deletions glue_jupyter/bqplot/image/frb_mark.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ def __init__(self, viewer, array_maker, compression='png'):
self.viewer.figure.axes[1].scale.observe(self.debounced_update, 'min')
self.viewer.figure.axes[1].scale.observe(self.debounced_update, 'max')

self._latest_hash = None

# NOTE: we deliberately don't call .update() here because when FRBImage
# is created for the main composite image layer the composite arrays
# haven't been set up yet, and for subset layers the layer gets force
Expand All @@ -62,7 +64,7 @@ def external_padding(self, value):
if value > previous_value: # no point updating if the value is smaller than before
self.debounced_update()

def update(self, *args, **kwargs):
def update(self, *args, force=False, **kwargs):

# Shape can be (0, 0) when viewer was created and then destroyed.
if self.shape is None or np.allclose(self.shape, 0):
Expand All @@ -77,6 +79,11 @@ def update(self, *args, **kwargs):
if xmin is None or xmax is None or ymin is None or ymax is None:
return

current_hash = (xmin, xmax, ymin, ymax, self.external_padding)

if not force and current_hash == self._latest_hash:
return

ny, nx = self.shape

# Expand beyond the boundary
Expand All @@ -103,5 +110,7 @@ def update(self, *args, **kwargs):
else:
self.image = EMPTY_IMAGE

self._latest_hash = current_hash

def invalidate_cache(self):
self.update()
self.update(force=True)
9 changes: 9 additions & 0 deletions glue_jupyter/bqplot/image/viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,15 @@ def __init__(self, session, compression='png'):
on_change([(self.state, 'aspect')])(self._sync_figure_aspect)
self._sync_figure_aspect()

def _update_bqplot_limits(self, *args, **kwargs):
# When the user explicitly changes the limits, we want the update to
# be immediate - debouncing should be ideally used mostly for preventing
# many successive updates from the front-end, e.g. when panning, but
# programmatically changing things should be immediate.
super()._update_bqplot_limits(*args, **kwargs)
if hasattr(self, '_composite_image'):
self._composite_image.update()

def _update_axes(self, *args):

if self.state.x_att_world is not None:
Expand Down

0 comments on commit 44e7df6

Please sign in to comment.