Skip to content

Commit 17ec286

Browse files
committed
Start a features mixin class
1 parent e6446fc commit 17ec286

File tree

2 files changed

+23
-11
lines changed

2 files changed

+23
-11
lines changed

src/napari_matplotlib/features.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import napari.layers
2+
3+
from napari_matplotlib.base import NapariMPLWidget
4+
from napari_matplotlib.util import Interval
5+
6+
7+
class FeaturesMixin(NapariMPLWidget):
8+
"""
9+
Mixin to help with widgets that plot data from a features table stored
10+
on a single layer.
11+
"""
12+
13+
n_layers_input = Interval(1, 1)
14+
# All layers that have a .features attributes
15+
input_layer_types = (
16+
napari.layers.Labels,
17+
napari.layers.Points,
18+
napari.layers.Shapes,
19+
napari.layers.Tracks,
20+
napari.layers.Vectors,
21+
)

src/napari_matplotlib/scatter.py

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from qtpy.QtWidgets import QComboBox, QLabel, QVBoxLayout, QWidget
66

77
from .base import SingleAxesWidget
8+
from .features import FeaturesMixin
89
from .util import Interval
910

1011
__all__ = ["ScatterBaseWidget", "ScatterWidget", "FeaturesScatterWidget"]
@@ -85,21 +86,11 @@ def _get_data(self) -> Tuple[npt.NDArray[Any], npt.NDArray[Any], str, str]:
8586
return x, y, x_axis_name, y_axis_name
8687

8788

88-
class FeaturesScatterWidget(ScatterBaseWidget):
89+
class FeaturesScatterWidget(ScatterBaseWidget, FeaturesMixin):
8990
"""
9091
Widget to scatter data stored in two layer feature attributes.
9192
"""
9293

93-
n_layers_input = Interval(1, 1)
94-
# All layers that have a .features attributes
95-
input_layer_types = (
96-
napari.layers.Labels,
97-
napari.layers.Points,
98-
napari.layers.Shapes,
99-
napari.layers.Tracks,
100-
napari.layers.Vectors,
101-
)
102-
10394
def __init__(
10495
self,
10596
napari_viewer: napari.viewer.Viewer,

0 commit comments

Comments
 (0)