[英]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:
我有两个问题:
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”)看起来是顶级的节点?
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.