D3 Javascript中的力定向图中节点之间的链接 [英] The links between the nodes in Force-Directed Graph in D3 Javascript

查看:101
本文介绍了D3 Javascript中的力定向图中节点之间的链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究一个基本上包含至少150个使用D3 Javascript的节点的图。这个想法可以描述如下:

一个节点连接到100个节点。
这100个节点中有49个节点连接到其他49个节点。



让我们来澄清一下。我认识100人。他们中有49人有生日。每一个都代表一个节点。



通过这种方式,我可以设法使用 source target 通过JavaScript中的一些数组。我想我错过了一些非常重要的事情来理解D3中的Force-Directed Graph。据我所知,链接可以用 source target 来实现。我的问题是我无法理解如何将这些链接链接到这些节点。我不知道在什么基础上我可以创建一个阵列来保存我的名字,人们的姓名和生日,这样他们就可以联系在一起。在我的图中,它给了我合适的人,但错误的生日。任何人都可以请指导我如何处理这件事的正确方法。我正在学习本教程:并且无法理解我如何创建一个数组来添加诸如姓名,人名和生日等信息。


http://bl.ocks.org/mbostock/4062045


非常感谢您的协助。

解决方案

节点和链接的链接方式是按索引。也就是说,如果 target:0 ,这意味着该链接的目标节点是节点列表中的第一个节点,并传递给强制布局。您可以将所需的任何数据添加到链接和节点 - 对于链接,节点也可通过 link.source link.target



或者,您可以指定链接的源和目标作为对象本身 - 这实际上是D3在内部通过时执行的操作链接到部队布局。因为它不能与索引一起工作,所以它们被替换为已解析的节点对象(这就是为什么您可以通过链接访问实际对象)。



如果您通过外部数据(例如JSON)指定图结构,那么您应该使用索引来标识链接中的节点。如果您使用Javascript生成数据结构,则可以使用对实际对象的引用。


I am working on a graph which basically contains at least 150 nodes using D3 Javascript. The idea can be described as follows:

One node is connected to 100 nodes. 49 nodes of these 100 nodes are connected to other 49 nodes.

Let's clarify it. I know 100 people. 49 people of them have birthdays. Each of which represents a node.

In such a way, I could manage to link them together using source and target through some arrays in Javascript. I think I am missing something very important to understand in Force-Directed Graph in D3. As far as I am aware, the links can be implemented with source and target. My problem is I cant understand how I can link these links to these nodes. I do not know on what basis I can create an array to hold my name, peoples' names and their birthdays so they can be linked together. In my graph, it gives me the right person but the wrong birthday. Could anyone please guide me the right way how to do with this matter. I am following this tutorial: and could not understand how I can create an array to add the information such as: name, peoples names and birthday.

http://bl.ocks.org/mbostock/4062045

Your assistance would be very much appreciated.

解决方案

The way the nodes and links are linked is by index. That is, if target: 0, it means that the target node of that link is the first one in the list of nodes, as passed to the force layout. You can add any data you need to both links and nodes -- for links, the nodes are also available through link.source and link.target.

Alternatively, you can specify the source and target of a link as the object itself -- this is actually what D3 does internally when you pass the links to the force layout. As it can't work with the indices as such, they are replaced with the resolved node objects (this is why you can access the actual objects through the links).

If you're specifying the graph structure through external data (e.g. JSON), then you should use indices to identify nodes in links. If you're generating the data structure in Javascript, you could use references to the actual objects instead.

这篇关于D3 Javascript中的力定向图中节点之间的链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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