@@ -818,6 +818,26 @@ describe('Pie traces', function() {
818
818
. catch ( failTest )
819
819
. then ( done ) ;
820
820
} ) ;
821
+
822
+ it ( 'should be able to toggle visibility' , function ( done ) {
823
+ var mock = Lib . extendDeep ( { } , require ( '@mocks/pie_title_multiple.json' ) ) ;
824
+
825
+ function _assert ( msg , exp ) {
826
+ return function ( ) {
827
+ var layer = d3 . select ( gd ) . select ( '.pielayer' ) ;
828
+ expect ( layer . selectAll ( '.trace' ) . size ( ) ) . toBe ( exp , msg ) ;
829
+ } ;
830
+ }
831
+
832
+ Plotly . plot ( gd , mock )
833
+ . then ( _assert ( 'base' , 4 ) )
834
+ . then ( function ( ) { return Plotly . restyle ( gd , 'visible' , false ) ; } )
835
+ . then ( _assert ( 'both visible:false' , 0 ) )
836
+ . then ( function ( ) { return Plotly . restyle ( gd , 'visible' , true ) ; } )
837
+ . then ( _assert ( 'back to visible:true' , 4 ) )
838
+ . catch ( failTest )
839
+ . then ( done ) ;
840
+ } ) ;
821
841
} ) ;
822
842
823
843
describe ( 'pie hovering' , function ( ) {
@@ -1384,3 +1404,85 @@ describe('pie relayout', function() {
1384
1404
. then ( done ) ;
1385
1405
} ) ;
1386
1406
} ) ;
1407
+
1408
+ describe ( 'Test pie interactions edge cases:' , function ( ) {
1409
+ var gd ;
1410
+
1411
+ beforeEach ( function ( ) { gd = createGraphDiv ( ) ; } ) ;
1412
+
1413
+ afterEach ( destroyGraphDiv ) ;
1414
+
1415
+ function _mouseEvent ( type , v ) {
1416
+ return function ( ) {
1417
+ var el = d3 . select ( gd ) . select ( '.slice:nth-child(' + v + ')' ) . node ( ) ;
1418
+ mouseEvent ( type , 0 , 0 , { element : el } ) ;
1419
+ } ;
1420
+ }
1421
+
1422
+ function hover ( v ) {
1423
+ return _mouseEvent ( 'mouseover' , v ) ;
1424
+ }
1425
+
1426
+ function unhover ( v ) {
1427
+ return _mouseEvent ( 'mouseout' , v ) ;
1428
+ }
1429
+
1430
+ it ( 'should keep tracking hover labels and hover events after *calc* edits' , function ( done ) {
1431
+ var mock = Lib . extendFlat ( { } , require ( '@mocks/pie_simple.json' ) ) ;
1432
+ var hoverCnt = 0 ;
1433
+ var unhoverCnt = 0 ;
1434
+
1435
+ // see https://github.com/plotly/plotly.js/issues/3618
1436
+
1437
+ function _assert ( msg , exp ) {
1438
+ expect ( hoverCnt ) . toBe ( exp . hoverCnt , msg + ' - hover cnt' ) ;
1439
+ expect ( unhoverCnt ) . toBe ( exp . unhoverCnt , msg + ' - unhover cnt' ) ;
1440
+
1441
+ var label = d3 . select ( gd ) . select ( 'g.hovertext' ) ;
1442
+ expect ( label . size ( ) ) . toBe ( exp . hoverLabel , msg + ' - hover label cnt' ) ;
1443
+
1444
+ hoverCnt = 0 ;
1445
+ unhoverCnt = 0 ;
1446
+ }
1447
+
1448
+ Plotly . plot ( gd , mock )
1449
+ . then ( function ( ) {
1450
+ gd . on ( 'plotly_hover' , function ( ) {
1451
+ hoverCnt ++ ;
1452
+ // N.B. trigger a 'calc' edit
1453
+ Plotly . restyle ( gd , 'textinfo' , 'percent' ) ;
1454
+ } ) ;
1455
+ gd . on ( 'plotly_unhover' , function ( ) {
1456
+ unhoverCnt ++ ;
1457
+ // N.B. trigger a 'calc' edit
1458
+ Plotly . restyle ( gd , 'textinfo' , null ) ;
1459
+ } ) ;
1460
+ } )
1461
+ . then ( hover ( 1 ) )
1462
+ . then ( function ( ) {
1463
+ _assert ( 'after hovering on first sector' , {
1464
+ hoverCnt : 1 ,
1465
+ unhoverCnt : 0 ,
1466
+ hoverLabel : 1
1467
+ } ) ;
1468
+ } )
1469
+ . then ( unhover ( 1 ) )
1470
+ . then ( function ( ) {
1471
+ _assert ( 'after un-hovering from first sector' , {
1472
+ hoverCnt : 0 ,
1473
+ unhoverCnt : 1 ,
1474
+ hoverLabel : 0
1475
+ } ) ;
1476
+ } )
1477
+ . then ( hover ( 2 ) )
1478
+ . then ( function ( ) {
1479
+ _assert ( 'after hovering onto second sector' , {
1480
+ hoverCnt : 1 ,
1481
+ unhoverCnt : 0 ,
1482
+ hoverLabel : 1
1483
+ } ) ;
1484
+ } )
1485
+ . catch ( failTest )
1486
+ . then ( done ) ;
1487
+ } ) ;
1488
+ } ) ;
0 commit comments