@@ -71,10 +71,15 @@ module.exports = function manageModeBar(gd) {
7171// logic behind which buttons are displayed by default
7272function getButtonGroups ( gd , buttonsToRemove , buttonsToAdd ) {
7373 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 = [ ] ;
7883
7984 function addGroup ( newGroup ) {
8085 var out = [ ] ;
@@ -88,52 +93,42 @@ function getButtonGroups(gd, buttonsToRemove, buttonsToAdd) {
8893 groups . push ( out ) ;
8994 }
9095
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+
91109 // buttons common to all plot types
92110 addGroup ( [ 'toImage' , 'sendDataToCloud' ] ) ;
93111
94- if ( fullLayout . _hasGL3D ) {
112+ if ( hasGL3D ) {
95113 addGroup ( [ 'zoom3d' , 'pan3d' , 'orbitRotation' , 'tableRotation' ] ) ;
96114 addGroup ( [ 'resetCameraDefault3d' , 'resetCameraLastSave3d' ] ) ;
97115 addGroup ( [ 'hoverClosest3d' ] ) ;
98116 }
99117
100- if ( fullLayout . _hasGeo ) {
118+ if ( hasGeo ) {
101119 addGroup ( [ 'zoomInGeo' , 'zoomOutGeo' , 'resetGeo' ] ) ;
102120 addGroup ( [ 'hoverClosestGeo' ] ) ;
103121 }
104122
105- var hasCartesian = fullLayout . _hasCartesian ,
106- hasGL2D = fullLayout . _hasGL2D ,
107- allAxesFixed = areAllAxesFixed ( fullLayout ) ,
123+ var allAxesFixed = areAllAxesFixed ( fullLayout ) ,
108124 dragModeGroup = [ ] ;
109125
110126 if ( ( hasCartesian || hasGL2D ) && ! allAxesFixed ) {
111127 dragModeGroup = [ 'zoom2d' , 'pan2d' ] ;
112128 }
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' ) ;
137132 }
138133 if ( dragModeGroup . length ) addGroup ( dragModeGroup ) ;
139134
@@ -147,21 +142,11 @@ function getButtonGroups(gd, buttonsToRemove, buttonsToAdd) {
147142 if ( hasGL2D ) {
148143 addGroup ( [ 'hoverClosestGl2d' ] ) ;
149144 }
150- if ( fullLayout . _hasPie ) {
145+ if ( hasPie ) {
151146 addGroup ( [ 'hoverClosestPie' ] ) ;
152147 }
153148
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 ) ;
165150}
166151
167152function areAllAxesFixed ( fullLayout ) {
@@ -178,6 +163,32 @@ function areAllAxesFixed(fullLayout) {
178163 return allFixed ;
179164}
180165
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+
181192// fill in custom buttons referring to default mode bar buttons
182193function fillCustomButton ( customButtons ) {
183194 for ( var i = 0 ; i < customButtons . length ; i ++ ) {
0 commit comments