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

Allow basic editing for supported shapes and display rotation for rectangle and ellipse #1427

Merged
merged 9 commits into from
Aug 12, 2022

Conversation

pllim
Copy link
Contributor

@pllim pllim commented Jun 28, 2022

Description

This pull request is to allow basic shape editing. Also shows rotation angle for some shapes.

Screenshot 2022-08-05 223316

Related:

Address the centering part of #634 because rotation is blocked by glue-viz/glue-astronomy#74 .

TODO

  • Allow edit of region center
  • Allow edit of region radius/width
  • Allow edit of angles. While edit is possible, we cannot get that rotated shape back out. This needs upstream fix, so disable for now.
  • What about composite regions? Edit is disabled for composite regions.
  • What about masked subset? Edit is disabled for masked subset.
  • Have clear message for weird shapes where edits not allowed. Not needed, we just hide the GUI.
  • Make sure this works with other stuff. For example, does Aperture Photometry take rotated Subset?
  • Write tests
  • Update docs
  • Optional: Why does this not play nice with ipypopout?

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)? 🐱

@pllim pllim added this to the 2.7 milestone Jun 28, 2022
@codecov
Copy link

codecov bot commented Jun 28, 2022

Codecov Report

Merging #1427 (11d5ec4) into main (feadcb9) will increase coverage by 0.06%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##             main    #1427      +/-   ##
==========================================
+ Coverage   85.45%   85.52%   +0.06%     
==========================================
  Files          94       94              
  Lines        9061     9111      +50     
