File tree 2 files changed +67
-4
lines changed
2 files changed +67
-4
lines changed Original file line number Diff line number Diff line change @@ -72,10 +72,33 @@ function getButtonGroups(gd) {
72
72
var fullLayout = gd . _fullLayout ;
73
73
var fullData = gd . _fullData ;
74
74
var context = gd . _context ;
75
- var buttonsToAdd = context . modeBarButtonsToAdd
76
- . concat ( fullLayout . modebar . add . split ( '+' ) ) ;
77
- var buttonsToRemove = context . modeBarButtonsToRemove
78
- . concat ( fullLayout . modebar . remove . split ( '+' ) ) ;
75
+
76
+ function match ( name , B ) {
77
+ if ( typeof B === 'string' ) {
78
+ if ( B === name ) return true ;
79
+ } else {
80
+ if ( B . name === name || B . _cat === name ) return true ;
81
+ }
82
+ return false ;
83
+ }
84
+
85
+ var buttonsToAdd = context . modeBarButtonsToAdd . concat (
86
+ fullLayout . modebar . add . split ( '+' ) . filter ( function ( e ) {
87
+ for ( var i = 0 ; i < context . modeBarButtonsToRemove . length ; i ++ ) {
88
+ if ( match ( e , context . modeBarButtonsToRemove [ i ] ) ) return false ;
89
+ }
90
+ return true ;
91
+ } )
92
+ ) ;
93
+
94
+ var buttonsToRemove = context . modeBarButtonsToRemove . concat (
95
+ fullLayout . modebar . remove . split ( '+' ) . filter ( function ( e ) {
96
+ for ( var i = 0 ; i < context . modeBarButtonsToAdd . length ; i ++ ) {
97
+ if ( match ( e , context . modeBarButtonsToAdd [ i ] ) ) return false ;
98
+ }
99
+ return true ;
100
+ } )
101
+ ) ;
79
102
80
103
var hasCartesian = fullLayout . _has ( 'cartesian' ) ;
81
104
var hasGL3D = fullLayout . _has ( 'gl3d' ) ;
Original file line number Diff line number Diff line change @@ -1726,6 +1726,46 @@ describe('ModeBar', function() {
1726
1726
} )
1727
1727
. then ( done , done . fail ) ;
1728
1728
} ) ;
1729
+
1730
+ it ( 'add button if removed by layout and added by config' , function ( done ) {
1731
+ function countButtons ( ) {
1732
+ var modeBarEl = gd . _fullLayout . _modeBar . element ;
1733
+ return d3Select ( modeBarEl ) . selectAll ( 'a.modebar-btn' ) . size ( ) ;
1734
+ }
1735
+
1736
+ var initial = 10 ;
1737
+ Plotly . newPlot ( gd , [ { y : [ 1 , 2 ] } ] , {
1738
+ modebar : {
1739
+ remove : 'zoom'
1740
+ }
1741
+ } , {
1742
+ modeBarButtonsToAdd : [ 'zoom' ]
1743
+ } )
1744
+ . then ( function ( ) {
1745
+ expect ( countButtons ( ) ) . toBe ( initial ) ;
1746
+ } )
1747
+ . then ( done , done . fail ) ;
1748
+ } ) ;
1749
+
1750
+ it ( 'remove button if added by layout and removed by config' , function ( done ) {
1751
+ function countButtons ( ) {
1752
+ var modeBarEl = gd . _fullLayout . _modeBar . element ;
1753
+ return d3Select ( modeBarEl ) . selectAll ( 'a.modebar-btn' ) . size ( ) ;
1754
+ }
1755
+
1756
+ var initial = 10 ;
1757
+ Plotly . newPlot ( gd , [ { y : [ 1 , 2 ] } ] , {
1758
+ modebar : {
1759
+ add : 'drawline'
1760
+ }
1761
+ } , {
1762
+ modeBarButtonsToRemove : [ 'drawline' ]
1763
+ } )
1764
+ . then ( function ( ) {
1765
+ expect ( countButtons ( ) ) . toBe ( initial ) ;
1766
+ } )
1767
+ . then ( done , done . fail ) ;
1768
+ } ) ;
1729
1769
} ) ;
1730
1770
1731
1771
describe ( 'modebar html' , function ( ) {
You can’t perform that action at this time.
0 commit comments