@@ -47,37 +47,62 @@ module.exports = function manageModebar(gd) {
4747} ;
4848
4949function chooseButtons ( fullLayout , buttonsToRemove ) {
50- var buttons = findButtons ( 'all' ) ;
50+ var buttons = findButtons ( { category : 'all' } ) ,
51+ buttons2d = findButtons ( { category : '2d' } ) ;
5152
52- if ( fullLayout . _hasGL3D ) buttons = buttons . concat ( findButtons ( 'gl3d' ) ) ;
53+ // TODO how to plots of multiple types?
5354
54- if ( fullLayout . _hasGeo ) buttons = buttons . concat ( findButtons ( 'geo' ) ) ;
55+ if ( fullLayout . _hasGL3D ) {
56+ buttons = buttons . concat ( findButtons ( { category : 'gl3d' } ) ) ;
57+ }
58+
59+ if ( fullLayout . _hasGeo ) {
60+ buttons = buttons . concat ( findButtons ( { category : 'geo' } ) ) ;
61+ }
5562
56- if ( fullLayout . _hasCartesian && ! areAllAxesFixed ( fullLayout ) ) {
57- buttons = buttons . concat ( findButtons ( '2d' ) ) ;
58- buttons = buttons . concat ( findButtons ( 'cartesian' ) ) ;
63+ if ( fullLayout . _hasCartesian ) {
64+ if ( areAllAxesFixed ( fullLayout ) ) {
65+ buttons = buttons . concat ( findButtons ( {
66+ category : 'cartesian' ,
67+ group : 'hover'
68+ } ) ) ;
69+ }
70+ else {
71+ buttons = buttons . concat ( buttons2d ) ;
72+ buttons = buttons . concat ( findButtons ( { category : 'cartesian' } ) ) ;
73+ }
5974 }
6075
6176 if ( fullLayout . _hasGL2D ) {
62- buttons = buttons . concat ( findButtons ( '2d' ) ) ;
63- buttons = buttons . concat ( findButtons ( 'gl2d' ) ) ;
77+ buttons = buttons . concat ( buttons2d ) ;
78+ buttons = buttons . concat ( findButtons ( { category : 'gl2d' } ) ) ;
6479 }
6580
66- if ( fullLayout . _hasPie ) buttons = buttons . concat ( findButtons ( 'pie' ) ) ;
81+ if ( fullLayout . _hasPie ) {
82+ buttons = buttons . concat ( findButtons ( { category : 'pie' } ) ) ;
83+ }
6784
6885 buttons = filterButtons ( buttons , buttonsToRemove ) ;
6986 buttons = groupButtons ( buttons ) ;
7087
7188 return buttons ;
7289}
7390
74- function findButtons ( category , list ) {
75- var buttonNames = Object . keys ( buttonsConfig ) ;
91+ // Find buttons in buttonsConfig by category or group
92+ function findButtons ( opts ) {
93+ var buttonNames = Object . keys ( buttonsConfig ) ,
94+ category = opts . category ,
95+ group = opts . group ;
96+
7697 var out = [ ] ;
7798
7899 for ( var i = 0 ; i < buttonNames . length ; i ++ ) {
79100 var buttonName = buttonNames [ i ] ;
80- if ( buttonsConfig [ buttonName ] . category === category ) out . push ( buttonName ) ;
101+
102+ if ( category && buttonsConfig [ buttonName ] . category !== category ) continue ;
103+ if ( group && buttonsConfig [ buttonName ] . group !== group ) continue ;
104+
105+ out . push ( buttonName ) ;
81106 }
82107
83108 return out ;
0 commit comments