@@ -2,17 +2,44 @@ var Plotly = require('@lib/index');
22var Lib = require ( '@src/lib' ) ;
33var ScatterPolarGl = require ( '@src/traces/scatterpolargl' ) ;
44
5+ var d3Select = require ( '../../strict-d3' ) . select ;
56var d3SelectAll = require ( '../../strict-d3' ) . selectAll ;
67var createGraphDiv = require ( '../assets/create_graph_div' ) ;
78var destroyGraphDiv = require ( '../assets/destroy_graph_div' ) ;
89
10+ var delay = require ( '../assets/delay' ) ;
911var mouseEvent = require ( '../assets/mouse_event' ) ;
1012var readPixel = require ( '../assets/read_pixel' ) ;
1113
1214var customAssertions = require ( '../assets/custom_assertions' ) ;
1315var assertHoverLabelContent = customAssertions . assertHoverLabelContent ;
1416var checkTextTemplate = require ( '../assets/check_texttemplate' ) ;
1517
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+
1643describe ( 'Test scatterpolargl hover:' , function ( ) {
1744 var gd ;
1845
@@ -132,6 +159,18 @@ describe('Test scatterpolargl interactions:', function() {
132159 . reduce ( function ( acc , v ) { return acc + v ; } , 0 ) ;
133160 }
134161
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+
135174 it ( '@gl should be able to toggle from svg to gl' , function ( done ) {
136175 gd = createGraphDiv ( ) ;
137176
@@ -258,6 +297,50 @@ describe('Test scatterpolargl interactions:', function() {
258297 } )
259298 . then ( done , done . fail ) ;
260299 } ) ;
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+ } ) ;
261344} ) ;
262345
263346describe ( 'Test scatterpolargl autorange:' , function ( ) {
0 commit comments