-
-
Notifications
You must be signed in to change notification settings - Fork 395
/
test_selection.py
759 lines (611 loc) · 27.4 KB
/
test_selection.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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
from unittest import skip, skipIf
import holoviews as hv
import pandas as pd
from holoviews.core.options import Cycle, Store
from holoviews.element import ErrorBars, Points, Rectangles, Table, VSpan
from holoviews.plotting.util import linear_gradient
from holoviews.selection import link_selections
from holoviews.streams import SelectionXY
from holoviews.element.comparison import ComparisonTestCase
try:
from holoviews.operation.datashader import datashade, dynspread
except ImportError:
datashade = None
ds_skip = skipIf(datashade is None, "Datashader not available")
unselected_color = "#ff0000"
box_region_color = linear_gradient(unselected_color, "#000000", 9)[3]
hist_region_color = linear_gradient(unselected_color, "#000000", 9)[1]
class TestLinkSelections(ComparisonTestCase):
__test__ = False
def setUp(self):
self.data = pd.DataFrame(
{'x': [1, 2, 3],
'y': [0, 3, 2],
'e': [1, 1.5, 2],
},
columns=['x', 'y', 'e']
)
def element_color(self, element):
raise NotImplementedError
def check_base_points_like(self, base_points, lnk_sel, data=None):
if data is None:
data = self.data
self.assertEqual(
self.element_color(base_points),
lnk_sel.unselected_color
)
self.assertEqual(base_points.data, data)
@staticmethod
def get_value_with_key_type(d, hvtype):
for k, v in d.items():
if isinstance(k, hvtype) or \
isinstance(k, hv.DynamicMap) and k.type == hvtype:
return v
raise KeyError(f"No key with type {hvtype}")
@staticmethod
def expected_selection_color(element, lnk_sel):
if lnk_sel.selected_color is not None:
expected_color = lnk_sel.selected_color
else:
expected_color = element.opts.get(group='style')[0].get('color')
return expected_color
def check_overlay_points_like(self, overlay_points, lnk_sel, data):
self.assertEqual(
self.element_color(overlay_points),
self.expected_selection_color(overlay_points, lnk_sel),
)
self.assertEqual(overlay_points.data, data)
def test_points_selection(self, dynamic=False, show_regions=True):
points = Points(self.data)
if dynamic:
# Convert points to DynamicMap that returns the element
points = hv.util.Dynamic(points)
lnk_sel = link_selections.instance(show_regions=show_regions,
unselected_color='#ff0000')
linked = lnk_sel(points)
current_obj = linked[()]
# Check initial state of linked dynamic map
self.assertIsInstance(current_obj, hv.Overlay)
unselected, selected, region, region2 = current_obj.values()
# Check initial base layer
self.check_base_points_like(unselected, lnk_sel)
# Check selection layer
self.check_overlay_points_like(selected, lnk_sel, self.data)
# Perform selection of second and third point
selectionxy = TestLinkSelections.get_value_with_key_type(
lnk_sel._selection_expr_streams, hv.Points
).input_streams[0].input_stream.input_streams[0]
self.assertIsInstance(selectionxy, hv.streams.SelectionXY)
selectionxy.event(bounds=(0, 1, 5, 5))
unselected, selected, region, region2 = linked[()].values()
# Check that base layer is unchanged
self.check_base_points_like(unselected, lnk_sel)
# Check selection layer
self.check_overlay_points_like(selected, lnk_sel, self.data.iloc[1:])
if show_regions:
self.assertEqual(region, Rectangles([(0, 1, 5, 5)]))
else:
self.assertEqual(region, Rectangles([]))
def test_points_selection_hide_region(self):
self.test_points_selection(show_regions=False)
def test_points_selection_dynamic(self):
self.test_points_selection(dynamic=True)
def test_layout_selection_points_table(self):
points = Points(self.data)
table = Table(self.data)
lnk_sel = link_selections.instance(
selected_color="#aa0000", unselected_color='#ff0000'
)
linked = lnk_sel(points + table)
current_obj = linked[()]
# Check initial base points
self.check_base_points_like(
current_obj[0][()].Points.I,
lnk_sel
)
# Check initial selection points
self.check_overlay_points_like(current_obj[0][()].Points.II, lnk_sel,
self.data)
# Check initial table
self.assertEqual(
self.element_color(current_obj[1][()]),
[lnk_sel.selected_color] * len(self.data)
)
# Select first and third point
selectionxy = TestLinkSelections.get_value_with_key_type(
lnk_sel._selection_expr_streams, hv.Points
).input_streams[0].input_stream.input_streams[0]
selectionxy.event(bounds=(0, 0, 4, 2))
current_obj = linked[()]
# Check base points
self.check_base_points_like(
current_obj[0][()].Points.I,
lnk_sel
)
# Check selection points
self.check_overlay_points_like(current_obj[0][()].Points.II, lnk_sel,
self.data.iloc[[0, 2]])
# Check selected table
self.assertEqual(
self.element_color(current_obj[1][()]),
[
lnk_sel.selected_color,
lnk_sel.unselected_color,
lnk_sel.selected_color,
]
)
def test_overlay_points_errorbars(self, dynamic=False):
points = Points(self.data)
error = ErrorBars(self.data, kdims='x', vdims=['y', 'e'])
lnk_sel = link_selections.instance(unselected_color='#ff0000')
overlay = points * error
if dynamic:
overlay = hv.util.Dynamic(overlay)
linked = lnk_sel(overlay)
current_obj = linked[()]
# Check initial base layers
self.check_base_points_like(current_obj.Points.I, lnk_sel)
self.check_base_points_like(current_obj.ErrorBars.I, lnk_sel)
# Check initial selection layers
self.check_overlay_points_like(current_obj.Points.II, lnk_sel, self.data)
self.check_overlay_points_like(current_obj.ErrorBars.II, lnk_sel, self.data)
# Select first and third point
selectionxy = TestLinkSelections.get_value_with_key_type(
lnk_sel._selection_expr_streams, hv.Points
).input_streams[0].input_stream.input_streams[0]
selectionxy.event(bounds=(0, 0, 4, 2))
current_obj = linked[()]
# Check base layers haven't changed
self.check_base_points_like(current_obj.Points.I, lnk_sel)
self.check_base_points_like(current_obj.ErrorBars.I, lnk_sel)
# Check selected layers
self.check_overlay_points_like(current_obj.Points.II, lnk_sel,
self.data.iloc[[0, 2]])
self.check_overlay_points_like(current_obj.ErrorBars.II, lnk_sel,
self.data.iloc[[0, 2]])
@ds_skip
def test_datashade_selection(self):
points = Points(self.data)
layout = points + dynspread(datashade(points))
lnk_sel = link_selections.instance(unselected_color='#ff0000')
linked = lnk_sel(layout)
current_obj = linked[()]
# Check base points layer
self.check_base_points_like(current_obj[0][()].Points.I, lnk_sel)
# Check selection layer
self.check_overlay_points_like(current_obj[0][()].Points.II, lnk_sel, self.data)
# Check RGB base layer
self.assertEqual(
current_obj[1][()].RGB.I,
dynspread(
datashade(points, cmap=lnk_sel.unselected_cmap, alpha=255)
)[()]
)
# Check RGB selection layer
self.assertEqual(
current_obj[1][()].RGB.II,
dynspread(
datashade(points, cmap=lnk_sel.selected_cmap, alpha=255)
)[()]
)
# Perform selection of second and third point
selectionxy = TestLinkSelections.get_value_with_key_type(
lnk_sel._selection_expr_streams, hv.Points
).input_streams[0].input_stream.input_streams[0]
self.assertIsInstance(selectionxy, SelectionXY)
selectionxy.event(bounds=(0, 1, 5, 5))
current_obj = linked[()]
# Check that base points layer is unchanged
self.check_base_points_like(current_obj[0][()].Points.I, lnk_sel)
# Check points selection layer
self.check_overlay_points_like(current_obj[0][()].Points.II, lnk_sel,
self.data.iloc[1:])
# Check that base RGB layer is unchanged
self.assertEqual(
current_obj[1][()].RGB.I,
dynspread(
datashade(points, cmap=lnk_sel.unselected_cmap, alpha=255)
)[()]
)
# Check selection RGB layer
self.assertEqual(
current_obj[1][()].RGB.II,
dynspread(
datashade(
points.iloc[1:], cmap=lnk_sel.selected_cmap, alpha=255
)
)[()]
)
@ds_skip
def test_datashade_in_overlay_selection(self):
points = Points(self.data)
layout = points * dynspread(datashade(points))
lnk_sel = link_selections.instance(unselected_color='#ff0000')
linked = lnk_sel(layout)
current_obj = linked[()]
# Check base points layer
self.check_base_points_like(current_obj[()].Points.I, lnk_sel)
# Check selection layer
self.check_overlay_points_like(current_obj[()].Points.II, lnk_sel, self.data)
# Check RGB base layer
self.assertEqual(
current_obj[()].RGB.I,
dynspread(
datashade(points, cmap=lnk_sel.unselected_cmap, alpha=255)
)[()]
)
# Check RGB selection layer
self.assertEqual(
current_obj[()].RGB.II,
dynspread(
datashade(points, cmap=lnk_sel.selected_cmap, alpha=255)
)[()]
)
# Perform selection of second and third point
selectionxy = TestLinkSelections.get_value_with_key_type(
lnk_sel._selection_expr_streams, hv.Points
).input_streams[0].input_stream.input_streams[0]
self.assertIsInstance(selectionxy, SelectionXY)
selectionxy.event(bounds=(0, 1, 5, 5))
current_obj = linked[()]
# Check that base points layer is unchanged
self.check_base_points_like(current_obj[()].Points.I, lnk_sel)
# Check points selection layer
self.check_overlay_points_like(current_obj[()].Points.II, lnk_sel,
self.data.iloc[1:])
# Check that base RGB layer is unchanged
self.assertEqual(
current_obj[()].RGB.I,
dynspread(
datashade(points, cmap=lnk_sel.unselected_cmap, alpha=255)
)[()]
)
# Check selection RGB layer
self.assertEqual(
current_obj[()].RGB.II,
dynspread(
datashade(
points.iloc[1:], cmap=lnk_sel.selected_cmap, alpha=255
)
)[()]
)
def test_points_selection_streaming(self):
buffer = hv.streams.Buffer(self.data.iloc[:2], index=False)
points = hv.DynamicMap(Points, streams=[buffer])
lnk_sel = link_selections.instance(unselected_color='#ff0000')
linked = lnk_sel(points)
# Perform selection of first and (future) third point
selectionxy = TestLinkSelections.get_value_with_key_type(
lnk_sel._selection_expr_streams, hv.Points
).input_streams[0].input_stream.input_streams[0]
self.assertIsInstance(selectionxy, hv.streams.SelectionXY)
selectionxy.event(bounds=(0, 0, 4, 2))
current_obj = linked[()]
# Check initial base layer
self.check_base_points_like(
current_obj.Points.I, lnk_sel, self.data.iloc[:2]
)
# Check selection layer
self.check_overlay_points_like(current_obj.Points.II, lnk_sel,
self.data.iloc[[0]])
# Now stream third point to the DynamicMap
buffer.send(self.data.iloc[[2]])
current_obj = linked[()]
# Check initial base layer
self.check_base_points_like(
current_obj.Points.I, lnk_sel, self.data
)
# Check selection layer
self.check_overlay_points_like(current_obj.Points.II, lnk_sel,
self.data.iloc[[0, 2]])
def do_crossfilter_points_histogram(
self, selection_mode, cross_filter_mode, selected1, selected2,
selected3, selected4, points_region1, points_region2,
points_region3, points_region4, hist_region2, hist_region3,
hist_region4, show_regions=True, dynamic=False):
points = Points(self.data)
hist = points.hist('x', adjoin=False, normed=False, num_bins=5)
if dynamic:
# Convert points to DynamicMap that returns the element
hist_orig = hist
points = hv.util.Dynamic(points)
else:
hist_orig = hist
lnk_sel = link_selections.instance(
selection_mode=selection_mode,
cross_filter_mode=cross_filter_mode,
show_regions=show_regions,
selected_color='#00ff00',
unselected_color='#ff0000'
)
linked = lnk_sel(points + hist)
current_obj = linked[()]
# Check initial base points
self.check_base_points_like(
current_obj[0][()].Points.I,
lnk_sel
)
# Check initial selection overlay points
self.check_overlay_points_like(current_obj[0][()].Points.II, lnk_sel,
self.data)
# Initial region bounds all None
self.assertEqual(len(current_obj[0][()].Curve.I), 0)
# Check initial base histogram
base_hist = current_obj[1][()].Histogram.I
self.assertEqual(
self.element_color(base_hist), lnk_sel.unselected_color
)
self.assertEqual(base_hist.data, hist_orig.data)
# Check initial selection overlay Histogram
selection_hist = current_obj[1][()].Histogram.II
self.assertEqual(
self.element_color(selection_hist),
self.expected_selection_color(selection_hist, lnk_sel)
)
self.assertEqual(selection_hist, base_hist)
# No selection region
region_hist = current_obj[1][()].NdOverlay.I.last
self.assertEqual(region_hist.data, [None, None])
# (1) Perform selection on points of points [1, 2]
points_selectionxy = TestLinkSelections.get_value_with_key_type(
lnk_sel._selection_expr_streams, hv.Points
).input_streams[0].input_stream.input_streams[0]
self.assertIsInstance(points_selectionxy, SelectionXY)
points_selectionxy.event(bounds=(1, 1, 4, 4))
# Get current object
current_obj = linked[()]
# Check base points unchanged
self.check_base_points_like(
current_obj[0][()].Points.I,
lnk_sel
)
# Check points selection overlay
self.check_overlay_points_like(current_obj[0][()].Points.II, lnk_sel,
self.data.iloc[selected1])
# Check points region bounds
region_bounds = current_obj[0][()].Rectangles.I
self.assertEqual(region_bounds, Rectangles(points_region1))
if show_regions:
self.assertEqual(
self.element_color(region_bounds),
box_region_color
)
# (2) Perform selection on histogram bars [0, 1]
hist_selectionxy = TestLinkSelections.get_value_with_key_type(
lnk_sel._selection_expr_streams, hv.Histogram
).input_streams[0].input_stream.input_streams[0]
self.assertIsInstance(hist_selectionxy, SelectionXY)
hist_selectionxy.event(bounds=(0, 0, 2.5, 2))
points_unsel, points_sel, points_region, points_region_poly = current_obj[0][()].values()
# Check points selection overlay
self.check_overlay_points_like(points_sel, lnk_sel, self.data.iloc[selected2])
self.assertEqual(points_region, Rectangles(points_region2))
# Check base histogram unchanged
base_hist, region_hist, sel_hist = current_obj[1][()].values()
self.assertEqual(self.element_color(base_hist), lnk_sel.unselected_color)
self.assertEqual(base_hist.data, hist_orig.data)
# Check selection region covers first and second bar
if show_regions:
self.assertEqual(self.element_color(region_hist.last), hist_region_color)
if not len(hist_region2) and lnk_sel.selection_mode != 'inverse':
self.assertEqual(len(region_hist), 1)
else:
self.assertEqual(
region_hist.last.data, [0, 2.5]
)
# Check histogram selection overlay
self.assertEqual(
self.element_color(sel_hist),
self.expected_selection_color(sel_hist, lnk_sel)
)
self.assertEqual(
sel_hist.data, hist_orig.pipeline(hist_orig.dataset.iloc[selected2]).data
)
# (3) Perform selection on points points [0, 2]
points_selectionxy = TestLinkSelections.get_value_with_key_type(
lnk_sel._selection_expr_streams, hv.Points
).input_streams[0].input_stream.input_streams[0]
self.assertIsInstance(points_selectionxy, SelectionXY)
points_selectionxy.event(bounds=(0, 0, 4, 2.5))
# Check selection overlay points contains only second point
self.check_overlay_points_like(current_obj[0][()].Points.II, lnk_sel,
self.data.iloc[selected3])
# Check points region bounds
region_bounds = current_obj[0][()].Rectangles.I
self.assertEqual(region_bounds, Rectangles(points_region3))
# Check second and third histogram bars selected
selection_hist = current_obj[1][()].Histogram.II
self.assertEqual(
selection_hist.data, hist_orig.pipeline(hist_orig.dataset.iloc[selected3]).data
)
# Check selection region covers first and second bar
region_hist = current_obj[1][()].NdOverlay.I.last
if not len(hist_region3) and lnk_sel.selection_mode != 'inverse':
self.assertEqual(len(region_hist), 1)
else:
self.assertEqual(region_hist.data, [0, 2.5])
# (4) Perform selection of bars [1, 2]
hist_selectionxy = TestLinkSelections.get_value_with_key_type(
lnk_sel._selection_expr_streams, hv.Histogram
).input_streams[0].input_stream.input_streams[0]
self.assertIsInstance(hist_selectionxy, SelectionXY)
hist_selectionxy.event(bounds=(1.5, 0, 3.5, 2))
# Check points selection overlay
self.check_overlay_points_like(current_obj[0][()].Points.II, lnk_sel,
self.data.iloc[selected4])
# Check points region bounds
region_bounds = current_obj[0][()].Rectangles.I
self.assertEqual(region_bounds, Rectangles(points_region4))
# Check bar selection region
region_hist = current_obj[1][()].NdOverlay.I.last
if show_regions:
self.assertEqual(
self.element_color(region_hist), hist_region_color
)
if not len(hist_region4) and lnk_sel.selection_mode != 'inverse':
self.assertEqual(len(region_hist), 1)
elif (lnk_sel.cross_filter_mode != 'overwrite' and not
(lnk_sel.cross_filter_mode == 'intersect' and lnk_sel.selection_mode == 'overwrite')):
self.assertEqual(region_hist.data, [0, 3.5])
else:
self.assertEqual(region_hist.data, [1.5, 3.5])
# Check bar selection overlay
selection_hist = current_obj[1][()].Histogram.II
self.assertEqual(
self.element_color(selection_hist),
self.expected_selection_color(selection_hist, lnk_sel)
)
self.assertEqual(
selection_hist.data, hist_orig.pipeline(hist_orig.dataset.iloc[selected4]).data
)
# cross_filter_mode="overwrite"
def test_points_histogram_overwrite_overwrite(self, dynamic=False):
self.do_crossfilter_points_histogram(
selection_mode="overwrite", cross_filter_mode="overwrite",
selected1=[1, 2], selected2=[0, 1], selected3=[0, 2], selected4=[1, 2],
points_region1=[(1, 1, 4, 4)],
points_region2=[],
points_region3=[(0, 0, 4, 2.5)],
points_region4=[],
hist_region2=[0, 1], hist_region3=[], hist_region4=[1, 2],
dynamic=dynamic
)
def test_points_histogram_overwrite_overwrite_dynamic(self):
self.test_points_histogram_overwrite_overwrite(dynamic=True)
def test_points_histogram_intersect_overwrite(self, dynamic=False):
self.do_crossfilter_points_histogram(
selection_mode="intersect", cross_filter_mode="overwrite",
selected1=[1, 2], selected2=[0, 1], selected3=[0, 2], selected4=[1, 2],
points_region1=[(1, 1, 4, 4)],
points_region2=[],
points_region3=[(0, 0, 4, 2.5)],
points_region4=[],
hist_region2=[0, 1], hist_region3=[], hist_region4=[1, 2],
dynamic=dynamic
)
def test_points_histogram_intersect_overwrite_dynamic(self):
self.test_points_histogram_intersect_overwrite(dynamic=True)
def test_points_histogram_union_overwrite(self, dynamic=False):
self.do_crossfilter_points_histogram(
selection_mode="union", cross_filter_mode="overwrite",
selected1=[1, 2], selected2=[0, 1], selected3=[0, 2], selected4=[1, 2],
points_region1=[(1, 1, 4, 4)],
points_region2=[],
points_region3=[(0, 0, 4, 2.5)],
points_region4=[],
hist_region2=[0, 1], hist_region3=[], hist_region4=[1, 2],
dynamic=dynamic
)
def test_points_histogram_union_overwrite_dynamic(self):
self.test_points_histogram_union_overwrite(dynamic=True)
# cross_filter_mode="intersect"
def test_points_histogram_overwrite_intersect(self, dynamic=False):
self.do_crossfilter_points_histogram(
selection_mode="overwrite", cross_filter_mode="intersect",
selected1=[1, 2], selected2=[1], selected3=[0], selected4=[2],
points_region1=[(1, 1, 4, 4)],
points_region2=[(1, 1, 4, 4)],
points_region3=[(0, 0, 4, 2.5)],
points_region4=[(0, 0, 4, 2.5)],
hist_region2=[0, 1], hist_region3=[0, 1], hist_region4=[1, 2],
dynamic=dynamic
)
def test_points_histogram_overwrite_intersect_dynamic(self):
self.test_points_histogram_overwrite_intersect(dynamic=True)
def test_points_histogram_overwrite_intersect_hide_region(self, dynamic=False):
self.do_crossfilter_points_histogram(
selection_mode="overwrite", cross_filter_mode="intersect",
selected1=[1, 2], selected2=[1], selected3=[0], selected4=[2],
points_region1=[],
points_region2=[],
points_region3=[],
points_region4=[],
hist_region2=[], hist_region3=[], hist_region4=[],
show_regions=False, dynamic=dynamic
)
def test_points_histogram_overwrite_intersect_hide_region_dynamic(self):
self.test_points_histogram_overwrite_intersect_hide_region(dynamic=True)
def test_points_histogram_intersect_intersect(self, dynamic=False):
self.do_crossfilter_points_histogram(
selection_mode="intersect", cross_filter_mode="intersect",
selected1=[1, 2], selected2=[1], selected3=[], selected4=[],
points_region1=[(1, 1, 4, 4)],
points_region2=[(1, 1, 4, 4)],
points_region3=[(1, 1, 4, 4), (0, 0, 4, 2.5)],
points_region4=[(1, 1, 4, 4), (0, 0, 4, 2.5)],
hist_region2=[0, 1], hist_region3=[0, 1], hist_region4=[1],
dynamic=dynamic
)
def test_points_histogram_intersect_intersect_dynamic(self):
self.test_points_histogram_intersect_intersect(dynamic=True)
def test_points_histogram_union_intersect(self, dynamic=False):
self.do_crossfilter_points_histogram(
selection_mode="union", cross_filter_mode="intersect",
selected1=[1, 2], selected2=[1], selected3=[0, 1], selected4=[0, 1, 2],
points_region1=[(1, 1, 4, 4)],
points_region2=[(1, 1, 4, 4)],
points_region3=[(1, 1, 4, 4), (0, 0, 4, 2.5)],
points_region4=[(1, 1, 4, 4), (0, 0, 4, 2.5)],
hist_region2=[0, 1], hist_region3=[0, 1], hist_region4=[0, 1, 2],
dynamic=dynamic
)
def test_points_histogram_union_intersect_dynamic(self):
self.test_points_histogram_union_intersect(dynamic=True)
def test_points_histogram_inverse_intersect(self, dynamic=False):
self.do_crossfilter_points_histogram(
selection_mode="inverse", cross_filter_mode="intersect",
selected1=[0], selected2=[], selected3=[], selected4=[],
points_region1=[(1, 1, 4, 4)],
points_region2=[(1, 1, 4, 4)],
points_region3=[(1, 1, 4, 4), (0, 0, 4, 2.5)],
points_region4=[(1, 1, 4, 4), (0, 0, 4, 2.5)],
hist_region2=[], hist_region3=[], hist_region4=[],
dynamic=dynamic
)
def test_points_histogram_inverse_intersect_dynamic(self):
self.test_points_histogram_inverse_intersect(dynamic=True)
# Backend implementations
class TestLinkSelectionsPlotly(TestLinkSelections):
__test__ = True
def setUp(self):
import holoviews.plotting.plotly # noqa
super().setUp()
self._backend = Store.current_backend
Store.set_current_backend('plotly')
def tearDown(self):
Store.current_backend = self._backend
def element_color(self, element, color_prop=None):
if isinstance(element, Table):
color = element.opts.get('style').kwargs['fill']
elif isinstance(element, (Rectangles, VSpan)):
color = element.opts.get('style').kwargs['line_color']
else:
color = element.opts.get('style').kwargs['color']
if isinstance(color, (Cycle, str)):
return color
else:
return list(color)
class TestLinkSelectionsBokeh(TestLinkSelections):
__test__ = True
def setUp(self):
import holoviews.plotting.bokeh # noqa
super().setUp()
self._backend = Store.current_backend
Store.set_current_backend('bokeh')
def tearDown(self):
Store.current_backend = self._backend
def element_color(self, element):
color = element.opts.get('style').kwargs['color']
if isinstance(color, str):
return color
else:
return list(color)
@skip("Coloring Bokeh table not yet supported")
def test_layout_selection_points_table(self):
pass
@skip("Bokeh ErrorBars selection not yet supported")
def test_overlay_points_errorbars(self):
pass
@skip("Bokeh ErrorBars selection not yet supported")
def test_overlay_points_errorbars_dynamic(self):
pass