-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
/
Copy pathselect_test.js
832 lines (724 loc) · 28.1 KB
/
select_test.js
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
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
var d3 = require('d3');
var Plotly = require('@lib/index');
var Lib = require('@src/lib');
var doubleClick = require('../assets/double_click');
var createGraphDiv = require('../assets/create_graph_div');
var destroyGraphDiv = require('../assets/destroy_graph_div');
var fail = require('../assets/fail_test');
var mouseEvent = require('../assets/mouse_event');
var touchEvent = require('../assets/touch_event');
var LONG_TIMEOUT_INTERVAL = 5 * jasmine.DEFAULT_TIMEOUT_INTERVAL;
function drag(path, options) {
var len = path.length;
if(!options) options = {type: 'mouse'};
Lib.clearThrottle();
if(options.type === 'touch') {
touchEvent('touchstart', path[0][0], path[0][1]);
path.slice(1, len).forEach(function(pt) {
Lib.clearThrottle();
touchEvent('touchmove', pt[0], pt[1]);
});
touchEvent('touchend', path[len - 1][0], path[len - 1][1]);
return;
}
mouseEvent('mousemove', path[0][0], path[0][1]);
mouseEvent('mousedown', path[0][0], path[0][1]);
path.slice(1, len).forEach(function(pt) {
Lib.clearThrottle();
mouseEvent('mousemove', pt[0], pt[1]);
});
mouseEvent('mouseup', path[len - 1][0], path[len - 1][1]);
}
function assertSelectionNodes(cornerCnt, outlineCnt) {
expect(d3.selectAll('.zoomlayer > .zoombox-corners').size())
.toBe(cornerCnt, 'selection corner count');
expect(d3.selectAll('.zoomlayer > .select-outline').size())
.toBe(outlineCnt, 'selection outline count');
}
var selectingCnt, selectingData, selectedCnt, selectedData, deselectCnt, doubleClickData;
var selectedPromise, deselectPromise;
function resetEvents(gd) {
selectingCnt = 0;
selectedCnt = 0;
deselectCnt = 0;
doubleClickData = null;
gd.removeAllListeners();
selectedPromise = new Promise(function(resolve) {
gd.on('plotly_selecting', function(data) {
// note that since all of these events test node counts,
// and all of the other tests at some point check that each of
// these event handlers was called (via assertEventCounts),
// we no longer need separate tests that these nodes are created
// and this way *all* subplot variants get the test.
assertSelectionNodes(1, 2);
selectingCnt++;
selectingData = data;
});
gd.on('plotly_selected', function(data) {
assertSelectionNodes(0, 2);
selectedCnt++;
selectedData = data;
resolve();
});
});
deselectPromise = new Promise(function(resolve) {
gd.on('plotly_deselect', function(data) {
assertSelectionNodes(0, 0);
deselectCnt++;
doubleClickData = data;
resolve();
});
});
}
function assertEventCounts(selecting, selected, deselect, msg) {
expect(selectingCnt).toBe(selecting, 'plotly_selecting call count: ' + msg);
expect(selectedCnt).toBe(selected, 'plotly_selected call count: ' + msg);
expect(deselectCnt).toBe(deselect, 'plotly_deselect call count: ' + msg);
}
// events for box or lasso select mouse moves then a doubleclick
var NOEVENTS = [0, 0, 0];
// deselect gives an extra plotly_selected event on the first click
// event data is undefined
var BOXEVENTS = [1, 2, 1];
// assumes 5 points in the lasso path
var LASSOEVENTS = [4, 2, 1];
describe('Test select box and lasso in general:', function() {
var mock = require('@mocks/14.json');
var selectPath = [[93, 193], [143, 193]];
var lassoPath = [[316, 171], [318, 239], [335, 243], [328, 169]];
afterEach(destroyGraphDiv);
function assertRange(actual, expected) {
var PRECISION = 4;
expect(actual.x).toBeCloseToArray(expected.x, PRECISION);
expect(actual.y).toBeCloseToArray(expected.y, PRECISION);
}
function assertEventData(actual, expected, msg) {
expect(actual.length).toBe(expected.length, msg + ' same number of pts');
expected.forEach(function(e, i) {
var a = actual[i];
var m = msg + ' (pt ' + i + ')';
expect(a.data).toBeDefined(m + ' has data ref');
expect(a.fullData).toBeDefined(m + ' has fullData ref');
expect(Object.keys(a).length - 2).toBe(Object.keys(e).length, m + ' has correct number of keys');
Object.keys(e).forEach(function(k) {
expect(a[k]).toBe(e[k], m + ' ' + k);
});
});
}
describe('select events', function() {
var mockCopy = Lib.extendDeep({}, mock);
mockCopy.layout.dragmode = 'select';
mockCopy.data[0].ids = mockCopy.data[0].x
.map(function(v) { return 'id-' + v; });
mockCopy.data[0].customdata = mockCopy.data[0].y
.map(function(v) { return 'customdata-' + v; });
var gd;
beforeEach(function(done) {
gd = createGraphDiv();
Plotly.plot(gd, mockCopy.data, mockCopy.layout)
.then(done);
});
it('should trigger selecting/selected/deselect events', function(done) {
resetEvents(gd);
drag(selectPath);
selectedPromise.then(function() {
expect(selectingCnt).toBe(1, 'with the correct selecting count');
assertEventData(selectingData.points, [{
curveNumber: 0,
pointNumber: 0,
x: 0.002,
y: 16.25,
id: 'id-0.002',
customdata: 'customdata-16.25'
}, {
curveNumber: 0,
pointNumber: 1,
x: 0.004,
y: 12.5,
id: 'id-0.004',
customdata: 'customdata-12.5'
}], 'with the correct selecting points (1)');
assertRange(selectingData.range, {
x: [0.002000, 0.0046236],
y: [0.10209191961595454, 24.512223978291406]
}, 'with the correct selecting range');
expect(selectedCnt).toBe(1, 'with the correct selected count');
assertEventData(selectedData.points, [{
curveNumber: 0,
pointNumber: 0,
x: 0.002,
y: 16.25,
id: 'id-0.002',
customdata: 'customdata-16.25'
}, {
curveNumber: 0,
pointNumber: 1,
x: 0.004,
y: 12.5,
id: 'id-0.004',
customdata: 'customdata-12.5'
}], 'with the correct selected points (2)');
assertRange(selectedData.range, {
x: [0.002000, 0.0046236],
y: [0.10209191961595454, 24.512223978291406]
}, 'with the correct selected range');
return doubleClick(250, 200);
})
.then(deselectPromise)
.then(function() {
expect(doubleClickData).toBe(null, 'with the correct deselect data');
})
.catch(fail)
.then(done);
});
});
describe('lasso events', function() {
var mockCopy = Lib.extendDeep({}, mock);
mockCopy.layout.dragmode = 'lasso';
var gd;
beforeEach(function(done) {
gd = createGraphDiv();
Plotly.plot(gd, mockCopy.data, mockCopy.layout)
.then(done);
});
it('should trigger selecting/selected/deselect events', function(done) {
resetEvents(gd);
drag(lassoPath);
selectedPromise.then(function() {
expect(selectingCnt).toBe(3, 'with the correct selecting count');
assertEventData(selectingData.points, [{
curveNumber: 0,
pointNumber: 10,
x: 0.099,
y: 2.75
}], 'with the correct selecting points (1)');
expect(selectedCnt).toBe(1, 'with the correct selected count');
assertEventData(selectedData.points, [{
curveNumber: 0,
pointNumber: 10,
x: 0.099,
y: 2.75,
}], 'with the correct selected points (2)');
expect(selectedData.lassoPoints.x).toBeCloseToArray(
[0.084, 0.087, 0.115, 0.103], 'lasso points x coords');
expect(selectedData.lassoPoints.y).toBeCloseToArray(
[4.648, 1.342, 1.247, 4.821], 'lasso points y coords');
return doubleClick(250, 200);
})
.then(deselectPromise)
.then(function() {
expect(doubleClickData).toBe(null, 'with the correct deselect data');
})
.catch(fail)
.then(done);
});
it('should trigger selecting/selected/deselect events for touches', function(done) {
resetEvents(gd);
drag(lassoPath, {type: 'touch'});
selectedPromise.then(function() {
expect(selectingCnt).toBe(3, 'with the correct selecting count');
assertEventData(selectingData.points, [{
curveNumber: 0,
pointNumber: 10,
x: 0.099,
y: 2.75
}], 'with the correct selecting points (1)');
expect(selectedCnt).toBe(1, 'with the correct selected count');
assertEventData(selectedData.points, [{
curveNumber: 0,
pointNumber: 10,
x: 0.099,
y: 2.75,
}], 'with the correct selected points (2)');
return doubleClick(250, 200);
})
.then(deselectPromise)
.then(function() {
expect(doubleClickData).toBe(null, 'with the correct deselect data');
})
.catch(fail)
.then(done);
});
});
it('should skip over non-visible traces', function(done) {
var mockCopy = Lib.extendDeep({}, mock);
mockCopy.layout.dragmode = 'select';
var gd = createGraphDiv();
function resetAndSelect() {
resetEvents(gd);
drag(selectPath);
return selectedPromise;
}
function resetAndLasso() {
resetEvents(gd);
drag(lassoPath);
return selectedPromise;
}
function checkPointCount(cnt, msg) {
expect((selectedData.points || []).length).toBe(cnt, msg);
}
Plotly.plot(gd, mockCopy.data, mockCopy.layout)
.then(resetAndSelect)
.then(function() {
checkPointCount(2, '(case 0)');
return Plotly.restyle(gd, 'visible', 'legendonly');
})
.then(resetAndSelect)
.then(function() {
checkPointCount(0, '(legendonly case)');
return Plotly.restyle(gd, 'visible', true);
})
.then(resetAndSelect)
.then(function() {
checkPointCount(2, '(back to case 0)');
return Plotly.relayout(gd, 'dragmode', 'lasso');
})
.then(resetAndLasso)
.then(function() {
checkPointCount(1, '(case 0 lasso)');
return Plotly.restyle(gd, 'visible', 'legendonly');
})
.then(resetAndSelect)
.then(function() {
checkPointCount(0, '(lasso legendonly case)');
return Plotly.restyle(gd, 'visible', true);
})
.then(resetAndLasso)
.then(function() {
checkPointCount(1, '(back to lasso case 0)');
})
.catch(fail)
.then(done);
});
it('should skip over BADNUM items', function(done) {
var data = [{
mode: 'markers',
x: [null, undefined, NaN, 0, 'NA'],
y: [NaN, null, undefined, 0, 'NA']
}];
var layout = {
dragmode: 'select',
width: 400,
heigth: 400,
};
var gd = createGraphDiv();
Plotly.plot(gd, data, layout).then(function() {
resetEvents(gd);
drag([[100, 100], [300, 300]]);
return selectedPromise;
})
.then(function() {
expect(selectedData.points.length).toBe(1);
expect(selectedData.points[0].x).toBe(0);
expect(selectedData.points[0].y).toBe(0);
return Plotly.relayout(gd, 'dragmode', 'lasso');
})
.then(function() {
resetEvents(gd);
drag([[100, 100], [100, 300], [300, 300], [300, 100], [100, 100]]);
return selectedPromise;
})
.then(function() {
expect(selectedData.points.length).toBe(1);
expect(selectedData.points[0].x).toBe(0);
expect(selectedData.points[0].y).toBe(0);
})
.catch(fail)
.then(done);
});
});
describe('Test select box and lasso per trace:', function() {
var gd;
beforeEach(function() {
gd = createGraphDiv();
});
afterEach(destroyGraphDiv);
function makeAssertPoints(keys) {
var callNumber = 0;
return function(expected) {
var msg = '(call #' + callNumber + ') ';
var pts = (selectedData || {}).points || [];
expect(pts.length).toBe(expected.length, msg + 'selected points length');
pts.forEach(function(p, i) {
var e = expected[i] || [];
keys.forEach(function(k, j) {
var msgFull = msg + 'selected pt ' + i + ' - ' + k + ' val';
if(typeof e[j] === 'number') {
expect(p[k]).toBeCloseTo(e[j], 1, msgFull);
} else {
expect(p[k]).toBe(e[j], msgFull);
}
});
});
callNumber++;
};
}
function makeAssertRanges(subplot, tol) {
tol = tol || 1;
var callNumber = 0;
return function(expected) {
var msg = '(call #' + callNumber + ') select box range ';
var ranges = selectedData.range || {};
if(subplot) {
expect(ranges[subplot] || [])
.toBeCloseTo2DArray(expected, tol, msg + 'for ' + subplot);
} else {
expect(ranges.x || [])
.toBeCloseToArray(expected[0], tol, msg + 'x coords');
expect(ranges.y || [])
.toBeCloseToArray(expected[1], tol, msg + 'y coords');
}
callNumber++;
};
}
function makeAssertLassoPoints(subplot, tol) {
tol = tol || 1;
var callNumber = 0;
return function(expected) {
var msg = '(call #' + callNumber + ') lasso points ';
var lassoPoints = selectedData.lassoPoints || {};
if(subplot) {
expect(lassoPoints[subplot] || [])
.toBeCloseTo2DArray(expected, tol, msg + 'for ' + subplot);
} else {
expect(lassoPoints.x || [])
.toBeCloseToArray(expected[0], tol, msg + 'x coords');
expect(lassoPoints.y || [])
.toBeCloseToArray(expected[1], tol, msg + 'y coords');
}
callNumber++;
};
}
function _run(dragPath, afterDragFn, dblClickPos, eventCounts, msg) {
afterDragFn = afterDragFn || function() {};
dblClickPos = dblClickPos || [250, 200];
resetEvents(gd);
assertSelectionNodes(0, 0);
drag(dragPath);
return (eventCounts[0] ? selectedPromise : Promise.resolve())
.then(afterDragFn)
.then(function() {
// before dblclick we also have one less plotly_selected event
// because the first click of the dblclick emits plotly_selected
// even though it does so with undefined event data.
assertEventCounts(eventCounts[0], Math.max(0, eventCounts[1] - 1), 0, msg);
return doubleClick(dblClickPos[0], dblClickPos[1]);
})
.then(eventCounts[2] ? deselectPromise : Promise.resolve())
.then(function() {
assertEventCounts(eventCounts[0], eventCounts[1], eventCounts[2], msg);
});
}
it('should work on scatterternary traces', function(done) {
var assertPoints = makeAssertPoints(['a', 'b', 'c']);
var fig = Lib.extendDeep({}, require('@mocks/ternary_simple'));
fig.layout.width = 800;
fig.layout.dragmode = 'select';
Plotly.plot(gd, fig).then(function() {
return _run(
[[400, 200], [445, 235]],
function() {
assertPoints([[0.5, 0.25, 0.25]]);
},
[380, 180],
BOXEVENTS, 'scatterternary select'
);
})
.then(function() {
return Plotly.relayout(gd, 'dragmode', 'lasso');
})
.then(function() {
return _run(
[[400, 200], [445, 200], [445, 235], [400, 235], [400, 200]],
function() { assertPoints([[0.5, 0.25, 0.25]]); },
[380, 180],
LASSOEVENTS, 'scatterternary lasso'
);
})
.then(function() {
// should work after a relayout too
return Plotly.relayout(gd, 'width', 400);
})
.then(function() {
return _run(
[[200, 200], [230, 200], [230, 230], [200, 230], [200, 200]],
function() { assertPoints([[0.5, 0.25, 0.25]]); },
[180, 180],
LASSOEVENTS, 'scatterternary lasso after relayout'
);
})
.catch(fail)
.then(done);
});
it('should work on scattercarpet traces', function(done) {
var assertPoints = makeAssertPoints(['a', 'b']);
var fig = Lib.extendDeep({}, require('@mocks/scattercarpet'));
fig.layout.dragmode = 'select';
Plotly.plot(gd, fig).then(function() {
return _run(
[[300, 200], [400, 250]],
function() { assertPoints([[0.2, 1.5]]); },
null, BOXEVENTS, 'scattercarpet select'
);
})
.then(function() {
return Plotly.relayout(gd, 'dragmode', 'lasso');
})
.then(function() {
return _run(
[[300, 200], [400, 200], [400, 250], [300, 250], [300, 200]],
function() { assertPoints([[0.2, 1.5]]); },
null, LASSOEVENTS, 'scattercarpet lasso'
);
})
.catch(fail)
.then(done);
});
it('@noCI should work on scattermapbox traces', function(done) {
var assertPoints = makeAssertPoints(['lon', 'lat']);
var assertRanges = makeAssertRanges('mapbox');
var assertLassoPoints = makeAssertLassoPoints('mapbox');
var fig = Lib.extendDeep({}, require('@mocks/mapbox_bubbles-text'));
fig.layout.dragmode = 'select';
fig.config = {
mapboxAccessToken: require('@build/credentials.json').MAPBOX_ACCESS_TOKEN
};
Plotly.plot(gd, fig).then(function() {
return _run(
[[370, 120], [500, 200]],
function() {
assertPoints([[30, 30]]);
assertRanges([[21.99, 34.55], [38.14, 25.98]]);
},
null, BOXEVENTS, 'scattermapbox select'
);
})
.then(function() {
return Plotly.relayout(gd, 'dragmode', 'lasso');
})
.then(function() {
return _run(
[[300, 200], [300, 300], [400, 300], [400, 200], [300, 200]],
function() {
assertPoints([[20, 20]]);
assertLassoPoints([
[13.28, 25.97], [13.28, 14.33], [25.71, 14.33], [25.71, 25.97], [13.28, 25.97]
]);
},
null, LASSOEVENTS, 'scattermapbox lasso'
);
})
.then(function() {
// make selection handlers don't get called in 'pan' dragmode
return Plotly.relayout(gd, 'dragmode', 'pan');
})
.then(function() {
return _run(
[[370, 120], [500, 200]], null, null, NOEVENTS, 'scattermapbox pan'
);
})
.catch(fail)
.then(done);
}, LONG_TIMEOUT_INTERVAL);
it('should work on scattergeo traces', function(done) {
var assertPoints = makeAssertPoints(['lon', 'lat']);
var assertRanges = makeAssertRanges('geo');
var assertLassoPoints = makeAssertLassoPoints('geo');
Plotly.plot(gd, [{
type: 'scattergeo',
lon: [10, 20, 30],
lat: [10, 20, 30]
}, {
type: 'scattergeo',
lon: [-10, -20, -30],
lat: [10, 20, 30]
}], {
showlegend: false,
dragmode: 'select',
width: 800,
height: 600
})
.then(function() {
return _run(
[[350, 200], [450, 400]],
function() {
assertPoints([[10, 10], [20, 20], [-10, 10], [-20, 20]]);
assertRanges([[-28.13, 61.88], [28.13, -50.64]]);
},
null, BOXEVENTS, 'scattergeo select'
);
})
.then(function() {
return Plotly.relayout(gd, 'dragmode', 'lasso');
})
.then(function() {
return _run(
[[300, 200], [300, 300], [400, 300], [400, 200], [300, 200]],
function() {
assertPoints([[-10, 10], [-20, 20], [-30, 30]]);
assertLassoPoints([
[-56.25, 61.88], [-56.24, 5.63], [0, 5.63], [0, 61.88], [-56.25, 61.88]
]);
},
null, LASSOEVENTS, 'scattergeo lasso'
);
})
// .then(deselectPromise)
.then(function() {
// assertEventCounts(4, 2, 1, 'de-lasso');
// make sure selection handlers don't get called in 'pan' dragmode
return Plotly.relayout(gd, 'dragmode', 'pan');
})
.then(function() {
return _run(
[[370, 120], [500, 200]], null, null, NOEVENTS, 'scattergeo pan'
);
})
.catch(fail)
.then(done);
}, LONG_TIMEOUT_INTERVAL);
it('should work on choropleth traces', function(done) {
var assertPoints = makeAssertPoints(['location', 'z']);
var assertRanges = makeAssertRanges('geo', -0.5);
var assertLassoPoints = makeAssertLassoPoints('geo', -0.5);
var fig = Lib.extendDeep({}, require('@mocks/geo_choropleth-text'));
fig.layout.width = 870;
fig.layout.height = 450;
fig.layout.dragmode = 'select';
fig.layout.geo.scope = 'europe';
// add a trace with no locations which will then make trace invisible, lacking DOM elements
fig.data.push(Lib.extendDeep({}, fig.data[0]));
fig.data[1].text = [];
fig.data[1].locations = [];
fig.data[1].z = [];
Plotly.plot(gd, fig)
.then(function() {
return _run(
[[350, 200], [400, 250]],
function() {
assertPoints([['GBR', 26.507354205352502], ['IRL', 86.4125147625692]]);
assertRanges([[-19.11, 63.06], [7.31, 53.72]]);
},
[280, 190],
BOXEVENTS, 'choropleth select'
);
})
.then(function() {
return Plotly.relayout(gd, 'dragmode', 'lasso');
})
.then(function() {
return _run(
[[350, 200], [400, 200], [400, 250], [350, 250], [350, 200]],
function() {
assertPoints([['GBR', 26.507354205352502], ['IRL', 86.4125147625692]]);
assertLassoPoints([
[-19.11, 63.06], [5.50, 65.25], [7.31, 53.72], [-12.90, 51.70], [-19.11, 63.06]
]);
},
[280, 190],
LASSOEVENTS, 'choropleth lasso'
);
})
.then(function() {
// make selection handlers don't get called in 'pan' dragmode
return Plotly.relayout(gd, 'dragmode', 'pan');
})
.then(function() {
return _run(
[[370, 120], [500, 200]], null, [280, 190], NOEVENTS, 'choropleth pan'
);
})
.catch(fail)
.then(done);
}, LONG_TIMEOUT_INTERVAL);
it('should work for bar traces', function(done) {
var assertPoints = makeAssertPoints(['curveNumber', 'x', 'y']);
var assertRanges = makeAssertRanges();
var assertLassoPoints = makeAssertLassoPoints();
var fig = Lib.extendDeep({}, require('@mocks/0'));
fig.layout.dragmode = 'lasso';
Plotly.plot(gd, fig)
.then(function() {
return _run(
[[350, 200], [400, 200], [400, 250], [350, 250], [350, 200]],
function() {
assertPoints([
[0, 4.9, 0.371], [0, 5, 0.368], [0, 5.1, 0.356], [0, 5.2, 0.336],
[0, 5.3, 0.309], [0, 5.4, 0.275], [0, 5.5, 0.235], [0, 5.6, 0.192],
[0, 5.7, 0.145],
[1, 5.1, 0.485], [1, 5.2, 0.409], [1, 5.3, 0.327],
[1, 5.4, 0.24], [1, 5.5, 0.149], [1, 5.6, 0.059],
[2, 4.9, 0.473], [2, 5, 0.368], [2, 5.1, 0.258],
[2, 5.2, 0.146], [2, 5.3, 0.036]
]);
assertLassoPoints([
[4.87, 5.74, 5.74, 4.87, 4.87],
[0.53, 0.53, -0.02, -0.02, 0.53]
]);
},
null, LASSOEVENTS, 'bar lasso'
);
})
.then(function() {
return Plotly.relayout(gd, 'dragmode', 'select');
})
.then(function() {
return _run(
[[350, 200], [370, 220]],
function() {
assertPoints([
[0, 4.9, 0.371], [0, 5, 0.368], [0, 5.1, 0.356], [0, 5.2, 0.336],
[1, 5.1, 0.485], [1, 5.2, 0.41],
[2, 4.9, 0.473], [2, 5, 0.37]
]);
assertRanges([[4.87, 5.22], [0.31, 0.53]]);
},
null, BOXEVENTS, 'bar select'
);
})
.catch(fail)
.then(done);
});
it('should work for histogram traces', function(done) {
var assertPoints = makeAssertPoints(['curveNumber', 'x', 'y']);
var assertRanges = makeAssertRanges();
var assertLassoPoints = makeAssertLassoPoints();
var fig = Lib.extendDeep({}, require('@mocks/hist_grouped'));
fig.layout.dragmode = 'lasso';
fig.layout.width = 600;
fig.layout.height = 500;
Plotly.plot(gd, fig)
.then(function() {
return _run(
[[200, 200], [400, 200], [400, 350], [200, 350], [200, 200]],
function() {
assertPoints([
[0, 1.8, 2], [1, 2.2, 1], [1, 3.2, 1]
]);
assertLassoPoints([
[1.66, 3.59, 3.59, 1.66, 1.66],
[2.17, 2.17, 0.69, 0.69, 2.17]
]);
},
null, LASSOEVENTS, 'histogram lasso'
);
})
.then(function() {
return Plotly.relayout(gd, 'dragmode', 'select');
})
.then(function() {
return _run(
[[200, 200], [400, 350]],
function() {
assertPoints([
[0, 1.8, 2], [1, 2.2, 1], [1, 3.2, 1]
]);
assertRanges([[1.66, 3.59], [0.69, 2.17]]);
},
null, BOXEVENTS, 'bar select'
);
})
.catch(fail)
.then(done);
});
});