@@ -71,10 +71,15 @@ module.exports = function manageModeBar(gd) {
71
71
// logic behind which buttons are displayed by default
72
72
function getButtonGroups ( gd , buttonsToRemove , buttonsToAdd ) {
73
73
var fullLayout = gd . _fullLayout ,
74
- fullData = gd . _fullData ,
75
- groups = [ ] ,
76
- i ,
77
- trace ;
74
+ fullData = gd . _fullData ;
75
+
76
+ var hasCartesian = fullLayout . _hasCartesian ,
77
+ hasGL3D = fullLayout . _hasGL3D ,
78
+ hasGeo = fullLayout . _hasGeo ,
79
+ hasPie = fullLayout . _hasPie ,
80
+ hasGL2D = fullLayout . _hasGL2D ;
81
+
82
+ var groups = [ ] ;
78
83
79
84
function addGroup ( newGroup ) {
80
85
var out = [ ] ;
@@ -88,52 +93,42 @@ function getButtonGroups(gd, buttonsToRemove, buttonsToAdd) {
88
93
groups . push ( out ) ;
89
94
}
90
95
96
+ function appendButtonsToAdd ( groups ) {
97
+ if ( buttonsToAdd . length ) {
98
+ if ( Array . isArray ( buttonsToAdd [ 0 ] ) ) {
99
+ for ( var i = 0 ; i < buttonsToAdd . length ; i ++ ) {
100
+ groups . push ( buttonsToAdd [ i ] ) ;
101
+ }
102
+ }
103
+ else groups . push ( buttonsToAdd ) ;
104
+ }
105
+
106
+ return groups ;
107
+ }
108
+
91
109
// buttons common to all plot types
92
110
addGroup ( [ 'toImage' , 'sendDataToCloud' ] ) ;
93
111
94
- if ( fullLayout . _hasGL3D ) {
112
+ if ( hasGL3D ) {
95
113
addGroup ( [ 'zoom3d' , 'pan3d' , 'orbitRotation' , 'tableRotation' ] ) ;
96
114
addGroup ( [ 'resetCameraDefault3d' , 'resetCameraLastSave3d' ] ) ;
97
115
addGroup ( [ 'hoverClosest3d' ] ) ;
98
116
}
99
117
100
- if ( fullLayout . _hasGeo ) {
118
+ if ( hasGeo ) {
101
119
addGroup ( [ 'zoomInGeo' , 'zoomOutGeo' , 'resetGeo' ] ) ;
102
120
addGroup ( [ 'hoverClosestGeo' ] ) ;
103
121
}
104
122
105
- var hasCartesian = fullLayout . _hasCartesian ,
106
- hasGL2D = fullLayout . _hasGL2D ,
107
- allAxesFixed = areAllAxesFixed ( fullLayout ) ,
123
+ var allAxesFixed = areAllAxesFixed ( fullLayout ) ,
108
124
dragModeGroup = [ ] ;
109
125
110
126
if ( ( hasCartesian || hasGL2D ) && ! allAxesFixed ) {
111
127
dragModeGroup = [ 'zoom2d' , 'pan2d' ] ;
112
128
}
113
- if ( hasCartesian ) {
114
- // look for traces that support selection
115
- // to be updated as we add more selectPoints handlers
116
- var selectable = false ;
117
- for ( i = 0 ; i < fullData . length ; i ++ ) {
118
- if ( selectable ) break ;
119
- trace = fullData [ i ] ;
120
- if ( ! trace . _module || ! trace . _module . selectPoints ) continue ;
121
-
122
- if ( trace . type === 'scatter' ) {
123
- if ( scatterSubTypes . hasMarkers ( trace ) || scatterSubTypes . hasText ( trace ) ) {
124
- selectable = true ;
125
- }
126
- }
127
- // assume that in general if the trace module has selectPoints,
128
- // then it's selectable. Scatter is an exception to this because it must
129
- // have markers or text, not just be a scatter type.
130
- else selectable = true ;
131
- }
132
-
133
- if ( selectable ) {
134
- dragModeGroup . push ( 'select2d' ) ;
135
- dragModeGroup . push ( 'lasso2d' ) ;
136
- }
129
+ if ( hasCartesian && isSelectable ( fullData ) ) {
130
+ dragModeGroup . push ( 'select2d' ) ;
131
+ dragModeGroup . push ( 'lasso2d' ) ;
137
132
}
138
133
if ( dragModeGroup . length ) addGroup ( dragModeGroup ) ;
139
134
@@ -147,21 +142,11 @@ function getButtonGroups(gd, buttonsToRemove, buttonsToAdd) {
147
142
if ( hasGL2D ) {
148
143
addGroup ( [ 'hoverClosestGl2d' ] ) ;
149
144
}
150
- if ( fullLayout . _hasPie ) {
145
+ if ( hasPie ) {
151
146
addGroup ( [ 'hoverClosestPie' ] ) ;
152
147
}
153
148
154
- // append buttonsToAdd to the groups
155
- if ( buttonsToAdd . length ) {
156
- if ( Array . isArray ( buttonsToAdd [ 0 ] ) ) {
157
- for ( i = 0 ; i < buttonsToAdd . length ; i ++ ) {
158
- groups . push ( buttonsToAdd [ i ] ) ;
159
- }
160
- }
161
- else groups . push ( buttonsToAdd ) ;
162
- }
163
-
164
- return groups ;
149
+ return appendButtonsToAdd ( groups ) ;
165
150
}
166
151
167
152
function areAllAxesFixed ( fullLayout ) {
@@ -178,6 +163,32 @@ function areAllAxesFixed(fullLayout) {
178
163
return allFixed ;
179
164
}
180
165
166
+ // look for traces that support selection
167
+ // to be updated as we add more selectPoints handlers
168
+ function isSelectable ( fullData ) {
169
+ var selectable = false ;
170
+
171
+ for ( var i = 0 ; i < fullData . length ; i ++ ) {
172
+ if ( selectable ) break ;
173
+
174
+ var trace = fullData [ i ] ;
175
+
176
+ if ( ! trace . _module || ! trace . _module . selectPoints ) continue ;
177
+
178
+ if ( trace . type === 'scatter' ) {
179
+ if ( scatterSubTypes . hasMarkers ( trace ) || scatterSubTypes . hasText ( trace ) ) {
180
+ selectable = true ;
181
+ }
182
+ }
183
+ // assume that in general if the trace module has selectPoints,
184
+ // then it's selectable. Scatter is an exception to this because it must
185
+ // have markers or text, not just be a scatter type.
186
+ else selectable = true ;
187
+ }
188
+
189
+ return selectable ;
190
+ }
191
+
181
192
// fill in custom buttons referring to default mode bar buttons
182
193
function fillCustomButton ( customButtons ) {
183
194
for ( var i = 0 ; i < customButtons . length ; i ++ ) {
0 commit comments