Skip to content

Commit f2d8995

Browse files
committed
Move ready_to_plot
1 parent 866e0a7 commit f2d8995

File tree

2 files changed

+17
-18
lines changed

2 files changed

+17
-18
lines changed

Diff for: src/napari_matplotlib/features.py

+16
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,22 @@ def _get_valid_axis_keys(self) -> List[str]:
7070
else:
7171
return self.layers[0].features.keys()
7272

73+
def _ready_to_plot(self) -> bool:
74+
"""
75+
Return True if selected layer has a feature table we can plot with,
76+
and the columns to plot have been selected.
77+
"""
78+
if not hasattr(self.layers[0], "features"):
79+
return False
80+
81+
feature_table = self.layers[0].features
82+
valid_keys = self._get_valid_axis_keys()
83+
return (
84+
feature_table is not None
85+
and len(feature_table) > 0
86+
and all([self.get_key(dim) in valid_keys for dim in self.dims])
87+
)
88+
7389
def on_update_layers(self) -> None:
7490
"""
7591
Called when the layer selection changes by ``self.update_layers()``.

Diff for: src/napari_matplotlib/scatter.py

+1-18
Original file line numberDiff line numberDiff line change
@@ -114,28 +114,11 @@ def __init__(
114114
FeaturesMixin.__init__(self, ndim=2)
115115
self._update_layers(None)
116116

117-
def _ready_to_scatter(self) -> bool:
118-
"""
119-
Return True if selected layer has a feature table we can scatter with,
120-
and the two columns to be scatterd have been selected.
121-
"""
122-
if not hasattr(self.layers[0], "features"):
123-
return False
124-
125-
feature_table = self.layers[0].features
126-
valid_keys = self._get_valid_axis_keys()
127-
return (
128-
feature_table is not None
129-
and len(feature_table) > 0
130-
and self.get_key("x") in valid_keys
131-
and self.get_key("y") in valid_keys
132-
)
133-
134117
def draw(self) -> None:
135118
"""
136119
Scatter two features from the currently selected layer.
137120
"""
138-
if self._ready_to_scatter():
121+
if self._ready_to_plot():
139122
super().draw()
140123

141124
def _get_data(self) -> Tuple[npt.NDArray[Any], npt.NDArray[Any], str, str]:

0 commit comments

Comments
 (0)