d3-plugins icon indicating copy to clipboard operation
d3-plugins copied to clipboard

Sankey diagram hangs with more than 6 nodes

Open edelsbrunner opened this issue 12 years ago • 5 comments

Im having issues using the sankey diagram with my data.

Basically I have 7 nodes connected with a not defined number of links between them.

I created an example of data.json that hangs using 12 links between each node:

{
"nodes":[
{"name":"first","text":"first"},
{"name":"second","text":"second"},
{"name":"third","text":"third"},
{"name":"fourth","text":"fourth"},
{"name":"fifth","text":"fifth"},
{"name":"sixth","text":"sixth"},
{"name":"last","text":"last"}],

"links":[
{"source":"first","target":"second","value":1},
{"source":"second","target":"third","value":1},
{"source":"third","target":"fourth","value":1},
{"source":"fourth","target":"fifth","value":1},
{"source":"fifth","target":"sixth","value":1},
{"source":"sixth","target":"last","value":1},

{"source":"first","target":"second","value":1},
{"source":"second","target":"third","value":1},
{"source":"third","target":"fourth","value":1},
{"source":"fourth","target":"fifth","value":1},
{"source":"fifth","target":"sixth","value":1},
{"source":"sixth","target":"last","value":1},

{"source":"first","target":"second","value":1},
{"source":"second","target":"third","value":1},
{"source":"third","target":"fourth","value":1},
{"source":"fourth","target":"fifth","value":1},
{"source":"fifth","target":"sixth","value":1},
{"source":"sixth","target":"last","value":1},

{"source":"first","target":"second","value":1},
{"source":"second","target":"third","value":1},
{"source":"third","target":"fourth","value":1},
{"source":"fourth","target":"fifth","value":1},
{"source":"fifth","target":"sixth","value":1},
{"source":"sixth","target":"last","value":1},

{"source":"first","target":"second","value":1},
{"source":"second","target":"third","value":1},
{"source":"third","target":"fourth","value":1},
{"source":"fourth","target":"fifth","value":1},
{"source":"fifth","target":"sixth","value":1},
{"source":"sixth","target":"last","value":1},

{"source":"first","target":"second","value":1},
{"source":"second","target":"third","value":1},
{"source":"third","target":"fourth","value":1},
{"source":"fourth","target":"fifth","value":1},
{"source":"fifth","target":"sixth","value":1},
{"source":"sixth","target":"last","value":1},

{"source":"first","target":"second","value":1},
{"source":"second","target":"third","value":1},
{"source":"third","target":"fourth","value":1},
{"source":"fourth","target":"fifth","value":1},
{"source":"fifth","target":"sixth","value":1},
{"source":"sixth","target":"last","value":1},

{"source":"first","target":"second","value":1},
{"source":"second","target":"third","value":1},
{"source":"third","target":"fourth","value":1},
{"source":"fourth","target":"fifth","value":1},
{"source":"fifth","target":"sixth","value":1},
{"source":"sixth","target":"last","value":1},

{"source":"first","target":"second","value":1},
{"source":"second","target":"third","value":1},
{"source":"third","target":"fourth","value":1},
{"source":"fourth","target":"fifth","value":1},
{"source":"fifth","target":"sixth","value":1},
{"source":"sixth","target":"last","value":1},

{"source":"first","target":"second","value":1},
{"source":"second","target":"third","value":1},
{"source":"third","target":"fourth","value":1},
{"source":"fourth","target":"fifth","value":1},
{"source":"fifth","target":"sixth","value":1},
{"source":"sixth","target":"last","value":1},

{"source":"first","target":"second","value":1},
{"source":"second","target":"third","value":1},
{"source":"third","target":"fourth","value":1},
{"source":"fourth","target":"fifth","value":1},
{"source":"fifth","target":"sixth","value":1},
{"source":"sixth","target":"last","value":1},

{"source":"first","target":"second","value":1},
{"source":"second","target":"third","value":1},
{"source":"third","target":"fourth","value":1},
{"source":"fourth","target":"fifth","value":1},
{"source":"fifth","target":"sixth","value":1},
{"source":"sixth","target":"last","value":1}]
}

There are some factors that make it work normally (no hangs):

  • If I remove 1 node, and leave only 6 nodes (5 nodes connected).
  • If I remove half of the link data, it does not hang even with 7 or 8 nodes. (leave only 6 links from those 12 link blocks)

There are also some facts that make it slows down gradually (short hangs):

  • If I remove 4 or 5 links blocks from those 12, it takes a while and works slowly, however it loads.

I've tracked the hangs and it occurs in sankey.js line 120, inside computeNodeBreadths() in node.sourceLinks.forEach.

As you see in my data example above, I dont have any circular connections.

Also, I did no changes in sankey.js and i get it from this repository: https://github.com/d3/d3-plugins/tree/master/sankey, and my index.js is exactly like in this example http://bl.ocks.org/d3noob/5028304 (i based my sankey propotype in this example)

Is there any reported bug or solution for this situation?

Best regards,

Marius

edelsbrunner avatar Aug 13 '14 13:08 edelsbrunner

I think I am seeing the same problem (browser freezes in computeNodeBreadths), but I was not able to reproduce the problem with the example given here, even when increasing the number of links by just duplicating blocks of links in the JSON.

thiloplanz avatar Dec 17 '14 08:12 thiloplanz

It turns out that the problem with my chart was incorrect input data that caused a cycle in the graph.

I cannot reproduce the problem described here.

thiloplanz avatar Dec 17 '14 09:12 thiloplanz

I can't reproduce this problem either.

Fransan avatar Sep 19 '16 19:09 Fransan

I am also getting same issue. Here is the url http://jsfiddle.net/hq97qL62/ It works fine for 4 Nodes and 1350 links but it breaks for 4 nodes and 1500 links.

Please set "var testLinksCount = 500 ;" to reproduce the issue .

haggarwal90 avatar Aug 28 '17 10:08 haggarwal90

I had a similar issue to @thiloplanz. It turned out I had generated a link with a source and target of the same value resulting in an infinite cycle, so just in case anyone else has this problem!

Adoni5 avatar May 16 '18 13:05 Adoni5