-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
More robust Sankey #2629
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
More robust Sankey #2629
Conversation
@@ -437,6 +437,8 @@ function recurseIntoValObject(valObject, parts, i) { | |||
return valObject; | |||
} | |||
|
|||
// note: this is different from Lib.isIndex, this one doesn't accept numeric | |||
// strings, only actual numbers. |
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 initially made isIndex
into a Lib
function thinking I could reuse it here... but in this context it's in principle important that an index is actually a number, to distinguish an array index from an object property that happens to be a number. That said I don't think it's possible to use a number as an object property in nestedProperty
...
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.
Oh we could use this for validating selectedpoints
items as done here:
Lines 497 to 499 in a132b85
function isPtIndexValid(v) { | |
return isNumeric(v) && v >= 0 && v % 1 === 0; | |
} |
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.
... by this I mean Lib.isIndex
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.
links[i].source = nodeIndices[links[i].source]; | ||
links[i].target = nodeIndices[links[i].target]; | ||
} | ||
} |
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.
For the most part it didn't cause problems to have extra unused nodes in the list, but sometimes the layout algorithm would reserve extra space for these nodes (leaving extra margins or making the whole diagram S-shaped, for example) so it's better to remove them. The sankey_messy
mock includes a whole bunch of extra nodes both before (to test this link reassignment) and after the real ones to test this.
src/traces/sankey/calc.js
Outdated
@@ -14,13 +14,16 @@ var wrap = require('../../lib/gup').wrap; | |||
|
|||
function circularityPresent(nodeList, sources, targets) { | |||
|
|||
var nodes = nodeList.map(function() {return [];}); | |||
var nodes = nodeList.map(function() { return []; }); |
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.
Would be nice to reuse:
Lines 13 to 17 in a132b85
exports.init2dArray = function(rowLength, colLength) { | |
var array = new Array(rowLength); | |
for(var i = 0; i < rowLength; i++) array[i] = new Array(colLength); | |
return array; | |
}; |
describe('No warnings for missing nodes', function() { | ||
// we used to warn when some nodes were not used in the links | ||
// not doing that anymore, it's not really consistent with | ||
// the rest of our data processing. |
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.
nicely done 👌
Great PR 💃 |
... my comments are non-blocking. |
Make Sankey more accepting of messy data (fixing #2480)
supplyDefaults
, so was called frequently, and had a fairly slow implementation so could be a drag on large Sankey traces.cc @etpinard