Skip to content
New issue

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

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

Already on GitHub? # to your account

re-usable component for viewer dropdown #1195

Merged
merged 4 commits into from
Mar 29, 2022

Conversation

kecnry
Copy link
Member

@kecnry kecnry commented Mar 24, 2022

Description

This pull request continues the pattern in #1156 to pull up duplicated logic from plugins and into a re-usable component for viewer select dropdowns. In doing so, it also gives flexibility for reference vs ID (so that cubeviz will show the more user-friendly "uncert-viewer" names instead of "cubeviz-2" but imviz will still work with IDs since references are never created). All other functionality should be unchanged - this is mostly just a code refactoring.

Checklist for package maintainer(s)

This checklist is meant to remind the package maintainer(s) who will review this pull request of some common things to look for. This list is not exhaustive.

  • Are two approvals required? Branch protection rule does not check for the second approval. If a second approval is not necessary, please apply the trivial label.
  • Do the proposed changes actually accomplish desired goals? Also manually run the affected example notebooks, if necessary.
  • Do the proposed changes follow the STScI Style Guides?
  • Are tests added/updated as required? If so, do they follow the STScI Style Guides?
  • Are docs added/updated as required? If so, do they follow the STScI Style Guides?
  • Did the CI pass? If not, are the failures related?
  • Is a change log needed? If yes, is it added to CHANGES.rst?
  • Is a milestone set?
  • After merge, any internal documentations need updating (e.g., JIRA, Innerspace)?

@github-actions github-actions bot added the imviz label Mar 24, 2022
@kecnry kecnry added this to the 2.4 milestone Mar 24, 2022
@kecnry kecnry added the plugin Label for plugins common to multiple configurations label Mar 24, 2022
@kecnry kecnry force-pushed the viewer-select-component branch from 177fda0 to c3d3d48 Compare March 24, 2022 20:03
@codecov
Copy link

codecov bot commented Mar 24, 2022

Codecov Report

Merging #1195 (54a502c) into main (918464d) will increase coverage by 0.00%.
The diff coverage is 91.76%.

@@           Coverage Diff           @@
##             main    #1195   +/-   ##
=======================================
  Coverage   77.99%   77.99%           
=======================================
  Files          90       90           
  Lines        7143     7175   +32     
=======================================
+ Hits         5571     5596   +25     
- Misses       1572     1579    +7     
Impacted Files Coverage Δ
...configs/default/plugins/export_plot/export_plot.py 64.28% <66.66%> (-15.72%) ⬇️
jdaviz/configs/imviz/plugins/compass/compass.py 72.72% <90.00%> (-12.28%) ⬇️
jdaviz/core/template_mixin.py 92.53% <91.22%> (-0.41%) ⬇️
jdaviz/app.py 91.04% <100.00%> (+0.01%) ⬆️
...nfigs/default/plugins/plot_options/plot_options.py 95.12% <100.00%> (+1.24%) ⬆️
jdaviz/core/tools.py 75.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 918464d...54a502c. Read the comment docs.

@kecnry kecnry added the no-changelog-entry-needed changelog bot directive label Mar 24, 2022
@kecnry kecnry force-pushed the viewer-select-component branch 3 times, most recently from 8fb74b8 to 4383328 Compare March 28, 2022 12:58
@kecnry kecnry marked this pull request as ready for review March 28, 2022 14:21
@javerbukh
Copy link
Contributor

Got a traceback when running the MosvizNIRISS example notebook, which links to this section:
https://github.com/spacetelescope/jdaviz/blob/main/jdaviz/configs/mosviz/helper.py#L470-L475

@kecnry
Copy link
Member Author

kecnry commented Mar 28, 2022

Got a traceback when running the MosvizNIRISS example notebook

I can't seem to reproduce. Did you do anything other than running the cells? (I also doubt that anything in that line should be caused by this PR, but still worth investigating).

I'll work to rebase on main as well since I see there are now conflicts.

@javerbukh
Copy link
Contributor

Nothing other than running the cells. Specifically it was line 475 that caused the traceback. I'll try again after you rebase.

* pulls duplicated logic from plugins into a component/mixin
* all instances now show (to the user) the reference if it exists and falls back on the ID (which is required for additional viewers in imviz)
@kecnry kecnry force-pushed the viewer-select-component branch from 4383328 to 2d4b311 Compare March 28, 2022 20:31
Copy link
Contributor

@pllim pllim left a comment

Choose a reason for hiding this comment

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

General review right now. I will do some manual testing tomorrow, in case you decide to apply some updates to the code.

In principle, I like the simplification of code across the board. Thanks!

jdaviz/core/template_mixin.py Outdated Show resolved Hide resolved
jdaviz/core/template_mixin.py Show resolved Hide resolved
jdaviz/core/template_mixin.py Outdated Show resolved Hide resolved
jdaviz/core/template_mixin.py Outdated Show resolved Hide resolved
jdaviz/core/template_mixin.py Outdated Show resolved Hide resolved
for item in self.items:
if item['ref_or_id'] == self.selected:
return item
# try again but this time allow match to id alone. Note that _selected_changed
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this needed? Looks like the tests don't go here according to codecov.

Copy link
Member Author

Choose a reason for hiding this comment

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

This is needed in order to support setting the selected item based on the id. I think its worth keeping, so will add tests to cover it.

jdaviz/core/template_mixin.py Outdated Show resolved Hide resolved
d = {'id': viewer_item['id']}
if viewer_item.get('reference') is not None:
d['reference'] = viewer_item['reference']
d['ref_or_id'] = viewer_item['reference']
Copy link
Contributor

Choose a reason for hiding this comment

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

This gives me a headache. Haha. We really need to get rid of reference some day.

d['ref_or_id'] = viewer_item['id']
return d

self.items = [_dict_from_viewer(self.app._viewer_item_by_id(vid))
Copy link
Contributor

Choose a reason for hiding this comment

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

Why store as a separate dict here instead of accessing app._viewer_store directly in the mixin?

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm not sure that would work... it needs to be a traitlet so that it can push changes to the UI.

jdaviz/core/template_mixin.py Outdated Show resolved Hide resolved
Co-authored-by: P. L. Lim <2090236+pllim@users.noreply.github.com>
@kecnry kecnry force-pushed the viewer-select-component branch from 915c6bd to 60241e9 Compare March 29, 2022 13:10
* and use cubeviz with multiple viewers instead of specviz
Copy link
Contributor

@javerbukh javerbukh left a comment

Choose a reason for hiding this comment

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

New conda environment fixed the problem I was seeing. After testing all the configurations everything functions as expected. Nice work!

NOTE: isinstance instead of class name would result in circular import
Copy link
Collaborator

@rosteen rosteen left a comment

Choose a reason for hiding this comment

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

Works in the contexts where it's currently used, code looks good I think. I'm glad you documented the usage a bit in the mixin docstring, but it does remind me that we're due for a bit of a developer docs refresh at some point.

Testing this made me notice one small bug, but it's also present on main so I'll report it in a separate issue.

@rosteen rosteen merged commit 9dc0124 into spacetelescope:main Mar 29, 2022
@kecnry kecnry deleted the viewer-select-component branch March 29, 2022 15:47
@kecnry kecnry mentioned this pull request Mar 31, 2022
9 tasks
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
imviz no-changelog-entry-needed changelog bot directive plugin Label for plugins common to multiple configurations Ready for final review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants