Add option to plotter for layer export#420
Conversation
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
…//github.com/BiAPoL/napari-clusters-plotter into add-context-menu-to-plotter-for-layer-export
for more information, see https://pre-commit.ci
…//github.com/BiAPoL/napari-clusters-plotter into add-context-menu-to-plotter-for-layer-export
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
Also changed the code for the color mapping to an if/elif structure for better readability
for more information, see https://pre-commit.ci
…//github.com/BiAPoL/napari-clusters-plotter into add-context-menu-to-plotter-for-layer-export
for more information, see https://pre-commit.ci
…//github.com/BiAPoL/napari-clusters-plotter into add-context-menu-to-plotter-for-layer-export
There was a problem hiding this comment.
Pull Request Overview
This PR adds a context menu for exporting clusters to new layers, refactors layer identification and color application to use unique_id, and broadens test coverage with new utilities for multiple layer types.
- Introduces a right-click context menu (
QMenu) and_on_export_clustersfor exporting clusters. - Refactors feature aggregation and color application to match layers by
unique_idinstead ofname. - Expands tests with utility functions (
create_points,create_shapes,create_labels) and parametrized cluster export tests.
Reviewed Changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/napari_clusters_plotter/_tests/test_plotter.py | Adds utilities and tests for creating and exporting clusters |
| src/napari_clusters_plotter/_tests/test_dimensionality_reduction.py | Updates tests to assert against unique_id instead of name |
| src/napari_clusters_plotter/_new_plotter_widget.py | Adds context menu, export logic, and refactors color logic |
| src/napari_clusters_plotter/_dim_reduction_and_clustering.py | Updates clustering output handling to use unique_id |
| src/napari_clusters_plotter/_algorithm_widget.py | Changes feature tagging to use unique_id |
Comments suppressed due to low confidence (4)
src/napari_clusters_plotter/_tests/test_plotter.py:9
- The function parameter
locis immediately overwritten byloc = 5, so callers cannot customize the location. Remove the hardcoded assignment or use the passed-in parameter.
loc = 5
src/napari_clusters_plotter/_tests/test_plotter.py:166
- This function uses
Pointsbutfrom napari.layers import Pointswas removed. Re-add the import to avoid a NameError.
def create_multi_point_layer(n_samples: int = 100):
src/napari_clusters_plotter/_new_plotter_widget.py:801
- The docstring declares
subcluster_indexasstr, but the parameter is used as anint. Update the type in the docstring tointfor accuracy.
subcluster_index : str
src/napari_clusters_plotter/_tests/test_plotter.py:441
- The parameter
create_multi_shapes_layersdoes not match the actual helper namecreate_multi_shapes_layer. This will cause a NameError in the parametrization.
create_multi_shapes_layers,
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
Co-Authored-By: Marcelo Zoccoler <26173597+zoccoler@users.noreply.github.com>
Co-Authored-By: Marcelo Zoccoler <26173597+zoccoler@users.noreply.github.com>
Co-Authored-By: Marcelo Zoccoler <26173597+zoccoler@users.noreply.github.com>
for more information, see https://pre-commit.ci
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #420 +/- ##
==========================================
- Coverage 88.19% 85.57% -2.62%
==========================================
Files 11 11
Lines 1084 1206 +122
==========================================
+ Hits 956 1032 +76
- Misses 128 174 +46 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
This pull request introduces a new feature for exporting selected clusters to new layers, refactors the color application logic for layers, and adds comprehensive test coverage for the new functionality. It also includes utility functions for creating test data across multiple layer types.
New Feature: Cluster Export
QMenu) to the plotting widget that allows users to export selected clusters to new layers. The_on_export_clustersmethod handles the export process, creating a new layer with the selected cluster's data and features. (src/napari_clusters_plotter/_new_plotter_widget.py, [1] [2]Refactoring: Layer Color Application
_apply_layer_colorfunction by replacing the dictionary-based approach with direct conditional checks for layer types. This improves readability and maintainability. (src/napari_clusters_plotter/_new_plotter_widget.py, src/napari_clusters_plotter/_new_plotter_widget.pyL452-R569)Test Coverage: Cluster Export
PointsandShapeslayers. Tests ensure the correct data and features are transferred to the new layer. (src/napari_clusters_plotter/_tests/test_plotter.py, src/napari_clusters_plotter/_tests/test_plotter.pyL74-R231)Utility Functions: Test Data Creation
create_points,create_shapes,create_labels) for generating test data across multiple layer types (Points,Shapes,Labels) with random features and geometries. These functions support robust testing of layer-related operations. (src/napari_clusters_plotter/_tests/test_plotter.py, src/napari_clusters_plotter/_tests/test_plotter.pyR2-L6)Code Enhancement: Context Menu Integration
QMenufromqtpy.QtWidgetsto enable context menu functionality in the plotting widget. (src/napari_clusters_plotter/_new_plotter_widget.py, src/napari_clusters_plotter/_new_plotter_widget.pyL14-R14)