Skip to content

Commit 208af97

Browse files
authored
Merge branch 'main' into feat/hist-bin-params
2 parents 67a8641 + 0501fab commit 208af97

File tree

5 files changed

+34
-12
lines changed

5 files changed

+34
-12
lines changed

.pre-commit-config.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@ repos:
1717
- id: napari-plugin-checks
1818

1919
- repo: https://github.com/pre-commit/mirrors-mypy
20-
rev: v1.10.0
20+
rev: v1.10.1
2121
hooks:
2222
- id: mypy
2323
additional_dependencies: [numpy, matplotlib]
2424

2525
- repo: https://github.com/astral-sh/ruff-pre-commit
2626
# Ruff version.
27-
rev: 'v0.4.2'
27+
rev: 'v0.5.1'
2828
hooks:
2929
- id: ruff
3030

docs/changelog.rst

+11
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,24 @@
11
Changelog
22
=========
3+
4+
2.0.3
5+
-----
6+
Bug fixes
7+
~~~~~~~~~
8+
- Fix an error that happened when the histogram widget was open, but a layer that doesn't support
9+
histogramming (e.g., a labels layer) was selected.
10+
311
2.0.2
412
-----
513
Dependencies
614
~~~~~~~~~~~~
715
napari-matplotlib now adheres to `SPEC 0 <https://scientific-python.org/specs/spec-0000/>`_, and has:
16+
817
- Dropped support for Python 3.9
918
- Added support for Python 3.12
1019
- Added a minimum required numpy verison of 1.23
20+
- Pinned the maximum napari version to ``< 0.5``.
21+
Version 3.0 of ``napari-matplotlib`` will introduce support for ``napari`` version 0.5.
1122

1223
2.0.1
1324
-----

setup.cfg

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ project_urls =
2828
packages = find:
2929
install_requires =
3030
matplotlib
31-
napari
31+
napari<0.5
3232
numpy>=1.23
3333
tinycss2
3434
python_requires = >=3.10

src/napari_matplotlib/base.py

+12-5
Original file line numberDiff line numberDiff line change
@@ -224,14 +224,24 @@ def _setup_callbacks(self) -> None:
224224
self._update_layers
225225
)
226226

227+
@property
228+
def _valid_layer_selection(self) -> bool:
229+
"""
230+
Return `True` if layer selection is valid.
231+
"""
232+
return self.n_selected_layers in self.n_layers_input and all(
233+
isinstance(layer, self.input_layer_types) for layer in self.layers
234+
)
235+
227236
def _update_layers(self, event: napari.utils.events.Event) -> None:
228237
"""
229238
Update the ``layers`` attribute with currently selected layers and re-draw.
230239
"""
231240
self.layers = list(self.viewer.layers.selection)
232241
self.layers = sorted(self.layers, key=lambda layer: layer.name)
233242
self.on_update_layers()
234-
self._draw()
243+
if self._valid_layer_selection:
244+
self._draw()
235245

236246
def _draw(self) -> None:
237247
"""
@@ -243,10 +253,7 @@ def _draw(self) -> None:
243253
with mplstyle.context(self.napari_theme_style_sheet):
244254
# everything should be done in the style context
245255
self.clear()
246-
if self.n_selected_layers in self.n_layers_input and all(
247-
isinstance(layer, self.input_layer_types)
248-
for layer in self.layers
249-
):
256+
if self._valid_layer_selection:
250257
self.draw()
251258
self.canvas.draw() # type: ignore[no-untyped-call]
252259

src/napari_matplotlib/histogram.py

+8-4
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,10 @@ def on_update_layers(self) -> None:
9999
Called when the selected layers are updated.
100100
"""
101101
super().on_update_layers()
102-
for layer in self.viewer.layers:
103-
layer.events.contrast_limits.connect(self._update_contrast_lims)
102+
if self._valid_layer_selection:
103+
self.layers[0].events.contrast_limits.connect(
104+
self._update_contrast_lims
105+
)
104106

105107
if not self.layers:
106108
return
@@ -274,10 +276,12 @@ def draw(self) -> None:
274276
# get the colormap from the layer depending on its type
275277
if isinstance(self.layers[0], napari.layers.Points):
276278
colormap = self.layers[0].face_colormap
277-
self.layers[0].face_color = self.x_axis_key
279+
if self.x_axis_key:
280+
self.layers[0].face_color = self.x_axis_key
278281
elif isinstance(self.layers[0], napari.layers.Vectors):
279282
colormap = self.layers[0].edge_colormap
280-
self.layers[0].edge_color = self.x_axis_key
283+
if self.x_axis_key:
284+
self.layers[0].edge_color = self.x_axis_key
281285
else:
282286
colormap = None
283287

0 commit comments

Comments
 (0)