Skip to content

Commit

Permalink
add cursor and pixel information to mouseover display
Browse files Browse the repository at this point in the history
  • Loading branch information
kecnry committed Jan 5, 2023
1 parent 463bae9 commit 9be2cf4
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 57 deletions.
4 changes: 2 additions & 2 deletions docs/specviz/displaying.rst
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ Cursor Information
==================

By moving your cursor along the spectrum viewer, you will be able to see information on the
index, spectral axis value, and flux value of the closest data point to the cursor
(not to be confused with the actual cursor position).
cursor position as well as the spectral axis value, pixel, and flux of the closest data point
to the cursor.
This information is displayed in the top bar of the UI, on the middle-right side.

Home
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,23 +69,19 @@ def test_linking_after_spectral_smooth(cubeviz_helper, spectrum1d_cube):
# to another, depending on which one is closer.

spec_viewer.on_mouse_or_key_event({'event': 'mousemove', 'domain': {'x': 4.6236e-7, 'y': 60}})
assert spec_viewer.label_mouseover.pixel == 'x=01.0'
assert spec_viewer.label_mouseover.pixel == '4.62360e-07, 6.00000e+01'
assert spec_viewer.label_mouseover.world_label_prefix == 'Wave'
assert spec_viewer.label_mouseover.world_ra == '4.62360e-07'
assert spec_viewer.label_mouseover.world_dec == 'm'
assert spec_viewer.label_mouseover.world_ra == '4.62360e-07 m (1 pix)'
assert spec_viewer.label_mouseover.world_label_prefix_2 == 'Flux'
assert spec_viewer.label_mouseover.world_ra_deg == '9.20000e+01'
assert spec_viewer.label_mouseover.world_dec_deg == 'Jy'
assert spec_viewer.label_mouseover.world_ra_deg == '9.20000e+01 Jy'
assert spec_viewer.label_mouseover.icon == 'a'

spec_viewer.on_mouse_or_key_event({'event': 'mousemove', 'domain': {'x': 4.6236e-7, 'y': 20}})
assert spec_viewer.label_mouseover.pixel == 'x=01.0'
assert spec_viewer.label_mouseover.pixel == '4.62360e-07, 2.00000e+01'
assert spec_viewer.label_mouseover.world_label_prefix == 'Wave'
assert spec_viewer.label_mouseover.world_ra == '4.62360e-07'
assert spec_viewer.label_mouseover.world_dec == 'm'
assert spec_viewer.label_mouseover.world_ra == '4.62360e-07 m (1 pix)'
assert spec_viewer.label_mouseover.world_label_prefix_2 == 'Flux'
assert spec_viewer.label_mouseover.world_ra_deg == '1.47943e+01'
assert spec_viewer.label_mouseover.world_dec_deg == 'Jy'
assert spec_viewer.label_mouseover.world_ra_deg == '1.47943e+01 Jy'
assert spec_viewer.label_mouseover.icon == 'b'

# Check mouseover behavior when we hide everything.
Expand Down Expand Up @@ -142,23 +138,18 @@ def test_spectrum1d_smooth(specviz_helper, spectrum1d):
# to another, depending on which one is closer.

spec_viewer.on_mouse_or_key_event({'event': 'mousemove', 'domain': {'x': 6400, 'y': 120}})
assert spec_viewer.label_mouseover.pixel == 'x=02.0'
assert spec_viewer.label_mouseover.pixel == '6.40000e+03, 1.20000e+02'
assert spec_viewer.label_mouseover.world_label_prefix == 'Wave'
assert spec_viewer.label_mouseover.world_ra == '6.44444e+03'
assert spec_viewer.label_mouseover.world_dec == 'Angstrom'
assert spec_viewer.label_mouseover.world_ra == '6.44444e+03 Angstrom (2 pix)'
assert spec_viewer.label_mouseover.world_label_prefix_2 == 'Flux'
assert spec_viewer.label_mouseover.world_ra_deg == '1.35366e+01'
assert spec_viewer.label_mouseover.world_dec_deg == 'Jy'
assert spec_viewer.label_mouseover.world_ra_deg == '1.35366e+01 Jy'
assert spec_viewer.label_mouseover.icon == 'a'

