d3.js 家谱中的多个合作伙伴? [英] Multiple partners in a family tree in d3.js?

查看:26
本文介绍了d3.js 家谱中的多个合作伙伴?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

其中,root 对象存储所有内容.它有一个 children 数组,其中包含没有父级的最一代".它还包含一个包含这些兄弟对象/节点的子对象的对象.在上面的例子中,这是 root.children[2].

我想我必须重构数据结构的 children 并注入有关孩子来自谁的父母的信息.只是在概念化这个以及这条线时遇到了麻烦

结局应该是这样的,除了情妇在左边:

解决方案

@medder 感谢欣赏!

为此,我在约翰和情妇之间添加了一个隐藏节点.

并在该隐藏节点中添加了一个孩子,因此看起来好像约翰和情妇有一个孩子隐藏的儿子"所以 JSON 看起来像

<代码>{姓名:《情妇》,编号:9000,no_parent: 真}, {name: "",//这是情妇和约翰之间的新节点编号:100,no_parent: true,//它没有父母隐藏:真实,孩子们: [{//所以这个隐藏节点会有一个子节点//这将使它看起来好像约翰和情妇有一个孩子.name: "隐藏的儿子",编号:9001}]}, {姓名:约翰",编号:16,no_parent: 真},

工作代码这里

希望这有帮助!

I have a family tree from Cyril's amazing answer but I'm trying to figure out how to adjust it to support multiple partners. In this case, I added a "Mistress" node and am trying to denote that "Mistress" and "John" had a child named "Hidden Son".

The current data structure works like this:

In that, the root object stores everything. It has a children array which contains the up most "generation" with no parents. It also contains an object that contains the children of these sibling objects/nodes. In the example above, this is root.children[2].

I'm thinking I would have to refactor the data structure's children and inject information about whos parents the child is from. Just having trouble conceptualizing this, as well as the line

The end would would be something like this, except mistress would be on the left side:

解决方案

@medder thanks for the appreciation!

To do that I have added a hidden node between john and mistress.

And added a child to that hidden node, so it appears as if john and mistress have a child "Hidden Son" So the JSON looks like

{
    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
  },

Working code here

Hope this helps!

这篇关于d3.js 家谱中的多个合作伙伴?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