Skip to content

Commit

Permalink
Linelist improvements (#1327)
Browse files Browse the repository at this point in the history
* First pass: Copy logic from plot options collapsible color picker

* Add missing Bool Traitlet

* Remove unneeded template; call item directly

Co-authored-by: Kyle Conroy <kyleconroy@gmail.com>

* Use item key to reference list_contents dict to retrieve color; force reset dict for traitlet

Co-authored-by: Kyle Conroy <kyleconroy@gmail.com>

* Cleanup dict reset to trigger only one UI change

Co-authored-by: Kyle Conroy <kyleconroy@gmail.com>

* Only open active linelist color picker

* Throttle Color Picker

* Add colorpicker tooltip

* Move color picker to expansion header

* Add tooltip to color picker

* Add icons to plot/erase all btns; make btns solid

* Add btn to filter spectral range

* Codestyle

* Set spectral range icon to bell curve

* Add Lines separator

* Prevent Linelist header from overflowing; collapse name with ellipsis if needed

* Fit spectral range button on same line as line search

* Update Plot/Erase All Button Styling

* Condense Rest/Obs Freq textfields

* First pass: Filter on wavelength range

* Patch debugging change

* Track spectrum viewer limits by traitlet

* Spectral Range btn styling

* Spectral range works independently of text filter

* Remove unneeded vue method

* Codestyle

* Clarify Tooltip

* Add changelog entry

* Add new icon and adjust padding

* Change callback strategy to mitigate race condition

Co-authored-by: Kyle Conroy <kyleconroy@gmail.com>

* Codestyle

* Replace All Lists plot buttons with new style

* Remove number type from rest wavelength display to disable arrow incrementers in firefox

* Make wavelength fields dense

* Move list buttons to top, adjust ordering of line descriptors

* Introduce manual label to allow bolding of wavelength labels

* Add comment to indicate RS slider relying on traitlet value

* Add missing height directive

* Increase padding between line elements

* Fix vertical padding between Line Name and wavelength fields

Co-authored-by: Kyle Conroy <kyleconroy@gmail.com>
  • Loading branch information
duytnguyendtn and kecnry authored May 20, 2022
1 parent 7e1454f commit c372458
Show file tree
Hide file tree
Showing 6 changed files with 187 additions and 86 deletions.
3 changes: 3 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ Mosviz
Specviz
^^^^^^^

- Line List Spectral Range filter displays only lines with an observed
wavelength within the range of the spectrum viewer [#1327]

API Changes
-----------

Expand Down
2 changes: 2 additions & 0 deletions jdaviz/components/tooltip.vue
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ const tooltips = {
'plugin-line-lists-line-identify-chip-inactive': 'No line currently highlighted. Use selection tool in spectrum viewer to identify a line.',
'plugin-line-lists-line-visible': 'Toggle showing the line in the spectrum viewer',
'plugin-line-lists-line-identify': 'Highlight this line in the spectrum viewer for easy identification',
'plugin-line-lists-color-picker': 'Change the color of this list',
'plugin-line-lists-spectral-range': 'Toggle filter to only lines observable within the range of the Spectrum Viewer',
'plugin-line-analysis-sync-identify': 'Lock/unlock selection with identified line',
'plugin-line-analysis-assign': 'Assign the centroid wavelength and update the redshift',
'plugin-moment-save-fits': 'Save moment map as FITS file',
Expand Down
7 changes: 7 additions & 0 deletions jdaviz/components/tray_plugin.vue
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@ module.exports = {
padding-left: 0px !important;
}
.row-no-vertical-padding-margin {
padding-top: 0px !important;
padding-bottom: 0px !important;
margin-bottom: 0px !important;
margin-top: 0px !important;
}
.row-no-outside-padding .col:last-of-type {
padding-right: 0px !important;
}
Expand Down
33 changes: 27 additions & 6 deletions jdaviz/configs/default/plugins/line_lists/line_lists.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,13 @@ class LineListTool(PluginTemplateMixin):
custom_unit = Unicode().tag(sync=True)

lines_filter = Any().tag(sync=True) # string or None
filter_range = Bool(False).tag(sync=True)
spectrum_viewer_min = Float(0.01).tag(sync=True)
spectrum_viewer_max = Float(0.01).tag(sync=True)

identify_label = Unicode().tag(sync=True)
identify_line_icon = Unicode(read_icon(os.path.join(ICON_DIR, 'line_select.svg'), 'svg+xml')).tag(sync=True) # noqa
filter_range_icon = Unicode(read_icon(os.path.join(ICON_DIR, 'spectral_range.svg'), 'svg+xml')).tag(sync=True) # noqa

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
Expand Down Expand Up @@ -103,7 +107,10 @@ def __init__(self, *args, **kwargs):
handler=self._process_identify_change)

# if set to auto (default), update the slider range when zooming on the spectrum viewer
self._viewer.scales['x'].observe(self._auto_slider_range, names=['min', 'max'])
self._viewer.state.add_callback("x_min",
lambda x_min: self._on_spectrum_viewer_limits_changed())
self._viewer.state.add_callback("x_max",
lambda x_max: self._on_spectrum_viewer_limits_changed())

def _on_viewer_data_changed(self, msg=None):
"""
Expand Down Expand Up @@ -155,7 +162,7 @@ def _on_viewer_data_changed(self, msg=None):
self.rs_redshift = (viewer_data.redshift.value
if hasattr(viewer_data.redshift, 'value')
else viewer_data.redshift)
self._auto_slider_range() # will also trigger _auto_slider_step
self._on_spectrum_viewer_limits_changed() # will also trigger _auto_slider_step

# set the choices (and default) for the units for new custom lines
self.custom_unit_choices = create_spectral_equivalencies_list(viewer_data)
Expand Down Expand Up @@ -367,12 +374,23 @@ def vue_slider_reset(self, event):
# updating during slide, so update them now
self.vue_unpause_tables()

def _on_spectrum_viewer_limits_changed(self, event=None):
sv = self.app.get_viewer('spectrum-viewer')
self.spectrum_viewer_min = sv.state.x_min
self.spectrum_viewer_max = sv.state.x_max

# Also update the slider range
self._auto_slider_range()

def _auto_slider_range(self, event=None):
"""
Automatically adjusts the Redshift slider range to the values of the
spectrum_viewer_min and spectrum_viewer_max traitlets
"""
if not self.rs_slider_range_auto:
return
# if set to auto, default the range based on the limits of the spectrum plot
sv = self.app.get_viewer('spectrum-viewer')
x_min, x_max = sv.state.x_min, sv.state.x_max
x_min, x_max = self.spectrum_viewer_min, self.spectrum_viewer_max
x_mid = abs(x_max + x_min) / 2.
# we'll *estimate* the redshift range to shift the range of the viewer
# (for a line with a rest wavelength in the center of the viewer),
Expand All @@ -393,7 +411,7 @@ def _auto_slider_range(self, event=None):
@observe('rs_slider_range_auto')
def _on_rs_slider_range_auto_updated(self, event):
if event['new']:
self._auto_slider_range()
self._on_spectrum_viewer_limits_changed()

@observe('rs_slider_half_range')
def _auto_slider_step(self, event=None):
Expand Down Expand Up @@ -740,7 +758,8 @@ def vue_set_color(self, data):
color = data['color']
if "listname" in data:
listname = data["listname"]
lc = self.list_contents[listname]
# force a copy so that the change is picked up by traitlets
lc = self.list_contents[listname].copy()
lc["color"] = color

for line in lc["lines"]:
Expand All @@ -752,6 +771,8 @@ def vue_set_color(self, data):
if name_rest in self.line_mark_dict:
self.line_mark_dict[name_rest].colors = [color]

self.list_contents = {**self.list_contents, listname: lc}

elif "linename" in data:
pass

Expand Down
Loading

0 comments on commit c372458

Please # to comment.