-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Persistent point selection #2135
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 19 commits
8b60b4e
b209a55
2a04371
6903d31
3ef323f
1efe144
9f3f58d
782bc66
ec0578b
1bd832e
10c5b7b
eeace5b
bf039ab
5cfadbd
f54a08a
d4d1728
eeaca74
5ca8b36
4e83ef7
67cefad
10a2fa9
2fcdb7c
54cc67b
638d03d
b30fab4
949b311
315e632
9b79b3f
9210278
261387d
1859256
d3cdd6f
451778b
c8d715b
7543dc6
a95e47b
9d86a2f
6437081
9bbf55b
9ccccd3
3d2049c
a7f06fa
80eee22
aff9dbf
ab7b8f1
88fb812
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,7 +24,9 @@ var MINSELECT = constants.MINSELECT; | |
function getAxId(ax) { return ax._id; } | ||
|
||
module.exports = function prepSelect(e, startX, startY, dragOptions, mode) { | ||
var zoomLayer = dragOptions.gd._fullLayout._zoomlayer, | ||
var gd = dragOptions.gd, | ||
fullLayout = gd._fullLayout, | ||
zoomLayer = fullLayout._zoomlayer, | ||
dragBBox = dragOptions.element.getBoundingClientRect(), | ||
plotinfo = dragOptions.plotinfo, | ||
xs = plotinfo.xaxis._offset, | ||
|
@@ -66,8 +68,7 @@ module.exports = function prepSelect(e, startX, startY, dragOptions, mode) { | |
|
||
// find the traces to search for selection points | ||
var searchTraces = []; | ||
var gd = dragOptions.gd; | ||
var throttleID = gd._fullLayout._uid + constants.SELECTID; | ||
var throttleID = fullLayout._uid + constants.SELECTID; | ||
var selection = []; | ||
var i, cd, trace, searchInfo, eventData; | ||
|
||
|
@@ -83,6 +84,7 @@ module.exports = function prepSelect(e, startX, startY, dragOptions, mode) { | |
) { | ||
searchTraces.push({ | ||
selectPoints: trace._module.selectPoints, | ||
style: trace._module.style, | ||
cd: cd, | ||
xaxis: dragOptions.xaxes[0], | ||
yaxis: dragOptions.yaxes[0] | ||
|
@@ -94,6 +96,7 @@ module.exports = function prepSelect(e, startX, startY, dragOptions, mode) { | |
|
||
searchTraces.push({ | ||
selectPoints: trace._module.selectPoints, | ||
style: trace._module.style, | ||
cd: cd, | ||
xaxis: axes.getFromId(gd, trace.xaxis), | ||
yaxis: axes.getFromId(gd, trace.yaxis) | ||
|
@@ -202,6 +205,7 @@ module.exports = function prepSelect(e, startX, startY, dragOptions, mode) { | |
} | ||
|
||
eventData = {points: selection}; | ||
updateSelectedState(gd, searchTraces, eventData); | ||
fillRangeItems(eventData, poly, pts); | ||
dragOptions.gd.emit('plotly_selecting', eventData); | ||
} | ||
|
@@ -221,6 +225,7 @@ module.exports = function prepSelect(e, startX, startY, dragOptions, mode) { | |
searchInfo.selectPoints(searchInfo, false); | ||
} | ||
|
||
updateSelectedState(gd, searchTraces); | ||
gd.emit('plotly_deselect', null); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @alexcjohnson The failing test on CI can be fixed by moving So, there must a race condition somewhere in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shamefully fixed via 6437081 |
||
} | ||
else { | ||
|
@@ -230,6 +235,40 @@ module.exports = function prepSelect(e, startX, startY, dragOptions, mode) { | |
}; | ||
}; | ||
|
||
function updateSelectedState(gd, searchTraces, eventData) { | ||
var i, searchInfo; | ||
|
||
if(eventData) { | ||
var pts = eventData.points || []; | ||
|
||
for(i = 0; i < searchTraces.length; i++) { | ||
searchInfo = searchTraces[i]; | ||
searchInfo.cd[0].trace.selectedpoints = []; | ||
searchInfo.cd[0].trace._input.selectedpoints = []; | ||
} | ||
|
||
for(i = 0; i < pts.length; i++) { | ||
var pt = pts[i]; | ||
var ptNumber = pt.pointNumber; | ||
|
||
pt.data.selectedpoints.push(ptNumber); | ||
pt.fullData.selectedpoints.push(ptNumber); | ||
} | ||
} | ||
else { | ||
for(i = 0; i < searchTraces.length; i++) { | ||
searchInfo = searchTraces[i]; | ||
delete searchInfo.cd[0].trace.selectedpoints; | ||
delete searchInfo.cd[0].trace._input.selectedpoints; | ||
} | ||
} | ||
|
||
for(i = 0; i < searchTraces.length; i++) { | ||
searchInfo = searchTraces[i]; | ||
if(searchInfo.style) searchInfo.style(gd, searchInfo.cd); | ||
} | ||
} | ||
|
||
function fillSelectionItem(selection, searchInfo) { | ||
if(Array.isArray(selection)) { | ||
var trace = searchInfo.cd[0].trace; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This means that if marker opacity is an array, you won't be able to keep that during selection. I feel like we can do better than that:
[un]selected.marker.opacity
a default value if you don't set any other[un]selected
attributes - so if you want to keep opacity intact but just change marker color during selection, you can do that.[un]selected
opacities is set, the other state should revert to thearrayOk
logic(d.mo + 1 || marker.opacity + 1) - 1
arrayOk
logic - perhaps we want to stash this color ind
though, as this logic is a bit more involved? Anyway, that would allow selections like in parcoords (deselected is gray, selected keeps its color) or like our S&P notifiers (deselected keeps its color, selected is bright red)(selectedAttrs.marker || {}).opacity
calculation out of the.each
loop - alsosmc
andusmc
(Semper Fi!) below. That said I'd love it if some day these attributes all becomearrayOk
in which case they'd have to move at least partially back into the loop... But that's not for this PR, single-value is great for now.marker.color
for the other state?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But then
[un]selected.marker.opacity
won't appear in_fullData
, and @monfera 😏 won't be able to populate his style panels. Personally, I think keeping the same default selection behavior is more important, so thanks @alexcjohnson for pointing this out!Good point here. I haven't tested any of the mocks with
marker.gradient
turned on.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Revised logic in 1859256 and d3cdd6f with tests.