Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Expose spectrum-viewer bounds in UI #2604

Merged
merged 21 commits into from
Jan 8, 2024

Conversation

rosteen
Copy link
Collaborator

@rosteen rosteen commented Dec 11, 2023

This allows the user to update the bounds of the spectrum viewer from the Plot Options plugin. I erred on the conservative side for now, and only have this active in single-select with spectrum-viewer chosen, or in multi-select if only spectrum-viewer is chosen.

Still needs tests, and it probably actually needs to handle the case of multiple non-image viewers already - I was thinking that everything in Jdaviz only has a single spectrum-viewer, but @kecnry does lcviz have multiple profile viewers already that we would want to update with this?

Copy link

codecov bot commented Dec 11, 2023

Codecov Report

Attention: 4 lines in your changes are missing coverage. Please review.

Comparison is base (88a5ed1) 91.52% compared to head (b31e268) 91.53%.

Files Patch % Lines
...nfigs/default/plugins/plot_options/plot_options.py 92.98% 4 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2604      +/-   ##
==========================================
+ Coverage   91.52%   91.53%   +0.01%     
==========================================
  Files         161      161              
  Lines       19995    20056      +61     
==========================================
+ Hits        18300    18359      +59     
- Misses       1695     1697       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@kecnry
Copy link
Member

kecnry commented Dec 11, 2023

lcviz doesn't have profile viewers, but it definitely would be nice for this to be able to work there. The only thing that I think needs to be disabled for now is image viewers (because we need to respect aspect ratio, which probably means setting the center and zoom level, or deciding to recompute limits that encompass the user-provided bounds, etc).

@camipacifici
Copy link
Contributor

I just tried this in Cubeviz and it works really well!! Thank you!!

@kecnry
Copy link
Member

kecnry commented Dec 11, 2023

@rosteen - could we use something like #2606 to handle mixed state (by having an overlay over the entire widget you created if mixed state is detected in any of the inputs)?

@rosteen rosteen added this to the 3.9 milestone Dec 12, 2023
@rosteen rosteen added UI/UX😍 plugin Label for plugins common to multiple configurations labels Dec 12, 2023
@rosteen rosteen force-pushed the specviz-viewer-bounds-ui branch 2 times, most recently from 2b717e0 to 0560f05 Compare December 19, 2023 19:46
@rosteen rosteen marked this pull request as ready for review December 19, 2023 19:47
@rosteen
Copy link
Collaborator Author

rosteen commented Dec 19, 2023

@camipacifici Would you try this again, please? Due to some updates it now live updates the viewer bounds as you edit the fields, I want to check that that behavior is ok for this.

@camipacifici
Copy link
Contributor

I like it! Responds well. It's ok for me.

Copy link
Contributor

@cshanahan1 cshanahan1 left a comment

Choose a reason for hiding this comment

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

This looks good so far, just adding some comments now and i'll continue to test and review:

  1. a 'reset' button might be nice to have in the plugin. i know the home button will do the same thing but i think it would be nice to also have it here.
  2. display less decimal points?
  3. are there any consequences to having an empty entry for a boundary? you can delete one of the bounds entirely and if you click off it it doesn't snap back to its previous value or zero. this doesn't seem to matter but im not sure if the viewer limits are being used elsewhere and this could cause issues

@@ -753,14 +753,19 @@ def _update_viewer_bound_steps(self, msg={}):

viewer = self.viewer.selected_obj[0] if self.viewer_multiselect else self.viewer.selected_obj # noqa
if not isinstance(viewer.state, ImageViewerState):
# We round these values to show, e.g., 7.15 instead of 7.1499999
Copy link
Member

Choose a reason for hiding this comment

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

this also limits the ability to zoom in to small wavelength ranges... I'm not sure that is worth it

Copy link
Member

Choose a reason for hiding this comment

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

maybe decimals can be based on the current range instead?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Changing this to depend on the difference between min and max rather than just max makes sense to me.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

That also prevents decreasing v_max to be less than v_min, which is nice.

@rosteen
Copy link
Collaborator Author

rosteen commented Dec 28, 2023

Note that using glue-float-field to handle empty fields now requires glue-viz/glue-jupyter#417, since currently glue-float-field doesn't respect input step values.

