File tree Expand file tree Collapse file tree 2 files changed +37
-0
lines changed Expand file tree Collapse file tree 2 files changed +37
-0
lines changed Original file line number Diff line number Diff line change @@ -47,12 +47,19 @@ module.exports = function manageModeBar(gd) {
4747 ] . join ( ' ' ) ) ;
4848 }
4949
50+ var customButtons = context . modeBarButtons ;
51+ var buttonGroups ;
5052
53+ if ( Array . isArray ( customButtons ) && customButtons . length > 1 ) {
54+ buttonGroups = fillCustomButton ( customButtons ) ;
55+ }
56+ else {
5157 buttonGroups = getButtonGroups (
5258 fullLayout ,
5359 context . modeBarButtonsToRemove ,
5460 context . modeBarButtonsToAdd
5561 ) ;
62+ }
5663
5764 if ( modeBar ) modeBar . update ( gd , buttonGroups ) ;
5865 else fullLayout . _modeBar = createModeBar ( gd , buttonGroups ) ;
@@ -125,3 +132,27 @@ function areAllAxesFixed(fullLayout) {
125132
126133 return allFixed ;
127134}
135+
136+ // fill in custom buttons referring to default mode bar buttons
137+ function fillCustomButton ( customButtons ) {
138+ for ( var i = 0 ; i < customButtons . length ; i ++ ) {
139+ var buttonGroup = customButtons [ i ] ;
140+
141+ for ( var j = 0 ; j < buttonGroup . length ; j ++ ) {
142+ var button = buttonGroup [ j ] ;
143+
144+ if ( typeof button === 'string' )
145+ if ( modeBarButtons [ button ] !== undefined ) {
146+ customButtons [ i ] [ j ] = modeBarButtons [ button ] ;
147+ }
148+ else {
149+ throw new Error ( [
150+ '*modeBarButtons* configuration options' ,
151+ 'invalid button name'
152+ ] . join ( ' ' ) ) ;
153+ }
154+ }
155+ }
156+
157+ return customButtons ;
158+ }
Original file line number Diff line number Diff line change @@ -66,6 +66,12 @@ module.exports = {
6666 // (see ./components/modebar/buttons.js for list of arguments)
6767 modeBarButtonsToAdd : [ ] ,
6868
69+ // fully custom mode bar buttons as nested array,
70+ // where the outer arrays represents button groups, and
71+ // the inner arrays have buttons config objects or names of default buttons
72+ // (see ./components/modebar/buttons.js for more info)
73+ modeBarButtons : false ,
74+
6975 // add the plotly logo on the end of the mode bar
7076 displaylogo : true ,
7177
You can’t perform that action at this time.
0 commit comments