8000 Add optional fixed `length` parameter to scale bar by jo-mueller · Pull Request #7167 · napari/napari · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Add optional fixed length parameter to scale bar #7167

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

Merged
merged 22 commits into from
Aug 12, 2024

Conversation

jo-mueller
Copy link
Contributor
@jo-mueller jo-mueller commented Aug 7, 2024

Description

Fixes #7164

This PR adds a mew parameter length to the scale bar that allows to set the the scale to a fixed width in physical units which will grow or shrink together with the zoom of the canvas.

2024-08-0912-46-36-ezgif com-video-to-gif-converter

Changes

  • ScaleBarOverlay class

    • Add length parameter with default value None
  • VispyScaleBarOverlay class

    • Add handling for length parameter
    • Update _on_zoom_change method to use fixed_width if not None
    • Add _on_length_change method

Checklist

  • My PR is the minimum possible work for the desired functionality
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to docstrings and documentation
    (open a PR on the docs repository (https://github.com/napari/docs) if relevant!)
  • I have added tests that prove my fix is effective or that my feature works
  • Tests
    • Add test for length parameter in VispyScaleBarOverlay class

…erlay` classes

* **ScaleBarOverlay class**
  - Add `fixed_width` parameter with default value `None`

* **VispyScaleBarOverlay class**
  - Add handling for `fixed_width` parameter
  - Update `_on_zoom_change` method to use `fixed_width` if not `None`
  - Add `_on_fixed_width_change` method

* **Examples**
  - Add example usage of `viewer.scale_bar.fixed_width` in `examples/scale_bar.py`

* **Tests**
  - Add test for `fixed_width` parameter in `VispyScaleBarOverlay` class
  - Add test for `fixed_width` parameter in `ScaleBarOverlay` class
@github-actions github-actions bot added the tests Something related to our tests label Aug 7, 2024
Copy link
codecov bot commented Aug 7, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 92.92%. Comparing base (9a9e7e8) to head (0309623).
Report is 7 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #7167      +/-   ##
==========================================
- Coverage   93.01%   92.92%   -0.10%     
==========================================
  Files         619      620       +1     
  Lines       56757    56777      +20     
==========================================
- Hits        52792    52758      -34     
- Misses       3965     4019      +54     

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

8000

@brisvag brisvag added the feature New feature or request label Aug 8, 2024
Copy link
Contributor
@brisvag brisvag left a comment

Choose a reason for hiding this comment

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

Love this! It's great to see how relatively small the change needed was, and how little help you needed to do this! Great work 💪

I left a few comments, none of them big issues.

The main thing I'm unsure about is the name width, which to me is a bit strange. Maybe this is typical nomenclature and I'm unaware, but to me width means the other direction ("thickness" of the line). So I'd rather call this length. Otherwise, size for something more generic. I feel like @psobolewskiPhD will have opinions on this :)

@jo-mueller jo-mueller requested review from melonora and a team as code owners August 8, 2024 08:38
@jo-mueller
Copy link
Contributor Author
jo-mueller commented Aug 8, 2024

Thanks @brisvag for the quick review :)

and how little help you needed to do this!

I must admit that the github workspace helps big time in getting started to find the right places for modifications :)

As for the naming conventions, I went with fixed_width because I could imagine that people may want to also control the thickness of the scale bar somehow, which would then have to be controlled by a parameter that can be easily distinguished from the width. That being said - now that I write it - the two parameters could be called length and thickness and that would probably be verbose enough to tell the average user what to do with them.

On the GUI for scale bar control - is there already an issue for this?

@brisvag
Copy link
Contributor
brisvag commented Aug 8, 2024

That being said - now that I write it - the two parameters could be called length and thickness and that would probably be verbose enough to tell the average user what to do with them.

I find this more intuitive, yeah. No risk of confusing them, unlike "width".

One the GUI for scale bar control - is there already an issue for this?

I don't think so! Feel free to create and link to the other one!

Copy link
Contributor
@brisvag brisvag left a comment

Choose a reason for hiding this comment

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

Looking good to me :) Let's see what CI thinks about it now.

Co-authored-by: Lorenzo Gaifas <brisvag@gmail.com>
@brisvag brisvag changed the title Add fixed_width parameter to ScaleBarOverlay and `VispyScaleBarOv… Add optional fixe length parameter to scale bar Aug 8, 2024
Copy link
Contributor
@melonora melonora left a comment

Choose a reason for hiding this comment

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

Great work @jo-mueller ! Thanks for picking this up

jo-mueller and others added 2 commits August 8, 2024 11:37
@brisvag brisvag added the topic:vispy Vispy integration label Aug 8, 2024
@brisvag brisvag added this to the 0.5.2 milestone Aug 8, 2024
Co-Authored-By: Lorenzo Gaifas <brisvag@gmail.com>
@brisvag
Copy link
Contributor
brisvag commented Aug 8, 2024

Wrong line :P it's the self._target_length that needed changing!

Co-Authored-By: Lorenzo Gaifas <brisvag@gmail.com>
@jo-mueller
Copy link
Contributor Author

I'm dumb 🙈 thanks for the fix(es) :)

@brisvag
Copy link
Contributor
brisvag commented Aug 8, 2024

It did look very similar :P It's annoying cause when a code line is far enough from the changes in the PR, github doesn't allow to make suggestions on it, so you have to resort to linking like above ^^'

I think we might be done 💪

@brisvag
Copy link
Contributor
brisvag commented Aug 8, 2024

@jo-mueller since the description will become the commit message, could you update it so it reflects the current status?

@jo-mueller
Copy link
Contributor Author

@brisvag you mean the title of the PR?

@brisvag
Copy link
Contributor
brisvag commented Aug 8, 2024

I mean the description of the pr, which still refers to fixed_width and some other changes that are not in here anymore.

@jo-mueller
Copy link
Contributor Author

@brisvag should be correct now - I updated the gif and all the descriptions :)

@brisvag
Copy link
Contributor
brisvag commented Aug 9, 2024

Idea (but also ok to leave for followup): update the example export_figure.py to include enabling the scale bar and setting a fixed length, since this is probably the typical application!

Co-Authored-By: Lorenzo Gaifas <brisvag@gmail.com>
@jo-mueller
Copy link
Contributor Author

@brisvag

update the example export_figure.py to include enabling the scale bar and setting a fixed length

Just added it. But for future reference, this may look not so nice in the high-res screenshot due to #6758.

@brisvag
Copy link
Contributor
brisvag commented Aug 9, 2024

Good to flag it, thanks! I think @melonora's on it already :)

Copy link
Member
@psobolewskiPhD psobolewskiPhD left a comment

Choose a reason for hiding this comment

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

Late to the party, but love it.
length makes sense to me as the name.

Because it came to my mind playing with this, for a followup PR: it should be possible to disable the text, so show just the scale bar -- then in the legend you say all the scale bars are 50 um or whatever and don't deal with text clipping the scale bar (make the font large and zoom out a bit).

I'm not sure adding this to the export_figure example makes much sense for this, because it uses reset_view, so you can't get a zoomed view. This is more for a figure with two different zoom levels? Like an inset for example.
What we need to do--in a followup PR--is update the scale_bar example to include all the cool new shit you can do. It's been on my todo #7007 👀

Co-Authored-By: Lorenzo Gaifas <brisvag@gmail.com>
@jo-mueller
Copy link
Contributor Author

@psobolewskiPhD I have added it here because I think there's no harm in showing some functionality in multiple different places of the docs. But I also agree, a more comprehensive example on how to use the scale bar would be a great addon to the docs. The export_figure function for instance I didn't know but it's very helpful for me :)

@brisvag brisvag added the ready to merge Last chance for comments! Will be merged in ~24h label Aug 12, 2024
@Czaki
Copy link
Collaborator
Czaki commented Aug 12, 2024

Hm. Maybe it will be a nice improvement to change the length parameter from float to pint.Qunatity). To use one parameter to define the length of scale bar?

DFEA

@brisvag
Copy link
Contributor
brisvag commented Aug 12, 2024

I think it could go either way... but maybe two parameters of simple types is more ergonomic to work with, since most people are not familiar with pint?

@jni jni merged commit fb98ee0 into napari:main Aug 12, 2024
39 of 40 checks passed
@github-actions github-actions bot removed the ready to merge Last chance for comments! Will be merged in ~24h label Aug 12, 2024
@jni jni added the highlight PR that should be mentioned in next release notes label Aug 12, 2024
@jo-mueller jo-mueller deleted the add-fixed-width branch August 13, 2024 06:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request highlight PR that should be mentioned in next release notes tests Something related to our tests topic:vispy Vispy integration
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Set scale bar width to fixed physical size
6 participants
0