@@ -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,47 @@ describe('Test scatterpolargl interactions:', function() {
258297 } )
259298 . then ( done , done . fail ) ;
260299 } ) ;
300+
301+ [
302+ [ 'linear' , [ 0 , 180 ] ] ,
303+ [ 'category' , [ 'A' , 'B' ] ] ,
304+ ] . forEach ( function ( test ) {
305+ var axType = test [ 0 ] ;
306+ var x = test [ 1 ] ;
307+ it ( '@gl should return the same eventData as scatter on ' + axType + ' axis' , function ( done ) {
308+ var _mock = {
309+ data : [ { type : 'scatterpolar' , r : [ 5 , 10 ] , theta : x } ] ,
310+ layout : { dragmode : 'select' , width : 400 , height : 400 }
311+ } ;
312+ gd = createGraphDiv ( ) ;
313+ var scatterpolarEventData = { } ;
314+ var selectPath = [ [ 200 , 150 ] , [ 400 , 250 ] ] ;
315+
316+ Plotly . newPlot ( gd , _mock )
317+ . then ( delay ( 20 ) )
318+ . then ( function ( ) {
319+ expect ( gd . _fullLayout . polar . angularaxis . type ) . toEqual ( test [ 0 ] ) ;
320+ return select ( gd , selectPath ) ;
321+ } )
322+ . then ( delay ( 20 ) )
323+ . then ( function ( eventData ) {
324+ scatterpolarEventData = eventData ;
325+ // Make sure we selected a point
326+ expect ( eventData . points . length ) . toBe ( 1 ) ;
327+ return Plotly . restyle ( gd , 'type' , 'scatterpolargl' ) ;
328+ } )
329+ . then ( delay ( 20 ) )
330+ . then ( function ( ) {
331+ expect ( gd . _fullLayout . polar . angularaxis . type ) . toEqual ( test [ 0 ] ) ;
332+ return select ( gd , selectPath ) ;
333+ } )
334+ . then ( delay ( 20 ) )
335+ . then ( function ( eventData ) {
336+ assertEventData ( eventData , scatterpolarEventData ) ;
337+ } )
338+ . then ( done , done . fail ) ;
339+ } ) ;
340+ } ) ;
261341} ) ;
262342
263343describe ( 'Test scatterpolargl autorange:' , function ( ) {
0 commit comments