@@ -4,29 +4,106 @@ var Plotly = require('@lib/index');
4
4
5
5
var createGraphDiv = require ( '../assets/create_graph_div' ) ;
6
6
var destroyGraphDiv = require ( '../assets/destroy_graph_div' ) ;
7
+ var mouseEvent = require ( '../assets/mouse_event' ) ;
7
8
8
9
/*
9
10
* WebGL interaction test cases fail on the CircleCI
10
11
* most likely due to a WebGL/driver issue
11
12
*
12
13
*/
13
14
15
+ var PLOT_DELAY = 100 ;
16
+ var MOUSE_DELAY = 20 ;
14
17
15
- describe ( 'Test plot structure' , function ( ) {
18
+
19
+ describe ( 'Test gl plot interactions' , function ( ) {
16
20
'use strict' ;
17
21
18
22
afterEach ( destroyGraphDiv ) ;
19
23
20
24
describe ( 'gl3d plots' , function ( ) {
21
25
var mock = require ( '@mocks/gl3d_marker-arrays.json' ) ;
26
+ var gd ;
27
+
28
+ function mouseEventScatter3d ( type , opts ) {
29
+ mouseEvent ( type , 605 , 271 , opts ) ;
30
+ }
22
31
23
32
beforeEach ( function ( done ) {
24
- Plotly . plot ( createGraphDiv ( ) , mock . data , mock . layout ) . then ( done ) ;
33
+ gd = createGraphDiv ( ) ;
34
+ Plotly . plot ( gd , mock . data , mock . layout ) . then ( done ) ;
25
35
} ) ;
26
36
27
- it ( 'has one *canvas* node' , function ( ) {
28
- var nodes = d3 . selectAll ( 'canvas' ) ;
29
- expect ( nodes [ 0 ] . length ) . toEqual ( 1 ) ;
37
+ describe ( 'scatter3d hover' , function ( ) {
38
+ var node , ptData ;
39
+
40
+ beforeEach ( function ( done ) {
41
+ gd . on ( 'plotly_hover' , function ( eventData ) {
42
+ ptData = eventData . points [ 0 ] ;
43
+ } ) ;
44
+
45
+ setTimeout ( function ( ) {
46
+ mouseEventScatter3d ( 'mouseover' ) ;
47
+ setTimeout ( done , MOUSE_DELAY ) ;
48
+ } , PLOT_DELAY ) ;
49
+ } ) ;
50
+
51
+ it ( 'should have' , function ( ) {
52
+ node = d3 . selectAll ( 'canvas' ) ;
53
+ expect ( node [ 0 ] . length ) . toEqual ( 1 , 'one canvas node' ) ;
54
+
55
+ node = d3 . selectAll ( 'g.hovertext' ) ;
56
+ expect ( node . size ( ) ) . toEqual ( 1 , 'one hover text group' ) ;
57
+
58
+ node = d3 . selectAll ( 'g.hovertext' ) . selectAll ( 'tspan' ) [ 0 ] ;
59
+ expect ( node [ 0 ] . innerHTML ) . toEqual ( 'x: 140.72' , 'x val on hover' ) ;
60
+ expect ( node [ 1 ] . innerHTML ) . toEqual ( 'y: −96.97' , 'y val on hover' ) ;
61
+ expect ( node [ 2 ] . innerHTML ) . toEqual ( 'z: −96.97' , 'z val on hover' ) ;
62
+
63
+ expect ( Object . keys ( ptData ) ) . toEqual ( [
64
+ 'x' , 'y' , 'z' ,
65
+ 'data' , 'fullData' , 'curveNumber' , 'pointNumber'
66
+ ] , 'correct hover data fields' ) ;
67
+
68
+ expect ( ptData . x ) . toBe ( '140.72' , 'x val hover data' ) ;
69
+ expect ( ptData . y ) . toBe ( '−96.97' , 'y val hover data' ) ;
70
+ expect ( ptData . z ) . toEqual ( '−96.97' , 'z val hover data' ) ;
71
+ expect ( ptData . curveNumber ) . toEqual ( 0 , 'curveNumber hover data' ) ;
72
+ expect ( ptData . pointNumber ) . toEqual ( 2 , 'pointNumber hover data' ) ;
73
+ } ) ;
74
+
75
+ } ) ;
76
+
77
+ describe ( 'scatter3d click events' , function ( ) {
78
+ var ptData ;
79
+
80
+ beforeEach ( function ( done ) {
81
+ gd . on ( 'plotly_click' , function ( eventData ) {
82
+ ptData = eventData . points [ 0 ] ;
83
+ } ) ;
84
+
85
+ setTimeout ( function ( ) {
86
+
87
+ // N.B. gl3d click events are 'mouseover' events
88
+ // with button 1 pressed
89
+ mouseEventScatter3d ( 'mouseover' , { buttons : 1 } ) ;
90
+ setTimeout ( done , MOUSE_DELAY ) ;
91
+ } , PLOT_DELAY ) ;
92
+ } ) ;
93
+
94
+ it ( 'should have' , function ( ) {
95
+ expect ( Object . keys ( ptData ) ) . toEqual ( [
96
+ 'x' , 'y' , 'z' ,
97
+ 'data' , 'fullData' , 'curveNumber' , 'pointNumber'
98
+ ] , 'correct hover data fields' ) ;
99
+
100
+
101
+ expect ( ptData . x ) . toBe ( '140.72' , 'x val click data' ) ;
102
+ expect ( ptData . y ) . toBe ( '−96.97' , 'y val click data' ) ;
103
+ expect ( ptData . z ) . toEqual ( '−96.97' , 'z val click data' ) ;
104
+ expect ( ptData . curveNumber ) . toEqual ( 0 , 'curveNumber click data' ) ;
105
+ expect ( ptData . pointNumber ) . toEqual ( 2 , 'pointNumber click data' ) ;
106
+ } ) ;
30
107
} ) ;
31
108
} ) ;
32
109
0 commit comments