@@ -40,72 +40,62 @@ module.exports = function manageModebar(gd) {
40
40
] . join ( ' ' ) ) ;
41
41
}
42
42
43
- var buttons = chooseButtons ( fullLayout , context . modebarButtonsToRemove ) ;
43
+ var buttonGroups = getButtonGroups ( fullLayout , context . modebarButtonsToRemove ) ;
44
44
45
- if ( modebar ) modebar . update ( gd , buttons ) ;
46
- else fullLayout . _modebar = createModebar ( gd , buttons ) ;
45
+ if ( modebar ) modebar . update ( gd , buttonGroups ) ;
46
+ else fullLayout . _modebar = createModebar ( gd , buttonGroups ) ;
47
47
} ;
48
48
49
- function chooseButtons ( fullLayout , buttonsToRemove ) {
50
- var buttons = findButtons ( { category : 'all' } ) ,
51
- buttons2d = findButtons ( { category : '2d' } ) ;
49
+ // logic behind which buttons are displayed by default
50
+ function getButtonGroups ( fullLayout , buttonsToRemove ) {
51
+ var groups = [ ] ;
52
52
53
- // TODO how to plots of multiple types?
53
+ function addGroup ( newGroup ) {
54
+ var out = [ ] ;
54
55
55
- if ( fullLayout . _hasGL3D ) {
56
- buttons = buttons . concat ( findButtons ( { category : 'gl3d' } ) ) ;
57
- }
56
+ for ( var i = 0 ; i < newGroup . length ; i ++ ) {
57
+ var button = newGroup [ i ] ;
58
+ if ( buttonsToRemove . indexOf ( button ) !== - 1 ) continue ;
59
+ out . push ( modebarButtons [ button ] ) ;
60
+ }
58
61
59
- if ( fullLayout . _hasGeo ) {
60
- buttons = buttons . concat ( findButtons ( { category : 'geo' } ) ) ;
62
+ groups . push ( out ) ;
61
63
}
62
64
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
- }
74
- }
65
+ // buttons common to all plot types
66
+ addGroup ( [ 'toImage' , 'sendDataToCloud' ] ) ;
75
67
76
- if ( fullLayout . _hasGL2D ) {
77
- buttons = buttons . concat ( buttons2d ) ;
78
- buttons = buttons . concat ( findButtons ( { category : 'gl2d' } ) ) ;
68
+ if ( fullLayout . _hasGL3D ) {
69
+ addGroup ( [ 'zoom3d' , 'pan3d' , 'orbitRotation' , 'tableRotation' ] ) ;
70
+ addGroup ( [ 'resetCameraDefault3d' , 'resetCameraLastSave3d' ] ) ;
71
+ addGroup ( [ 'hoverClosest3d' ] ) ;
79
72
}
80
73
81
- if ( fullLayout . _hasPie ) {
82
- buttons = buttons . concat ( findButtons ( { category : 'pie' } ) ) ;
74
+ if ( fullLayout . _hasGeo ) {
75
+ addGroup ( [ 'zoomInGeo' , 'zoomOutGeo' , 'resetGeo' ] ) ;
76
+ addGroup ( [ 'hoverClosestGeo' ] ) ;
83
77
}
84
78
85
- buttons = filterButtons ( buttons , buttonsToRemove ) ;
86
- buttons = groupButtons ( buttons ) ;
87
-
88
- return buttons ;
89
- }
90
-
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
-
97
- var out = [ ] ;
79
+ var hasCartesian = fullLayout . _hasCartesian ,
80
+ hasGL2D = fullLayout . _hasGL2D ,
81
+ allAxesFixed = areAllAxesFixed ( fullLayout ) ;
98
82
99
- for ( var i = 0 ; i < buttonNames . length ; i ++ ) {
100
- var buttonName = buttonNames [ i ] ;
101
-
102
- if ( category && buttonsConfig [ buttonName ] . category !== category ) continue ;
103
- if ( group && buttonsConfig [ buttonName ] . group !== group ) continue ;
83
+ if ( ( hasCartesian || hasGL2D ) && ! allAxesFixed ) {
84
+ addGroup ( [ 'zoom2d' , 'pan2d' ] ) ;
85
+ addGroup ( [ 'zoomIn2d' , 'zoomOut2d' , 'autoScale2d' , 'resetScale2d' ] ) ;
86
+ }
104
87
105
- out . push ( buttonName ) ;
88
+ if ( hasCartesian ) {
89
+ addGroup ( [ 'hoverClosestCartesian' , 'hoverCompareCartesian' ] ) ;
90
+ }
91
+ if ( hasGL2D ) {
92
+ addGroup ( [ 'hoverClosestGl2d' ] ) ;
93
+ }
94
+ if ( fullLayout . _hasPie ) {
95
+ addGroup ( [ 'hoverClosestPie' ] ) ;
106
96
}
107
97
108
- return out ;
98
+ return groups ;
109
99
}
110
100
111
101
function areAllAxesFixed ( fullLayout ) {
@@ -121,40 +111,3 @@ function areAllAxesFixed(fullLayout) {
121
111
122
112
return allFixed ;
123
113
}
124
-
125
- // Remove buttons according to modebarButtonsToRemove plot config options
126
- function filterButtons ( buttons , buttonsToRemove ) {
127
- var out = [ ] ;
128
-
129
- for ( var i = 0 ; i < buttons . length ; i ++ ) {
130
- var button = buttons [ i ] ;
131
-
132
- if ( buttonsToRemove . indexOf ( button ) !== - 1 ) continue ;
133
-
134
- out . push ( button ) ;
135
- }
136
-
137
- return out ;
138
- }
139
-
140
- function groupButtons ( buttons ) {
141
- var hashObj = { } ;
142
- var i ;
143
-
144
- for ( i = 0 ; i < buttons . length ; i ++ ) {
145
- var button = buttons [ i ] ,
146
- group = buttonsConfig [ button ] . group ;
147
-
148
- if ( hashObj [ group ] === undefined ) hashObj [ group ] = [ button ] ;
149
- else hashObj [ group ] . push ( button ) ;
150
- }
151
-
152
- var groups = Object . keys ( hashObj ) ;
153
- var out = [ ] ;
154
-
155
- for ( i = 0 ; i < groups . length ; i ++ ) {
156
- out . push ( hashObj [ groups [ i ] ] ) ;
157
- }
158
-
159
- return out ;
160
- }
0 commit comments