简体   繁体   中英

Multi Level mappings in Parent/Child hierarchy in D3 Possible?

I've a flat file which is of format

"id":1,"depends_on":2
"id":1,"depends_on":4
"id":1,"depends_on":5
"id":2,"depends_on":3
"id":4,"depends_on":5

Normally if I don't have

"id":1,"depends_on":5

I can plot the D3 Layout as follows

没有多级映射

When I include "id":1,"depends_on":5

Graph that's being plot will be

具有多级映射

Ideally I should have a line between 1 & 5 too, along with other mappings.

1) How can I achieve this?

2) How should the data-structure should be? Does it really need to have duplicate entries (objects) in various parts of main data-structure ( to obtain in the format D3 needed (parent,children[])

Using d3.layout.force produces

部队布局

Check out this example , which uses d3.layout.force() .

A force layout's data structure involves 2 arrays:

an array of nodes

[{id: 1}, {id: 2}, {id: 3}, {id: 4}]`

and array of links

[
  { source: {id: 1}, target: {id: 2} },
  { source: {id: 1}, target: {id: 3} }, 
  { source: {id: 2}, target: {id: 4} }
]

The objects used in the nodes array and links array should be the same objects. Ie, in the example above, nodes[0] == links.source[0] should be true.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM