简体   繁体   English

D3中“父/子”层次结构中的多级映射可能吗?

[英]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 我可以按照以下方式绘制D3布局

没有多级映射

When I include "id":1,"depends_on":5 当我包含"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和5之间有一条线。

1) How can I achieve this? 1) 我该如何实现?

2) How should the data-structure should be? 2) 数据结构应该如何? 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[]) 它是否真的需要在主要数据结构的各个部分中具有重复的条目(对象)(以所需的D3格式(parent,children []获得)

Using d3.layout.force produces 使用d3.layout.force会产生

部队布局

Check out this example , which uses d3.layout.force() . 查看此示例该示例使用d3.layout.force()

A force layout's data structure involves 2 arrays: 部队布局的数据结构包含2个数组:

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. 即,在上面的示例中, nodes[0] == links.source[0]应该为true。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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