diff --git a/glue/viewers/histogram/tests/test_state.py b/glue/viewers/histogram/tests/test_state.py index 2073e67c4..131a0c720 100644 --- a/glue/viewers/histogram/tests/test_state.py +++ b/glue/viewers/histogram/tests/test_state.py @@ -1,3 +1,6 @@ +import numpy as np +from numpy.testing import assert_allclose + from glue.viewers.common.viewer import Viewer from glue.viewers.histogram.state import HistogramViewerState from glue.core.application_base import Application @@ -57,3 +60,41 @@ def test_incompatible_datasets(): viewer.state.x_att = data2.id['y'] viewer.state.hist_n_bin = 20 + + +def test_reset_limits(): + + data1 = Data(x=np.arange(1000), label='data') + + app = Application() + app.data_collection.append(data1) + + viewer = app.new_data_viewer(TestHistogramViewer) + viewer.add_data(data1) + + viewer.state.reset_limits() + + assert_allclose(viewer.state.x_min, 0) + assert_allclose(viewer.state.x_max, 999) + + viewer.state.x_limits_percentile = 90 + + viewer.state.reset_limits() + + assert_allclose(viewer.state.x_min, 49.95) + assert_allclose(viewer.state.x_max, 949.05) + + assert_allclose(viewer.state.hist_x_min, 49.95) + assert_allclose(viewer.state.hist_x_max, 949.05) + + viewer.state.update_bins_on_reset_limits = False + + viewer.state.x_limits_percentile = 80 + + viewer.state.reset_limits() + + assert_allclose(viewer.state.x_min, 99.9) + assert_allclose(viewer.state.x_max, 899.1) + + assert_allclose(viewer.state.hist_x_min, 49.95) + assert_allclose(viewer.state.hist_x_max, 949.05) diff --git a/glue/viewers/scatter/tests/__init__.py b/glue/viewers/scatter/tests/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/glue/viewers/scatter/tests/test_state.py b/glue/viewers/scatter/tests/test_state.py new file mode 100644 index 000000000..da4ddcc9e --- /dev/null +++ b/glue/viewers/scatter/tests/test_state.py @@ -0,0 +1,43 @@ +import numpy as np +from numpy.testing import assert_allclose + +from glue.viewers.common.viewer import Viewer +from glue.viewers.scatter.state import ScatterViewerState +from glue.core.application_base import Application +from glue.core.data import Data + + +class TestScatterViewer(Viewer): + _state_cls = ScatterViewerState + + +def test_reset_limits(): + + data1 = Data(x=np.arange(1000), y=np.arange(1000) + 1000, label='data') + + app = Application() + app.data_collection.append(data1) + + viewer = app.new_data_viewer(TestScatterViewer) + viewer.add_data(data1) + + viewer.state.reset_limits() + + # Note that there is a margin included which is why the limits are not 0 to 999 + + assert_allclose(viewer.state.x_min, -39.96) + assert_allclose(viewer.state.x_max, 1038.96) + + assert_allclose(viewer.state.y_min, 1000 - 39.96) + assert_allclose(viewer.state.y_max, 1000 + 1038.96) + + viewer.state.x_limits_percentile = 90 + viewer.state.y_limits_percentile = 80 + + viewer.state.reset_limits() + + assert_allclose(viewer.state.x_min, 13.986) + assert_allclose(viewer.state.x_max, 985.014) + + assert_allclose(viewer.state.y_min, 1000 + 67.932) + assert_allclose(viewer.state.y_max, 1000 + 931.068)