Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose axes limits in viewer options #304

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions glue_jupyter/common/state_widgets/viewer_image.py
Original file line number Diff line number Diff line change
@@ -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']
Expand All @@ -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__()

Expand All @@ -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:
Expand Down
3 changes: 3 additions & 0 deletions glue_jupyter/common/state_widgets/viewer_image.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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 />
</div>
<div>
<jupyter-widget :widget="axes_limits_widget"></jupyter-widget>
</div>
</div>
</template>
<script>
Expand Down
6 changes: 6 additions & 0 deletions glue_jupyter/common/state_widgets/viewer_profile.py
Original file line number Diff line number Diff line change
@@ -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']

Expand All @@ -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__()

Expand All @@ -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)
4 changes: 4 additions & 0 deletions glue_jupyter/common/state_widgets/viewer_profile.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
<v-select :items="function_items" label="function" v-model="function_selected"/>
</div>

<div>
<jupyter-widget :widget="axes_limits_widget"></jupyter-widget>
</div>

<div class="d-inline-flex flex-wrap">
<v-btn-toggle dense multiple :value="modeSet" @change="modeSetChange" style="margin-right: 8px">

Expand Down
3 changes: 2 additions & 1 deletion glue_jupyter/widgets/__init__.py
Original file line number Diff line number Diff line change
@@ -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']
38 changes: 38 additions & 0 deletions glue_jupyter/widgets/axes_limits.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import traitlets
import ipyvuetify as v
from echo import delay_callback
from ..link import dlink
from ..state_traitlets_helpers import GlueState

__all__ = ['AxesLimits']


class AxesLimits(v.VuetifyTemplate):
template_file = (__file__, 'axes_limits.vue')

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
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)
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

Check warning on line 38 in glue_jupyter/widgets/axes_limits.py

View check run for this annotation

Codecov / codecov/patch

glue_jupyter/widgets/axes_limits.py#L29-L38

Added lines #L29 - L38 were not covered by tests
Comment on lines +30 to +38
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when used in an image viewer (now enabled), how is a change in all limits, with equal aspect enabled, handled with this delayed callback? From testing, it seems that the user-set x-limits are preserved and the y-limits are somehow adjusted to enforce the equal aspect?

I'm honestly not sure what the expected behavior should be in this case... maybe the smallest bounding box in x and y that contains the user-provided values?

27 changes: 27 additions & 0 deletions glue_jupyter/widgets/axes_limits.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<template>
<div>
<v-row no-gutters>
<v-col cols="6">
<glue-float-field class="mr-1" label="xmin" :value.sync="x_min" />
</v-col>
<v-col cols="6">
<glue-float-field class="ml-1" label="xmax" :value.sync="x_max" />
</v-col>
</v-row>
<v-row no-gutters>
<v-col cols="6">
<glue-float-field class="mr-1" label="ymin" :value.sync="y_min" />
</v-col>
<v-col cols="6">
<glue-float-field class="ml-1" label="ymax" :value.sync="y_max" />
</v-col>
</v-row>
<v-row>
<v-col class="text-center" cols="12">
<v-btn @click="apply_limits">
Apply limits
</v-btn>
</v-col>
</v-row>
</div>
</template>