Skip to content

Commit c2c268c

Browse files
committed
Add select tests for zindex traces
1 parent b76e894 commit c2c268c

File tree

2 files changed

+104
-11
lines changed

2 files changed

+104
-11
lines changed

test/jasmine/tests/cartesian_interact_test.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2558,15 +2558,15 @@ describe('Cartesian taces with zindex', function() {
25582558
afterEach(destroyGraphDiv);
25592559

25602560
var data0 = [
2561-
{x: [1, 2], y: [1, 1], type: 'scatter', zindex: 10},
2562-
{x: [1, 2], y: [1, 2], type: 'scatter'},
2563-
{x: [1, 2], y: [1, 3], type: 'scatter', zindex: 5}
2561+
{x: [1, 2], y: [1, 1], type: 'scatter', marker: {size: 10}, zindex: 10},
2562+
{x: [1, 2], y: [1, 2], type: 'scatter', marker: {size: 30}},
2563+
{x: [1, 2], y: [1, 3], type: 'scatter', marker: {size: 20}, zindex: 5}
25642564
];
25652565

25662566
var data1 = [
2567-
{x: [1, 2], y: [1, 1], type: 'scatter'},
2568-
{x: [1, 2], y: [1, 2], type: 'scatter', zindex: -5},
2569-
{x: [1, 2], y: [1, 3], type: 'scatter', zindex: 10},
2567+
{x: [1, 2], y: [1, 1], type: 'scatter', marker: {size: 10}},
2568+
{x: [1, 2], y: [1, 2], type: 'scatter', marker: {size: 30}, zindex: -5},
2569+
{x: [1, 2], y: [1, 3], type: 'scatter', marker: {size: 20}, zindex: 10},
25702570
];
25712571

25722572
function fig(data) {
@@ -2671,14 +2671,14 @@ describe('Cartesian taces with zindex', function() {
26712671
Plotly.newPlot(gd, fig(data0))
26722672
.then(function() {
26732673
var tracesData = d3SelectAll('g[class^="scatterlayer"]')[0];
2674-
expect(tracesData.length).toBe(3)
2674+
expect(tracesData.length).toBe(3);
26752675
})
26762676
.then(function() {
26772677
return Plotly.react(gd, fig([data0[0]]));
26782678
})
26792679
.then(function() {
26802680
var tracesData = d3SelectAll('g[class^="scatterlayer"]')[0];
2681-
expect(tracesData.length).toBe(1)
2681+
expect(tracesData.length).toBe(1);
26822682
})
26832683
.then(done, done.fail);
26842684
});
@@ -2687,14 +2687,14 @@ describe('Cartesian taces with zindex', function() {
26872687
Plotly.newPlot(gd, fig([data0[0]]))
26882688
.then(function() {
26892689
var tracesData = d3SelectAll('g[class^="scatterlayer"]')[0];
2690-
expect(tracesData.length).toBe(1)
2690+
expect(tracesData.length).toBe(1);
26912691
})
26922692
.then(function() {
26932693
return Plotly.react(gd, fig(data0));
26942694
})
26952695
.then(function() {
26962696
var tracesData = d3SelectAll('g[class^="scatterlayer"]')[0];
2697-
expect(tracesData.length).toBe(3)
2697+
expect(tracesData.length).toBe(3);
26982698
})
26992699
.then(done, done.fail);
27002700
});

test/jasmine/tests/select_test.js

Lines changed: 94 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,22 @@ var BOXEVENTS = [1, 2, 1];
144144
// assumes 5 points in the lasso path
145145
var LASSOEVENTS = [4, 2, 1];
146146

147-
describe('Click-to-select', function() {
147+
var mockZindex = {
148+
data: [
149+
{x: [1, 2], y: [1, 1], type: 'scatter', zindex: 10, marker: {size: 50}},
150+
{x: [1, 2], y: [1, 2], type: 'scatter', marker: {size: 50}},
151+
{x: [1, 2], y: [1, 3], type: 'scatter', zindex: 5, marker: {size: 50}}
152+
],
153+
layout: {
154+
width: 400,
155+
height: 400,
156+
clickmode: 'event+select',
157+
dragmode: 'select',
158+
hovermode: 'closest'
159+
}
160+
};
161+
162+
fdescribe('Click-to-select', function() {
148163
var mock14Pts = {
149164
1: { x: 134, y: 116 },
150165
7: { x: 270, y: 160 },
@@ -264,6 +279,84 @@ describe('Click-to-select', function() {
264279
.then(done, done.fail);
265280
});
266281

282+
it('selects a single data point when being clicked on trace with zindex', function(done) {
283+
_newPlot(gd, mockZindex.data, mockZindex.layout)
284+
.then(function() {
285+
return _immediateClickPt({ x: 270, y: 150 });
286+
})
287+
.then(function() {
288+
assertSelectedPoints([], [], [1]);
289+
return _clickPt({ x: 270, y: 200 });
290+
})
291+
.then(function() {
292+
assertSelectedPoints([], [1], []);
293+
return _clickPt({ x: 270, y: 250 });
294+
})
295+
.then(done, done.fail);
296+
});
297+
298+
it('should only select top most zindex trace if overlapping position on single click', function(done) {
299+
_newPlot(gd, mockZindex.data, mockZindex.layout)
300+
.then(function() {
301+
return _immediateClickPt({ x: 130, y: 250 });
302+
})
303+
.then(function() {
304+
assertSelectedPoints([], [1], []);
305+
})
306+
.then(done, done.fail);
307+
});
308+
309+
it('should lasso select all overlapping points regardless of zindex', function(done) {
310+
mockZindex.layout.dragmode = 'lasso';
311+
_newPlot(gd, mockZindex.data, mockZindex.layout)
312+
.then(function() {
313+
drag([[200, 200], [200, 300], [100, 300], [100, 200], [200, 200]]);
314+
})
315+
.then(function() {
316+
expect(gd.data[0].selectedpoints).toEqual([0]);
317+
expect(gd.data[1].selectedpoints).toEqual([0]);
318+
expect(gd.data[2].selectedpoints).toEqual([0]);
319+
})
320+
.then(function() {
321+
return doubleClick(200, 200); // Clear selection
322+
})
323+
.then(function() {
324+
drag([[200, 100], [200, 300], [300, 300], [300, 100], [200, 100]]);
325+
})
326+
.then(function() {
327+
expect(gd.data[0].selectedpoints).toEqual([1]);
328+
expect(gd.data[1].selectedpoints).toEqual([1]);
329+
expect(gd.data[2].selectedpoints).toEqual([1]);
330+
})
331+
.then(done, done.fail);
332+
});
333+
334+
fit('should box select all overlapping points regardless of zindex', function(done) {
335+
mockZindex.layout.dragmode = 'select';
336+
_newPlot(gd, mockZindex.data, mockZindex.layout)
337+
.then(function() {
338+
drag([[200, 200], [100, 300]]);
339+
})
340+
.then(function() {
341+
expect(gd.data[0].selectedpoints).toEqual([0]);
342+
expect(gd.data[1].selectedpoints).toEqual([0]);
343+
expect(gd.data[2].selectedpoints).toEqual([0]);
344+
})
345+
.then(function() {
346+
return doubleClick(200, 200); // Clear selection
347+
})
348+
.then(function() {
349+
drag([[200, 100], [300, 300]]);
350+
})
351+
.then(function() {
352+
expect(gd.data[0].selectedpoints).toEqual([1]);
353+
expect(gd.data[1].selectedpoints).toEqual([1]);
354+
expect(gd.data[2].selectedpoints).toEqual([1]);
355+
})
356+
.then(done, done.fail);
357+
});
358+
359+
267360
it('cleanly clears and starts selections although add/subtract mode on', function(done) {
268361
plotMock14()
269362
.then(function() {

0 commit comments

Comments
 (0)