Skip to content

Commit

Permalink
Initial work on adding unit support for scatter viewer
Browse files Browse the repository at this point in the history
  • Loading branch information
astrofrog committed Aug 12, 2024
1 parent ab63d9d commit 800cdb3
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 3 deletions.
14 changes: 13 additions & 1 deletion glue_jupyter/bqplot/scatter/layer_artist.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from glue.viewers.scatter.layer_artist import DensityMapLimits
from glue.viewers.scatter.state import ScatterLayerState
from glue_jupyter.bqplot.scatter.scatter_density_mark import GenericDensityMark
from glue.core.units import UnitConverter

from ...utils import colormap_to_hexlist, float_or_none
from ..compatibility import ScatterGL, LinesGL
Expand Down Expand Up @@ -175,7 +176,6 @@ def _update_data(self):
x = ensure_numerical(self.layer[self._viewer_state.x_att].ravel())
if x.dtype.kind == "M":
x = datetime64_to_mpl(x)

except (IncompatibleAttribute, IndexError):
# The following includes a call to self.clear()
self.disable_invalid_attributes(self._viewer_state.x_att)
Expand All @@ -195,6 +195,18 @@ def _update_data(self):
else:
self.enable()

converter = UnitConverter()

x = converter.to_unit(self._viewer_state.x_att.parent,
self._viewer_state.x_att,
x,
self._viewer_state.x_display_unit)

y = converter.to_unit(self._viewer_state.y_att.parent,
self._viewer_state.y_att,
y,
self._viewer_state.y_display_unit)

if self.state.markers_visible:

if self.state.density_map:
Expand Down
10 changes: 8 additions & 2 deletions glue_jupyter/bqplot/scatter/viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,13 @@ def __init__(self, *args, **kwargs):
def _update_axes(self, *args):

if self.state.x_att is not None:
self.state.x_axislabel = str(self.state.x_att)
if self.state.x_display_unit:
self.state.x_axislabel = str(self.state.x_att) + f' [{self.state.x_display_unit}]'
else:
self.state.x_axislabel = str(self.state.x_att)

if self.state.y_att is not None:
self.state.y_axislabel = str(self.state.y_att)
if self.state.y_display_unit:
self.state.y_axislabel = str(self.state.y_att) + f' [{self.state.y_display_unit}]'
else:
self.state.y_axislabel = str(self.state.y_att)
8 changes: 8 additions & 0 deletions glue_jupyter/common/state_widgets/viewer_scatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ class ScatterViewerStateWidget(v.VuetifyTemplate):
y_att_items = traitlets.List().tag(sync=True)
y_att_selected = traitlets.Int(allow_none=True).tag(sync=True)

x_display_unit_items = traitlets.List().tag(sync=True)
x_display_unit_selected = traitlets.Int(allow_none=True).tag(sync=True)

y_display_unit_items = traitlets.List().tag(sync=True)
y_display_unit_selected = traitlets.Int(allow_none=True).tag(sync=True)

def __init__(self, viewer_state):

super().__init__()
Expand All @@ -28,3 +34,5 @@ def __init__(self, viewer_state):

link_glue_choices(self, viewer_state, "x_att")
link_glue_choices(self, viewer_state, "y_att")
link_glue_choices(self, viewer_state, 'x_display_unit')
link_glue_choices(self, viewer_state, 'y_display_unit')
6 changes: 6 additions & 0 deletions glue_jupyter/common/state_widgets/viewer_scatter.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@
<div>
<v-select label="y axis" :items="y_att_items" v-model="y_att_selected" hide-details />
</div>
<div>
<v-select :items="x_display_unit_items" label="x axis units" v-model="x_display_unit_selected" hide-details/>
</div>
<div>
<v-select :items="y_display_unit_items" label="y axis units" v-model="y_display_unit_selected" hide-details/>
</div>
<div>
<v-subheader class="pl-0 slider-label">show axes</v-subheader>
<v-switch v-model="glue_state.show_axes" hide-details style="margin-top: 0"/>
Expand Down

0 comments on commit 800cdb3

Please sign in to comment.