med*_*iev 22 charts family-tree d3.js
我有一个来自Cyril惊人答案的家谱,但我正在试图弄清楚如何调整它以支持多个合作伙伴.在这种情况下,我添加了一个"情妇"节点,并试图表示"女主人"和"约翰"有一个名为"隐藏的儿子"的孩子.
当前的数据结构如下:
在那里,root
对象存储一切.它有一个children
数组,其中包含没有父母的最"代".它还包含一个包含这些兄弟对象/节点的子对象的对象.在上面的例子中,这是root.children[2]
.
我想我将不得不重构数据结构children
并注入有关孩子的父母的信息.只是在概念化这个以及线路时遇到了麻烦
最终将是这样的,除了情妇将在左侧:
Cyr*_*ian 25
@medder感谢您的赞赏!
为此,我在john和情妇之间添加了一个隐藏节点.
并将一个孩子添加到该隐藏节点,因此看起来好像约翰和情妇有一个孩子"隐藏的儿子"所以JSON看起来像
{
name: "Mistress",
id: 9000,
no_parent: true
}, {
name: "",//this is the new node between Mistress and John
id: 100,
no_parent: true,//it has no parents
hidden: true,
children: [{
// so this hidden node will have a child
// which will make it appear as if john and mistress has a child.
name: "Hidden Son",
id: 9001
}]
}, {
name: "John",
id: 16,
no_parent: true
},
Run Code Online (Sandbox Code Playgroud)
在这里工作代码
希望这可以帮助!