@@ -1435,7 +1435,7 @@ describe('ModeBar', function() {
1435
1435
} ) ;
1436
1436
} ) ;
1437
1437
1438
- describe ( 'modebar styling ' , function ( ) {
1438
+ describe ( 'modebar relayout ' , function ( ) {
1439
1439
var gd ;
1440
1440
var colors = [ 'rgba(128, 128, 128, 0.7)' , 'rgba(255, 0, 128, 0.2)' ] ;
1441
1441
var targetBtn = 'pan2d' ;
@@ -1559,6 +1559,81 @@ describe('ModeBar', function() {
1559
1559
} )
1560
1560
. then ( done , done . fail ) ;
1561
1561
} ) ;
1562
+
1563
+ it ( 'add and remove predefined shape drawing and hover buttons via layout.modebar.buttonstoadd' , function ( done ) {
1564
+ function countButtons ( ) {
1565
+ var modeBarEl = gd . _fullLayout . _modeBar . element ;
1566
+ return d3Select ( modeBarEl ) . selectAll ( 'a.modebar-btn' ) . size ( ) ;
1567
+ }
1568
+
1569
+ var initial = 10 ;
1570
+ Plotly . newPlot ( gd , [ { y : [ 1 , 2 ] } ] , { } )
1571
+ . then ( function ( ) {
1572
+ expect ( countButtons ( ) ) . toBe ( initial ) ;
1573
+
1574
+ return Plotly . relayout ( gd , 'modebar.buttonstoadd' , [
1575
+ 'drawline' ,
1576
+ 'drawopenpath' ,
1577
+ 'drawclosedpath' ,
1578
+ 'drawcircle' ,
1579
+ 'drawrect' ,
1580
+ 'eraseshape'
1581
+ ] . join ( '+' ) ) ;
1582
+ } )
1583
+ . then ( function ( ) {
1584
+ expect ( countButtons ( ) ) . toBe ( initial + 6 ) ;
1585
+
1586
+ return Plotly . relayout ( gd , 'modebar.buttonstoadd' , '' ) ;
1587
+ } )
1588
+ . then ( function ( ) {
1589
+ expect ( countButtons ( ) ) . toBe ( initial ) ;
1590
+
1591
+ return Plotly . relayout ( gd , 'modebar.buttonstoadd' , [
1592
+ 'hovercompare' ,
1593
+ 'hoverclosest' ,
1594
+ 'togglespikelines'
1595
+ ] . join ( '+' ) ) ;
1596
+ } )
1597
+ . then ( function ( ) {
1598
+ expect ( countButtons ( ) ) . toBe ( initial + 3 ) ;
1599
+
1600
+ return Plotly . relayout ( gd , 'modebar.buttonstoadd' , '' ) ;
1601
+ } )
1602
+ . then ( function ( ) {
1603
+ expect ( countButtons ( ) ) . toBe ( initial ) ;
1604
+
1605
+ return Plotly . relayout ( gd , 'modebar.buttonstoadd' , [
1606
+ 'v1hovermode' ,
1607
+ 'togglespikelines'
1608
+ ] . join ( '+' ) ) ;
1609
+ } )
1610
+ . then ( function ( ) {
1611
+ expect ( countButtons ( ) ) . toBe ( initial + 3 ) ;
1612
+
1613
+ return Plotly . relayout ( gd , 'modebar.buttonstoadd' , [
1614
+ 'v1hovermode' ,
1615
+ 'togglespikelines' ,
1616
+ 'togglehover' ,
1617
+ 'hovercompare' ,
1618
+ 'hoverclosest' ,
1619
+ 'eraseshape' ,
1620
+ 'eraseshape' ,
1621
+ 'eraseshape'
1622
+ ] . join ( '+' ) ) ;
1623
+ } )
1624
+ . then ( function ( ) {
1625
+ expect ( countButtons ( ) ) . toBe ( initial + 4 , 'skip duplicates' ) ;
1626
+
1627
+ return Plotly . relayout ( gd , 'modebar.buttonstoadd' , [
1628
+ 'drawline' ,
1629
+ 'invalid'
1630
+ ] . join ( '+' ) ) ;
1631
+ } )
1632
+ . then ( function ( ) {
1633
+ expect ( countButtons ( ) ) . toBe ( initial + 1 , 'skip invalid' ) ;
1634
+ } )
1635
+ . then ( done , done . fail ) ;
1636
+ } ) ;
1562
1637
} ) ;
1563
1638
1564
1639
describe ( 'modebar html' , function ( ) {
0 commit comments