==========================================
+ Hits         7743     7792      +49     
- Misses       1318     1319       +1     
Impacted Files Coverage Δ
...igs/default/plugins/subset_plugin/subset_plugin.py 97.81% <100.00%> (+<0.01%) ⬆️
jdaviz/core/template_mixin.py 91.30% <100.00%> (+0.04%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@rosteen rosteen modified the milestones: 2.7, 2.8 Jul 6, 2022
@rosteen rosteen modified the milestones: 2.8, 2.9 Jul 21, 2022
@pllim pllim force-pushed the you-spin-me-right-round-right-round branch from 5b002c6 to 32d2fe7 Compare August 3, 2022 19:53
@pllim pllim changed the title Allow rotation for rectangle and ellipse Allow basic editing for supported shapes and rotation for rectangle and ellipse Aug 3, 2022
@pllim pllim changed the title Allow basic editing for supported shapes and rotation for rectangle and ellipse Allow basic editing for supported shapes and display rotation for rectangle and ellipse Aug 5, 2022
@pllim pllim force-pushed the you-spin-me-right-round-right-round branch from 3b5b8ef to 1cff3f1 Compare August 6, 2022 02:14
@pllim pllim marked this pull request as ready for review August 6, 2022 02:30
Copy link
Collaborator

@duytnguyendtn duytnguyendtn left a comment

Choose a reason for hiding this comment

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

Currently working on a full review, but wanted to get this feature request in, in the mean time: could it be possible to apply the update when I press "Enter" on a field? Even better if it automatically moves me down to the next field? 🙏

@pllim
Copy link
Contributor Author

pllim commented Aug 8, 2022

Even better if it automatically moves me down to the next field?

That is some front-end dark magic that I don't know how to do. If you do, please suggest the changes!

Does <tab> already works? I never tried it.

Comment on lines 29 to 34
<v-text-field
:label="item.name"
v-model.number="item.value"
type="number"
:disabled="item.name=='Angle'"
></v-text-field>
Copy link
Collaborator

@duytnguyendtn duytnguyendtn Aug 8, 2022

Choose a reason for hiding this comment

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

For the former, I think it would be something like this:

Suggested change
<v-text-field
:label="item.name"
v-model.number="item.value"
type="number"
:disabled="item.name=='Angle'"
></v-text-field>
<v-text-field
:label="item.name"
v-model.number="item.value"
@keyup.enter="update_subset"
type="number"
:disabled="item.name=='Angle'"
></v-text-field>

Injecting it in on myside seems to do the trick

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm... but this will:

(a) make this plugin behavior different from the other ones; and
(b) might prematurely update a shape when someone accidentally hits enter but really want to also update other fields?

Copy link
Collaborator

Choose a reason for hiding this comment

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

(a) make this plugin behavior different from the other ones

I'm not sure if there's a consistent pattern here. Take, for instance, the Line Width field for plot options: when I update the text field, it immediately updates the line width, doesn't even wait for the user. I'd argue that it might be annoying to the user to have the field update while the user is trying to type the bounds, hence why I proposed Enter to accept. Though now that I say it, is the UPDATE button even necessary in this context? Why not just have it accept automatically? Which of course leads to...

want to also update other fields?

Is there a problem with updating one field at a time? I don't necessarily see it as an issue if I update the xcenter and THEN the ycenter rather than changing both fields simultaneously

Copy link
Collaborator

@duytnguyendtn duytnguyendtn Aug 8, 2022

Choose a reason for hiding this comment

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

Come to think about it, I wonder if the disconnect here has to do with perspective. For Line Width I think of that field as an actual representation of the value, hence when I change the number, I expect it to immediately update. For Model Fit, it's more like a command, so I fill out all the necessary boxes and then tell it to activate via the button click.

As I tested it now, this PR appears to be more of the "command" like paradigm, where the user fills out all the information and then actively requests the plugin to "UPDATE" the subset by pressing the button. I suppose my request is really wondering whether it would be better to change this to the "representation" paradigm to have it behave more like plot options, like Line Width for instance.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Subset update may be expensive, because it might affect other calculations etc. You would only want to update it when you are sure you want to update it.

Copy link
Member

Choose a reason for hiding this comment

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

here are the options for updating a traitlet from a v-text-field with type="number" that are used elsewhere already:

  • live updating on keypress: use v-model (see slice plugin for a good example) and then @observe in python. We use this quite often and it mimics what glue widgets do, so unless there are performance limitations, this might be worth trying first.
  • update on change (loss of focus) or mousepress on the up/down buttons: use @change and @mousedown to call a JS or python method to update the traitlet manually (play_pause widget does something similar - but this also uses v-model and just triggers acting on it at those times, you could do the same to always have the traitlet update but only trigger the “update” when this happens, or if you want to have an @observe still in python, then you might need extra traitlets).

Copy link
Contributor Author

@pllim pllim Aug 9, 2022

Choose a reason for hiding this comment

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

Re: lag -- I tried with 6 4k x 2k and Imviz is already super laggy (the lag from Subset update doesn't matter much at that point because the whole thing is unusable, which is out of scope here). With 4 of those images, Imviz lag is tolerable but you can really see the lag in Subset shape catching up with each click to Update. So, I am still not convinced live-updating is a good idea.

You can try for yourselves like this:

  1. Open up Imviz example notebook.
  2. Load the example images twice (so you get 4 total) with this additional call:
imviz.load_data(acs_47tuc_1, data_label='acs_47tuc_3')
imviz.load_data(acs_47tuc_2, data_label='acs_47tuc_4')
  1. Link them by WCS without fast approximation: imviz.link_data(link_type='wcs', wcs_use_affine=False)
  2. Draw a Subset.
  3. Use this new edit feature and change some field of the Subset, click Update. See lag.

Copy link
Contributor Author

@pllim pllim Aug 9, 2022

Choose a reason for hiding this comment

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

p.s. This step is also important: imviz.link_data(link_type='wcs', wcs_use_affine=False) (links them by WCS without fast approximation). I updated the instructions above.

Copy link
Member

Choose a reason for hiding this comment

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

Down the road I think we can either look into improving the performance or perhaps have this plugin check the number of links (and if fast approximation is enabled) and switch itself between live-updating and the update button. But I'm ok considering that as a follow-up effort and moving forward with the PR with the update button.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Having the button come and go is even more confusing than just allowing live-update unconditionally. But I agree this can be future work.

Please approve if the PR is okay as-is or if there are more changes needed here. Thanks!

@duytnguyendtn
Copy link
Collaborator

duytnguyendtn commented Aug 8, 2022

Does tab already works?

Come to think about it, maybe is sufficient if my cursor stayed selected on the field. If the former suggestion works (press enter to auto update), and my cursor stayed on the same field, then I could just press tab to advance. The problem currently is when I press enter, it takes my cursor off, so I have to go back to my mouse to reselect on the next field

@pllim
Copy link
Contributor Author

pllim commented Aug 8, 2022

when I press enter, it takes my cursor off

But why are you pressing Enter in the first place? It currently does not do anything. I think this applies to all the plugins.

@duytnguyendtn
Copy link
Collaborator

It currently does not do anything

Sorry, that comment was meant for if we go with the "press enter to update" direction

Copy link
Collaborator

@duytnguyendtn duytnguyendtn left a comment

Choose a reason for hiding this comment

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

Ok here's my official review! Functionality and code looks good! Thanks Pey-Lian!

I have one comment concerning the spacing of the elements, and another in the above chain concerning the UPDATE button. IMHO, I feel these the subset tools plugin should behave more like an "inspector", similar to Plot Options. By that I mean modifications to the values should immediately (or if not immediately, then at least when the user "exits" the scope of the text field by clicking off or pressing ENTER. Therefore, the UPDATE button would be largely unnecessary, like how we don't have one in Plot Options. I'll try to remember to bring this up at parking lot tomorrow for the team to discuss

Comment on lines 26 to 29
<div v-if="is_editable">
<v-row v-for="(item, index2) in subset_definitions[0]" no-gutters>
<v-col>
<v-text-field
Copy link
Collaborator

Choose a reason for hiding this comment

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

Not sure whether we want to include this in scope, but I feel like this spacing feels awkwardly large to me. Thoughts @Jenneh?
image

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll be happy to reduce the spacing if you tell me how to do it.

I am still hesitant about the "update immediately" model. I feel like the performance hit is going to come back and bite us as we build more features. But we can discuss tomorrow.

Copy link
Member

Choose a reason for hiding this comment

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

The extra spacing is caused by the nested v-cols inside v-rows. When there is only a single column, its easiest to just remove v-col entirely. Otherwise you'll want to add class="row-no-outside-padding" to the v-row. See the third bullet in the plugin style guide (and feel free to clean that up if any of it seems confusing)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I removed the v-col (didn't make much difference) and neither did class="row-no-outside-padding", but the class="pt-0 pb-0 mt-0 mb-0" seems to work. I copy-pasted that from other parts of subset_plugin.vue.

@pllim pllim force-pushed the you-spin-me-right-round-right-round branch from 3a14b2c to 0db834f Compare August 9, 2022 22:44
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.

Seems to work well! Is support for editing sub-subsets out-of-scope (it can display the sub-subsets, but doesn't show the logical operators between them)?

Is there a need for displaying both the edit box and the static read-only version of the subset parameters in cases where editing is supported? It seems to me that showing both sections adds quite a bit of code overhead (needing to trace the current widget value in addition to the original value), that might be simplified if the read-only section is just replaced with the widgets when editing is supported? But then without live-updating, we might want to have a cancel/reset button to revert the widget values to the current state?

@camipacifici
Copy link
Contributor

This looks very nice!
I tried both in Imviz and Specviz and here are my comments:

  • Indeed there is a lag when not using the fast approximation when linking in Imviz. The lag is present (and annoying) even with just 2 images on my machine. Out of scope for this ticket, but it needs to be investigated.
  • I would not want the live update to kick in when I start modifying the value. It would be nice to have it when I click the arrows, but it is useful really only for Imviz where a jump of "1" is ok. A jump of "1" in Specviz is completely useless because it goes to a completely different region of the spectrum (e.g. the starting value is 1.234um, I click the arrow, it goes to 2um), so I do not think I would ever use the arrows there.
  • It would be nice to have the live update when tabbing to the next entry. Could this be an option?
  • Said that, I do not find a big overhead in, for example, tabbing twice and then hitting return. I guess I need to try with different science cases, but a non-live update looks good to me (for now).

@pllim
Copy link
Contributor Author

pllim commented Aug 12, 2022

it can display the sub-subsets, but doesn't show the logical operators between them

That is a known issue and has existed before this PR. In fact, https://jdaviz.readthedocs.io/en/latest/imviz/plugins.html#subset-tools documents this in the second paragraph.

@pllim
Copy link
Contributor Author

pllim commented Aug 12, 2022

Is support for editing sub-subsets out-of-scope

I would say, yes. I have not found any use for compound subsets yet in Imviz. I guess it is more useful in Specviz but working on it would exceed the points for this ticket the PR is tied to.

I mean, when someone edits a compound subset so that the two sub-subsets now overlap, do we just create a single non-compound subset or throw error? There are extra stuff we need to ponder.

@pllim
Copy link
Contributor Author

pllim commented Aug 12, 2022

Is there a need for displaying both the edit box and the static read-only version of the subset parameters in cases where editing is supported?

I originally combined them but find the display to be confusing because then I cannot be sure if the values are the ones I just entered or from the actual Subset state. When I edit a Subset, personally as a user, I find it useful to be able to see the current value and compare to what I just entered to make sure I am not trying to do something crazy.

@kecnry
Copy link
Member

kecnry commented Aug 12, 2022

I originally combined them but find the display to be confusing because then I cannot be sure if the values are the ones I just entered or from the actual Subset state. When I edit a Subset, personally as a user, I find it useful to be able to see the current value and compare to what I just entered

I'd be curious what @Jenneh thinks, but we can always iterate after merge if/when everything else is ready to go.

@pllim
Copy link
Contributor Author

pllim commented Aug 12, 2022

Indeed there is a lag when not using the fast approximation when linking in Imviz. The lag is present (and annoying) even with just 2 images on my machine. Out of scope for this ticket, but it needs to be investigated.

That is the reason why we have fast approximation in the WCS transform. I do not recommend people turn fast approx. off but I turn it on to show you the worst case scenario with the lag.

@pllim
Copy link
Contributor Author

pllim commented Aug 12, 2022

It would be nice to have the live update when tabbing to the next entry.

That was original request from @duytnguyendtn as well. But looks like we can defer this feature for now as Cami wants to try the plugin on different use cases first.

@pllim pllim force-pushed the you-spin-me-right-round-right-round branch from 0db834f to bbc3593 Compare August 12, 2022 19:56
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.

Still a few things to consider in future iterations (just summarizing points from multiple threads above, but I think we're ok to merge this as-is, once CI passes):

  • re-consider live-updating and performance implications
  • consult with @Jenneh if the read-only and edit version should both be shown
  • re-implement popout button when issues with subsets failing to update are fixed
  • enable support for angle rotation once supported upstream
  • possible support for editing sub-subsets (see conversation above about why this might get difficult)

@pllim
Copy link
Contributor Author

pllim commented Aug 12, 2022

Thanks! I'll merge and can always open follow-up PRs if someone else submits a late review.

@pllim
Copy link
Contributor Author

pllim commented Aug 12, 2022

Follow-up issues:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants