Skip to content

Add scatter figure test #137

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/napari_matplotlib/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ 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()

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 20 additions & 5 deletions src/napari_matplotlib/tests/test_scatter.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,32 @@
from copy import deepcopy
from typing import Any, Dict, Tuple

import numpy as np
import numpy.typing as npt
import pytest

from napari_matplotlib import FeaturesScatterWidget, ScatterWidget


def test_scatter(make_napari_viewer):
# Smoke test adding a scatter widget
@pytest.mark.mpl_image_compare
def test_scatter(make_napari_viewer, astronaut_data):
viewer = make_napari_viewer()
viewer.add_image(np.random.random((100, 100)))
viewer.add_image(np.random.random((100, 100)))
ScatterWidget(viewer)
widget = ScatterWidget(viewer)
fig = widget.figure

viewer.add_image(astronaut_data[0], **astronaut_data[1], name="astronaut")

viewer.add_image(
astronaut_data[0] * -1, **astronaut_data[1], name="astronaut_reversed"
)
# De-select existing selection
viewer.layers.selection.clear()

# Select images
viewer.layers.selection.add(viewer.layers[0])
viewer.layers.selection.add(viewer.layers[1])

return deepcopy(fig)


def test_features_scatter_widget(make_napari_viewer):
Expand Down