@@ -1308,34 +1308,28 @@ describe('hover on fill', function() {
1308
1308
afterEach ( destroyGraphDiv ) ;
1309
1309
1310
1310
function assertLabelsCorrect ( mousePos , labelPos , labelText ) {
1311
- return new Promise ( function ( resolve ) {
1312
- Lib . clearThrottle ( ) ;
1313
- mouseEvent ( 'mousemove' , mousePos [ 0 ] , mousePos [ 1 ] ) ;
1314
-
1315
- var hoverText = d3 . selectAll ( 'g.hovertext' ) ;
1316
- expect ( hoverText . size ( ) ) . toEqual ( 1 ) ;
1317
- expect ( hoverText . text ( ) ) . toEqual ( labelText ) ;
1311
+ Lib . clearThrottle ( ) ;
1312
+ mouseEvent ( 'mousemove' , mousePos [ 0 ] , mousePos [ 1 ] ) ;
1318
1313
1319
- var transformParts = hoverText . attr ( 'transform' ) . split ( '(' ) ;
1320
- expect ( transformParts [ 0 ] ) . toEqual ( 'translate' ) ;
1321
- var transformCoords = transformParts [ 1 ] . split ( ')' ) [ 0 ] . split ( ',' ) ;
1322
- expect ( + transformCoords [ 0 ] ) . toBeCloseTo ( labelPos [ 0 ] , - 1.2 , labelText + ':x' ) ;
1323
- expect ( + transformCoords [ 1 ] ) . toBeCloseTo ( labelPos [ 1 ] , - 1.2 , labelText + ':y' ) ;
1314
+ var hoverText = d3 . selectAll ( 'g.hovertext' ) ;
1315
+ expect ( hoverText . size ( ) ) . toEqual ( 1 ) ;
1316
+ expect ( hoverText . text ( ) ) . toEqual ( labelText ) ;
1324
1317
1325
- resolve ( ) ;
1326
- } ) ;
1318
+ var transformParts = hoverText . attr ( 'transform' ) . split ( '(' ) ;
1319
+ expect ( transformParts [ 0 ] ) . toEqual ( 'translate' ) ;
1320
+ var transformCoords = transformParts [ 1 ] . split ( ')' ) [ 0 ] . split ( ',' ) ;
1321
+ expect ( + transformCoords [ 0 ] ) . toBeCloseTo ( labelPos [ 0 ] , - 1.2 , labelText + ':x' ) ;
1322
+ expect ( + transformCoords [ 1 ] ) . toBeCloseTo ( labelPos [ 1 ] , - 1.2 , labelText + ':y' ) ;
1327
1323
}
1328
1324
1329
1325
it ( 'should always show one label in the right place' , function ( done ) {
1330
1326
var mock = Lib . extendDeep ( { } , require ( '@mocks/scatter_fill_self_next.json' ) ) ;
1331
1327
mock . data . forEach ( function ( trace ) { trace . hoveron = 'fills' ; } ) ;
1332
1328
1333
1329
Plotly . plot ( createGraphDiv ( ) , mock . data , mock . layout ) . then ( function ( ) {
1334
- return assertLabelsCorrect ( [ 242 , 142 ] , [ 252 , 133.8 ] , 'trace 2' ) ;
1335
- } ) . then ( function ( ) {
1336
- return assertLabelsCorrect ( [ 242 , 292 ] , [ 233 , 210 ] , 'trace 1' ) ;
1337
- } ) . then ( function ( ) {
1338
- return assertLabelsCorrect ( [ 147 , 252 ] , [ 158.925 , 248.1 ] , 'trace 0' ) ;
1330
+ assertLabelsCorrect ( [ 242 , 142 ] , [ 252 , 133.8 ] , 'trace 2' ) ;
1331
+ assertLabelsCorrect ( [ 242 , 292 ] , [ 233 , 210 ] , 'trace 1' ) ;
1332
+ assertLabelsCorrect ( [ 147 , 252 ] , [ 158.925 , 248.1 ] , 'trace 0' ) ;
1339
1333
} ) . then ( done ) ;
1340
1334
} ) ;
1341
1335
@@ -1353,17 +1347,16 @@ describe('hover on fill', function() {
1353
1347
margin : { l : 50 , t : 50 , r : 50 , b : 50 }
1354
1348
} )
1355
1349
. then ( function ( ) {
1356
- return assertLabelsCorrect ( [ 200 , 200 ] , [ 73.75 , 250 ] , 'trace 0' ) ;
1357
- } )
1358
- . then ( function ( ) {
1350
+ assertLabelsCorrect ( [ 200 , 200 ] , [ 73.75 , 250 ] , 'trace 0' ) ;
1351
+
1359
1352
return Plotly . restyle ( gd , {
1360
1353
x : [ [ 6 , 7 , 8 , 7 ] ] ,
1361
1354
y : [ [ 5 , 4 , 5 , 6 ] ]
1362
1355
} ) ;
1363
1356
} )
1364
1357
. then ( function ( ) {
1365
1358
// gives same results w/o closing point
1366
- return assertLabelsCorrect ( [ 200 , 200 ] , [ 73.75 , 250 ] , 'trace 0' ) ;
1359
+ assertLabelsCorrect ( [ 200 , 200 ] , [ 73.75 , 250 ] , 'trace 0' ) ;
1367
1360
} )
1368
1361
. catch ( fail )
1369
1362
. then ( done ) ;
@@ -1378,16 +1371,14 @@ describe('hover on fill', function() {
1378
1371
1379
1372
// hover over a point when that's closest, even if you're over
1380
1373
// a fill, because by default we have hoveron='points+fills'
1381
- return assertLabelsCorrect ( [ 237 , 150 ] , [ 240.0 , 144 ] ,
1374
+ assertLabelsCorrect ( [ 237 , 150 ] , [ 240.0 , 144 ] ,
1382
1375
'trace 2Component A: 0.8Component B: 0.1Component C: 0.1' ) ;
1383
- } ) . then ( function ( ) {
1376
+
1384
1377
// the rest are hovers over fills
1385
- return assertLabelsCorrect ( [ 237 , 170 ] , [ 247.7 , 166 ] , 'trace 2' ) ;
1386
- } ) . then ( function ( ) {
1387
- return assertLabelsCorrect ( [ 237 , 218 ] , [ 266.75 , 265 ] , 'trace 1' ) ;
1388
- } ) . then ( function ( ) {
1389
- return assertLabelsCorrect ( [ 237 , 240 ] , [ 247.7 , 254 ] , 'trace 0' ) ;
1390
- } ) . then ( function ( ) {
1378
+ assertLabelsCorrect ( [ 237 , 170 ] , [ 247.7 , 166 ] , 'trace 2' ) ;
1379
+ assertLabelsCorrect ( [ 237 , 218 ] , [ 266.75 , 265 ] , 'trace 1' ) ;
1380
+ assertLabelsCorrect ( [ 237 , 240 ] , [ 247.7 , 254 ] , 'trace 0' ) ;
1381
+
1391
1382
// zoom in to test clipping of large out-of-viewport shapes
1392
1383
return Plotly . relayout ( gd , {
1393
1384
'ternary.aaxis.min' : 0.5 ,
@@ -1396,13 +1387,13 @@ describe('hover on fill', function() {
1396
1387
} ) . then ( function ( ) {
1397
1388
// this particular one has a hover label disconnected from the shape itself
1398
1389
// so if we ever fix this, the test will have to be fixed too.
1399
- return assertLabelsCorrect ( [ 295 , 218 ] , [ 275.1 , 166 ] , 'trace 2' ) ;
1400
- } ) . then ( function ( ) {
1390
+ assertLabelsCorrect ( [ 295 , 218 ] , [ 275.1 , 166 ] , 'trace 2' ) ;
1391
+
1401
1392
// trigger an autoscale redraw, which goes through dragElement
1402
1393
return doubleClick ( 237 , 251 ) ;
1403
1394
} ) . then ( function ( ) {
1404
1395
// then make sure we can still select a *different* item afterward
1405
- return assertLabelsCorrect ( [ 237 , 218 ] , [ 266.75 , 265 ] , 'trace 1' ) ;
1396
+ assertLabelsCorrect ( [ 237 , 218 ] , [ 266.75 , 265 ] , 'trace 1' ) ;
1406
1397
} )
1407
1398
. catch ( fail )
1408
1399
. then ( done ) ;
@@ -1421,14 +1412,14 @@ describe('hover on fill', function() {
1421
1412
1422
1413
// hover over a point when that's closest, even if you're over
1423
1414
// a fill, because by default we have hoveron='points+fills'
1424
- return assertLabelsCorrect ( [ 237 , 150 ] , [ 240.0 , 144 ] ,
1415
+ assertLabelsCorrect ( [ 237 , 150 ] , [ 240.0 , 144 ] ,
1425
1416
'trace 2Component A: 0.8Component B: 0.1Component C: 0.1' ) ;
1426
- } ) . then ( function ( ) {
1417
+
1427
1418
// hovers over fills
1428
- return assertLabelsCorrect ( [ 237 , 170 ] , [ 247.7 , 166 ] , 'trace 2' ) ;
1429
- } ) . then ( function ( ) {
1419
+ assertLabelsCorrect ( [ 237 , 170 ] , [ 247.7 , 166 ] , 'trace 2' ) ;
1420
+
1430
1421
// hover on the cartesian trace in the corner
1431
- return assertLabelsCorrect ( [ 363 , 122 ] , [ 363 , 122 ] , 'trace 38' ) ;
1422
+ assertLabelsCorrect ( [ 363 , 122 ] , [ 363 , 122 ] , 'trace 38' ) ;
1432
1423
} )
1433
1424
. catch ( fail )
1434
1425
. then ( done ) ;
@@ -1441,29 +1432,25 @@ describe('hover updates', function() {
1441
1432
afterEach ( destroyGraphDiv ) ;
1442
1433
1443
1434
function assertLabelsCorrect ( mousePos , labelPos , labelText , msg ) {
1444
- return new Promise ( function ( resolve ) {
1445
- if ( mousePos ) {
1446
- mouseEvent ( 'mousemove' , mousePos [ 0 ] , mousePos [ 1 ] ) ;
1447
- }
1435
+ Lib . clearThrottle ( ) ;
1448
1436
1449
- setTimeout ( function ( ) {
1450
- var hoverText = d3 . selectAll ( 'g.hovertext' ) ;
1451
- if ( labelPos ) {
1452
- expect ( hoverText . size ( ) ) . toBe ( 1 , msg ) ;
1453
- expect ( hoverText . text ( ) ) . toBe ( labelText , msg ) ;
1454
-
1455
- var transformParts = hoverText . attr ( 'transform' ) . split ( '(' ) ;
1456
- expect ( transformParts [ 0 ] ) . toBe ( 'translate' , msg ) ;
1457
- var transformCoords = transformParts [ 1 ] . split ( ')' ) [ 0 ] . split ( ',' ) ;
1458
- expect ( + transformCoords [ 0 ] ) . toBeCloseTo ( labelPos [ 0 ] , - 1 , labelText + ':x ' + msg ) ;
1459
- expect ( + transformCoords [ 1 ] ) . toBeCloseTo ( labelPos [ 1 ] , - 1 , labelText + ':y ' + msg ) ;
1460
- } else {
1461
- expect ( hoverText . size ( ) ) . toEqual ( 0 ) ;
1462
- }
1437
+ if ( mousePos ) {
1438
+ mouseEvent ( 'mousemove' , mousePos [ 0 ] , mousePos [ 1 ] ) ;
1439
+ }
1463
1440
1464
- resolve ( ) ;
1465
- } , HOVERMINTIME ) ;
1466
- } ) ;
1441
+ var hoverText = d3 . selectAll ( 'g.hovertext' ) ;
1442
+ if ( labelPos ) {
1443
+ expect ( hoverText . size ( ) ) . toBe ( 1 , msg ) ;
1444
+ expect ( hoverText . text ( ) ) . toBe ( labelText , msg ) ;
1445
+
1446
+ var transformParts = hoverText . attr ( 'transform' ) . split ( '(' ) ;
1447
+ expect ( transformParts [ 0 ] ) . toBe ( 'translate' , msg ) ;
1448
+ var transformCoords = transformParts [ 1 ] . split ( ')' ) [ 0 ] . split ( ',' ) ;
1449
+ expect ( + transformCoords [ 0 ] ) . toBeCloseTo ( labelPos [ 0 ] , - 1 , labelText + ':x ' + msg ) ;
1450
+ expect ( + transformCoords [ 1 ] ) . toBeCloseTo ( labelPos [ 1 ] , - 1 , labelText + ':y ' + msg ) ;
1451
+ } else {
1452
+ expect ( hoverText . size ( ) ) . toEqual ( 0 ) ;
1453
+ }
1467
1454
}
1468
1455
1469
1456
it ( 'should update the labels on animation' , function ( done ) {
@@ -1484,28 +1471,30 @@ describe('hover updates', function() {
1484
1471
var gd = createGraphDiv ( ) ;
1485
1472
Plotly . plot ( gd , mock ) . then ( function ( ) {
1486
1473
// The label text gets concatenated together when queried. Such is life.
1487
- return assertLabelsCorrect ( [ 100 , 100 ] , [ 103 , 100 ] , 'trace 00.5' , 'animation/update 0' ) ;
1474
+ assertLabelsCorrect ( [ 100 , 100 ] , [ 103 , 100 ] , 'trace 00.5' , 'animation/update 0' ) ;
1488
1475
} ) . then ( function ( ) {
1489
1476
return Plotly . animate ( gd , [ {
1490
1477
data : [ { x : [ 0 ] , y : [ 0 ] } , { x : [ 0.5 ] , y : [ 0.5 ] } ] ,
1491
1478
traces : [ 0 , 1 ] ,
1492
1479
} ] , { frame : { redraw : false , duration : 0 } } ) ;
1493
- } ) . then ( function ( ) {
1480
+ } )
1481
+ . then ( delay ( HOVERMINTIME ) )
1482
+ . then ( function ( ) {
1494
1483
// No mouse event this time. Just change the data and check the label.
1495
1484
// Ditto on concatenation. This is "trace 1" + "0.5"
1496
- return assertLabelsCorrect ( null , [ 103 , 100 ] , 'trace 10.5' , 'animation/update 1' ) ;
1497
- } ) . then ( function ( ) {
1485
+ assertLabelsCorrect ( null , [ 103 , 100 ] , 'trace 10.5' , 'animation/update 1' ) ;
1486
+
1498
1487
// Restyle to move the point out of the window:
1499
1488
return Plotly . relayout ( gd , { 'xaxis.range' : [ 2 , 3 ] } ) ;
1500
1489
} ) . then ( function ( ) {
1501
1490
// Assert label removed:
1502
- return assertLabelsCorrect ( null , null , null , 'animation/update 2' ) ;
1503
- } ) . then ( function ( ) {
1491
+ assertLabelsCorrect ( null , null , null , 'animation/update 2' ) ;
1492
+
1504
1493
// Move back to the original xaxis range:
1505
1494
return Plotly . relayout ( gd , { 'xaxis.range' : [ 0 , 1 ] } ) ;
1506
1495
} ) . then ( function ( ) {
1507
1496
// Assert label restored:
1508
- return assertLabelsCorrect ( null , [ 103 , 100 ] , 'trace 10.5' , 'animation/update 3' ) ;
1497
+ assertLabelsCorrect ( null , [ 103 , 100 ] , 'trace 10.5' , 'animation/update 3' ) ;
1509
1498
} ) . catch ( fail ) . then ( done ) ;
1510
1499
} ) ;
1511
1500
@@ -1514,12 +1503,8 @@ describe('hover updates', function() {
1514
1503
var colors0 = [ '#000000' , '#000000' , '#000000' , '#000000' , '#000000' , '#000000' , '#000000' ] ;
1515
1504
1516
1505
function unhover ( ) {
1517
- return new Promise ( function ( resolve ) {
1518
- mouseEvent ( 'mousemove' , 394 , 285 ) ;
1519
- setTimeout ( function ( ) {
1520
- resolve ( ) ;
1521
- } , HOVERMINTIME ) ;
1522
- } ) ;
1506
+ Lib . clearThrottle ( ) ;
1507
+ mouseEvent ( 'mousemove' , 394 , 285 ) ;
1523
1508
}
1524
1509
1525
1510
var hoverCnt = 0 ;
@@ -1549,17 +1534,15 @@ describe('hover updates', function() {
1549
1534
Plotly . restyle ( gd , 'marker.color' , [ colors0 . slice ( ) ] ) ;
1550
1535
} ) ;
1551
1536
1552
- return assertLabelsCorrect ( [ 351 , 251 ] , [ 358 , 272 ] , '2' , 'events 0' ) ;
1553
- } )
1554
- . then ( unhover )
1555
- . then ( function ( ) {
1537
+ assertLabelsCorrect ( [ 351 , 251 ] , [ 358 , 272 ] , '2' , 'events 0' ) ;
1538
+
1539
+ unhover ( ) ;
1556
1540
expect ( hoverCnt ) . toEqual ( 1 ) ;
1557
1541
expect ( unHoverCnt ) . toEqual ( 1 ) ;
1558
1542
1559
- return assertLabelsCorrect ( [ 420 , 100 ] , [ 435 , 198 ] , '3' , 'events 1' ) ;
1560
- } )
1561
- . then ( unhover )
1562
- . then ( function ( ) {
1543
+ assertLabelsCorrect ( [ 420 , 100 ] , [ 435 , 198 ] , '3' , 'events 1' ) ;
1544
+
1545
+ unhover ( ) ;
1563
1546
expect ( hoverCnt ) . toEqual ( 2 ) ;
1564
1547
expect ( unHoverCnt ) . toEqual ( 2 ) ;
1565
1548
} )
0 commit comments