-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Sankey fix for 4+ multilinks #1934
Conversation
441ee32
to
7c179ae
Compare
93b6100
to
da7ff49
Compare
da7ff49
to
6ae3b70
Compare
src/traces/sankey/render.js
Outdated
@@ -155,7 +155,7 @@ function linkModel(uniqueKeys, d, l) { | |||
var tc = tinycolor(l.color); | |||
var basicKey = l.source.label + '|' + l.target.label; | |||
var foundKey = uniqueKeys[basicKey]; | |||
uniqueKeys[basicKey] = (foundKey === void(0) ? foundKey : 0) + 1; | |||
uniqueKeys[basicKey] = (foundKey === void(0) ? 0 : foundKey) + 1; |
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.
@monfera thanks for updating the baseline to 🔒 this fix down 🎉
For documentation purposes, can you explain what's going on this line?
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.
The code relies on a unique key for the purpose of entering / exiting the proper links. A simple solution would be to lean on the index for this. But it's better to associate semantically meaningful elements, e.g. some specific node or link, with the DOM element - useful for future possible animations or tweening. As we don't require an unique identifier array from users, an approximation is
- for nodes: the node label
- for links: the labels of the nodes they link
As there can be more than one link between two arbitrary nodes, the data binding key is made unique by a lookup that generates a new key for additional links. The ternary got flipped during an unrelated refactoring and the lookup came up with a NaN suffix repeatedly which made the data binding to swallow elements over 3 multilinks, considering them identical.
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.
might be clearer if we just use the fact that foundKey
will always be truthy if it exists?
uniqueKeys[basicKey] = (foundKey || 0) + 1;
var key = basicKay + (foundKey ? '' : ('__' + foundKey));
Which brings up: it might be very uncommon, but what if the user actually had a label
like 'name'
and another like 'name__1'
? I could see this popping out of some upstream disambiguation... Wouldn't it be more robust to always add the suffix like:
var keyCounter = uniqueKeys[basicKey] || 0;
uniqueKeys[basicKey] = keyCounter + 1;
var key = basicKey + '_' + keyCounter;
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.
@alexcjohnson yes, the 1st suggestion works out if we 1-index things as you do, and indeed there is a small risk of name collision - commit on the way
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.
Thanks for 📚 @monfera
💃
Nice, looks good to me! 💃 |
Purports to fix #1886