1010'use strict' ;
1111
1212var Plotly = require ( '../../plotly' ) ;
13+ var scatterSubTypes = require ( '../../traces/scatter/subtypes' ) ;
1314
1415var createModeBar = require ( './' ) ;
1516var modeBarButtons = require ( './buttons' ) ;
@@ -57,7 +58,7 @@ module.exports = function manageModeBar(gd) {
5758 }
5859 else {
5960 buttonGroups = getButtonGroups (
60- fullLayout ,
61+ gd ,
6162 context . modeBarButtonsToRemove ,
6263 context . modeBarButtonsToAdd
6364 ) ;
@@ -68,8 +69,12 @@ module.exports = function manageModeBar(gd) {
6869} ;
6970
7071// 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 ;
7378
7479 function addGroup ( newGroup ) {
7580 var out = [ ] ;
@@ -106,8 +111,29 @@ function getButtonGroups(fullLayout, buttonsToRemove, buttonsToAdd) {
106111 dragModeGroup = [ 'zoom2d' , 'pan2d' ] ;
107112 }
108113 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+ }
111137 }
112138 if ( dragModeGroup . length ) addGroup ( dragModeGroup ) ;
113139
@@ -128,7 +154,7 @@ function getButtonGroups(fullLayout, buttonsToRemove, buttonsToAdd) {
128154 // append buttonsToAdd to the groups
129155 if ( buttonsToAdd . length ) {
130156 if ( Array . isArray ( buttonsToAdd [ 0 ] ) ) {
131- for ( var i = 0 ; i < buttonsToAdd . length ; i ++ ) {
157+ for ( i = 0 ; i < buttonsToAdd . length ; i ++ ) {
132158 groups . push ( buttonsToAdd [ i ] ) ;
133159 }
134160 }
0 commit comments