简体   繁体   English

D3冰柱图中可以有多个父/根节点吗?

[英]Is it possible to have multiple parent/root nodes in a D3 Icicle plot?

I am new to d3 and currently working on the Icicle layout example . 我是d3的新手,目前正在研究Icicle布局示例 I have 2 questions: 我有两个问题:

  1. Is it possible to have multiple top-level nodes in this example? 在此示例中是否可以有多个顶级节点? In other words, instead of a single top-level node of "flare", can we have 3 top-level nodes ("flare1", "flare 2" and "flare 3"), which can then have their respective children nodes? 换句话说,我们可以拥有3个顶级节点(“ flare1”,“ flare 2”和“ flare 3”),而不是单个单独的顶级节点“ flare”吗? I have tried importing the json data as an array of objects but that did not work. 我曾尝试将json数据作为对象数组导入,但这没有用。

If it is not possible to have multiple top-level nodes, how can I hide the root node ("flare") so that the 2nd level nodes ("vis", "util", "animate") appear to be top-level nodes? 如果不可能有多个顶级节点,如何隐藏根节点(“ flare”),使第二级节点(“ vis”,“ util”,“ animate”)看起来是顶级的节点?

  1. How can we sort the nodes (on a particular level) based on their position in the json file, rather than their size? 我们如何根据节点在json文件中的位置而不是其大小对节点(在特定级别上)进行排序? In other words, how can we sort the second level nodes in the above example so that they appear (from left to right) in the order of "analytics", "cluster", "graph" and so on (their order in json file); 换句话说,如何在上面的示例中对第二级节点进行排序,以便它们按“分析”,“集群”,“图”等(它们在json文件中的顺序)的顺序(从左到右)出现(从左到右) ); instead of their current order ("vis", "util", "animate", etc.). 而不是其当前顺序(“可见”,“实用”,“动画”等)。

Multiple parent/nodes is probably not possible with a single partition layout, since it's a hierarchical layout that assumes single-parent relationship. 一个分区布局可能无法使用多个父节点/节点,因为它是一种假定单亲关系的层次布局。 But it should be achievable using two partition layouts backed by two different hierarchical jsons. 但是应该使用两个分区布局(由两个不同的分层json支持)来实现。 You can generate the two jsons out of a single flat array (ie unlike flare.json), by using d3.nest() . 您可以使用d3.nest()从单个平面数组(即与flare.json不同)生成两个json。

The rendering code will likely need to get more sophisticated too, so that it can negotiate between the 2 layouts. 渲染代码也可能需要变得更加复杂,以便可以在这两种布局之间进行协商。

For #2, you can use partition.sort() to order them however you'd like. 对于#2,您可以根据需要使用partition.sort()进行排序。 In your case, you'd want to sort by their index in the input array. 对于您的情况,您想按输入数组中它们的索引排序。

UPDATE UPDATE

You can achieve what you describe rather simply — if each node truly has exactly one parent. 如果每个节点确实只有一个父节点,则可以非常简单地实现您所描述的内容。 So if you want 3 nodes at the top, they still need to be "wrapped" in a single common parent, which you pass to the partition layout. 因此,如果您希望顶部有3个节点,则仍然需要将它们“包装”在单个公共父节点中,然后将其传递给分区布局。 Then you'll need to take care of NOT rendering the parent node, by either filtering it out before binding and appending DOM nodes, or by setting it to display none. 然后,您需要注意不要渲染父节点,方法是在绑定和附加DOM节点之前将其过滤掉,或者将其设置为不显示。 In either case, you can check if d.depth == 0 to identify the root node. 无论哪种情况,都可以检查d.depth == 0是否标识根节点。 And you'll also need to translate all the nodes up to account for the gap left by the missing root node, since the layout will set all the x and y coords as if the root node is in the layout. 而且,您还需要平移所有节点,以弥补缺少的根节点留下的间隙,因为布局将设置所有x和y坐标,就好像根节点在布局中一样。 (Maybe there's a way to have the layout "realize" the root node is gone when assigning x and y positions if you use the .size() function to return 0 for the root node). (如果使用.size()函数为根节点返回0,也许在分配x和y位置时有一种使布局“实现”根节点消失的方法)。

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

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