Skip to content

Commit

Permalink
Re-use attribute_display_unit from glue-core
Browse files Browse the repository at this point in the history
  • Loading branch information
astrofrog committed Apr 16, 2024
1 parent c873822 commit 3ce8770
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 24 deletions.
2 changes: 1 addition & 1 deletion glue_jupyter/bqplot/image/layer_artist.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def _update_contour_lines(self):
contour_data = converter.to_unit(self.state.layer,
self.state.attribute,
contour_data,
self.state.c_display_unit)
self.state.attribute_display_unit)

for level in self.state.levels:
if level not in self._contour_line_cache:
Expand Down
21 changes: 1 addition & 20 deletions glue_jupyter/bqplot/image/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ class BqplotImageViewerState(ImageViewerState):
class BqplotImageLayerState(ImageLayerState):
c_min = DDCProperty(docstring='The lower level used for the contours')
c_max = DDCProperty(docstring='The upper level used for the contours')
c_display_unit = DDSCProperty(docstring='The units to use to display contour levels')
level_mode = DDSCProperty(0, docstring='How to distribute the contour levels')
n_levels = DDCProperty(5, docstring='The number of levels, in Linear mode')
levels = CallbackProperty(docstring='List of values where to create the contour lines')
Expand Down Expand Up @@ -56,17 +55,13 @@ def format_unit(unit):
else:
return unit

BqplotImageLayerState.c_display_unit.set_display_func(self, format_unit)

self.add_callback('n_levels', self._update_levels)
self.add_callback('c_min', self._update_levels)
self.add_callback('c_max', self._update_levels)
self.add_callback('level_mode', self._update_levels)
self.add_callback('levels', self._update_labels)
self.add_callback('attribute', self._update_c_display_unit_choices)
self.add_callback('c_display_unit', self._convert_units_c_limits, echo_old=True)
self.add_callback('attribute_display_unit', self._convert_units_c_limits, echo_old=True)

self._update_c_display_unit_choices()
self._update_levels()

def _update_priority(self, name):
Expand All @@ -86,20 +81,6 @@ def _update_labels(self, ignore=None):
# TODO: we may want to have ways to configure this in the future
self.labels = ["{0:.4g}".format(level) for level in self.levels]

def _update_c_display_unit_choices(self, *args):

if self.layer is None:
BqplotImageLayerState.c_display_unit.set_choices(self, [])
return

component = self.layer.get_component(self.attribute)
if component.units:
c_choices = find_unit_choices([(self.layer, self.attribute, component.units)])
else:
c_choices = ['']
BqplotImageLayerState.c_display_unit.set_choices(self, c_choices)
self.c_display_unit = component.units

def _convert_units_c_limits(self, old_unit, new_unit):

if (
Expand Down
2 changes: 1 addition & 1 deletion glue_jupyter/bqplot/image/tests/test_visual.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def test_contour_units(

assert_allclose(image.state.layers[0].levels, [0.1, 0.3, 0.5, 0.7, 0.9])

image.state.layers[0].c_display_unit = 'm'
image.state.layers[0].attribute_display_unit = 'm'

assert_allclose(image.state.layers[0].levels, [100, 300, 500, 700, 900])
assert image.state.layers[0].labels == ['100', '300', '500', '700', '900']
Expand Down
3 changes: 1 addition & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ python_requires = >=3.8
setup_requires =
setuptools_scm
install_requires =
glue-core>=1.17.1
glue-core>=1.19.0
glue-vispy-viewers>=1.0
notebook>=4.0
ipympl>=0.3.0
Expand All @@ -33,7 +33,6 @@ test =
pytest
pytest-cov
nbconvert>=6.4.5
glue-core!=1.2.4; python_version == '3.10'
visualtest =
playwright
pytest-playwright
Expand Down

0 comments on commit 3ce8770

Please sign in to comment.