From 9e2553746b6135b76b977c45c25293513644e4b6 Mon Sep 17 00:00:00 2001 From: Kyle Conroy Date: Mon, 4 Apr 2022 09:45:00 -0400 Subject: [PATCH 1/5] expose axes limits in profile viewer options --- .../common/state_widgets/viewer_profile.py | 6 ++++++ .../common/state_widgets/viewer_profile.vue | 4 ++++ glue_jupyter/widgets/__init__.py | 3 ++- glue_jupyter/widgets/axes_limits.py | 14 ++++++++++++++ glue_jupyter/widgets/axes_limits.vue | 18 ++++++++++++++++++ 5 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 glue_jupyter/widgets/axes_limits.py create mode 100644 glue_jupyter/widgets/axes_limits.vue diff --git a/glue_jupyter/common/state_widgets/viewer_profile.py b/glue_jupyter/common/state_widgets/viewer_profile.py index f5b33d90..57a742d7 100644 --- a/glue_jupyter/common/state_widgets/viewer_profile.py +++ b/glue_jupyter/common/state_widgets/viewer_profile.py @@ -1,7 +1,9 @@ import ipyvuetify as v +import ipywidgets as widgets import traitlets from ...state_traitlets_helpers import GlueState from ...vuetify_helpers import link_glue_choices +from ...widgets import AxesLimits __all__ = ['ProfileViewerStateWidget'] @@ -26,6 +28,8 @@ class ProfileViewerStateWidget(v.VuetifyTemplate): y_display_unit_items = traitlets.List().tag(sync=True) y_display_unit_selected = traitlets.Int(allow_none=True).tag(sync=True) + axes_limits_widget = traitlets.Any().tag(sync=True, **widgets.widget_serialization) + def __init__(self, viewer_state): super().__init__() @@ -36,3 +40,5 @@ def __init__(self, viewer_state): link_glue_choices(self, viewer_state, 'function') link_glue_choices(self, viewer_state, 'x_display_unit') link_glue_choices(self, viewer_state, 'y_display_unit') + + self.axes_limits_widget = AxesLimits(viewer_state) diff --git a/glue_jupyter/common/state_widgets/viewer_profile.vue b/glue_jupyter/common/state_widgets/viewer_profile.vue index 11f87aeb..7199197a 100644 --- a/glue_jupyter/common/state_widgets/viewer_profile.vue +++ b/glue_jupyter/common/state_widgets/viewer_profile.vue @@ -16,6 +16,10 @@ +
+ +
+
diff --git a/glue_jupyter/widgets/__init__.py b/glue_jupyter/widgets/__init__.py index 031f1ed4..944222c6 100644 --- a/glue_jupyter/widgets/__init__.py +++ b/glue_jupyter/widgets/__init__.py @@ -1,5 +1,6 @@ +from .axes_limits import AxesLimits from .color import Color from .size import Size from .linked_dropdown import LinkedDropdown -__all__ = ['Color', 'Size', 'LinkedDropdown'] +__all__ = ['AxesLimits', 'Color', 'Size', 'LinkedDropdown'] diff --git a/glue_jupyter/widgets/axes_limits.py b/glue_jupyter/widgets/axes_limits.py new file mode 100644 index 00000000..e55c81fa --- /dev/null +++ b/glue_jupyter/widgets/axes_limits.py @@ -0,0 +1,14 @@ +import ipyvuetify as v +from ..state_traitlets_helpers import GlueState + +__all__ = ['AxesLimits'] + + +class AxesLimits(v.VuetifyTemplate): + template_file = (__file__, 'axes_limits.vue') + + glue_state = GlueState().tag(sync=True) + + def __init__(self, viewer_state): + super().__init__() + self.glue_state = viewer_state diff --git a/glue_jupyter/widgets/axes_limits.vue b/glue_jupyter/widgets/axes_limits.vue new file mode 100644 index 00000000..c2a64a80 --- /dev/null +++ b/glue_jupyter/widgets/axes_limits.vue @@ -0,0 +1,18 @@ + From f3d98013a301945e10eddd5f1e3fd8e017630191 Mon Sep 17 00:00:00 2001 From: Kyle Conroy Date: Mon, 4 Apr 2022 12:14:24 -0400 Subject: [PATCH 2/5] Apply suggestions from code review Co-authored-by: Mario Buikhuizen --- glue_jupyter/widgets/axes_limits.vue | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/glue_jupyter/widgets/axes_limits.vue b/glue_jupyter/widgets/axes_limits.vue index c2a64a80..5a0922eb 100644 --- a/glue_jupyter/widgets/axes_limits.vue +++ b/glue_jupyter/widgets/axes_limits.vue @@ -1,18 +1,20 @@ From 693d72bd4778a06024579753dc19d25615a05464 Mon Sep 17 00:00:00 2001 From: Thomas Robitaille Date: Tue, 12 Sep 2023 11:16:12 +0100 Subject: [PATCH 3/5] Only sync limits with glue state when 'Apply limits' button is clicked --- glue_jupyter/widgets/axes_limits.py | 19 +++++++++++++++++++ glue_jupyter/widgets/axes_limits.vue | 15 +++++++++++---- 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/glue_jupyter/widgets/axes_limits.py b/glue_jupyter/widgets/axes_limits.py index e55c81fa..5c4035d4 100644 --- a/glue_jupyter/widgets/axes_limits.py +++ b/glue_jupyter/widgets/axes_limits.py @@ -1,4 +1,6 @@ +import traitlets import ipyvuetify as v +from echo import delay_callback from ..state_traitlets_helpers import GlueState __all__ = ['AxesLimits'] @@ -9,6 +11,23 @@ class AxesLimits(v.VuetifyTemplate): glue_state = GlueState().tag(sync=True) + x_min = traitlets.Float(default_value=None, allow_none=True).tag(sync=True) + x_max = traitlets.Float(default_value=None, allow_none=True).tag(sync=True) + y_min = traitlets.Float(default_value=None, allow_none=True).tag(sync=True) + y_max = traitlets.Float(default_value=None, allow_none=True).tag(sync=True) + def __init__(self, viewer_state): super().__init__() self.glue_state = viewer_state + + def vue_apply_limits(self, data): + self._cache = (self.x_min, self.x_max, self.y_min, self.y_max) + with delay_callback(self.glue_state, 'x_min', 'x_max', 'y_min', 'y_max'): + if self.x_min is not None: + self.glue_state.x_min = self.x_min + if self.x_max is not None: + self.glue_state.x_max = self.x_max + if self.y_min is not None: + self.glue_state.y_min = self.y_min + if self.y_max is not None: + self.glue_state.y_max = self.y_max diff --git a/glue_jupyter/widgets/axes_limits.vue b/glue_jupyter/widgets/axes_limits.vue index 5a0922eb..575444d5 100644 --- a/glue_jupyter/widgets/axes_limits.vue +++ b/glue_jupyter/widgets/axes_limits.vue @@ -2,18 +2,25 @@
- + - + - + - + + + + + + + Apply limits +
From a0727097934edf8403780b7dab82f715d8e745e8 Mon Sep 17 00:00:00 2001 From: Thomas Robitaille Date: Tue, 12 Sep 2023 11:21:31 +0100 Subject: [PATCH 4/5] Make sure limits are synced with glue state changes --- glue_jupyter/widgets/axes_limits.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/glue_jupyter/widgets/axes_limits.py b/glue_jupyter/widgets/axes_limits.py index 5c4035d4..06375863 100644 --- a/glue_jupyter/widgets/axes_limits.py +++ b/glue_jupyter/widgets/axes_limits.py @@ -1,6 +1,7 @@ import traitlets import ipyvuetify as v from echo import delay_callback +from ..link import dlink from ..state_traitlets_helpers import GlueState __all__ = ['AxesLimits'] @@ -19,6 +20,10 @@ class AxesLimits(v.VuetifyTemplate): def __init__(self, viewer_state): super().__init__() self.glue_state = viewer_state + dlink((self.glue_state, 'x_min'), (self, 'x_min')) + dlink((self.glue_state, 'x_max'), (self, 'x_max')) + dlink((self.glue_state, 'y_min'), (self, 'y_min')) + dlink((self.glue_state, 'y_max'), (self, 'y_max')) def vue_apply_limits(self, data): self._cache = (self.x_min, self.x_max, self.y_min, self.y_max) From ffdf1754865cb6d2b0cf018f930bf4c161b90e69 Mon Sep 17 00:00:00 2001 From: Kyle Conroy Date: Tue, 12 Sep 2023 09:32:27 -0400 Subject: [PATCH 5/5] enable axes limits for image viewer --- glue_jupyter/common/state_widgets/viewer_image.py | 6 ++++++ glue_jupyter/common/state_widgets/viewer_image.vue | 3 +++ 2 files changed, 9 insertions(+) diff --git a/glue_jupyter/common/state_widgets/viewer_image.py b/glue_jupyter/common/state_widgets/viewer_image.py index 9d58143a..dab73809 100644 --- a/glue_jupyter/common/state_widgets/viewer_image.py +++ b/glue_jupyter/common/state_widgets/viewer_image.py @@ -1,9 +1,11 @@ from glue.viewers.image.state import AggregateSlice from glue.core.coordinate_helpers import world_axis import ipyvuetify as v +import ipywidgets as widgets import traitlets from ...state_traitlets_helpers import GlueState from ...vuetify_helpers import link_glue_choices +from ...widgets import AxesLimits __all__ = ['ImageViewerStateWidget'] @@ -28,6 +30,8 @@ class ImageViewerStateWidget(v.VuetifyTemplate): sliders = traitlets.List().tag(sync=True) + axes_limits_widget = traitlets.Any().tag(sync=True, **widgets.widget_serialization) + def __init__(self, viewer_state): super().__init__() @@ -54,6 +58,8 @@ def __init__(self, viewer_state): self._sync_sliders_from_state() + self.axes_limits_widget = AxesLimits(viewer_state) + def _sync_sliders_from_state(self, *not_used): if self.viewer_state.reference_data is None or self.viewer_state.slices is None: diff --git a/glue_jupyter/common/state_widgets/viewer_image.vue b/glue_jupyter/common/state_widgets/viewer_image.vue index 72e21f7c..03bbe1ed 100644 --- a/glue_jupyter/common/state_widgets/viewer_image.vue +++ b/glue_jupyter/common/state_widgets/viewer_image.vue @@ -28,6 +28,9 @@ v-if="glue_state.slices && glue_state.slices.length > 0" wait="300" :max="slider.max" :value.sync="glue_state.slices[slider.index]" hide-details />
+
+ +