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
Overlay backend refactor #4907
Overlay backend refactor #4907
Conversation
Codecov Report
@@ Coverage Diff @@
## main #4907 +/- ##
==========================================
+ Coverage 87.76% 87.77% +0.01%
==========================================
Files 578 583 +5
Lines 49371 49373 +2
==========================================
+ Hits 43330 43338 +8
+ Misses 6041 6035 -6
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for splitting this out @brisvag - I think this is close. I just flagged two things for discussion - one is if we need all the different overlay model classes right away, and the other is if we can put some of these model classes behind something private so they are less exposed.
vispy changes look good.
napari/components/overlays/base.py
Outdated
from .._viewer_constants import CanvasPosition | ||
|
||
|
||
class Overlay(EventedModel): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We've got quite a lot of classes here - not sure if this is a pattern @jni would want us to go too right away. Maybe we just start with Overlay
with everything on it and drop CanvasOverlay / SceneOverlay
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah ok I just saw in #4894
CanvasOverlay: things that live in canvas space (ScaleBar, TextOverlay, InteractionBox, the welcome screen, and in the future maybe ColorBars and other HUD-like visuals) and thus should be children of canvas.view
SceneOverlay: things that live in scene space -- also referred to as "displayed coordinates"; this is the 2D or 3D slices being rendered -- and thus should be children of the canvas.view.scene
So I see how these are two different types of thing - still not quite clear to me they need their own classes, but maybe. If so it would be good to have some nice doc strings for the them, and maybe make _Overlay
or OverlayBase
so that it was clear it was not something to be used directly
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's definitely reasonable to make them private for now.
The reason for having different classes is mainly because in #4894 I used isinstance
checks to choose how to parent the visual. This can probably be done with an attribute just as well, so I'm not particularly attached to class separation; I just found it more intuitive.
@@ -0,0 +1,5 @@ | |||
from .axes import AxesOverlay |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could overlays be _overlays
and private? I don't think we think users will import and uses these objects publicaly, so we could hide them which might make iterating and refactoring easier
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aren't the equivalents (e.g. napari.components.axes
) public right now though? And they have (and will continue to have?) a pretty prominent/public entry point (i.e. Viewer.axes
or maybe later Viewer.overlays.axes
that will need to publicly documented?
Or do you just want to make this module private and import these publicly?
Not that I mind making the public API smaller, but wanted to check.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't mind either way. I think probably the path of least resistance is to do this change with 0.5 and not deal with all the possible deprecations.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This mostly looks great and I think could be merged pretty soon. Are there any high level parts you're more uncertain about or want particular feedback on? Or do you think this could also go in pretty soon?
@@ -0,0 +1,5 @@ | |||
from .axes import AxesOverlay |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aren't the equivalents (e.g. napari.components.axes
) public right now though? And they have (and will continue to have?) a pretty prominent/public entry point (i.e. Viewer.axes
or maybe later Viewer.overlays.axes
that will need to publicly documented?
Or do you just want to make this module private and import these publicly?
Not that I mind making the public API smaller, but wanted to check.
|
||
|
||
class SceneOverlay(Overlay): | ||
# TODO: should transform live here? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you give an example of a scene overlay transform? Maybe the interaction box transform?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not convinced of what should be our "default" here; for example, the InteractionBox
(or BoundingBoxOverlay
from #4849 which will probably be merged with it) do not need a transform that is directly settable by the user (despite having an affine themselves), since they derive it from the layer, and should never be offset manually. On the other hand, stuff like the manipulators from alisterburt/napari-threedee
should have an easily settable transform. It's probably something the subclass should expose, though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given we don't have a huge number of overlays, how about taking the suggestion of @sofroniewn and just removing CanvasOverlay
and SceneOverlay
as distinct subclasses for now? They only add the position
attribute in CanvasOverlay
, which could just be added to the small number of canvas overlays we have right now.
I guess having distinction might introduce some nice clear semantics, but I also think that could come later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah right, I guess you explained that in: https://github.com/napari/napari/pull/4907/files#r946860221
I don't feel particularly strongly here.
I think this is close to mergeable. I can see people having issues with the half-changed |
It seems like the biggest blocker here is around defining a release plan around 0.5, which is unclear to me. It would be great if we knew what we want to be in 0.5 and when |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@andy-sweet and @brisvag do we want to try to push for merging this in 0.4.17 or would you rather leave until 0.5.0? I'm happy either way, excited to see work on overlays move forwards!
FWIW - I'm very pro the clear semantics of CanvasOverlay
and SceneOverlay
despite the proliferation of classes, I agree with @sofroniewn's suggestion of renaming what is currently Overlay
to OverlayBase
to avoid confusion.
Longer term adding custom overlays is something we might want to support via the plugin API but this shouldn't be rushed so private for now seems a safe bet
I don't see the benefit of merging this without the followup, so I would say it's better to get all in for 0.5 :) I agree that we should keep the class separation. Note that while the "class proliferation" seems unnecessary here, its usefulness will be more clear in the followup PR. Remember that this PR is intended as a way to split out refactors and non-breaking changes from #4894 in order to ease code review. |
Agreed. |
…/vispy-overlays
Click here to download the docs artifacts |
I think I have addressed all the comments. @sofroniewn, @andy-sweet and @alisterburt, this is ready to be merged if you are happy with it. I can then focus on the real work on #4894. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed that this is a priority in terms of merging. Go for it!
Description
This is intended as a precursor to #4894. Most changes in this PR should be refactor only, with minimal changes to the public API. This way, we can discuss api details without this whole mess of diff in the way.
In short, these changes can be divided in 3 main branches:
_vispy/overlays/
and refactor the current code inVispyTextOverlay
& Co. to share a similar structure as theVispyLayers
_vispy/overlays/
the "visual code", which now lives in_vispy/visuals/
model
side of things insidenapari/components/overlays
Some quirks:
InteractionBox
was left mostly untouched: this is because I think it should be unified with theBoundingBox
from Layer bounding box #4849 and Overlays 2.0 #4894 and ultimately live on theLayer
as aLayerOverlay
. But that will come in a separate PR.opacity
for all of them, and everyCanvasPosition
is now available to bothText
andScaleBar
, instead of restricting the scale bar to just the corner.Type of change
References
How has this been tested?
as there are small differences between the two Qt bindings.
Final checklist:
trans.
to make them localizable.For more information see our translations guide.