-
-
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 7 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 |
---|---|---|
@@ -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; | ||
}; |
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 like this solution a lot. Very clean 🥇