@@ -2,17 +2,44 @@ var Plotly = require('@lib/index');
2
2
var Lib = require ( '@src/lib' ) ;
3
3
var ScatterPolarGl = require ( '@src/traces/scatterpolargl' ) ;
4
4
5
+ var d3Select = require ( '../../strict-d3' ) . select ;
5
6
var d3SelectAll = require ( '../../strict-d3' ) . selectAll ;
6
7
var createGraphDiv = require ( '../assets/create_graph_div' ) ;
7
8
var destroyGraphDiv = require ( '../assets/destroy_graph_div' ) ;
8
9
10
+ var delay = require ( '../assets/delay' ) ;
9
11
var mouseEvent = require ( '../assets/mouse_event' ) ;
10
12
var readPixel = require ( '../assets/read_pixel' ) ;
11
13
12
14
var customAssertions = require ( '../assets/custom_assertions' ) ;
13
15
var assertHoverLabelContent = customAssertions . assertHoverLabelContent ;
14
16
var checkTextTemplate = require ( '../assets/check_texttemplate' ) ;
15
17
18
+ function drag ( gd , path ) {
19
+ var len = path . length ;
20
+ var el = d3Select ( gd ) . select ( 'rect.nsewdrag' ) . node ( ) ;
21
+ var opts = { element : el } ;
22
+
23
+ Lib . clearThrottle ( ) ;
24
+ mouseEvent ( 'mousemove' , path [ 0 ] [ 0 ] , path [ 0 ] [ 1 ] , opts ) ;
25
+ mouseEvent ( 'mousedown' , path [ 0 ] [ 0 ] , path [ 0 ] [ 1 ] , opts ) ;
26
+
27
+ path . slice ( 1 , len ) . forEach ( function ( pt ) {
28
+ Lib . clearThrottle ( ) ;
29
+ mouseEvent ( 'mousemove' , pt [ 0 ] , pt [ 1 ] , opts ) ;
30
+ } ) ;
31
+
32
+ mouseEvent ( 'mouseup' , path [ len - 1 ] [ 0 ] , path [ len - 1 ] [ 1 ] , opts ) ;
33
+ }
34
+
35
+ function select ( gd , path ) {
36
+ return new Promise ( function ( resolve , reject ) {
37
+ gd . once ( 'plotly_selected' , resolve ) ;
38
+ setTimeout ( function ( ) { reject ( 'did not trigger *plotly_selected*' ) ; } , 200 ) ;
39
+ drag ( gd , path ) ;
40
+ } ) ;
41
+ }
42
+
16
43
describe ( 'Test scatterpolargl hover:' , function ( ) {
17
44
var gd ;
18
45
@@ -132,6 +159,18 @@ describe('Test scatterpolargl interactions:', function() {
132
159
. reduce ( function ( acc , v ) { return acc + v ; } , 0 ) ;
133
160
}
134
161
162
+ function assertEventData ( actual , expected ) {
163
+ expect ( actual . points . length ) . toBe ( expected . points . length ) ;
164
+
165
+ expected . points . forEach ( function ( e , i ) {
166
+ var a = actual . points [ i ] ;
167
+ if ( a ) {
168
+ expect ( a . r ) . toBe ( e . r , 'r' ) ;
169
+ expect ( a . theta ) . toBe ( e . theta , 'theta' ) ;
170
+ }
171
+ } ) ;
172
+ }
173
+
135
174
it ( '@gl should be able to toggle from svg to gl' , function ( done ) {
136
175
gd = createGraphDiv ( ) ;
137
176
@@ -258,6 +297,50 @@ describe('Test scatterpolargl interactions:', function() {
258
297
} )
259
298
. then ( done , done . fail ) ;
260
299
} ) ;
300
+
301
+ [ 'r' , 'theta' ] . forEach ( function ( ax ) {
302
+ [
303
+ [ 'linear' , [ 0 , 180 ] ] ,
304
+ [ 'category' , [ 'A' , 'B' ] ] ,
305
+ ] . forEach ( function ( test ) {
306
+ var axType = test [ 0 ] ;
307
+ var axNames = { 'r' : 'radialaxis' , 'theta' : 'angularaxis' } ;
308
+ it ( '@gl should return the same eventData as scatter on ' + axType + ' ' + ax + ' axis' , function ( done ) {
309
+ var _mock = {
310
+ data : [ { type : 'scatterpolar' , r : [ 5 , 10 ] , theta : [ 0 , 180 ] } ] ,
311
+ layout : { dragmode : 'select' , width : 400 , height : 400 }
312
+ } ;
313
+ _mock . data [ 0 ] [ ax ] = test [ 1 ] ;
314
+ gd = createGraphDiv ( ) ;
315
+ var scatterpolarEventData = { } ;
316
+ var selectPath = [ [ 185 , 150 ] , [ 400 , 250 ] ] ;
317
+
318
+ Plotly . newPlot ( gd , _mock )
319
+ . then ( delay ( 20 ) )
320
+ . then ( function ( ) {
321
+ expect ( gd . _fullLayout . polar [ axNames [ ax ] ] . type ) . toEqual ( test [ 0 ] ) ;
322
+ return select ( gd , selectPath ) ;
323
+ } )
324
+ . then ( delay ( 20 ) )
325
+ . then ( function ( eventData ) {
326
+ scatterpolarEventData = eventData ;
327
+ // Make sure we selected a point
328
+ expect ( eventData . points . length ) . toBe ( 1 ) ;
329
+ return Plotly . restyle ( gd , 'type' , 'scatterpolargl' ) ;
330
+ } )
331
+ . then ( delay ( 20 ) )
332
+ . then ( function ( ) {
333
+ expect ( gd . _fullLayout . polar [ axNames [ ax ] ] . type ) . toEqual ( test [ 0 ] ) ;
334
+ return select ( gd , selectPath ) ;
335
+ } )
336
+ . then ( delay ( 20 ) )
337
+ . then ( function ( eventData ) {
338
+ assertEventData ( eventData , scatterpolarEventData ) ;
339
+ } )
340
+ . then ( done , done . fail ) ;
341
+ } ) ;
342
+ } ) ;
343
+ } ) ;
261
344
} ) ;
262
345
263
346
describe ( 'Test scatterpolargl autorange:' , function ( ) {
0 commit comments