-
-
Notifications
You must be signed in to change notification settings - Fork 395
/
test_annotators.py
112 lines (85 loc) · 4.78 KB
/
test_annotators.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
from holoviews import Overlay
from holoviews.annotators import annotate, PointAnnotator, PathAnnotator
from holoviews.element import Points, Path, Table
from holoviews.element.tiles import EsriStreet, Tiles
from holoviews.tests.plotting.bokeh.test_plot import TestBokehPlot
class Test_annotate(TestBokehPlot):
def test_compose_annotators(self):
layout1 = annotate(Points([]), annotations=['Label'])
layout2 = annotate(Path([]), annotations=['Name'])
combined = annotate.compose(layout1, layout2)
overlay = combined.DynamicMap.I[()]
tables = combined.Annotator.I[()]
self.assertIsInstance(overlay, Overlay)
self.assertEqual(len(overlay), 2)
self.assertEqual(overlay.get(0), Points([], vdims='Label'))
self.assertEqual(overlay.get(1), Path([], vdims='Name'))
self.assertIsInstance(tables, Overlay)
self.assertEqual(len(tables), 3)
def test_annotate_overlay(self):
layout = annotate(EsriStreet() * Points([]), annotations=['Label'])
overlay = layout.DynamicMap.I[()]
tables = layout.Annotator.PointAnnotator[()]
self.assertIsInstance(overlay, Overlay)
self.assertEqual(len(overlay), 2)
self.assertIsInstance(overlay.get(0), Tiles)
self.assertEqual(overlay.get(1), Points([], vdims='Label'))
self.assertIsInstance(tables, Overlay)
self.assertEqual(len(tables), 1)
def test_annotated_property(self):
annotator = annotate.instance()
annotator(Points([]), annotations=['Label'])
self.assertIn('Label', annotator.annotated)
def test_selected_property(self):
annotator = annotate.instance()
annotator(Points([(1, 2), (2, 3)]), annotations=['Label'])
annotator.annotator._selection.update(index=[1])
self.assertEqual(annotator.selected, Points([(2, 3, '')], vdims='Label'))
class TestPointAnnotator(TestBokehPlot):
def test_add_annotations(self):
annotator = PointAnnotator(Points([]), annotations=['Label'])
self.assertIn('Label', annotator.object)
def test_add_name(self):
annotator = PointAnnotator(name="Test Annotator", annotations=['Label'])
self.assertEqual(annotator._stream.tooltip, 'Test Annotator Tool')
self.assertEqual(annotator._table.label, "Test Annotator")
self.assertEqual(annotator.editor._names, ["Test Annotator"])
def test_annotation_type(self):
annotator = PointAnnotator(Points([(1, 2)]), annotations={'Int': int})
expected = Table([(1, 2, 0)], ['x', 'y'], vdims=['Int'], label='PointAnnotator')
self.assertEqual(annotator._table, expected)
def test_replace_object(self):
annotator = PointAnnotator(Points([]), annotations=['Label'])
annotator.object = Points([(1, 2)])
self.assertIn('Label', annotator.object)
expected = Table([(1, 2, '')], ['x', 'y'], vdims=['Label'], label='PointAnnotator')
self.assertEqual(annotator._table, expected)
self.assertIs(annotator._link.target, annotator._table)
def test_stream_update(self):
annotator = PointAnnotator(Points([(1, 2)]), annotations=['Label'])
annotator._stream.event(data={'x': [1], 'y': [2], 'Label': ['A']})
self.assertEqual(annotator.object, Points([(1, 2, 'A')], vdims=['Label']))
class TestPathAnnotator(TestBokehPlot):
def test_add_annotations(self):
annotator = PathAnnotator(Path([]), annotations=['Label'])
self.assertIn('Label', annotator.object)
def test_add_name(self):
annotator = PathAnnotator(name="Test Annotator", annotations=['Label'])
self.assertEqual(annotator._stream.tooltip, 'Test Annotator Tool')
self.assertEqual(annotator._vertex_stream.tooltip, 'Test Annotator Edit Tool')
self.assertEqual(annotator._table.label, "Test Annotator")
self.assertEqual(annotator._vertex_table.label, "Test Annotator Vertices")
self.assertEqual(annotator.editor._names, ["Test Annotator", "Test Annotator Vertices"])
def test_add_vertex_annotations(self):
annotator = PathAnnotator(Path([]), vertex_annotations=['Label'])
self.assertIn('Label', annotator.object)
def test_replace_object(self):
annotator = PathAnnotator(Path([]), annotations=['Label'], vertex_annotations=['Value'])
annotator.object = Path([(1, 2), (2, 3), (0, 0)])
self.assertIn('Label', annotator.object)
expected = Table([('')], kdims=['Label'], label='PathAnnotator')
self.assertEqual(annotator._table, expected)
expected = Table([], ['x', 'y'], 'Value', label='PathAnnotator Vertices')
self.assertEqual(annotator._vertex_table, expected)
self.assertIs(annotator._link.target, annotator._table)
self.assertIs(annotator._vertex_link.target, annotator._vertex_table)