Skip to content

Commit fdf20cb

Browse files
authored
Merge pull request #2295 from plotly/scattergl-selection-fix
Speed up selection
2 parents cceff86 + 9607382 commit fdf20cb

File tree

3 files changed

+63
-5
lines changed

3 files changed

+63
-5
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@
9999
"regl": "^1.3.1",
100100
"regl-error2d": "^2.0.3",
101101
"regl-line2d": "^2.1.2",
102-
"regl-scatter2d": "^2.1.11",
102+
"regl-scatter2d": "^2.1.12",
103103
"right-now": "^1.0.0",
104104
"robust-orientation": "^1.1.3",
105105
"sane-topojson": "^2.0.0",

src/traces/scattergl/index.js

+21-3
Original file line numberDiff line numberDiff line change
@@ -387,12 +387,30 @@ function sceneOptions(container, subplot, trace, positions) {
387387

388388
if(hasMarkers) {
389389
markerOptions = makeMarkerOptions(markerOpts);
390-
selectedOptions = trace.selected ? makeMarkerOptions(extend({}, markerOpts, trace.selected.marker)) : markerOptions;
391-
unselectedOptions = trace.unselected ? makeMarkerOptions(extend({}, markerOpts, trace.unselected.marker)) : markerOptions;
390+
selectedOptions = makeSelectedOptions(trace.selected, markerOpts);
391+
unselectedOptions = makeSelectedOptions(trace.unselected, markerOpts);
392392

393393
markerOptions.positions = positions;
394394
}
395395

396+
function makeSelectedOptions(selected, markerOpts) {
397+
var options = {};
398+
399+
if(selected.marker.symbol) {
400+
options = makeMarkerOptions(extend({}, markerOpts, selected.marker));
401+
}
402+
403+
// shortcut simple selection logic
404+
else {
405+
options = {};
406+
if(selected.marker.size) options.sizes = selected.marker.size;
407+
if(selected.marker.color) options.colors = selected.marker.color;
408+
if(selected.marker.opacity !== undefined) options.opacity = selected.marker.opacity;
409+
}
410+
411+
return options;
412+
}
413+
396414
function makeMarkerOptions(markerOpts) {
397415
var markerOptions = {}, i;
398416

@@ -911,7 +929,7 @@ function plot(container, subplot, cdata) {
911929
if(!scene.select2d && scene.scatter2d) {
912930
var selectRegl = layout._glcanvas.data()[1].regl;
913931

914-
// smol hack to create scatter instance by cloning scatter2d
932+
// create scatter instance by cloning scatter2d
915933
scene.select2d = createScatter(selectRegl, {clone: scene.scatter2d});
916934
scene.select2d.update(scene.selectedOptions);
917935

test/jasmine/tests/gl2d_plot_interact_test.js

+41-1
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ describe('Test gl2d plots', function() {
378378
.then(done);
379379
});
380380

381-
it('@noCI should display selection of big number of points', function(done) {
381+
it('@noCI should display selection of big number of regular points', function(done) {
382382
// generate large number of points
383383
var x = [], y = [], n = 2e2, N = n * n;
384384
for(var i = 0; i < N; i++) {
@@ -406,6 +406,46 @@ describe('Test gl2d plots', function() {
406406
.then(done);
407407
});
408408

409+
410+
it('@noCI should display selection of big number of miscellaneous points', function(done) {
411+
var colorList = [
412+
'#006385', '#F06E75', '#90ed7d', '#f7a35c', '#8085e9',
413+
'#f15c80', '#e4d354', '#2b908f', '#f45b5b', '#91e8e1',
414+
'#5DA5DA', '#F06E75', '#F15854', '#B2912F', '#B276B2',
415+
'#DECF3F', '#FAA43A', '#4D4D4D', '#F17CB0', '#60BD68'
416+
];
417+
418+
// generate large number of points
419+
var x = [], y = [], n = 2e2, N = n * n, color = [], symbol = [], size = [];
420+
for(var i = 0; i < N; i++) {
421+
x.push((i % n) / n);
422+
y.push(i / N);
423+
color.push(colorList[i % colorList.length]);
424+
symbol.push('x');
425+
size.push(6);
426+
}
427+
428+
var mock = {
429+
data: [{
430+
x: x, y: y, type: 'scattergl', mode: 'markers',
431+
marker: {symbol: symbol, size: size, color: color}
432+
}],
433+
layout: {
434+
dragmode: 'select'
435+
}
436+
};
437+
438+
Plotly.plot(gd, mock)
439+
.then(select([[160, 100], [180, 100]]))
440+
.then(function() {
441+
expect(readPixel(gd.querySelector('.gl-canvas-context'), 168, 100)[3]).toBe(0);
442+
expect(readPixel(gd.querySelector('.gl-canvas-context'), 158, 100)[3]).not.toBe(0);
443+
expect(readPixel(gd.querySelector('.gl-canvas-focus'), 168, 100)[3]).not.toBe(0);
444+
})
445+
.catch(fail)
446+
.then(done);
447+
});
448+
409449
it('should be able to toggle from svg to gl', function(done) {
410450
Plotly.plot(gd, [{
411451
y: [1, 2, 1],

0 commit comments

Comments
 (0)