Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: matplotlib/napari-matplotlib
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v2.0.2
Choose a base ref
...
head repository: matplotlib/napari-matplotlib
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v2.0.3
Choose a head ref
  • 8 commits
  • 3 files changed
  • 1 contributor

Commits on Jul 12, 2024

  1. Copy the full SHA
    70dc256 View commit details
  2. Copy the full SHA
    72e5791 View commit details
  3. Debugging

    dstansby committed Jul 12, 2024
    Copy the full SHA
    2874081 View commit details
  4. Put self._draw() in clause

    dstansby committed Jul 12, 2024
    Copy the full SHA
    3ebea2f View commit details
  5. Always call on_update_layers

    dstansby committed Jul 12, 2024
    Copy the full SHA
    b01809f View commit details
  6. Fix layer selection

    dstansby committed Jul 12, 2024
    Copy the full SHA
    8a54595 View commit details
  7. Update changelog

    dstansby committed Jul 12, 2024
    Copy the full SHA
    25b9b0e View commit details
  8. Merge pull request #260 from dstansby/valid-layer-selection

    Only update layers when selection is valid
    dstansby authored Jul 12, 2024

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    0501fab View commit details
Showing with 27 additions and 9 deletions.
  1. +7 −0 docs/changelog.rst
  2. +12 −5 src/napari_matplotlib/base.py
  3. +8 −4 src/napari_matplotlib/histogram.py
7 changes: 7 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
Changelog
=========

2.0.3
-----
Bug fixes
~~~~~~~~~
- Fix an error that happened when the histogram widget was open, but a layer that doesn't support
histogramming (e.g., a labels layer) was selected.

2.0.2
-----
Dependencies
17 changes: 12 additions & 5 deletions src/napari_matplotlib/base.py
Original file line number Diff line number Diff line change
@@ -224,14 +224,24 @@ def _setup_callbacks(self) -> None:
self._update_layers
)

@property
def _valid_layer_selection(self) -> bool:
"""
Return `True` if layer selection is valid.
"""
return self.n_selected_layers in self.n_layers_input and all(
isinstance(layer, self.input_layer_types) for layer in self.layers
)

def _update_layers(self, event: napari.utils.events.Event) -> None:
"""
Update the ``layers`` attribute with currently selected layers and re-draw.
"""
self.layers = list(self.viewer.layers.selection)
self.layers = sorted(self.layers, key=lambda layer: layer.name)
self.on_update_layers()
self._draw()
if self._valid_layer_selection:
self._draw()

def _draw(self) -> None:
"""
@@ -243,10 +253,7 @@ def _draw(self) -> None:
with mplstyle.context(self.napari_theme_style_sheet):
# everything should be done in the style context
self.clear()
if self.n_selected_layers in self.n_layers_input and all(
isinstance(layer, self.input_layer_types)
for layer in self.layers
):
if self._valid_layer_selection:
self.draw()
self.canvas.draw() # type: ignore[no-untyped-call]

12 changes: 8 additions & 4 deletions src/napari_matplotlib/histogram.py
Original file line number Diff line number Diff line change
@@ -55,8 +55,10 @@ def on_update_layers(self) -> None:
Called when the selected layers are updated.
"""
super().on_update_layers()
for layer in self.viewer.layers:
layer.events.contrast_limits.connect(self._update_contrast_lims)
if self._valid_layer_selection:
self.layers[0].events.contrast_limits.connect(
self._update_contrast_lims
)

def _update_contrast_lims(self) -> None:
for lim, line in zip(
@@ -209,10 +211,12 @@ def draw(self) -> None:
# get the colormap from the layer depending on its type
if isinstance(self.layers[0], napari.layers.Points):
colormap = self.layers[0].face_colormap
self.layers[0].face_color = self.x_axis_key
if self.x_axis_key:
self.layers[0].face_color = self.x_axis_key
elif isinstance(self.layers[0], napari.layers.Vectors):
colormap = self.layers[0].edge_colormap
self.layers[0].edge_color = self.x_axis_key
if self.x_axis_key:
self.layers[0].edge_color = self.x_axis_key
else:
colormap = None