Skip to content

Commit fedd8b0

Browse files
committed
refactor splom scene.(un)selectBatch
... in a similar way than for scattergl in previous commit
1 parent 81367f1 commit fedd8b0

File tree

4 files changed

+38
-80
lines changed

4 files changed

+38
-80
lines changed

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@
5858
"dependencies": {
5959
"@plotly/d3-sankey": "0.7.2",
6060
"alpha-shape": "^1.0.0",
61-
"array-range": "^1.0.1",
6261
"canvas-fit": "^1.5.0",
6362
"color-normalize": "^1.3.0",
6463
"convex-hull": "^1.0.3",

src/traces/splom/base_plot.js

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ function dragOne(gd, trace, scene) {
7575
}
7676
}
7777

78-
if(scene.selectBatch) {
78+
if(scene.selectBatch.length || scene.unselectBatch.length) {
7979
scene.matrix.update({ranges: ranges}, {ranges: ranges});
8080
} else {
8181
scene.matrix.update({ranges: ranges});
@@ -201,30 +201,6 @@ function clean(newFullData, newFullLayout, oldFullData, oldFullLayout) {
201201
Cartesian.clean(newFullData, newFullLayout, oldFullData, oldFullLayout);
202202
}
203203

204-
function updateFx(gd) {
205-
Cartesian.updateFx(gd);
206-
207-
var fullLayout = gd._fullLayout;
208-
var dragmode = fullLayout.dragmode;
209-
210-
// unset selection styles when coming out of a selection mode
211-
if(dragmode === 'zoom' || dragmode === 'pan') {
212-
var cd = gd.calcdata;
213-
214-
for(var i = 0; i < cd.length; i++) {
215-
var cd0 = cd[i][0];
216-
var trace = cd0.trace;
217-
218-
if(trace.type === 'splom') {
219-
var scene = fullLayout._splomScenes[trace.uid];
220-
if(scene.selectBatch === null) {
221-
scene.matrix.update(scene.matrixOptions, null);
222-
}
223-
}
224-
}
225-
}
226-
}
227-
228204
module.exports = {
229205
name: SPLOM,
230206
attr: Cartesian.attr,
@@ -236,6 +212,6 @@ module.exports = {
236212
drag: drag,
237213
updateGrid: updateGrid,
238214
clean: clean,
239-
updateFx: updateFx,
215+
updateFx: Cartesian.updateFx,
240216
toSVG: Cartesian.toSVG
241217
};

src/traces/splom/index.js

Lines changed: 24 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
'use strict';
1010

1111
var createMatrix = require('regl-splom');
12-
var arrayRange = require('array-range');
1312

1413
var Registry = require('../../registry');
1514
var Grid = require('../../components/grid');
@@ -127,10 +126,9 @@ function sceneUpdate(gd, trace) {
127126
var reset = {dirty: true};
128127

129128
var first = {
130-
selectBatch: null,
131-
unselectBatch: null,
132129
matrix: false,
133-
select: null
130+
selectBatch: [],
131+
unselectBatch: []
134132
};
135133

136134
var scene = splomScenes[trace.uid];
@@ -140,7 +138,7 @@ function sceneUpdate(gd, trace) {
140138

141139
scene.draw = function draw() {
142140
if(scene.matrix && scene.matrix.draw) {
143-
if(scene.selectBatch) {
141+
if(scene.selectBatch.length || scene.unselectBatch.length) {
144142
scene.matrix.draw(scene.unselectBatch, scene.selectBatch);
145143
} else {
146144
scene.matrix.draw();
@@ -237,17 +235,11 @@ function plotOne(gd, cd0) {
237235
var clickSelectEnabled = fullLayout.clickmode.indexOf('select') > -1;
238236
var selectMode = dragmode === 'lasso' || dragmode === 'select' ||
239237
!!trace.selectedpoints || clickSelectEnabled;
240-
scene.selectBatch = null;
241-
scene.unselectBatch = null;
238+
var needsBaseUpdate = true;
242239

243240
if(selectMode) {
244241
var commonLength = trace._length;
245242

246-
if(!scene.selectBatch) {
247-
scene.selectBatch = [];
248-
scene.unselectBatch = [];
249-
}
250-
251243
// regenerate scene batch, if traces number changed during selection
252244
if(trace.selectedpoints) {
253245
scene.selectBatch = trace.selectedpoints;
@@ -288,18 +280,19 @@ function plotOne(gd, cd0) {
288280
}
289281
}
290282

291-
if(scene.selectBatch) {
292-
scene.matrix.update(matrixOpts, matrixOpts);
293-
scene.matrix.update(scene.unselectedOptions, scene.selectedOptions);
294-
scene.matrix.update(viewOpts, viewOpts);
295-
} else {
296-
// delete selection pass
297-
scene.matrix.update(viewOpts, null);
283+
if(scene.selectBatch.length || scene.unselectBatch.length) {
284+
var unselOpts = Lib.extendFlat({}, matrixOpts, scene.unselectedOptions, viewOpts);
285+
var selOpts = Lib.extendFlat({}, matrixOpts, scene.selectedOptions, viewOpts);
286+
scene.matrix.update(unselOpts, selOpts);
287+
needsBaseUpdate = false;
298288
}
299289
} else {
290+
stash.xpx = stash.ypx = null;
291+
}
292+
293+
if(needsBaseUpdate) {
300294
var opts = Lib.extendFlat({}, matrixOpts, viewOpts);
301295
scene.matrix.update(opts, null);
302-
stash.xpx = stash.ypx = null;
303296
}
304297
}
305298

@@ -374,7 +367,6 @@ function selectPoints(searchInfo, selectionTester) {
374367
var xa = searchInfo.xaxis;
375368
var ya = searchInfo.yaxis;
376369
var selection = [];
377-
var i;
378370

379371
if(!scene) return selection;
380372

@@ -389,14 +381,13 @@ function selectPoints(searchInfo, selectionTester) {
389381
var ypx = stash.ypx[yi];
390382
var x = cdata[xi];
391383
var y = cdata[yi];
384+
var els = [];
385+
var unels = [];
392386

393387
// degenerate polygon does not enable selection
394388
// filter out points by visible scatter ones
395-
var els = null;
396-
var unels = null;
397389
if(selectionTester !== false && !selectionTester.degenerate) {
398-
els = [], unels = [];
399-
for(i = 0; i < x.length; i++) {
390+
for(var i = 0; i < x.length; i++) {
400391
if(selectionTester.contains([xpx[i], ypx[i]], null, i, searchInfo)) {
401392
els.push(i);
402393
selection.push({
@@ -408,30 +399,22 @@ function selectPoints(searchInfo, selectionTester) {
408399
unels.push(i);
409400
}
410401
}
411-
} else {
412-
unels = arrayRange(stash.count);
413402
}
414403

415-
// make sure selectBatch is created
416-
if(!scene.selectBatch) {
417-
scene.selectBatch = [];
418-
scene.unselectBatch = [];
419-
}
404+
var matrixOpts = scene.matrixOptions;
420405

421-
if(!scene.selectBatch) {
422-
// enter every trace select mode
423-
for(i = 0; i < scene.count; i++) {
424-
scene.selectBatch = [];
425-
scene.unselectBatch = [];
426-
}
427-
// we should turn scatter2d into unselected once we have any points selected
428-
scene.matrix.update(scene.unselectedOptions, scene.selectedOptions);
406+
if(!els.length && !unels.length) {
407+
scene.matrix.update(matrixOpts, null);
408+
} else if(!scene.selectBatch.length && !scene.unselectBatch.length) {
409+
scene.matrix.update(
410+
scene.unselectedOptions,
411+
Lib.extendFlat({}, matrixOpts, scene.selectedOptions, scene.viewOpts)
412+
);
429413
}
430414

431415
scene.selectBatch = els;
432416
scene.unselectBatch = unels;
433417

434-
435418
return selection;
436419
}
437420

test/jasmine/tests/splom_test.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1771,24 +1771,24 @@ describe('Test splom select:', function() {
17711771
updateCnt: 0,
17721772
drawCnt: 0,
17731773
matrixTraces: 1,
1774-
selectBatch: null,
1775-
unselectBatch: null
1774+
selectBatch: [],
1775+
unselectBatch: []
17761776
});
17771777
})
17781778
.then(function() { return Plotly.relayout(gd, 'dragmode', 'select'); })
17791779
.then(function() {
17801780
_assert('under dragmode:select', {
1781-
updateCnt: 3, // updates positions, viewport and style in 3 calls
1781+
updateCnt: 1, // updates positions, viewport and style in 1 call
17821782
drawCnt: 1, // results in a 'plot' edit
1783-
matrixTraces: 2,
1783+
matrixTraces: 1,
17841784
selectBatch: [],
17851785
unselectBatch: []
17861786
});
17871787
})
17881788
.then(function() { return _select([[5, 5], [100, 100]]); })
17891789
.then(function() {
17901790
_assert('after selection', {
1791-
updateCnt: 0,
1791+
updateCnt: 1, // update to [un]selected styles
17921792
drawCnt: 1,
17931793
matrixTraces: 2,
17941794
selectBatch: [1],
@@ -1808,7 +1808,7 @@ describe('Test splom select:', function() {
18081808
.then(function() { return Plotly.relayout(gd, 'dragmode', 'select'); })
18091809
.then(function() {
18101810
_assert('back dragmode:select', {
1811-
updateCnt: 3,
1811+
updateCnt: 1,
18121812
drawCnt: 1, // a 'plot' edit (again)
18131813
matrixTraces: 2,
18141814
selectBatch: [1],
@@ -1818,20 +1818,20 @@ describe('Test splom select:', function() {
18181818
.then(function() { return doubleClick(100, 100); })
18191819
.then(function() {
18201820
_assert('after dblclick clearing selection', {
1821-
updateCnt: 0,
1821+
updateCnt: 1, // reset to 'base' styles
18221822
drawCnt: 1,
1823-
matrixTraces: 2,
1824-
selectBatch: null,
1823+
matrixTraces: 1,
1824+
selectBatch: [],
18251825
unselectBatch: []
18261826
});
18271827
})
18281828
.then(function() { return Plotly.relayout(gd, 'dragmode', 'pan'); })
18291829
.then(function() {
18301830
_assert('under dragmode:pan with NO active selection', {
1831-
updateCnt: 1, // to clear off 1 matrixTrace
1831+
updateCnt: 0,
18321832
drawCnt: 0,
1833-
matrixTraces: 1, // N.B. back to '1' here
1834-
selectBatch: null,
1833+
matrixTraces: 1,
1834+
selectBatch: [],
18351835
unselectBatch: []
18361836
});
18371837
})

0 commit comments

Comments
 (0)