Skip to content

Commit 15efc72

Browse files
committed
clear additional 'matrixTrace' use by regl-splom for selection
... when restyling dragmode to non-selection modes. Previously, select -> dblclick -> pan lead to a duplication of rendered pts.
1 parent 57ddadb commit 15efc72

File tree

2 files changed

+128
-2
lines changed

2 files changed

+128
-2
lines changed

src/traces/splom/base_plot.js

+25-1
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,30 @@ function clean(newFullData, newFullLayout, oldFullData, oldFullLayout, oldCalcda
227227
Cartesian.clean(newFullData, newFullLayout, oldFullData, oldFullLayout);
228228
}
229229

230+
function updateFx(gd) {
231+
Cartesian.updateFx(gd);
232+
233+
var fullLayout = gd._fullLayout;
234+
var dragmode = fullLayout.dragmode;
235+
236+
// unset selection styles when coming out of a selection mode
237+
if(dragmode === 'zoom' || dragmode === 'pan') {
238+
var cd = gd.calcdata;
239+
240+
for(var i = 0; i < cd.length; i++) {
241+
var cd0 = cd[i][0];
242+
var trace = cd0.trace;
243+
244+
if(trace.type === 'splom') {
245+
var scene = cd0.t._scene;
246+
if(scene.selectBatch === null) {
247+
scene.matrix.update(scene.matrixOptions, null);
248+
}
249+
}
250+
}
251+
}
252+
}
253+
230254
module.exports = {
231255
name: SPLOM,
232256
attr: Cartesian.attr,
@@ -237,6 +261,6 @@ module.exports = {
237261
plot: plot,
238262
drag: drag,
239263
clean: clean,
240-
updateFx: Cartesian.updateFx,
264+
updateFx: updateFx,
241265
toSVG: Cartesian.toSVG
242266
};

test/jasmine/tests/splom_test.js

+103-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ var destroyGraphDiv = require('../assets/destroy_graph_div');
1010
var failTest = require('../assets/fail_test');
1111
var mouseEvent = require('../assets/mouse_event');
1212
var drag = require('../assets/drag');
13+
var doubleClick = require('../assets/double_click');
1314

1415
var customAssertions = require('../assets/custom_assertions');
1516
var assertHoverLabelContent = customAssertions.assertHoverLabelContent;
@@ -918,7 +919,7 @@ describe('@gl Test splom select:', function() {
918919
}
919920

920921
it('should emit correct event data and draw selection outlines', function(done) {
921-
var fig = require('@mocks/splom_0.json');
922+
var fig = Lib.extendDeep({}, require('@mocks/splom_0.json'));
922923
fig.layout = {
923924
dragmode: 'select',
924925
width: 400,
@@ -1039,4 +1040,105 @@ describe('@gl Test splom select:', function() {
10391040
.catch(failTest)
10401041
.then(done);
10411042
});
1043+
1044+
it('should behave correctly during select->dblclick->pan scenarios', function(done) {
1045+
var fig = Lib.extendDeep({}, require('@mocks/splom_0.json'));
1046+
fig.layout = {
1047+
width: 400,
1048+
height: 400,
1049+
margin: {l: 0, t: 0, r: 0, b: 0},
1050+
grid: {xgap: 0, ygap: 0}
1051+
};
1052+
1053+
var scene;
1054+
1055+
function _assert(msg, exp) {
1056+
expect(scene.matrix.update).toHaveBeenCalledTimes(exp.updateCnt, 'update cnt');
1057+
expect(scene.matrix.draw).toHaveBeenCalledTimes(exp.drawCnt, 'draw cnt');
1058+
1059+
expect(scene.matrix.traces.length).toBe(exp.matrixTraces, '# of regl-splom traces');
1060+
expect(scene.selectBatch).toEqual(exp.selectBatch, 'selectBatch');
1061+
expect(scene.unselectBatch).toEqual(exp.unselectBatch, 'unselectBatch');
1062+
1063+
scene.matrix.update.calls.reset();
1064+
scene.matrix.draw.calls.reset();
1065+
}
1066+
1067+
Plotly.plot(gd, fig).then(function() {
1068+
scene = gd.calcdata[0][0].t._scene;
1069+
spyOn(scene.matrix, 'update').and.callThrough();
1070+
spyOn(scene.matrix, 'draw').and.callThrough();
1071+
})
1072+
.then(function() {
1073+
_assert('base', {
1074+
updateCnt: 0,
1075+
drawCnt: 0,
1076+
matrixTraces: 1,
1077+
selectBatch: null,
1078+
unselectBatch: null
1079+
});
1080+
})
1081+
.then(function() { return Plotly.relayout(gd, 'dragmode', 'select'); })
1082+
.then(function() {
1083+
_assert('under dragmode:select', {
1084+
updateCnt: 3, // updates positions, viewport and style in 3 calls
1085+
drawCnt: 1, // results in a 'plot' edit
1086+
matrixTraces: 2,
1087+
selectBatch: [],
1088+
unselectBatch: []
1089+
});
1090+
})
1091+
.then(function() { return _select([[5, 5], [100, 100]]); })
1092+
.then(function() {
1093+
_assert('after selection', {
1094+
updateCnt: 0,
1095+
drawCnt: 1,
1096+
matrixTraces: 2,
1097+
selectBatch: [1],
1098+
unselectBatch: [0, 2]
1099+
});
1100+
})
1101+
.then(function() { return Plotly.relayout(gd, 'dragmode', 'pan'); })
1102+
.then(function() {
1103+
_assert('under dragmode:pan with active selection', {
1104+
updateCnt: 0,
1105+
drawCnt: 0, // nothing here, this is a 'modebar' edit
1106+
matrixTraces: 2,
1107+
selectBatch: [1],
1108+
unselectBatch: [0, 2]
1109+
});
1110+
})
1111+
.then(function() { return Plotly.relayout(gd, 'dragmode', 'select'); })
1112+
.then(function() {
1113+
_assert('back dragmode:select', {
1114+
updateCnt: 3,
1115+
drawCnt: 1, // a 'plot' edit (again)
1116+
matrixTraces: 2,
1117+
selectBatch: [1],
1118+
unselectBatch: [0, 2]
1119+
});
1120+
})
1121+
.then(function() { return doubleClick(100, 100); })
1122+
.then(function() {
1123+
_assert('after dblclick clearing selection', {
1124+
updateCnt: 0,
1125+
drawCnt: 1,
1126+
matrixTraces: 2,
1127+
selectBatch: null,
1128+
unselectBatch: []
1129+
});
1130+
})
1131+
.then(function() { return Plotly.relayout(gd, 'dragmode', 'pan'); })
1132+
.then(function() {
1133+
_assert('under dragmode:pan with NO active selection', {
1134+
updateCnt: 1, // to clear off 1 matrixTrace
1135+
drawCnt: 0,
1136+
matrixTraces: 1, // N.B. back to '1' here
1137+
selectBatch: null,
1138+
unselectBatch: []
1139+
});
1140+
})
1141+
.catch(failTest)
1142+
.then(done);
1143+
});
10421144
});

0 commit comments

Comments
 (0)