10
10
'use strict' ;
11
11
12
12
var Plotly = require ( '../../plotly' ) ;
13
+ var scatterSubTypes = require ( '../../traces/scatter/subtypes' ) ;
13
14
14
15
var createModeBar = require ( './' ) ;
15
16
var modeBarButtons = require ( './buttons' ) ;
@@ -57,7 +58,7 @@ module.exports = function manageModeBar(gd) {
57
58
}
58
59
else {
59
60
buttonGroups = getButtonGroups (
60
- fullLayout ,
61
+ gd ,
61
62
context . modeBarButtonsToRemove ,
62
63
context . modeBarButtonsToAdd
63
64
) ;
@@ -68,8 +69,12 @@ module.exports = function manageModeBar(gd) {
68
69
} ;
69
70
70
71
// logic behind which buttons are displayed by default
71
- function getButtonGroups ( fullLayout , buttonsToRemove , buttonsToAdd ) {
72
- var groups = [ ] ;
72
+ function getButtonGroups ( gd , buttonsToRemove , buttonsToAdd ) {
73
+ var fullLayout = gd . _fullLayout ,
74
+ fullData = gd . _fullData ,
75
+ groups = [ ] ,
76
+ i ,
77
+ trace ;
73
78
74
79
function addGroup ( newGroup ) {
75
80
var out = [ ] ;
@@ -106,8 +111,29 @@ function getButtonGroups(fullLayout, buttonsToRemove, buttonsToAdd) {
106
111
dragModeGroup = [ 'zoom2d' , 'pan2d' ] ;
107
112
}
108
113
if ( hasCartesian ) {
109
- dragModeGroup . push ( 'select2d' ) ;
110
- dragModeGroup . push ( 'lasso2d' ) ;
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
+ }
111
137
}
112
138
if ( dragModeGroup . length ) addGroup ( dragModeGroup ) ;
113
139
@@ -128,7 +154,7 @@ function getButtonGroups(fullLayout, buttonsToRemove, buttonsToAdd) {
128
154
// append buttonsToAdd to the groups
129
155
if ( buttonsToAdd . length ) {
130
156
if ( Array . isArray ( buttonsToAdd [ 0 ] ) ) {
131
- for ( var i = 0 ; i < buttonsToAdd . length ; i ++ ) {
157
+ for ( i = 0 ; i < buttonsToAdd . length ; i ++ ) {
132
158
groups . push ( buttonsToAdd [ i ] ) ;
133
159
}
134
160
}
0 commit comments