Skip to content

Commit

Permalink
Fixes #4: avoid getting stuck in endless loop when there are cycles i…
Browse files Browse the repository at this point in the history
…n the graph
  • Loading branch information
soxofaan committed May 28, 2015
1 parent c553dde commit 0edba18
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
26 changes: 26 additions & 0 deletions examples/data/data06-with-cycle.js
@@ -0,0 +1,26 @@
sankeyDraw(
{
'nodes': [
{name: "a"},
{name: "b"},
{name: "c"},
{name: "d"},
{name: "e"},
{name: "f"},
{name: "g"}
],
'links': [
{source: 0, target: 2, value: 10},
{source: 0, target: 3, value: 4},
{source: 1, target: 2, value: 9},
{source: 1, target: 3, value: 8},
{source: 2, target: 4, value: 2},
{source: 2, target: 5, value: 6},
{source: 2, target: 6, value: 7},
{source: 3, target: 4, value: 8},
{source: 3, target: 5, value: 4},
{source: 3, target: 6, value: 2},
{source: 5, target: 1, value: 2}
]
}
);
3 changes: 2 additions & 1 deletion examples/example02.html
Expand Up @@ -142,7 +142,8 @@
'data/data02.js',
'data/data03.js',
'data/data04.js',
'data/data05.js'
'data/data05.js',
'data/data06-with-cycle.js'
];

// Try to get initial data set from url fragment.
Expand Down
2 changes: 1 addition & 1 deletion sankey.js
Expand Up @@ -123,7 +123,7 @@ d3.sankey = function() {

// Work from left to right.
// Keep updating the breath (x-position) of nodes that are target of recently updated nodes.
while (remainingNodes.length) {
while (remainingNodes.length && x < nodes.length) {
nextNodes = [];
remainingNodes.forEach(function(node) {
node.x = x;
Expand Down

0 comments on commit 0edba18

Please sign in to comment.