-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Updating to d3-sankey 0.7.1 #3355
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
Closed
Closed
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
03a3cb5
merge @Plotly/d3-sankey into plotly.js (es6 -> es5, tests in jasmine)
antoinerg 2504dc3
fix header for d3-sankey.js
antoinerg fd19907
move data conversion into its own function and run in calc() phase
antoinerg bde2a79
refactor d3-sankey to look more similar to upstream
antoinerg 5f89d78
fix indentation
antoinerg 1ad9586
updating to d3-sankey 0.7.1
antoinerg ee7088a
generate link path appropriately, reattach mouse events
antoinerg 5418d25
fix dragging, snapping, pushing and pass all tests
antoinerg File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/** | ||
* Copyright 2012-2018, 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'; | ||
|
||
var Lib = require('../../lib'); | ||
var isArrayOrTypedArray = Lib.isArrayOrTypedArray; | ||
var isIndex = Lib.isIndex; | ||
|
||
module.exports = function(trace) { | ||
var nodeSpec = trace.node; | ||
var linkSpec = trace.link; | ||
|
||
var links = []; | ||
var hasLinkColorArray = isArrayOrTypedArray(linkSpec.color); | ||
var linkedNodes = {}; | ||
|
||
var nodeCount = nodeSpec.label.length; | ||
var i; | ||
for(i = 0; i < linkSpec.value.length; i++) { | ||
var val = linkSpec.value[i]; | ||
// remove negative values, but keep zeros with special treatment | ||
var source = linkSpec.source[i]; | ||
var target = linkSpec.target[i]; | ||
if(!(val > 0 && isIndex(source, nodeCount) && isIndex(target, nodeCount))) { | ||
continue; | ||
} | ||
|
||
source = +source; | ||
target = +target; | ||
linkedNodes[source] = linkedNodes[target] = true; | ||
|
||
links.push({ | ||
pointNumber: i, | ||
label: linkSpec.label[i], | ||
color: hasLinkColorArray ? linkSpec.color[i] : linkSpec.color, | ||
source: source, | ||
target: target, | ||
value: +val | ||
}); | ||
} | ||
|
||
var hasNodeColorArray = isArrayOrTypedArray(nodeSpec.color); | ||
var nodes = []; | ||
var removedNodes = false; | ||
var nodeIndices = {}; | ||
|
||
for(i = 0; i < nodeCount; i++) { | ||
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. Non-blocking comment: when deleting from a list one may consider reversing the loop count and simply drop (pop) items from the array. |
||
if(linkedNodes[i]) { | ||
var l = nodeSpec.label[i]; | ||
nodeIndices[i] = nodes.length; | ||
nodes.push({ | ||
pointNumber: i, | ||
label: l, | ||
color: hasNodeColorArray ? nodeSpec.color[i] : nodeSpec.color | ||
}); | ||
} else removedNodes = true; | ||
} | ||
|
||
// need to re-index links now, since we didn't put all the nodes in | ||
if(removedNodes) { | ||
for(i = 0; i < links.length; i++) { | ||
links[i].source = nodeIndices[links[i].source]; | ||
links[i].target = nodeIndices[links[i].target]; | ||
} | ||
} | ||
|
||
return { | ||
links: links, | ||
nodes: nodes | ||
}; | ||
}; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 only appreciable change we have with d3-sankey is:
d3/d3-sankey@master...antoinerg:fix-large-padding#diff-968964796da46b424b314b4359ccde31
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 link above give me zero diff!
Thought the link one the line below may be the correct one?
d3/d3-sankey@master...antoinerg:fix-large-padding
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.
Yes, thank you @archmoj! The only changes I made are are in
src/sankey.js
.