@@ -961,7 +961,7 @@ describe('Test polar interactions:', function() {
961
961
. then ( done , done . fail ) ;
962
962
} ) ;
963
963
964
- it ( 'should response to drag interactions on radial drag area' , function ( done ) {
964
+ it ( 'should respond to drag interactions on radial drag area' , function ( done ) {
965
965
var fig = Lib . extendDeep ( { } , require ( '@mocks/polar_scatter.json' ) ) ;
966
966
967
967
// to avoid dragging on hover labels
@@ -1044,7 +1044,7 @@ describe('Test polar interactions:', function() {
1044
1044
. then ( done , done . fail ) ;
1045
1045
} ) ;
1046
1046
1047
- it ( 'should response to drag interactions on inner radial drag area' , function ( done ) {
1047
+ it ( 'should respond to drag interactions on inner radial drag area' , function ( done ) {
1048
1048
var fig = Lib . extendDeep ( { } , require ( '@mocks/polar_scatter.json' ) ) ;
1049
1049
fig . layout . polar . hole = 0.2 ;
1050
1050
// to avoid dragging on hover labels
@@ -1082,7 +1082,7 @@ describe('Test polar interactions:', function() {
1082
1082
. then ( done , done . fail ) ;
1083
1083
} ) ;
1084
1084
1085
- it ( 'should response to drag interactions on angular drag area' , function ( done ) {
1085
+ it ( 'should respond to drag interactions on angular drag area' , function ( done ) {
1086
1086
var fig = Lib . extendDeep ( { } , require ( '@mocks/polar_scatter.json' ) ) ;
1087
1087
1088
1088
// to avoid dragging on hover labels
@@ -1146,6 +1146,282 @@ describe('Test polar interactions:', function() {
1146
1146
. then ( done , done . fail ) ;
1147
1147
} ) ;
1148
1148
1149
+ describe ( 'dragmode === false' , function ( ) {
1150
+ it ( 'should not respond to drag interactions on plot area when dragmode === false' , function ( done ) {
1151
+ var fig = Lib . extendDeep ( { } , require ( '@mocks/polar_scatter.json' ) ) ;
1152
+ // adjust margins so that middle of plot area is at 300x300
1153
+ // with its middle at [200,200]
1154
+ fig . layout . width = 400 ;
1155
+ fig . layout . height = 400 ;
1156
+ fig . layout . margin = { l : 50 , t : 50 , b : 50 , r : 50 } ;
1157
+
1158
+ var mid = [ 200 , 200 ] ;
1159
+ var resetNumber = 0 ;
1160
+
1161
+ function _drag ( p0 , dp ) {
1162
+ var node = d3Select ( '.polar > .draglayer > .maindrag' ) . node ( ) ;
1163
+ return drag ( { node : node , dpos : dp , pos0 : p0 } ) ;
1164
+ }
1165
+
1166
+ function _assertRange ( rng , msg ) {
1167
+ expect ( gd . _fullLayout . polar . radialaxis . range ) . toBeCloseToArray ( rng , 1 , msg ) ;
1168
+ }
1169
+
1170
+ function _assertBase ( extra ) {
1171
+ var msg = 'base range' + ( extra ? ' ' + extra : '' ) ;
1172
+ _assertRange ( [ 0 , 11.1 ] , msg ) ;
1173
+ }
1174
+
1175
+ function _reset ( ) {
1176
+ resetNumber ++ ;
1177
+
1178
+ var extra = '(reset ' + resetNumber + ')' ;
1179
+ _assertBase ( extra ) ;
1180
+ expect ( eventCnts . plotly_doubleclick ) . toBe ( 0 , 'doubleclick event #' + extra ) ;
1181
+ }
1182
+
1183
+ _plot ( fig )
1184
+ . then ( _assertBase )
1185
+ . then ( function ( ) { return Plotly . relayout ( gd , 'dragmode' , false ) ; } )
1186
+ . then ( function ( ) { return _drag ( mid , [ 50 , 50 ] ) ; } )
1187
+ . then ( function ( ) {
1188
+ _assertBase ( 'from center move toward bottom-right' ) ;
1189
+ } )
1190
+ . then ( delay ( 20 ) )
1191
+ . then ( function ( ) { return _doubleClick ( mid ) ; } )
1192
+ . then ( delay ( 20 ) )
1193
+ . then ( _reset )
1194
+ . then ( function ( ) { return _drag ( mid , [ - 50 , - 50 ] ) ; } )
1195
+ . then ( function ( ) {
1196
+ _assertBase ( 'from center move toward top-left' ) ;
1197
+ } )
1198
+ . then ( delay ( 20 ) )
1199
+ . then ( function ( ) { return _doubleClick ( mid ) ; } )
1200
+ . then ( delay ( 20 ) )
1201
+ . then ( _reset )
1202
+ . then ( function ( ) { return _drag ( [ mid [ 0 ] + 30 , mid [ 0 ] - 30 ] , [ 50 , - 50 ] ) ; } )
1203
+ . then ( function ( ) {
1204
+ _assertBase ( 'from quadrant #1 move top-right' ) ;
1205
+ } )
1206
+ . then ( delay ( 20 ) )
1207
+ . then ( function ( ) { return _doubleClick ( mid ) ; } )
1208
+ . then ( delay ( 20 ) )
1209
+ . then ( _reset )
1210
+ . then ( function ( ) { return _drag ( [ 345 , 200 ] , [ - 50 , 0 ] ) ; } )
1211
+ . then ( function ( ) {
1212
+ _assertBase ( 'from right edge move left' ) ;
1213
+ } )
1214
+ . then ( delay ( 20 ) )
1215
+ . then ( function ( ) { return _doubleClick ( mid ) ; } )
1216
+ . then ( delay ( 20 ) )
1217
+ . then ( _reset )
1218
+ . then ( function ( ) { return _drag ( mid , [ 10 , 10 ] ) ; } )
1219
+ . then ( function ( ) { _assertBase ( 'from center to not far enough' ) ; } )
1220
+ . then ( function ( ) { return _drag ( [ mid [ 0 ] + 30 , mid [ 0 ] - 30 ] , [ - 10 , 0 ] ) ; } )
1221
+ . then ( function ( ) { _assertBase ( 'from quadrant #1 to not far enough' ) ; } )
1222
+ . then ( function ( ) { return _drag ( [ 345 , 200 ] , [ - 10 , 0 ] ) ; } )
1223
+ . then ( function ( ) { _assertBase ( 'from right edge to not far enough' ) ; } )
1224
+ . then ( function ( ) {
1225
+ expect ( eventCnts . plotly_relayout )
1226
+ . toBe ( 1 , 'no new relayout events after *not far enough* cases' ) ;
1227
+ } )
1228
+ . then ( delay ( 20 ) )
1229
+ . then ( function ( ) { return _doubleClick ( mid ) ; } )
1230
+ . then ( delay ( 20 ) )
1231
+ . then ( _reset )
1232
+ . then ( function ( ) { return Plotly . relayout ( gd , 'polar.hole' , 0.2 ) ; } )
1233
+ . then ( function ( ) { return _drag ( [ mid [ 0 ] + 30 , mid [ 0 ] - 30 ] , [ 50 , - 50 ] ) ; } )
1234
+ . then ( function ( ) {
1235
+ _assertRange ( [ 0 , 11.4 ] , 'with polar.hole>0, from quadrant #1 move top-right' ) ;
1236
+ } )
1237
+ . then ( done , done . fail ) ;
1238
+ } ) ;
1239
+
1240
+ it ( 'should not respond to drag interactions on radial drag area when dragmode === false' , function ( done ) {
1241
+ var fig = Lib . extendDeep ( { } , require ( '@mocks/polar_scatter.json' ) ) ;
1242
+ // adjust margins so that middle of plot area is at 300x300
1243
+ // with its middle at [200,200]
1244
+ fig . layout . width = 400 ;
1245
+ fig . layout . height = 400 ;
1246
+ fig . layout . margin = { l : 50 , t : 50 , b : 50 , r : 50 } ;
1247
+
1248
+ var dragPos0 = [ 375 , 200 ] ;
1249
+ var resetNumber = 0 ;
1250
+
1251
+ // use 'special' drag method - as we need two mousemove events
1252
+ // to activate the radial drag mode
1253
+ function _drag ( p0 , dp ) {
1254
+ var node = d3Select ( '.polar > .draglayer > .radialdrag' ) . node ( ) ;
1255
+ return drag ( { node : node , dpos : dp , pos0 : p0 , nsteps : 2 } ) ;
1256
+ }
1257
+
1258
+ function _assert ( rng , angle , evtRng1 , evtAngle , msg ) {
1259
+ expect ( gd . _fullLayout . polar . radialaxis . range )
1260
+ . toBeCloseToArray ( rng , 1 , msg + ' - range' ) ;
1261
+ expect ( gd . _fullLayout . polar . radialaxis . angle )
1262
+ . toBeCloseTo ( angle , 1 , msg + ' - angle' ) ;
1263
+
1264
+ if ( evtRng1 !== null ) {
1265
+ expect ( eventData [ 'polar.radialaxis.range[1]' ] )
1266
+ . toBeCloseTo ( evtRng1 , 1 , msg + ' - range[1] event data' ) ;
1267
+ }
1268
+ if ( evtAngle !== null ) {
1269
+ expect ( eventData [ 'polar.radialaxis.angle' ] )
1270
+ . toBeCloseTo ( evtAngle , 1 , msg + ' - angle event data' ) ;
1271
+ }
1272
+ }
1273
+
1274
+ function _assertBase ( extra ) {
1275
+ extra = extra ? ' ' + extra : '' ;
1276
+ _assert ( [ 0 , 11.1 ] , 0 , null , null , 'base' + extra ) ;
1277
+ }
1278
+
1279
+ function _reset ( ) {
1280
+ return delay ( 100 ) ( )
1281
+ . then ( function ( ) { return _doubleClick ( [ 200 , 200 ] ) ; } )
1282
+ . then ( function ( ) {
1283
+ resetNumber ++ ;
1284
+
1285
+ var extra = '(reset ' + resetNumber + ')' ;
1286
+ _assertBase ( extra ) ;
1287
+ expect ( eventCnts . plotly_doubleclick ) . toBe ( 0 , 'doubleclick event #' + extra ) ;
1288
+ } ) ;
1289
+ }
1290
+
1291
+ _plot ( fig )
1292
+ . then ( _assertBase )
1293
+ . then ( function ( ) { return Plotly . relayout ( gd , 'dragmode' , false ) ; } )
1294
+ . then ( function ( ) { return _drag ( dragPos0 , [ - 50 , 0 ] ) ; } )
1295
+ . then ( function ( ) {
1296
+ _assertBase ( 'move inward' ) ;
1297
+ } )
1298
+ . then ( _reset )
1299
+ . then ( function ( ) { return _drag ( dragPos0 , [ 50 , 0 ] ) ; } )
1300
+ . then ( function ( ) {
1301
+ _assertBase ( 'move outward' ) ;
1302
+ } )
1303
+ . then ( _reset )
1304
+ . then ( function ( ) { return _drag ( dragPos0 , [ 0 , - 50 ] ) ; } )
1305
+ . then ( function ( ) {
1306
+ _assertBase ( 'move counterclockwise' ) ;
1307
+ } )
1308
+ . then ( _reset )
1309
+ . then ( function ( ) { return _drag ( dragPos0 , [ 0 , 50 ] ) ; } )
1310
+ . then ( function ( ) {
1311
+ _assertBase ( 'move clockwise' ) ;
1312
+ } )
1313
+ . then ( _reset )
1314
+ . then ( function ( ) {
1315
+ expect ( eventCnts . plotly_relayout ) . toBe ( 1 , 'total # of relayout events' ) ;
1316
+ } )
1317
+ . then ( done , done . fail ) ;
1318
+ } ) ;
1319
+
1320
+ it ( 'should not respond to drag interactions on inner radial drag area when dragmode === false' , function ( done ) {
1321
+ var fig = Lib . extendDeep ( { } , require ( '@mocks/polar_scatter.json' ) ) ;
1322
+ fig . layout . polar . hole = 0.2 ;
1323
+ // adjust margins so that middle of plot area is at 300x300
1324
+ // with its middle at [200,200]
1325
+ fig . layout . width = 400 ;
1326
+ fig . layout . height = 400 ;
1327
+ fig . layout . margin = { l : 50 , t : 50 , b : 50 , r : 50 } ;
1328
+
1329
+ var dragPos0 = [ 200 , 200 ] ;
1330
+
1331
+ // use 'special' drag method - as we need two mousemove events
1332
+ // to activate the radial drag mode
1333
+ function _drag ( p0 , dp ) {
1334
+ var node = d3Select ( '.polar > .draglayer > .radialdrag-inner' ) . node ( ) ;
1335
+ return drag ( { node : node , dpos : dp , pos0 : p0 , nsteps : 2 } ) ;
1336
+ }
1337
+
1338
+ function _assert ( rng , msg ) {
1339
+ expect ( gd . _fullLayout . polar . radialaxis . range )
1340
+ . toBeCloseToArray ( rng , 1 , msg + ' - range' ) ;
1341
+ }
1342
+
1343
+ function _assertBase ( extra ) {
1344
+ extra = extra ? ' ' + extra : '' ;
1345
+ _assert ( [ 0 , 11.4 ] , 'base' + extra ) ;
1346
+ }
1347
+
1348
+ _plot ( fig )
1349
+ . then ( _assertBase )
1350
+ . then ( function ( ) { return Plotly . relayout ( gd , 'dragmode' , false ) ; } )
1351
+ . then ( function ( ) { return _drag ( dragPos0 , [ - 50 , 0 ] ) ; } )
1352
+ . then ( function ( ) {
1353
+ _assertBase ( 'move inward' ) ;
1354
+ } )
1355
+ . then ( function ( ) { return Plotly . relayout ( gd , 'polar.radialaxis.autorange' , true ) ; } )
1356
+ . then ( function ( ) { return _drag ( dragPos0 , [ 50 , 0 ] ) ; } )
1357
+ . then ( function ( ) {
1358
+ _assertBase ( 'move outward' ) ;
1359
+ } )
1360
+ . then ( done , done . fail ) ;
1361
+ } ) ;
1362
+
1363
+ it ( 'should not respond to drag interactions on angular drag area when dragmode === false' , function ( done ) {
1364
+ var fig = Lib . extendDeep ( { } , require ( '@mocks/polar_scatter.json' ) ) ;
1365
+ // adjust margins so that middle of plot area is at 300x300
1366
+ // with its middle at [200,200]
1367
+ fig . layout . width = 400 ;
1368
+ fig . layout . height = 400 ;
1369
+ fig . layout . margin = { l : 50 , t : 50 , b : 50 , r : 50 } ;
1370
+
1371
+ var dragPos0 = [ 350 , 150 ] ;
1372
+ var resetNumber = 0 ;
1373
+
1374
+ function _drag ( p0 , dp ) {
1375
+ var node = d3Select ( '.polar > .draglayer > .angulardrag' ) . node ( ) ;
1376
+ return drag ( { node : node , dpos : dp , pos0 : p0 } ) ;
1377
+ }
1378
+
1379
+ function _assert ( rot , msg , noEvent ) {
1380
+ expect ( gd . _fullLayout . polar . angularaxis . rotation )
1381
+ . toBeCloseTo ( rot , 1 , msg + ' - rotation' ) ;
1382
+ if ( ! noEvent ) {
1383
+ expect ( eventData [ 'polar.angularaxis.rotation' ] )
1384
+ . toBeCloseTo ( rot , 1 , msg + ' - rotation event data' ) ;
1385
+ }
1386
+ }
1387
+
1388
+ function _assertBase ( extra ) {
1389
+ extra = extra ? ' ' + extra : '' ;
1390
+ _assert ( 0 , 'base' + extra , true ) ;
1391
+ }
1392
+
1393
+ function _reset ( ) {
1394
+ return delay ( 100 ) ( )
1395
+ . then ( function ( ) { return _doubleClick ( [ 200 , 200 ] ) ; } )
1396
+ . then ( function ( ) {
1397
+ resetNumber ++ ;
1398
+
1399
+ var extra = '(reset ' + resetNumber + ')' ;
1400
+ _assertBase ( extra ) ;
1401
+ expect ( eventCnts . plotly_doubleclick ) . toBe ( 0 , 'doubleclick event #' + extra ) ;
1402
+ } ) ;
1403
+ }
1404
+
1405
+ _plot ( fig )
1406
+ . then ( _assertBase )
1407
+ . then ( function ( ) { return Plotly . relayout ( gd , 'dragmode' , false ) ; } )
1408
+ . then ( function ( ) { return _drag ( dragPos0 , [ - 20 , - 20 ] ) ; } )
1409
+ . then ( function ( ) {
1410
+ _assertBase ( 'move counterclockwise' ) ;
1411
+ } )
1412
+ . then ( _reset )
1413
+ . then ( function ( ) { return _drag ( dragPos0 , [ 20 , 20 ] ) ; } )
1414
+ . then ( function ( ) {
1415
+ _assertBase ( 'move clockwise' ) ;
1416
+ } )
1417
+ . then ( _reset )
1418
+ . then ( function ( ) {
1419
+ expect ( eventCnts . plotly_relayout ) . toBe ( 1 , 'total # of relayout events' ) ;
1420
+ } )
1421
+ . then ( done , done . fail ) ;
1422
+ } ) ;
1423
+ } ) ;
1424
+
1149
1425
describe ( 'should update scene during drag interactions on radial and angular drag area' , function ( ) {
1150
1426
var objs = [ 'scatter2d' , 'line2d' ] ;
1151
1427
var scene , gl , nTraces ;
0 commit comments