@@ -40,72 +40,62 @@ module.exports = function manageModebar(gd) {
4040 ] . join ( ' ' ) ) ;
4141 }
4242
43- var buttons = chooseButtons ( fullLayout , context . modebarButtonsToRemove ) ;
43+ var buttonGroups = getButtonGroups ( fullLayout , context . modebarButtonsToRemove ) ;
4444
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 ) ;
4747} ;
4848
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 = [ ] ;
5252
53- // TODO how to plots of multiple types?
53+ function addGroup ( newGroup ) {
54+ var out = [ ] ;
5455
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+ }
5861
59- if ( fullLayout . _hasGeo ) {
60- buttons = buttons . concat ( findButtons ( { category : 'geo' } ) ) ;
62+ groups . push ( out ) ;
6163 }
6264
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' ] ) ;
7567
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' ] ) ;
7972 }
8073
81- if ( fullLayout . _hasPie ) {
82- buttons = buttons . concat ( findButtons ( { category : 'pie' } ) ) ;
74+ if ( fullLayout . _hasGeo ) {
75+ addGroup ( [ 'zoomInGeo' , 'zoomOutGeo' , 'resetGeo' ] ) ;
76+ addGroup ( [ 'hoverClosestGeo' ] ) ;
8377 }
8478
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 ) ;
9882
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+ }
10487
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' ] ) ;
10696 }
10797
108- return out ;
98+ return groups ;
10999}
110100
111101function areAllAxesFixed ( fullLayout ) {
@@ -121,40 +111,3 @@ function areAllAxesFixed(fullLayout) {
121111
122112 return allFixed ;
123113}
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