Skip to content

Commit 08600ad

Browse files
authored
Merge pull request #644 from plotly/select-legendonly
Handle non-visible trace in dragmode 'select' and 'lasso'
2 parents 945325f + 2768b0a commit 08600ad

File tree

2 files changed

+49
-1
lines changed

2 files changed

+49
-1
lines changed

src/traces/scatter/select.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ module.exports = function selectPoints(searchInfo, polygon) {
2727
y;
2828

2929
// TODO: include lines? that would require per-segment line properties
30-
if(!subtypes.hasMarkers(trace) && ! subtypes.hasText(trace)) return;
30+
var hasOnlyLines = (!subtypes.hasMarkers(trace) && !subtypes.hasText(trace));
31+
if(trace.visible !== true || hasOnlyLines) return;
3132

3233
var opacity = Array.isArray(marker.opacity) ? 1 : marker.opacity;
3334

test/jasmine/tests/select_test.js

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,4 +286,51 @@ describe('select box and lasso', function() {
286286
});
287287
});
288288
});
289+
290+
it('should skip over non-visible traces', function(done) {
291+
var mockCopy = Lib.extendDeep({}, mock);
292+
mockCopy.layout.dragmode = 'select';
293+
294+
var selectPath = [[100, 200], [150, 200]];
295+
var lassoPath = [[331, 178], [333, 246], [350, 250], [343, 176]];
296+
297+
var gd = createGraphDiv();
298+
var selectedPtLength;
299+
300+
Plotly.plot(gd, mockCopy.data, mockCopy.layout).then(function() {
301+
gd.on('plotly_selected', function(data) {
302+
selectedPtLength = data.points.length;
303+
});
304+
305+
drag(selectPath);
306+
expect(selectedPtLength).toEqual(2, '(case 0)');
307+
308+
return Plotly.restyle(gd, 'visible', 'legendonly');
309+
}).then(function() {
310+
drag(selectPath);
311+
expect(selectedPtLength).toEqual(0, '(legendonly case)');
312+
313+
return Plotly.restyle(gd, 'visible', true);
314+
}).then(function() {
315+
drag(selectPath);
316+
expect(selectedPtLength).toEqual(2, '(back to case 0)');
317+
318+
return Plotly.relayout(gd, 'dragmode', 'lasso');
319+
}).then(function() {
320+
drag(lassoPath);
321+
expect(selectedPtLength).toEqual(1, '(case 0 lasso)');
322+
323+
return Plotly.restyle(gd, 'visible', 'legendonly');
324+
}).then(function() {
325+
drag(lassoPath);
326+
expect(selectedPtLength).toEqual(0, '(lasso legendonly case)');
327+
328+
return Plotly.restyle(gd, 'visible', true);
329+
}).then(function() {
330+
drag(lassoPath);
331+
expect(selectedPtLength).toEqual(1, '(back to lasso case 0)');
332+
333+
done();
334+
});
335+
});
289336
});

0 commit comments

Comments
 (0)