@@ -21,52 +21,12 @@ function countCanvases() {
21
21
return d3 . selectAll ( 'canvas' ) . size ( ) ;
22
22
}
23
23
24
- describe ( 'Test gl3d plots ' , function ( ) {
25
- var gd , ptData ;
24
+ describe ( 'Test gl3d before/after plot ' , function ( ) {
25
+ var gd ;
26
26
27
27
var mock = require ( '@mocks/gl3d_marker-arrays.json' ) ;
28
- var multipleScatter3dMock = require ( '@mocks/gl3d_multiple-scatter3d-traces.json' ) ;
29
-
30
- // lines, markers, text, error bars and surfaces each
31
- // correspond to one glplot object
32
- var mock2 = Lib . extendDeep ( { } , mock ) ;
33
- mock2 . data [ 0 ] . mode = 'lines+markers+text' ;
34
- mock2 . data [ 0 ] . error_z = { value : 10 } ;
35
- mock2 . data [ 0 ] . surfaceaxis = 2 ;
36
- mock2 . layout . showlegend = true ;
37
-
38
- var mock3 = require ( '@mocks/gl3d_autocolorscale' ) ;
39
-
40
- function assertHoverText ( xLabel , yLabel , zLabel , textLabel ) {
41
- var content = [ ] ;
42
- if ( xLabel ) content . push ( xLabel ) ;
43
- if ( yLabel ) content . push ( yLabel ) ;
44
- if ( zLabel ) content . push ( zLabel ) ;
45
- if ( textLabel ) content . push ( textLabel ) ;
46
- assertHoverLabelContent ( { nums : content . join ( '\n' ) } ) ;
47
- }
48
-
49
- function assertEventData ( x , y , z , curveNumber , pointNumber , extra ) {
50
- expect ( Object . keys ( ptData ) ) . toEqual ( jasmine . arrayContaining ( [
51
- 'x' , 'y' , 'z' ,
52
- 'data' , 'fullData' , 'curveNumber' , 'pointNumber'
53
- ] ) , 'correct hover data fields' ) ;
54
-
55
- expect ( ptData . x ) . toEqual ( x , 'x val' ) ;
56
- expect ( ptData . y ) . toEqual ( y , 'y val' ) ;
57
- expect ( ptData . z ) . toEqual ( z , 'z val' ) ;
58
- expect ( ptData . curveNumber ) . toEqual ( curveNumber , 'curveNumber' ) ;
59
- expect ( ptData . pointNumber ) . toEqual ( pointNumber , 'pointNumber' ) ;
60
-
61
- Object . keys ( extra || { } ) . forEach ( function ( k ) {
62
- expect ( ptData [ k ] ) . toBe ( extra [ k ] , k + ' val' ) ;
63
- } ) ;
64
- }
65
28
66
29
beforeEach ( function ( ) {
67
- gd = createGraphDiv ( ) ;
68
- ptData = { } ;
69
-
70
30
jasmine . DEFAULT_TIMEOUT_INTERVAL = 4000 ;
71
31
} ) ;
72
32
@@ -100,22 +60,26 @@ describe('Test gl3d plots', function() {
100
60
}
101
61
}
102
62
} ,
103
- mock2
63
+ mock
104
64
) ;
105
65
106
- // N.B. gl3d click events are 'mouseover' events
107
- // with button 1 pressed
108
- function _click ( ) {
109
- mouseEvent ( 'mouseover' , 605 , 271 , { buttons : 1 } ) ;
66
+ var x = 605 ;
67
+ var y = 271 ;
68
+
69
+ function _stayThere ( ) {
70
+ mouseEvent ( 'mousemove' , x , y ) ;
110
71
return delay ( 20 ) ( ) ;
111
72
}
112
73
113
- Plotly . plot ( gd , _mock )
114
- . then ( delay ( 20 ) )
74
+ function _clickThere ( ) {
75
+ mouseEvent ( 'mouseover' , x , y , { buttons : 1 } ) ;
76
+ return delay ( 20 ) ( ) ;
77
+ }
78
+
79
+ _stayThere ( )
115
80
. then ( function ( ) {
116
- gd . on ( 'plotly_click' , function ( eventData ) {
117
- ptData = eventData . points [ 0 ] ;
118
- } ) ;
81
+ gd = createGraphDiv ( ) ;
82
+ return Plotly . plot ( gd , _mock ) ;
119
83
} )
120
84
. then ( delay ( 20 ) )
121
85
. then ( function ( ) {
@@ -129,35 +93,95 @@ describe('Test gl3d plots', function() {
129
93
expect ( cameraIn . eye . x ) . toEqual ( 1.2 , 'cameraIn.eye.x' ) ;
130
94
expect ( cameraIn . eye . y ) . toEqual ( 1.2 , 'cameraIn.eye.y' ) ;
131
95
expect ( cameraIn . eye . z ) . toEqual ( 1.2 , 'cameraIn.eye.z' ) ;
132
-
133
- var cameraBefore = gd . _fullLayout . scene . _scene . glplot . camera ;
134
- expect ( cameraBefore . up [ 0 ] ) . toBeCloseTo ( 0 , 3 , 'cameraBefore.up[0]' ) ;
135
- expect ( cameraBefore . up [ 1 ] ) . toBeCloseTo ( 0 , 3 , 'cameraBefore.up[1]' ) ;
136
- expect ( cameraBefore . up [ 2 ] ) . toBeCloseTo ( 1 , 3 , 'cameraBefore.up[2]' ) ;
137
- expect ( cameraBefore . center [ 0 ] ) . toBeCloseTo ( 0 , 3 , 'cameraBefore.center[0]' ) ;
138
- expect ( cameraBefore . center [ 1 ] ) . toBeCloseTo ( 0 , 3 , 'cameraBefore.center[1]' ) ;
139
- expect ( cameraBefore . center [ 2 ] ) . toBeCloseTo ( 0 , 3 , 'cameraBefore.center[2]' ) ;
140
- expect ( cameraBefore . eye [ 0 ] ) . toBeCloseTo ( 1.2 , 3 , 'cameraBefore.eye[0]' ) ;
141
- expect ( cameraBefore . eye [ 1 ] ) . toBeCloseTo ( 1.2 , 3 , 'cameraBefore.eye[1]' ) ;
142
- expect ( cameraBefore . eye [ 2 ] ) . toBeCloseTo ( 1.2 , 3 , 'cameraBefore.eye[2]' ) ;
143
96
} )
144
- . then ( _click )
97
+ . then ( delay ( 20 ) )
98
+ . then ( function ( ) {
99
+ var cameraBefore = gd . _fullLayout . scene . _scene . glplot . camera ;
100
+ expect ( cameraBefore . up [ 0 ] ) . toBeCloseTo ( 0 , 2 , 'cameraBefore.up[0]' ) ;
101
+ expect ( cameraBefore . up [ 1 ] ) . toBeCloseTo ( 0 , 2 , 'cameraBefore.up[1]' ) ;
102
+ expect ( cameraBefore . up [ 2 ] ) . toBeCloseTo ( 1 , 2 , 'cameraBefore.up[2]' ) ;
103
+ expect ( cameraBefore . center [ 0 ] ) . toBeCloseTo ( 0 , 2 , 'cameraBefore.center[0]' ) ;
104
+ expect ( cameraBefore . center [ 1 ] ) . toBeCloseTo ( 0 , 2 , 'cameraBefore.center[1]' ) ;
105
+ expect ( cameraBefore . center [ 2 ] ) . toBeCloseTo ( 0 , 2 , 'cameraBefore.center[2]' ) ;
106
+ expect ( cameraBefore . eye [ 0 ] ) . toBeCloseTo ( 1.2 , 2 , 'cameraBefore.eye[0]' ) ;
107
+ expect ( cameraBefore . eye [ 1 ] ) . toBeCloseTo ( 1.2 , 2 , 'cameraBefore.eye[1]' ) ;
108
+ expect ( cameraBefore . eye [ 2 ] ) . toBeCloseTo ( 1.2 , 2 , 'cameraBefore.eye[2]' ) ;
109
+ expect ( cameraBefore . mouseListener . enabled === true ) ;
110
+ } )
111
+ . then ( _clickThere )
145
112
. then ( delay ( 20 ) )
146
113
. then ( function ( ) {
147
114
var cameraAfter = gd . _fullLayout . scene . _scene . glplot . camera ;
148
- expect ( cameraAfter . up [ 0 ] ) . toBeCloseTo ( 0 , 3 , 'cameraAfter.up[0]' ) ;
149
- expect ( cameraAfter . up [ 1 ] ) . toBeCloseTo ( 0 , 3 , 'cameraAfter.up[1]' ) ;
150
- expect ( cameraAfter . up [ 2 ] ) . toBeCloseTo ( 1 , 3 , 'cameraAfter.up[2]' ) ;
151
- expect ( cameraAfter . center [ 0 ] ) . toBeCloseTo ( 0 , 3 , 'cameraAfter.center[0]' ) ;
152
- expect ( cameraAfter . center [ 1 ] ) . toBeCloseTo ( 0 , 3 , 'cameraAfter.center[1]' ) ;
153
- expect ( cameraAfter . center [ 2 ] ) . toBeCloseTo ( 0 , 3 , 'cameraAfter.center[2]' ) ;
154
- expect ( cameraAfter . eye [ 0 ] ) . not . toBeCloseTo ( 1.2 , 3 , 'cameraAfter.eye[0]' ) ;
155
- expect ( cameraAfter . eye [ 1 ] ) . not . toBeCloseTo ( 1.2 , 3 , 'cameraAfter.eye[1]' ) ;
156
- expect ( cameraAfter . eye [ 2 ] ) . not . toBeCloseTo ( 1.2 , 3 , 'cameraAfter.eye[2]' ) ;
115
+ expect ( cameraAfter . up [ 0 ] ) . toBeCloseTo ( 0 , 2 , 'cameraAfter.up[0]' ) ;
116
+ expect ( cameraAfter . up [ 1 ] ) . toBeCloseTo ( 0 , 2 , 'cameraAfter.up[1]' ) ;
117
+ expect ( cameraAfter . up [ 2 ] ) . toBeCloseTo ( 1 , 2 , 'cameraAfter.up[2]' ) ;
118
+ expect ( cameraAfter . center [ 0 ] ) . toBeCloseTo ( 0 , 2 , 'cameraAfter.center[0]' ) ;
119
+ expect ( cameraAfter . center [ 1 ] ) . toBeCloseTo ( 0 , 2 , 'cameraAfter.center[1]' ) ;
120
+ expect ( cameraAfter . center [ 2 ] ) . toBeCloseTo ( 0 , 2 , 'cameraAfter.center[2]' ) ;
121
+ expect ( cameraAfter . eye [ 0 ] ) . not . toBeCloseTo ( 1.2 , 2 , 'cameraAfter.eye[0]' ) ;
122
+ expect ( cameraAfter . eye [ 1 ] ) . not . toBeCloseTo ( 1.2 , 2 , 'cameraAfter.eye[1]' ) ;
123
+ expect ( cameraAfter . eye [ 2 ] ) . not . toBeCloseTo ( 1.2 , 2 , 'cameraAfter.eye[2]' ) ;
124
+ expect ( cameraAfter . mouseListener . enabled === true ) ;
157
125
} )
158
126
. then ( done ) ;
159
127
} ) ;
160
128
129
+ } ) ;
130
+
131
+ describe ( 'Test gl3d plots' , function ( ) {
132
+ var gd , ptData ;
133
+
134
+ var mock = require ( '@mocks/gl3d_marker-arrays.json' ) ;
135
+ var multipleScatter3dMock = require ( '@mocks/gl3d_multiple-scatter3d-traces.json' ) ;
136
+
137
+ // lines, markers, text, error bars and surfaces each
138
+ // correspond to one glplot object
139
+ var mock2 = Lib . extendDeep ( { } , mock ) ;
140
+ mock2 . data [ 0 ] . mode = 'lines+markers+text' ;
141
+ mock2 . data [ 0 ] . error_z = { value : 10 } ;
142
+ mock2 . data [ 0 ] . surfaceaxis = 2 ;
143
+ mock2 . layout . showlegend = true ;
144
+
145
+ var mock3 = require ( '@mocks/gl3d_autocolorscale' ) ;
146
+
147
+ function assertHoverText ( xLabel , yLabel , zLabel , textLabel ) {
148
+ var content = [ ] ;
149
+ if ( xLabel ) content . push ( xLabel ) ;
150
+ if ( yLabel ) content . push ( yLabel ) ;
151
+ if ( zLabel ) content . push ( zLabel ) ;
152
+ if ( textLabel ) content . push ( textLabel ) ;
153
+ assertHoverLabelContent ( { nums : content . join ( '\n' ) } ) ;
154
+ }
155
+
156
+ function assertEventData ( x , y , z , curveNumber , pointNumber , extra ) {
157
+ expect ( Object . keys ( ptData ) ) . toEqual ( jasmine . arrayContaining ( [
158
+ 'x' , 'y' , 'z' ,
159
+ 'data' , 'fullData' , 'curveNumber' , 'pointNumber'
160
+ ] ) , 'correct hover data fields' ) ;
161
+
162
+ expect ( ptData . x ) . toEqual ( x , 'x val' ) ;
163
+ expect ( ptData . y ) . toEqual ( y , 'y val' ) ;
164
+ expect ( ptData . z ) . toEqual ( z , 'z val' ) ;
165
+ expect ( ptData . curveNumber ) . toEqual ( curveNumber , 'curveNumber' ) ;
166
+ expect ( ptData . pointNumber ) . toEqual ( pointNumber , 'pointNumber' ) ;
167
+
168
+ Object . keys ( extra || { } ) . forEach ( function ( k ) {
169
+ expect ( ptData [ k ] ) . toBe ( extra [ k ] , k + ' val' ) ;
170
+ } ) ;
171
+ }
172
+
173
+ beforeEach ( function ( ) {
174
+ gd = createGraphDiv ( ) ;
175
+ ptData = { } ;
176
+
177
+ jasmine . DEFAULT_TIMEOUT_INTERVAL = 4000 ;
178
+ } ) ;
179
+
180
+ afterEach ( function ( ) {
181
+ Plotly . purge ( gd ) ;
182
+ destroyGraphDiv ( ) ;
183
+ } ) ;
184
+
161
185
it ( '@noCI @gl should display correct hover labels of the second point of the very first scatter3d trace' , function ( done ) {
162
186
var _mock = Lib . extendDeep ( { } , multipleScatter3dMock ) ;
163
187
0 commit comments