spec_viewer.on_mouse_or_key_event({'event': 'mousemove', 'domain': {'x': 6400, 'y': 5}})
assert spec_viewer.label_mouseover.pixel == 'x=02.0'
assert spec_viewer.label_mouseover.world_label_prefix == 'Wave'
assert spec_viewer.label_mouseover.world_ra == '6.44444e+03'
assert spec_viewer.label_mouseover.world_dec == 'Angstrom'
assert spec_viewer.label_mouseover.world_ra == '6.44444e+03 Angstrom (2 pix)'
assert spec_viewer.label_mouseover.world_label_prefix_2 == 'Flux'
assert spec_viewer.label_mouseover.world_ra_deg == '5.34688e+00'
assert spec_viewer.label_mouseover.world_dec_deg == 'Jy'
assert spec_viewer.label_mouseover.world_ra_deg == '5.34688e+00 Jy'
assert spec_viewer.label_mouseover.icon == 'b'

# Out-of-bounds shows nothing.
Expand Down
3 changes: 3 additions & 0 deletions jdaviz/configs/imviz/plugins/coords_info/coords_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
class CoordsInfo(TemplateMixin):
template_file = __file__, "coords_info.vue"
icon = Unicode("").tag(sync=True)
pixel_prefix = Unicode("Pixel").tag(sync=True)
pixel = Unicode("").tag(sync=True)
value = Unicode("").tag(sync=True)
world_label_prefix = Unicode("\u00A0").tag(sync=True)
Expand Down Expand Up @@ -47,6 +48,7 @@ def marks(self):
return self._marks

