Skip to content

Commit

Permalink
switch order of setting ymin and ymax
Browse files Browse the repository at this point in the history
  • Loading branch information
cshanahan1 committed Dec 23, 2024
1 parent 6868bb5 commit 13756c3
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
7 changes: 5 additions & 2 deletions jdaviz/configs/default/plugins/viewers.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,10 +162,13 @@ def set_limits(self, x_min=None, x_max=None, y_min=None, y_max=None):
self.state.x_min = x_min
if x_max is not None:
self.state.x_max = x_max
if y_min is not None:
self.state.y_min = y_min
# NOTE: for some reason, setting ymax first avoids an issue
# where back-to-back calls of get_limits and set_limits
# give different results for y limits.
if y_max is not None:
self.state.y_max = y_max
if y_min is not None:
self.state.y_min = y_min

def get_limits(self):
"""Return current viewer axes limits.
Expand Down
21 changes: 21 additions & 0 deletions jdaviz/configs/imviz/tests/test_viewers.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,3 +118,24 @@ def test_plot_options_after_destroy(self):
po.stretch_function = "Square Root"
self.imviz.destroy_viewer("imviz-1")
assert len(po.layer.choices) == 2


def test_viewer_limits(imviz_helper):
"""
Test that sequential calls to set_limits and get_limits return the same
viewer limits.
"""
arr = np.ones((10, 10))
imviz_helper.load_data(arr, data_label='my_array')
viewer = imviz_helper.default_viewer._obj

# set limits then get limits and make sure they are the same
viewer.set_limits(x_min=0, x_max=20, y_min=0, y_max=20)
limits = viewer.get_limits()
assert limits == (0, 20, 0, 20)

# calling get_limits again should also return the same original limits, but
# it doesn't, uncomment once JDAT-5050 is done
# get limits again, make sure they are the same.
# limits = viewer.get_limits()
# assert limits == (0, 20, 0, 20)

0 comments on commit 13756c3

Please sign in to comment.