Tiling canvas overlays - #7836
Conversation
|
Wow so cool @brisvag! 😍 |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #7836 +/- ##
==========================================
+ Coverage 92.98% 93.04% +0.06%
==========================================
Files 703 704 +1
Lines 63365 63507 +142
==========================================
+ Hits 58920 59091 +171
+ Misses 4445 4416 -29 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
Looks awesome! How challenging would it be to add a vertical tiling option? This would generally be my preference for some things (like in the PR description). It's tough because it has to be generic enough for every canvas overlay, which might most often work nicely with horizontal (like colorbars). But, just thinking it would be the adjustment between using the x_offsets vs y_offsets. |
|
I agree that it would be cool; the problem with that is not the actual implementation (which is indeed pretty easy with Imagine a scenario where you have 4 overlays at the same corner. Let's say we have vertical and horizontal tiling be a parameter for each overlay, and we have 2 with "horizontal" and 2 with "vertical". What do you expect to happen? I don't think there's a unique answer to that :P But I would definitely like to explore this further, I'm just saying it's way more complex than simply sticking to a single direction, and should be done in a followup PR! |
|
Alternatively, a simpler partial solution would be to have a per-position tiling option somewhere in the settings or the viewer itself, allowing to set something like |
I was actually thinking of a hybrid of your two ideas. Sorry I didn't swing back to this much sooner! Instead of the tiling logic being with the overlay itself, its tied to the canvas. Thus it becomes Perhaps this waits until multi-canvas gets sorted and we go with this basic implementation for now. 😄 |
|
Ok, summary of all the tests: On my machine (no desktop environment, just window manager):
On @jni's mac:
On @Czaki's mac (uses an app called "better display" for rescaling:
On @Czaki's windows:
On @TimMonko's windows machines:
Conclusions:
|
|
Y'all, I think we got it! To summarize:
|
|
oh, and if its a struggled to figure out --- I want to be clear that my comment about the gridded text overlap with non-gridded is not a blocker. It's not a regression, because on main the same thing happens. I tried briefly to globally get the position of all overlays but only spent 15 minutes on it and got confused lol. |
|
That's not a bug, it's the intended behaviour (at least, I intended it xD). Overlays are tiled on a by-viewbox basiss, and the "main viewbox" (where non-gridded stuff goes) lives layered on top of the gridded viewboxes, so there is no interaction between overlays across views. If we wanted to get what you expect, it could only work with the corners (e.g: not with
Now that I write it out maybe it's not that hard... But yeah, let's do later xD |
# References and relevant issues - #5960 - #7587 - depends on #7836 - includes changes from #7835 and #7836. Relative diff: brisvag/napari@brisvag:napari:feature/tiling-overlays2...feature/colormap-overlay # Description Added a colormap/colorbar overlay. Try with: ```py import napari viewer = napari.Viewer() # enable grid with stride 2 to get layers split two-by-two viewer.grid.enabled = True viewer.grid.stride = 2 # set the scale bar to gridded mode so it appears in each grid box viewer.scale_bar.visible = True viewer.scale_bar.gridded = True layers = viewer.open_sample('napari', 'lily') # enable color bars for layer in layers: layer.color_bar.visible = True ```  --------- Co-authored-by: Grzegorz Bokota <bokota+github@gmail.com> Co-authored-by: Tim Monko <timmonko@gmail.com> Co-authored-by: Carol Willing <carolcode@willingconsulting.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
|
This pull request has been mentioned on Image.sc Forum. There might be relevant details there: |
# References and relevant issues - closes #8342 # Description This slipped through when refactoring in #7836. The root of the problem is: - canvas overlays can have "locked" position (top_left, bottom_right, etc), or "free" positions (whatever the overlay wants) - overlays need to opt out of the "locked" mode, which takes care of tiling and auto-sets the position - to opt out you need to specifically set `overlaymodel.position` to a value that *isn't* a `CanvasPosition` enum - you also should override the method `_on_position_change` in the `VispyOverlay` class in order to avoid unnecessarily updating the tiling I changed the naming scheme to adapt to this, and now everything works. Basically what was happening is that the overlay was being shifted to `bottom_right` automatically, which meant it was outside of the canvas :P
Original PR #7836 by brisvag Original: napari/napari#7836
Merged from original PR #7836 Original: napari/napari#7836
# References and relevant issues - closes #7321 - supersedes/closes #6678 - depends on #7836 - depends on #8513 # Description This PR refactors the `VispyTextOverlay` to be more easily reused (following ideas from #6678). The result is that we can easily subclass it to make custom text overlays that display different kinds of information. I added two such examples: the `LayerNameOverlay` (useful in grid mode) and the `CurrentSliceOverlay` (which shows the current slice on the canvas. Both of the above are especially useful for figure-making. ```py import napari v = napari.Viewer() v.grid.enabled = True ll = v.open_sample('napari', 'cells3d') for l in ll: l.name_overlay.visible = True v.scale_bar.visible = True v.scale_bar.gridded = True v._overlays['current_slice'].visible = True v._overlays['current_slice'].gridded = True v.dims.axis_labels = ['z', 'y', 'x'] ``` <img width="1112" height="553" alt="image" src="https://github.com/user-attachments/assets/15ccadfb-3651-4323-ab81-a2734979651c" /> --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Grzegorz Bokota <bokota+github@gmail.com> Co-authored-by: napari-bot <napari-bot@users.noreply.github.com> Co-authored-by: Tim Monko <timmonko@gmail.com> Co-authored-by: Carol Willing <carolcode@willingconsulting.com> Co-authored-by: Draga Doncila Pop <17995243+DragaDoncila@users.noreply.github.com> Co-authored-by: Peter Sobolewski <pete.sd@gmail.com>

References and relevant issues
Part of the work in #7832.
Depends on #7835.
Diff relative to #7835: brisvag/napari@refactor/overlays...brisvag:napari:feature/tiling-overlays2
Description
Canvas overlays can be positioned on the canvas using a limited set of positions (
top_left,bottom_rightand so on).Currently, if two overlays end up in the same place, they simply overlap.
This PR introduces tiling for canvas overlays by looping through all canvas overlays and assigning an (horizontal) offset equal to the space taken up by all previous overlays.
On main:

With this PR:
