Skip to content

Add option to plotter for layer export#420

Merged
jo-mueller merged 69 commits intomainfrom
add-context-menu-to-plotter-for-layer-export
Jul 16, 2025
Merged

Add option to plotter for layer export#420
jo-mueller merged 69 commits intomainfrom
add-context-menu-to-plotter-for-layer-export

Conversation

@jo-mueller
Copy link
Collaborator

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

  • Added a context menu (QMenu) to the plotting widget that allows users to export selected clusters to new layers. The _on_export_clusters method 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

  • Simplified the _apply_layer_color function 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

Utility Functions: Test Data Creation

  • Introduced utility functions (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

jo-mueller and others added 30 commits January 29, 2025 12:37
Also changed the code for the color mapping to an if/elif structure for better readability
@jo-mueller jo-mueller requested a review from Copilot June 8, 2025 21:55
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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_clusters for exporting clusters.
  • Refactors feature aggregation and color application to match layers by unique_id instead of name.
  • 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 loc is immediately overwritten by loc = 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 Points but from napari.layers import Points was 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_index as str, but the parameter is used as an int. Update the type in the docstring to int for accuracy.
    subcluster_index : str

src/napari_clusters_plotter/_tests/test_plotter.py:441

  • The parameter create_multi_shapes_layers does not match the actual helper name create_multi_shapes_layer. This will cause a NameError in the parametrization.
        create_multi_shapes_layers,

@jo-mueller jo-mueller changed the title WIP: Add context menu to plotter for layer export Add option to plotter for layer export Jul 16, 2025
jo-mueller and others added 6 commits July 16, 2025 14:02
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>
@jo-mueller jo-mueller merged commit 53d5275 into main Jul 16, 2025
16 checks passed
@jo-mueller jo-mueller deleted the add-context-menu-to-plotter-for-layer-export branch July 16, 2025 13:05
@codecov
Copy link

codecov bot commented Jul 16, 2025

Codecov Report

Attention: Patch coverage is 62.30769% with 49 lines in your changes missing coverage. Please review.

Project coverage is 85.57%. Comparing base (d2c94fa) to head (cf870d8).
Report is 70 commits behind head on main.

Files with missing lines Patch % Lines
src/napari_clusters_plotter/_tests/test_plotter.py 37.50% 40 Missing ⚠️
src/napari_clusters_plotter/_new_plotter_widget.py 85.71% 9 Missing ⚠️
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.
📢 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

None yet

Development

Successfully merging this pull request may close these issues.

2 participants