Skip to content

Commit

Permalink
initialize zoom center even when viewer not shown (#3222)
Browse files Browse the repository at this point in the history
* initialize zoom center even when viewer not shown

* simplified regression test
  • Loading branch information
kecnry authored Oct 17, 2024
1 parent 56e1ded commit 2170624
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 5 deletions.
2 changes: 1 addition & 1 deletion jdaviz/configs/cubeviz/plugins/viewers.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class CubevizImageView(JdavizViewerMixin, WithSliceSelection, BqplotImageView):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
# provide reference from state back to viewer to use for zoom syncing
self.state._viewer = self
self.state._set_viewer(self)

self._subscribe_to_layers_update()
self.state.add_callback('reference_data', self._initial_x_axis)
Expand Down
2 changes: 1 addition & 1 deletion jdaviz/configs/imviz/plugins/viewers.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class ImvizImageView(JdavizViewerMixin, BqplotImageView, AstrowidgetsImageViewer
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
# provide reference from state back to viewer to use for zoom syncing
self.state._viewer = self
self.state._set_viewer(self)
self.init_astrowidgets_api()
self._subscribe_to_layers_update()

Expand Down
9 changes: 9 additions & 0 deletions jdaviz/configs/imviz/tests/test_viewers.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,15 @@ def test_mastviz_config():
assert im.app.data_collection[0].shape == (2, 2)


def test_zoom_center_radius_init(imviz_helper):
"""Regression test for https://github.com/spacetelescope/jdaviz/issues/3217"""
arr = np.ones((10, 10))
imviz_helper.load_data(arr, data_label='my_array')
assert imviz_helper.default_viewer._obj.state.zoom_center_x > 0
assert imviz_helper.default_viewer._obj.state.zoom_center_y > 0
assert imviz_helper.default_viewer._obj.state.zoom_radius > 0


class TestDeleteData(BaseImviz_WCS_NoWCS):

def test_plot_options_after_destroy(self):
Expand Down
2 changes: 1 addition & 1 deletion jdaviz/configs/rampviz/plugins/viewers.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ class RampvizImageView(JdavizViewerMixin, WithSliceSelection, BqplotImageView):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
# provide reference from state back to viewer to use for zoom syncing
self.state._viewer = self
self.state._set_viewer(self)

self._subscribe_to_layers_update()
self.state.add_callback('reference_data', self._initial_x_axis)
Expand Down
8 changes: 6 additions & 2 deletions jdaviz/core/freezable_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ def __init__(self, *args, **kwargs):
self.add_callback(attr, self._set_axes_lim)
super().__init__(*args, **kwargs)

def _set_viewer(self, viewer):
self._viewer = viewer
self._set_axes_lim()

@contextmanager
def during_zoom_sync(self):
self._during_zoom_sync = True
Expand All @@ -82,7 +86,7 @@ def during_zoom_sync(self):
self._during_zoom_sync = False

def _set_zoom_radius_center(self, *args):
if self._during_zoom_sync or not hasattr(self, '_viewer') or self._viewer.shape is None:
if self._during_zoom_sync or not hasattr(self, '_viewer'):
return

# When WCS-linked (displayed on the sky): zoom_center_x/y and zoom_radius are in sky units,
Expand Down Expand Up @@ -117,7 +121,7 @@ def _set_axes_aspect_ratio(self, axes_ratio):
self._set_axes_lim()

def _set_axes_lim(self, *args):
if self._during_zoom_sync or not hasattr(self, '_viewer') or self._viewer.shape is None:
if self._during_zoom_sync or not hasattr(self, '_viewer'):
return
if None in (self.x_min, self.x_max, self.y_min, self.y_max):
return
Expand Down

0 comments on commit 2170624

Please sign in to comment.