Пример #1
0
 def peaks_view(self) -> PeaksViewerCollectionView:
     """Lazily instantiates PeaksViewer and returns it"""
     if self._peaks_view is None:
         self._peaks_view = PeaksViewerCollectionView(
             MplPainter(self.data_view), self.presenter)
         self.add_widget_to_splitter(self._peaks_view)
     return self._peaks_view
    def test_remove_calls_remove_on_artist(self):
        painter = MplPainter(MagicMock())
        mock_artist = MagicMock()

        painter.remove(mock_artist)

        mock_artist.remove.assert_called_once()
    def test_shell_adds_patch(self):
        axes = MagicMock()
        painter = MplPainter(axes)
        x, y, outer_radius, thick = 1, 2, 0.8, 0.2

        painter.shell(x, y, outer_radius, thick)

        axes.add_patch.assert_called_once()
        self._verify_patch(patch=axes.add_patch.call_args[0][0], nvertices=100, alpha=None)
    def test_circle_draws_circle_patch(self):
        axes = MagicMock()
        painter = MplPainter(axes)
        x, y, radius = 1, 2, 0.8

        artist = painter.circle(x, y, radius)

        axes.add_patch.assert_called_once()
        self.assertTrue(artist is not None)
    def test_ellipticalshell(self):
        axes = MagicMock()
        painter = MplPainter(axes)
        x, y, outer_width, outer_height, thick = 1, 2, 0.8, 1.0, 0.2
        alpha = 1.0

        painter.elliptical_shell(x, y, outer_width, outer_height, thick, alpha=alpha)

        axes.add_patch.assert_called_once()
        self._verify_patch(patch=axes.add_patch.call_args[0][0], nvertices=100, alpha=alpha)
    def test_cross_passes_kwargs_to_mpl(self):
        axes = MagicMock()
        painter = MplPainter(axes)
        x, y, half_width = 1, 2, 0.1
        alpha = 0.8

        painter.cross(x, y, half_width, alpha=alpha)

        axes.add_patch.assert_called_once()
        self._verify_patch(patch=axes.add_patch.call_args[0][0], nvertices=4, alpha=alpha)
    def test_cross_draws_with_only_xy(self):
        axes = MagicMock()
        painter = MplPainter(axes)
        x, y, half_width = 1, 2, 0.1

        artist = painter.cross(x, y, half_width)

        axes.add_patch.assert_called_once()
        self.assertTrue(artist is not None)
        self._verify_patch(patch=axes.add_patch.call_args[0][0], nvertices=4, alpha=None)
    def test_zoom_to_sets_xy_limits_so_xy_at_center(self):
        artist, axes, bbox, inv_trans = (MagicMock(), ) * 4
        # 1:1 transformation for simplicity
        inv_trans.transform.side_effect = lambda x: x
        axes.transData.inverted.return_value = inv_trans
        artist.get_extents.return_value = bbox
        bbox.min, bbox.max = (1., 1.5), (3., 3.5)
        painter = MplPainter(axes)

        painter.zoom_to(artist)

        axes.set_xlim.assert_called_once_with(0.6, 3.4)
        axes.set_ylim.assert_called_once_with(1.1, 3.9)
Пример #9
0
    def test_bbox_returns_ll_and_ur_of_containing_box(self):
        artist, axes, bbox, inv_trans = (MagicMock(), ) * 4
        # 1:1 transformation for simplicity
        inv_trans.transform.side_effect = lambda x: x
        axes.transData.inverted.return_value = inv_trans
        artist.get_extents.return_value = bbox
        bbox.min, bbox.max = (1., 1.5), (3., 3.5)
        painter = MplPainter(axes)

        ll, ur = painter.bbox(artist)

        self.assertEqual(bbox.min, ll)
        self.assertEqual(bbox.max, ur)
Пример #10
0
    def test_painted_viewlimits_returns_limits_for_last_artist(self):
        def create_mock_artist(extents):
            artist = MagicMock()
            bbox = MagicMock()
            bbox.min, bbox.max = extents
            artist.get_extents.return_value = bbox
            return artist

        axes, inv_trans = MagicMock(), MagicMock()
        # 1:1 transformation for simplicity
        inv_trans.transform.side_effect = lambda x: x
        axes.transData.inverted.return_value = inv_trans
        artists = create_mock_artist(((1., 1.5), (3., 3.5))), create_mock_artist(
            ((1.1, 1.3), (2.9, 3.6)))
        painter = MplPainter(axes)
        painted = Painted(painter, artists)

        xlim, ylim = painted.viewlimits()

        assert_allclose((0.64, 3.36), xlim)
        assert_allclose((0.84, 4.06), ylim)