简体   繁体   English

d3.js结合了Hierarchical Edge Bundling和Radial Reingold-Tilford Tree +数据

[英]d3.js combining Hierarchical Edge Bundling and Radial Reingold–Tilford Tree + data

I would like to (sort of) combine the Hierarchical Edge Bundling and the Radial Reingold–Tilford Tree 我想(有点)结合Hierarchical Edge BundlingRadial Reingold-Tilford Tree

It would look a little like this (pardon my horrible paint.net skills)*: 看起来有点像这样(原谅我糟糕的paint.net技能)*: 在此输入图像描述

*the children are supposed to be in an arc, like in the Tree. *孩子应该处于弧形,就像在树中一样。

I have setup this fiddle that shows simple data in HEB: https://fiddle.jshell.net/d1766z4r/2/ 我设置了这个小提琴,显示了HEB中的简单数据: https//fiddle.jshell.net/d1766z4r/2/

I have already combined the two types of data (in comments at the begining, that will replace the current variable "classes"): 我已经合并了两种类型的数据(在开头的评论中,将替换当前变量“类”):

var classes = [
{"name":"test.cluster1.item1","children": [
      {"name": "test.cluster1.item4","imports":["test.cluster1.item2","test.cluster1.item3"]},
      {"name": "test.cluster1.item5"}
     ]},
{"name":"test.cluster1.item2","imports":["test.cluster1.item3"]},
{"name":"test.cluster1.item3"}
];

If there is a better way to combine the data, feel free to change it accordingly. 如果有更好的方法来组合数据,请随意更改它。

Other than changing the data, I am not sure how to proceed, as I am a d3.js and javascript novice, especially when it'll come to linking the right subitem (item 4), but not the other (item 5). 除了更改数据,我不知道如何继续,因为我是d3.js和javascript新手,特别是当它来链接正确的子项目(项目4),而不是另一个(项目5)。 However, I will consider an answer that will show a link to all the children of item 1 as a way to start developing this. 但是,我会考虑一个答案,它将显示第1项所有子项的链接,作为开始开发此项目的方法。

Please update this fiddle or make a new one to back your code up if possible. 如果可能的话,请更新这个小提琴或制作一个新的代码。 Any advice on how to proceed is welcomed of course. 当然欢迎任何关于如何进行的建议。

The next step will be to make those children show or hide on click, using a method similar to the Collapsible Tree (feel free to give advice on that aswell, but it will probably be a new question later if I can't find out how to do it), as I will have to work with big amounts of data, justifying children in the first place. 下一步将是使用类似于可折叠树的方法让这些孩子在点击时显示或隐藏(随意给出建议,但如果我不知道如何,这可能是一个新的问题这样做,因为我将不得不处理大量数据,首先为儿童辩护。

Finally, every child could have children of its own, but 1 line of children will suffice for now. 最后,每个孩子都可以拥有自己的孩子,但现在只需1行孩子就可以了。 I'll get to that later I suppose. 我想以后我会这样做。

UPDATE: The answers don't have to be complete solutions, every bit (see what I did there?) helps! 更新:答案不一定是完整的解决方案,每一点(看看我在那里做了什么?)有帮助!

I might be completely off track to what you are asking, please clarify if this is the case. 我可能完全偏离你的要求,请澄清是否是这种情况。

TL;DR : Here is how it looks, based on what I interpreted from the question. TL; DR: 这里是它的外观的基础上,我从这个问题的解释。 Have added some more data for testing. 添加了一些用于测试的数据。

Hierarchical Edge Bundling, provides a way of visualizing non-hierarchical edges in the graph. 分层边缘捆绑,提供了一种可视化图形中非分层边缘的方法。 Here is the link to the paper which is implemented in d3, if you have not found. 如果你还没找到,这是d3中实现的论文的链接

In the example only leaf nodes are shown by filtering the other nodes: 在该示例中,仅通过过滤其他节点来显示叶节点:

node = node
      .data(nodes.filter(function(n) { return !n.children; }))
    .enter().append("text")
      .attr("class", "node")...

Hierarchical relations in the example are represented by dots in names, so cluster1 is the parent of item1, item2 and item3. 示例中的分层关系由名称中的点表示,因此cluster1是item1,item2和item3的父级。 Here is how it look if we remove the filter while appending nodes. 在这里 ,如果我们去除过滤器,同时追加节点它的外观。

Now, my interpretation of your question is you want to use Hierarchical Edge Bundling for visualizing the non-hierarchical relations (represented by imports in the example) and 'Radial Reingold–Tilford' for hierarchical relations. 现在,我对您的问题的解释是,您希望使用Hierarchical Edge Bundling来显示非层次关系(在示例中由导入表示)和'Radial Reingold-Tilford'用于层次关系。

Here is how this can be done: 以下是如何做到这一点:

Data format need not change to what you have proposed. 数据格式不需要改变你提出了什么。 Below should be okay: 下面应该没问题:

    var classes = [
        {
            "name": "test.cluster1.item1.item4",
            "imports": ["test.cluster1.item2", "test.cluster1.item3"]
        },
        {
            "name": "test.cluster1.item1.item5",
            "imports": []
        }
]

Adopt packageImports function to get hierarchical edges from the nodes: 采用packageImports函数从节点获取分层边缘:

nodes.forEach(function (d) {
            if(d.children && d.name !== "") d.children.forEach(function (i) {
                imports.push({
                    source: map[d.name],
                    target: i
                });
            });
        });

Add the radial diagonal generator from Radial Reingold–Tilford example : Radial Reingold-Tilford示例中添加径向对角线生成器:

  var diagonal = d3.svg.diagonal.radial()
                .projection(
                        function(d) {
                            debugger;
                            return [d.y, d.x / 180 * Math.PI];
                        }
                );

Append hierarchical edges path: 附加分层边缘路径:

treeLink = treeLink
            .data(getHeirarchialEdges(nodes))
            .enter().append("path")
            .attr("class", "tree-link")
            .attr("d", diagonal);

I have also added to the mouseover and mouseout functions to highlight the hierarchical nodes, try hovering over any parent node. 我还添加了mouseover和mouseout函数来突出显示分层节点,尝试将鼠标悬停在任何父节点上。

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

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