@@ -818,6 +818,26 @@ describe('Pie traces', function() {
818818 . catch ( failTest )
819819 . then ( done ) ;
820820 } ) ;
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+ } ) ;
821841} ) ;
822842
823843describe ( 'pie hovering' , function ( ) {
@@ -1434,3 +1454,85 @@ describe('pie relayout', function() {
14341454 . then ( done ) ;
14351455 } ) ;
14361456} ) ;
1457+
1458+ describe ( 'Test pie interactions edge cases:' , function ( ) {
1459+ var gd ;
1460+
1461+ beforeEach ( function ( ) { gd = createGraphDiv ( ) ; } ) ;
1462+
1463+ afterEach ( destroyGraphDiv ) ;
1464+
1465+ function _mouseEvent ( type , v ) {
1466+ return function ( ) {
1467+ var el = d3 . select ( gd ) . select ( '.slice:nth-child(' + v + ')' ) . node ( ) ;
1468+ mouseEvent ( type , 0 , 0 , { element : el } ) ;
1469+ } ;
1470+ }
1471+
1472+ function hover ( v ) {
1473+ return _mouseEvent ( 'mouseover' , v ) ;
1474+ }
1475+
1476+ function unhover ( v ) {
1477+ return _mouseEvent ( 'mouseout' , v ) ;
1478+ }
1479+
1480+ it ( 'should keep tracking hover labels and hover events after *calc* edits' , function ( done ) {
1481+ var mock = Lib . extendFlat ( { } , require ( '@mocks/pie_simple.json' ) ) ;
1482+ var hoverCnt = 0 ;
1483+ var unhoverCnt = 0 ;
1484+
1485+ // see https://github.com/plotly/plotly.js/issues/3618
1486+
1487+ function _assert ( msg , exp ) {
1488+ expect ( hoverCnt ) . toBe ( exp . hoverCnt , msg + ' - hover cnt' ) ;
1489+ expect ( unhoverCnt ) . toBe ( exp . unhoverCnt , msg + ' - unhover cnt' ) ;
1490+
1491+ var label = d3 . select ( gd ) . select ( 'g.hovertext' ) ;
1492+ expect ( label . size ( ) ) . toBe ( exp . hoverLabel , msg + ' - hover label cnt' ) ;
1493+
1494+ hoverCnt = 0 ;
1495+ unhoverCnt = 0 ;
1496+ }
1497+
1498+ Plotly . plot ( gd , mock )
1499+ . then ( function ( ) {
1500+ gd . on ( 'plotly_hover' , function ( ) {
1501+ hoverCnt ++ ;
1502+ // N.B. trigger a 'calc' edit
1503+ Plotly . restyle ( gd , 'textinfo' , 'percent' ) ;
1504+ } ) ;
1505+ gd . on ( 'plotly_unhover' , function ( ) {
1506+ unhoverCnt ++ ;
1507+ // N.B. trigger a 'calc' edit
1508+ Plotly . restyle ( gd , 'textinfo' , null ) ;
1509+ } ) ;
1510+ } )
1511+ . then ( hover ( 1 ) )
1512+ . then ( function ( ) {
1513+ _assert ( 'after hovering on first sector' , {
1514+ hoverCnt : 1 ,
1515+ unhoverCnt : 0 ,
1516+ hoverLabel : 1
1517+ } ) ;
1518+ } )
1519+ . then ( unhover ( 1 ) )
1520+ . then ( function ( ) {
1521+ _assert ( 'after un-hovering from first sector' , {
1522+ hoverCnt : 0 ,
1523+ unhoverCnt : 1 ,
1524+ hoverLabel : 0
1525+ } ) ;
1526+ } )
1527+ . then ( hover ( 2 ) )
1528+ . then ( function ( ) {
1529+ _assert ( 'after hovering onto second sector' , {
1530+ hoverCnt : 1 ,
1531+ unhoverCnt : 0 ,
1532+ hoverLabel : 1
1533+ } ) ;
1534+ } )
1535+ . catch ( failTest )
1536+ . then ( done ) ;
1537+ } ) ;
1538+ } ) ;
0 commit comments