Skip to content

Add scale bar widget#148

Open
carlosmariorr wants to merge 60 commits into
napari:mainfrom
carlosmariorr:add_scale_bar_widget
Open

Add scale bar widget#148
carlosmariorr wants to merge 60 commits into
napari:mainfrom
carlosmariorr:add_scale_bar_widget

Conversation

@carlosmariorr

Copy link
Copy Markdown
Collaborator

References and relevant issues

Build on and replaces #145. Related issues #138 and #136.

Description

This exposes some of the viewer properties by adding a new widget called Viewer metadata. It builds on the work started at #145 addressing some feedback from the community meetings and adds containers, vertical/horizontal layouts for the dock widget and exposes the attributes of the ScaleBarOverlay that is instantiated in the viewer as viewer.scale_bar.

Highlights:

  • Makes a new module for the ViewerMetadata widget. This widget follows the same pattern as the LayerMetadata widget, with collapsible containers, horizontal/vertical layouts, etc.
image
  • Exposes the viewer.dims.axis_labels through a QTableView and a custom QAbstractTableModel. This table is editable and can function as an access to modify directly the axis_labels of the viewer's dims AND the Layer.axis_labels. It can also pass labels from the active layer to the viewer dims directly using a button.
image
  • Exposes the viewer.scale_bar to control most aspects of the ScaleBarOverlay. It has many entries to control the attributes of the ScaleBarOverlay model such as the visibility, units, edge ticks, color, etc.
image

…dataWidget. Created the class ViewerMetadataWidget.
…dataWidget. Created the class ViewerMetadataWidget.
…ri. Added the _dims_and_units.py file to widgets and made basic classes to build and test the widget.
…stom model so it reads directly from the layer/viewer.
…ge back to bottom after containers and widget layout is decided.
…ecking if the setting column editable is not true.
@carlosmariorr

Copy link
Copy Markdown
Collaborator Author

@TimMonko This is what I've been working on for the Viewer metadata widget. Still a couple of things to do and some... strange behaviors of napari/napari that we probably want to sort out such as the VispyOverlays eating one event during lazy instantiation (This is hopefully fixed later on the psygnal side (napari/napari#8910, napari/napari#8911 and pyapp-kit/psygnal#413) and the scale_bar.box and scale_bar.box_color not updating as expected (I think we can make napari improve on their behavior).

I still need to add tooltips, docstrings and tests but Its getting pretty big so maybe we can check now and add those in a following PR?

@carlosmariorr

Copy link
Copy Markdown
Collaborator Author

I added the auto checkboxes for the scale bar color, box and fixed length fields.

I did find a bug that I haven't fixed:

  • when the viewer.scale_bar.unit is changed to a valid entry such as meters that is not present in the checkbox options, it won't update/show error in the combobox. This is a limitation of the units that we use for the napari-metadata plugin in the space enums. We probably need to change this so that we pull it form napari itself. The list should follow anything accepted by the scale bar units so we can pull it from there.

I haven't fixed the tests 🦖 will update after holidays in japan.

@codecov

codecov Bot commented May 19, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 63.40269% with 299 lines in your changes missing coverage. Please review.
✅ Project coverage is 84.81%. Comparing base (d6bf216) to head (1f94e6b).
⚠️ Report is 5 commits behind head on main.

Files with missing lines Patch % Lines
...napari_metadata/viewer_widgets/_viewer_metadata.py 13.88% 155 Missing ⚠️
src/napari_metadata/viewer_widgets/_scale_bar.py 72.98% 87 Missing ⚠️
src/napari_metadata/viewer_widgets/_dims.py 79.04% 57 Missing ⚠️

❌ Your patch check has failed because the patch coverage (63.40%) is below the target coverage (90.00%). You can increase the patch coverage or adjust the target coverage.
❌ Your project check has failed because the head coverage (84.81%) is below the target coverage (90.00%). You can increase the head coverage or adjust the target coverage.

Additional details and impacted files
@@             Coverage Diff             @@
##             main     #148       +/-   ##
===========================================
- Coverage   97.06%   84.81%   -12.25%     
===========================================
  Files          11       16        +5     
  Lines        1429     2246      +817     
===========================================
+ Hits         1387     1905      +518     
- Misses         42      341      +299     

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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

Labels

None yet

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

1 participant