def reset_coords_display(self):
self.pixel_prefix = "Pixel"
self.world_label_prefix = '\u00A0'
self.world_label_prefix_2 = '\u00A0'
self.world_label_icrs = '\u00A0'
Expand All @@ -69,6 +71,7 @@ def set_coords(self, sky, unreliable_world=False, unreliable_pixel=False):
if "nan" in (world_ra, world_dec, world_ra_deg, world_dec_deg):
self.reset_coords_display()
else:
self.pixel_prefix = 'Pixel'
self.world_label_prefix = 'World'
self.world_label_icrs = '(ICRS)'
self.world_label_deg = '(deg)'
Expand Down
2 changes: 1 addition & 1 deletion jdaviz/configs/imviz/plugins/coords_info/coords_info.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<table>
<tr>
<td colspan="4" :style="unreliable_pixel ? 'color: #B8B8B8' : ''">
<b v-if="pixel">Pixel </b>{{ pixel }}&nbsp;&nbsp;
<b v-if="pixel">{{ pixel_prefix }} </b>{{ pixel }}&nbsp;&nbsp;
<b v-if="value">Value </b>{{ value }}
</td>
</tr>
Expand Down
8 changes: 3 additions & 5 deletions jdaviz/configs/mosviz/tests/test_data_loading.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,13 +214,11 @@ def test_load_single_image_multi_spec(mosviz_helper, mos_image, spectrum1d, mos_
assert spec2d_viewer.label_mouseover.icon == 'b'

spec1d_viewer.on_mouse_or_key_event({'event': 'mousemove', 'domain': {'x': 7000, 'y': 170}})
assert spec1d_viewer.label_mouseover.pixel == 'x=04.0'
assert spec1d_viewer.label_mouseover.pixel == '7.00000e+03, 1.70000e+02'
assert spec1d_viewer.label_mouseover.world_label_prefix == 'Wave'
assert spec1d_viewer.label_mouseover.world_ra == '6.88889e+03'
assert spec1d_viewer.label_mouseover.world_dec == 'Angstrom'
assert spec1d_viewer.label_mouseover.world_ra == '6.88889e+03 Angstrom (4 pix)'
assert spec1d_viewer.label_mouseover.world_label_prefix_2 == 'Flux'
assert spec1d_viewer.label_mouseover.world_ra_deg == '1.35436e+01'
assert spec1d_viewer.label_mouseover.world_dec_deg == 'Jy'
assert spec1d_viewer.label_mouseover.world_ra_deg == '1.35436e+01 Jy'
assert spec1d_viewer.label_mouseover.icon == 'c'


Expand Down
18 changes: 8 additions & 10 deletions jdaviz/configs/specviz/plugins/viewers.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ def on_mouse_or_key_event(self, data):
closest_i = None
closest_wave = None
closest_flux = None
closest_maxsize = 0
closest_label = ''
closest_distance = None
for lyr in self.state.layers:
Expand Down Expand Up @@ -126,7 +125,6 @@ def on_mouse_or_key_event(self, data):
closest_i = cur_i
closest_wave = cur_wave
closest_flux = cur_flux
closest_maxsize = int(np.ceil(np.log10(sp.spectral_axis.size))) + 3
closest_label = self.jdaviz_app.state.layer_icons.get(lyr.layer.label)
except Exception: # nosec
# Something is loaded but not the right thing
Expand All @@ -142,24 +140,24 @@ def on_mouse_or_key_event(self, data):

# show the locked marker/coords only if either no tool or the default tool is active
locking_active = self.toolbar.active_tool_id in self.toolbar.default_tool_priority + [None] # noqa
self.label_mouseover.pixel_prefix = 'Cursor'
self.label_mouseover.pixel = f'{x:10.5e}, {y:10.5e}'
if locking_active:
fmt = 'x={:0' + str(closest_maxsize) + '.1f}'
self.label_mouseover.pixel = fmt.format(closest_i)
self.label_mouseover.world_label_prefix = 'Wave'
self.label_mouseover.world_ra = f'{closest_wave.value:10.5e}'
self.label_mouseover.world_dec = closest_wave.unit.to_string()
self.label_mouseover.world_ra = f'{closest_wave.value:10.5e} {closest_wave.unit.to_string()}' # noqa
if closest_wave.unit != u.pix:
self.label_mouseover.world_ra += f' ({closest_i} pix)'
self.label_mouseover.world_dec = ''
self.label_mouseover.world_label_prefix_2 = 'Flux'
self.label_mouseover.world_ra_deg = f'{closest_flux.value:10.5e}'
self.label_mouseover.world_dec_deg = closest_flux.unit.to_string()
self.label_mouseover.world_ra_deg = f'{closest_flux.value:10.5e} {closest_flux.unit.to_string()}' # noqa
self.label_mouseover.world_dec_deg = ''
self.label_mouseover.icon = closest_label
self.label_mouseover.value = "" # Not used
self.label_mouseover.marks[self._reference_id].update_xy([closest_wave.value], [closest_flux.value]) # noqa
self.label_mouseover.marks[self._reference_id].visible = True
else:
# show exact plot coordinates (useful for drawing spectral subsets or zoom ranges)
fmt = 'x={:+10.5e} y={:+10.5e}'
self.label_mouseover.icon = ""
self.label_mouseover.pixel = fmt.format(x, y)
self.label_mouseover.marks[self._reference_id].visible = False

elif data['event'] == 'mouseleave' or data['event'] == 'mouseenter':
Expand Down
24 changes: 9 additions & 15 deletions jdaviz/configs/specviz/tests/test_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,13 +225,11 @@ def test_get_spectral_regions_unit_conversion(specviz_helper, spectrum1d):
# Also check coordinates info panel.
# x=0 -> 6000 A, x=1 -> 6222.222 A
spec_viewer.on_mouse_or_key_event({'event': 'mousemove', 'domain': {'x': 6100, 'y': 12.5}})
assert spec_viewer.label_mouseover.pixel == 'x=00.0' # Actual: x=00.4
assert spec_viewer.label_mouseover.pixel == '6.10000e+03, 1.25000e+01'
assert spec_viewer.label_mouseover.world_label_prefix == 'Wave'
assert spec_viewer.label_mouseover.world_ra == '6.00000e+03'
assert spec_viewer.label_mouseover.world_dec == 'Angstrom'
assert spec_viewer.label_mouseover.world_ra == '6.00000e+03 Angstrom (0 pix)' # actual: 0.4
assert spec_viewer.label_mouseover.world_label_prefix_2 == 'Flux'
assert spec_viewer.label_mouseover.world_ra_deg == '1.24967e+01'
assert spec_viewer.label_mouseover.world_dec_deg == 'Jy'
assert spec_viewer.label_mouseover.world_ra_deg == '1.24967e+01 Jy'
assert spec_viewer.label_mouseover.icon == 'a'
spec_viewer.on_mouse_or_key_event({'event': 'mousemove', 'domain': {'x': None, 'y': 12.5}})
assert spec_viewer.label_mouseover.pixel == ''
Expand Down Expand Up @@ -266,13 +264,11 @@ def test_get_spectral_regions_unit_conversion(specviz_helper, spectrum1d):

# Coordinates info panel should show new unit
spec_viewer.on_mouse_or_key_event({'event': 'mousemove', 'domain': {'x': 0.61, 'y': 12.5}})
assert spec_viewer.label_mouseover.pixel == 'x=00.0'
assert spec_viewer.label_mouseover.pixel == '6.10000e-01, 1.25000e+01'
assert spec_viewer.label_mouseover.world_label_prefix == 'Wave'
assert spec_viewer.label_mouseover.world_ra == '6.00000e-01'
assert spec_viewer.label_mouseover.world_dec == 'micron'
assert spec_viewer.label_mouseover.world_ra == '6.00000e-01 micron (0 pix)'
assert spec_viewer.label_mouseover.world_label_prefix_2 == 'Flux'
assert spec_viewer.label_mouseover.world_ra_deg == '1.24967e+01'
assert spec_viewer.label_mouseover.world_dec_deg == 'Jy'
assert spec_viewer.label_mouseover.world_ra_deg == '1.24967e+01 Jy'
assert spec_viewer.label_mouseover.icon == 'b'
spec_viewer.on_mouse_or_key_event({'event': 'mouseleave'})
assert spec_viewer.label_mouseover.pixel == ''
Expand Down Expand Up @@ -401,11 +397,9 @@ def test_spectra_partial_overlap(specviz_helper):
# Test mouseover outside of left but in range for right.
# Should show right spectrum even when mouse is near left flux.
spec_viewer.on_mouse_or_key_event({'event': 'mousemove', 'domain': {'x': 7022, 'y': 1000}})
assert spec_viewer.label_mouseover.pixel == 'x=02.0'
assert spec_viewer.label_mouseover.pixel == '7.02200e+03, 1.00000e+03'
assert spec_viewer.label_mouseover.world_label_prefix == 'Wave'
assert spec_viewer.label_mouseover.world_ra == '7.02222e+03'
assert spec_viewer.label_mouseover.world_dec == 'Angstrom'
assert spec_viewer.label_mouseover.world_ra == '7.02222e+03 Angstrom (2 pix)'
assert spec_viewer.label_mouseover.world_label_prefix_2 == 'Flux'
assert spec_viewer.label_mouseover.world_ra_deg == '6.00000e+01'
assert spec_viewer.label_mouseover.world_dec_deg == 'nJy'
assert spec_viewer.label_mouseover.world_ra_deg == '6.00000e+01 nJy'
assert spec_viewer.label_mouseover.icon == 'b'
6 changes: 2 additions & 4 deletions jdaviz/configs/specviz2d/tests/test_parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,11 @@ def test_2d_parser_no_unit(specviz2d_helper, mos_spectrum2d):

viewer_1d = specviz2d_helper.app.get_viewer('spectrum-viewer')
viewer_1d.on_mouse_or_key_event({'event': 'mousemove', 'domain': {'x': 6.5, 'y': 3}})
assert viewer_1d.label_mouseover.pixel == 'x=006.0'
assert viewer_1d.label_mouseover.pixel == '6.50000e+00, 3.00000e+00'
assert viewer_1d.label_mouseover.world_label_prefix == 'Wave'
assert viewer_1d.label_mouseover.world_ra == '6.00000e+00'
assert viewer_1d.label_mouseover.world_dec == 'pix'
assert viewer_1d.label_mouseover.world_ra == '6.00000e+00 pix'
assert viewer_1d.label_mouseover.world_label_prefix_2 == 'Flux'
assert viewer_1d.label_mouseover.world_ra_deg == '-3.59571e+00'
assert viewer_1d.label_mouseover.world_dec_deg == ''
assert viewer_1d.label_mouseover.icon == 'b'


Expand Down

0 comments on commit 9be2cf4

Please sign in to comment.