1

I'm currently looking at building a tree layout from a CSV file using the d3.layout.tree module. I am able to replicate the answer given here. Yet by simply modifying the data to look like:

source,target
A0,A1
A0,A2
A1,A2
A2,A3
A2,A4

we find that after calling tree.node(links) we get the following sample output (from Chrome Dev console) for the first element in the link array

Object
source: Object
children: Array[2]
depth: 0
name: "A0"
x: NaN
y: 0
__proto__: Object
target: Object
children: Array[1]
depth: 1
name: "A1"
parent: Object
x: NaN
y: 440
__proto__: Object
__proto__: Object

and the corresponding node array is:

Object
children: Array[2]
0: Object
1: Object
length: 2
__proto__: Array[0]
depth: 0
name: "A0"
x: NaN
y: 0
__proto__: Object

Notice it includes "NaN" values in the "x" field. I am unable to determine why this example does not produce A0 is the root with two children (A1,A2) like A2 does for (A3,A4). Appreciate any help, really love D3. Clearly this means I will not get the desired tree, how do I construct the tree data structure to provide the desired tree?

Community
  • 1
  • 1
Justin
  • 287
  • 3
  • 11
  • @eicto updated with the question. I merely stated the problem, but I would like to generate the desired tree plot. How do fix the example cited on the d3.js website by @mbostock? – Justin Dec 16 '12 at 04:59

1 Answers1

0

Your data above is not a tree. With A1,A2 you are creating a circular reference (where one node can have more than one parent). If your data is correct, then this is a force-directed graph which can also be created in D3.

mccannf
  • 16,619
  • 3
  • 51
  • 63
  • d'oh. thanks for pointing out my mistake. I was working with force-directed before this, clearly my mindset was right for this data structure. – Justin Dec 17 '12 at 14:44