@@ -1213,6 +1213,86 @@ describe('Test polar *gridshape linear* interactions', function() {
12131213 . then ( done ) ;
12141214 } ) ;
12151215
1216- // - test handle position an
1216+ it ( 'should place zoombox handles at correct place on main drag' , function ( done ) {
1217+ var dragCoverNode ;
1218+ var p1 ;
1219+
1220+ // d attr to array of segment [x,y]
1221+ function path2coords ( path ) {
1222+ if ( ! path . size ( ) ) return [ [ ] ] ;
1223+ return path . attr ( 'd' )
1224+ . replace ( / Z / g, '' )
1225+ . split ( 'M' )
1226+ . filter ( Boolean )
1227+ . map ( function ( s ) {
1228+ return s . split ( 'L' )
1229+ . map ( function ( s ) { return s . split ( ',' ) . map ( Number ) ; } ) ;
1230+ } )
1231+ . reduce ( function ( a , b ) { return a . concat ( b ) ; } ) ;
1232+ }
1233+
1234+ function _dragStart ( p0 , dp ) {
1235+ var node = d3 . select ( '.polar > .draglayer > .maindrag' ) . node ( ) ;
1236+ mouseEvent ( 'mousemove' , p0 [ 0 ] , p0 [ 1 ] , { element : node } ) ;
1237+ mouseEvent ( 'mousedown' , p0 [ 0 ] , p0 [ 1 ] , { element : node } ) ;
1238+
1239+ var promise = drag . waitForDragCover ( ) . then ( function ( dcn ) {
1240+ dragCoverNode = dcn ;
1241+ p1 = [ p0 [ 0 ] + dp [ 0 ] , p0 [ 1 ] + dp [ 1 ] ] ;
1242+ mouseEvent ( 'mousemove' , p1 [ 0 ] , p1 [ 1 ] , { element : dragCoverNode } ) ;
1243+ } ) ;
1244+ return promise ;
1245+ }
12171246
1247+ function _assertAndDragEnd ( msg , exp ) {
1248+ var zl = d3 . select ( gd ) . select ( 'g.zoomlayer' ) ;
1249+
1250+ expect ( path2coords ( zl . select ( '.zoombox' ) ) )
1251+ . toBeCloseTo2DArray ( exp . zoombox , 2 , msg + ' - zoombox' ) ;
1252+ expect ( path2coords ( zl . select ( '.zoombox-corners' ) ) )
1253+ . toBeCloseTo2DArray ( exp . corners , 2 , msg + ' - corners' ) ;
1254+
1255+ mouseEvent ( 'mouseup' , p1 [ 0 ] , p1 [ 1 ] , { element : dragCoverNode } ) ;
1256+ return drag . waitForDragCoverRemoval ( ) ;
1257+ }
1258+
1259+ Plotly . plot ( gd , [ {
1260+ type : 'scatterpolar' ,
1261+ r : [ 1 , 2 , 3 , 2 , 3 ] ,
1262+ theta : [ 'a' , 'b' , 'c' , 'd' , 'e' ]
1263+ } ] , {
1264+ polar : {
1265+ gridshape : 'linear' ,
1266+ angularaxis : { direction : 'clockwise' }
1267+ } ,
1268+ width : 400 ,
1269+ height : 400 ,
1270+ margin : { l : 50 , t : 50 , b : 50 , r : 50 }
1271+ } )
1272+ . then ( function ( ) { return _dragStart ( [ 170 , 170 ] , [ 220 , 220 ] ) ; } )
1273+ . then ( function ( ) {
1274+ _assertAndDragEnd ( 'drag outward toward bottom right' , {
1275+ zoombox : [
1276+ [ - 142.658 , - 46.353 ] , [ - 88.167 , 121.352 ] ,
1277+ [ 88.167 , 121.352 ] , [ 142.658 , - 46.352 ] ,
1278+ [ 0 , - 150 ] , [ - 142.658 , - 46.352 ] ,
1279+ [ - 142.658 , - 46.352 ] ,
1280+ [ - 88.167 , 121.352 ] ,
1281+ [ 88.167 , 121.352 ] , [ 142.658 , - 46.352 ] ,
1282+ [ 0 , - 150 ] , [ - 142.658 , - 46.352 ] ,
1283+ [ - 49.261 , - 16.005 ] , [ - 30.445 , 41.904 ] ,
1284+ [ 30.44508691777904 , 41.904 ] , [ 49.261 , - 16.005 ] ,
1285+ [ 0 , - 51.796 ] , [ - 49.261 , - 16.005 ]
1286+ ] ,
1287+ corners : [
1288+ [ - 13.342 , - 39.630 ] , [ - 33.567 , - 24.935 ] ,
1289+ [ - 35.918 , - 28.171 ] , [ - 15.693 , - 42.866 ] ,
1290+ [ - 60.040 , - 103.905 ] , [ - 80.266 , - 89.210 ] ,
1291+ [ - 82.617 , - 92.446 ] , [ - 62.392 , - 107.141 ]
1292+ ]
1293+ } ) ;
1294+ } )
1295+ . catch ( failTest )
1296+ . then ( done ) ;
1297+ } ) ;
12181298} ) ;
0 commit comments