I'm working on a visualization of data with d3js and hierarchical layout. My data looks like this:
       0
     / | \
    /  |  \ 
   1   5   3
    \  |   |
     \ |   |
       4  /
       | /
       2
As I can't make link to multiple parent, I duplicates nodes on display:
       0
     / | \
    /  |  \ 
   1   5   3
   |   |   |
   |   |   |
   4   4   |
   |   |   |
   2   2   2
I've made a fiddle demo to show my problem:
- When I use correct data in my JSON input, I have the good layout (graphic in border blue).
- When I use a loop to parse my JSON input, I have strange graph (graphic in border green).
This is the loop I used to parse the input:
for (i in root[2].Arcs){
  var d = root[1].Nodes[root[2].Arcs[i].D];
  var s = root[1].Nodes[root[2].Arcs[i].S];
  if (!d.children){
    d.children = [];
  }
  d.children.push(s);
}
For me : both printed element in console are the same, but not the render of layout. There are maybe some differents in object reference.
A bad solution I found is to decode then encode my var :
    var root = JSON.parse(JSON.stringify(root));
Then the script works good. But I root is a long long array, the parsing takes long time...
Any idea to explain why I need to use that encode/decode to display same things ?
Thank you
 
     
     
     
     
    