@@ -47,37 +47,62 @@ module.exports = function manageModebar(gd) {
47
47
} ;
48
48
49
49
function chooseButtons ( fullLayout , buttonsToRemove ) {
50
- var buttons = findButtons ( 'all' ) ;
50
+ var buttons = findButtons ( { category : 'all' } ) ,
51
+ buttons2d = findButtons ( { category : '2d' } ) ;
51
52
52
- if ( fullLayout . _hasGL3D ) buttons = buttons . concat ( findButtons ( 'gl3d' ) ) ;
53
+ // TODO how to plots of multiple types?
53
54
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
+ }
55
62
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
+ }
59
74
}
60
75
61
76
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' } ) ) ;
64
79
}
65
80
66
- if ( fullLayout . _hasPie ) buttons = buttons . concat ( findButtons ( 'pie' ) ) ;
81
+ if ( fullLayout . _hasPie ) {
82
+ buttons = buttons . concat ( findButtons ( { category : 'pie' } ) ) ;
83
+ }
67
84
68
85
buttons = filterButtons ( buttons , buttonsToRemove ) ;
69
86
buttons = groupButtons ( buttons ) ;
70
87
71
88
return buttons ;
72
89
}
73
90
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
+
76
97
var out = [ ] ;
77
98
78
99
for ( var i = 0 ; i < buttonNames . length ; i ++ ) {
79
100
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 ) ;
81
106
}
82
107
83
108
return out ;
0 commit comments