-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
sankey: implement node grouping via mouse selection #3712
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 5 commits
627fd74
20d8c92
aa17f1b
98541b0
a25c1ad
506da4c
109f77e
f8a4073
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 |
---|---|---|
|
@@ -48,6 +48,8 @@ function prepSelect(e, startX, startY, dragOptions, mode) { | |
var allAxes = dragOptions.xaxes.concat(dragOptions.yaxes); | ||
var subtract = e.altKey; | ||
|
||
var doneFnCompleted = dragOptions.doneFnCompleted; | ||
|
||
var filterPoly, selectionTester, mergedPolygons, currentPolygon; | ||
var i, searchInfo, eventData; | ||
|
||
|
@@ -284,6 +286,8 @@ function prepSelect(e, startX, startY, dragOptions, mode) { | |
dragOptions.mergedPolygons.length = 0; | ||
[].push.apply(dragOptions.mergedPolygons, mergedPolygons); | ||
} | ||
|
||
doneFnCompleted(selection); | ||
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. I like this solution a lot. Very clean 🥇 |
||
}); | ||
}; | ||
} | ||
|
@@ -519,6 +523,11 @@ function determineSearchTraces(gd, xAxes, yAxes, subplot) { | |
var info = createSearchInfo(trace._module, cd, xAxes[0], yAxes[0]); | ||
info.scene = gd._fullLayout._splomScenes[trace.uid]; | ||
searchTraces.push(info); | ||
} else if( | ||
trace.type === 'sankey' | ||
) { | ||
var sankeyInfo = createSearchInfo(trace._module, cd, xAxes[0], yAxes[0]); | ||
searchTraces.push(sankeyInfo); | ||
} else { | ||
if(xAxisIds.indexOf(trace.xaxis) === -1) continue; | ||
if(yAxisIds.indexOf(trace.yaxis) === -1) continue; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/** | ||
* Copyright 2012-2019, Plotly, Inc. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
module.exports = function selectPoints(searchInfo, selectionTester) { | ||
var cd = searchInfo.cd; | ||
var selection = []; | ||
var fullData = cd[0].trace; | ||
|
||
var nodes = fullData._sankey.graph.nodes; | ||
|
||
for(var i = 0; i < nodes.length; i++) { | ||
var node = nodes[i]; | ||
if(node.partOfGroup) continue; // Those are invisible | ||
|
||
// Position of node's centroid | ||
var pos = [(node.x0 + node.x1) / 2, (node.y0 + node.y1) / 2]; | ||
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. Voting 👍 on centroid. 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. Ok 👍 I 🔪 the TODO in 20d8c92 Maybe we should add a visual cue to let the user know a given node is now part of a selection 🤔 This could also be added later on. |
||
|
||
// Swap x and y if trace is vertical | ||
if(fullData.orientation === 'v') pos.reverse(); | ||
|
||
if(selectionTester && selectionTester.contains(pos, false, i, searchInfo)) { | ||
selection.push({ | ||
pointNumber: node.pointNumber | ||
// TODO: add eventData | ||
}); | ||
} | ||
} | ||
return selection; | ||
}; |
Uh oh!
There was an error while loading. Please reload this page.
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.
As we discussed in person, it might be better to
restyle
back to the "initial" view rather than to just remove all the groups.To do so:
node.(x|y)
andgroups
infullData[i]
(see mapbox example)restyle
with the values in that stash each in the modebar button handler (see example)Uh oh!
There was an error while loading. Please reload this page.
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.
@antoinerg let me know if you need help implementing this 😄
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.
I don't think I can reuse
resetView
because it does arelayout
whereas we need arestyle
.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.
Right, no need to use
resetView()
found inmodebar/buttons.js
, but you should try to replicate the same pattern.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.
Done in commit 506da4c! Let me know if it is satisfactory.
I will now write Jasmine tests for the reset button. Is there anything else you would like me to add?
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.
Nop, once that jasmine test is in, this one will be good to go!
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.
Done in f8a4073