bound_step = (viewer.state.x_max) / 100.
decimals = -int(np.log10(bound_step))+1
bound_step = (viewer.state.x_max - viewer.state.x_min) / 100.
decimals = -int(np.log10(bound_step)) + 1
Copy link
Member

Choose a reason for hiding this comment

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

otherwise this can result in an OverflowError if bound_step == 0 (not sure what makes sense for the fallback, and will need to apply this to the case for y as well).

Suggested change
decimals = -int(np.log10(bound_step)) + 1
decimals = -int(np.log10(bound_step)) + 1 if bound_step > 0 else 6

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

How about just wrapping bound_step in abs() instead? I think we want that anyway now that I think about it - or are you thinking about a reverse axis case where the up arrow should decrease the value?

Copy link
Member

Choose a reason for hiding this comment

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

We still need to handle the bound_step==0 case in which log10(0) will resolve to -inf and raise an error when casting to an integer.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Honestly we should probably prevent min=max in general somewhere else, but for now I added this check.

Comment on lines 772 to 773
# This button is currently only exposed if only the spectrum viewer is selected
viewer = self.app.get_viewer('spectrum-viewer')
Copy link
Member

Choose a reason for hiding this comment

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

can we use the selected viewer reference directly instead of hardcoding for spectrum-viewer?

@@ -39,6 +39,64 @@
:hint="viewer_multiselect ? 'Select viewers to set options simultaneously' : 'Select the viewer to set options.'"
/>

<v-row v-if="viewer_selected === 'spectrum-viewer' || (viewer_selected[0] === 'spectrum-viewer' && viewer_selected.length === 1)">
Copy link
Member

@kecnry kecnry Jan 2, 2024

Choose a reason for hiding this comment

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

this logic prevents this from being used in lcviz (and will conflict with any future support for renaming viewers). I think we should be able to rely on the info in the sync traitlets to determine whether this is applicable or not.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I had worked on generalizing this and then reverted to just the initial scope of spectrum-viewer - I remember it was partially working for LCViz but something was messed up, don't remember exactly why I abandoned it. I can try that again now that some other things are resolved.

Copy link
Member

Choose a reason for hiding this comment

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

does the logic have to be in python with an extra traitlet or can we just use the existing logic in the PlotOptionsSyncState by doing v-if="viewer_x_min_sync.in_subscribed_states"?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I don't really know the details of what subscribed states is doing, so: maybe? 😆

I'll give it a try.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah, that doesn't stop the viewer bounds menu from showing up if you multiselect a spectrum viewer and an image viewer. So I think the way I have it now is necessary.

Copy link
Member

Choose a reason for hiding this comment

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

but I think that's ok and consistent with how everything else works in plot options. Do the viewer numbers appear in mutliselect (if not, that might avoid any confusion).

@rosteen
Copy link
Collaborator Author

rosteen commented Jan 2, 2024

@kecnry this now works in LCViz (as far as I tested anyway) and I also fixed a bug I noticed with the decimal rounding for large (>10) min/max separations.

Copy link
Contributor

@cshanahan1 cshanahan1 left a comment

Choose a reason for hiding this comment

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

this looks good and works well for me!

the only minor suggestion i have is that floats like (1., 2.) aren't accepted and i think it is reasonable that they should be

@kecnry kecnry mentioned this pull request Jan 5, 2024
15 tasks
@rosteen rosteen force-pushed the specviz-viewer-bounds-ui branch from 805aaa5 to b31e268 Compare January 8, 2024 13:42
@rosteen
Copy link
Collaborator Author

rosteen commented Jan 8, 2024

the only minor suggestion i have is that floats like (1., 2.) aren't accepted and i think it is reasonable that they should be

Hm, that seems to work ok for me:

Screenshot 2024-01-08 at 8 51 23 AM

Copy link
Member

@kecnry kecnry left a comment

Choose a reason for hiding this comment

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

Let's get this in and we can iterate on any multiviewer support as part of #2649 on top of this. Thanks!

@rosteen rosteen merged commit 03edac6 into spacetelescope:main Jan 8, 2024
14 of 15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
plugin Label for plugins common to multiple configurations UI/UX😍
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants