Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 090231b

Browse files
committed
fix and 🔒 selectionrevision with groupby
1 parent 874a72a commit 090231b

File tree

2 files changed

+52
-4
lines changed

2 files changed

+52
-4
lines changed

src/plots/cartesian/select.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -680,8 +680,8 @@ function updateSelectedState(gd, searchTraces, eventData) {
680680

681681
for(i = 0; i < searchTraces.length; i++) {
682682
trace = searchTraces[i].cd[0].trace;
683-
trace.selectedpoints = [];
684-
trace._input.selectedpoints = [];
683+
trace._input.selectedpoints = trace._fullInput.selectedpoints = [];
684+
if(trace._fullInput !== trace) trace.selectedpoints = [];
685685
}
686686

687687
for(i = 0; i < pts.length; i++) {
@@ -691,10 +691,14 @@ function updateSelectedState(gd, searchTraces, eventData) {
691691

692692
if(pt.pointIndices) {
693693
[].push.apply(data.selectedpoints, pt.pointIndices);
694-
[].push.apply(fullData.selectedpoints, pt.pointIndices);
694+
if(trace._fullInput !== trace) {
695+
[].push.apply(fullData.selectedpoints, pt.pointIndices);
696+
}
695697
} else {
696698
data.selectedpoints.push(pt.pointIndex);
697-
fullData.selectedpoints.push(pt.pointIndex);
699+
if(trace._fullInput !== trace) {
700+
fullData.selectedpoints.push(pt.pointIndex);
701+
}
698702
}
699703
}
700704
}
@@ -703,6 +707,9 @@ function updateSelectedState(gd, searchTraces, eventData) {
703707
trace = searchTraces[i].cd[0].trace;
704708
delete trace.selectedpoints;
705709
delete trace._input.selectedpoints;
710+
if(trace._fullInput !== trace) {
711+
delete trace._fullInput.selectedpoints;
712+
}
706713
}
707714
}
708715

test/jasmine/tests/plot_api_react_test.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1418,6 +1418,47 @@ describe('Plotly.react and uirevision attributes', function() {
14181418
_run(fig, editSelection, checkNoSelection, checkSelection).then(done);
14191419
});
14201420

1421+
it('preserves selectedpoints using selectedrevision (groupby case)', function(done) {
1422+
function fig(mainRev, selectionRev) {
1423+
return {
1424+
data: [{
1425+
x: [1, 2, 3, 1, 2, 3, 1, 2, 3],
1426+
y: [1, 1, 1, 2, 2, 2, 3, 3, 3],
1427+
mode: 'markers',
1428+
marker: {size: 20},
1429+
transforms: [{
1430+
type: 'groupby',
1431+
groups: [1, 2, 3, 2, 3, 1, 3, 1, 2]
1432+
}]
1433+
}],
1434+
layout: {
1435+
uirevision: mainRev,
1436+
selectionrevision: selectionRev,
1437+
dragmode: 'select',
1438+
width: 400,
1439+
height: 400,
1440+
margin: {l: 100, t: 100, r: 100, b: 100}
1441+
}
1442+
};
1443+
}
1444+
1445+
function editSelection() {
1446+
// drag across the upper right quadrant, so we'll select
1447+
// curve 0 point 1 and curve 1 point 2
1448+
return drag(document.querySelector('.nsewdrag'),
1449+
148, 148, '', 150, 102);
1450+
}
1451+
1452+
var checkNoSelection = checkState([{selectedpoints: undefined}]);
1453+
// the funny point order here is from the grouping:
1454+
// points 5 & 7 come first as they're in group 1
1455+
// point 8 is next, in group 2
1456+
// point 4 is last, in group 3
1457+
var checkSelection = checkState([{selectedpoints: [[5, 7, 8, 4]]}]);
1458+
1459+
_run(fig, editSelection, checkNoSelection, checkSelection).then(done);
1460+
});
1461+
14211462
it('preserves polar view changes using polar.uirevision', function(done) {
14221463
// polar you can control either at the subplot or the axis level
14231464
function fig(mainRev, polarRev) {

0 commit comments

Comments
 (0)