Skip to content

Commit 7d897a4

Browse files
committed
show select icons only when they apply
1 parent d8ed7a7 commit 7d897a4

File tree

2 files changed

+38
-7
lines changed

2 files changed

+38
-7
lines changed

src/components/modebar/manage.js

+32-6
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
'use strict';
1111

1212
var Plotly = require('../../plotly');
13+
var scatterSubTypes = require('../../traces/scatter/subtypes');
1314

1415
var createModeBar = require('./');
1516
var 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
}

src/plots/cartesian/graph_interact.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,12 @@ fx.layoutAttributes = {
2626
valType: 'enumerated',
2727
role: 'info',
2828
values: ['zoom', 'pan', 'select', 'lasso', 'orbit', 'turntable'],
29-
description: 'Determines the mode of drag interactions.'
29+
description: [
30+
'Determines the mode of drag interactions.',
31+
'\'select\' and \'lasso\' apply only to scatter traces with',
32+
'markers or text. \'orbit\' and \'turntable\' apply only to',
33+
'3D scenes.'
34+
].join(' ')
3035
},
3136
hovermode: {
3237
valType: 'enumerated',

0 commit comments

Comments
 (0)