从显示节点关系的csv文件中获取连接节点的数量
Get the number of connected nodes from a csv file that shows their relations
我有一个大的csv
文件,其格式为:
ServerID|AppID
01 | 01
01 | 02
02 | 02
02 | 03
02 | 04
03 | 04
我在d3
力布局中使用这些数据,如图所示。获取服务器和应用程序之间关系的关键代码是:
links.forEach(function (link) {
link.ApplicationName= nodeByName(link.ApplicationName, "A");
link.Servername = nodeByName(link.Servername, "S");
edges.push({ source: link.ApplicationName, target: link.Servername })
});
function nodeByName(name, SorA) {
var groupNo = 0;
switch (SorA) {
case "A":
groupNo = 1;
break;
case "S":
groupNo = 2;
break;
default:
groupNo = 0;
}
return nodesByNames[name] || (nodesByNames[name] = { Name: name, group: groupNo });
}
生成用于创建节点的服务器和应用程序的唯一列表的单独列表(edges
)以及具有服务器和应用之间的关系并用于创建链接节点的线的单独列表。
我希望能够根据运行在服务器节点上的应用程序的数量来设置服务器节点的半径。我很难想出一种优雅的方式来在当前系统中获取和存储这些信息。d3
中是否已经有什么可以在这里提供帮助,或者有人能在当前代码的情况下找到实现这一点的方法吗?
更新的plnkr:http://plnkr.co/edit/gtAcJinltdjkgu1MEPmY?p=preview
var circles = node.append("circle")
.each(function(d) {
d.amountOfNeighbours = 0;
link.each(function(e) {
console.log(e)
if (e.source.Name == d.Name) { //if the source of the link is this node, amountOfNeighbours++
d.amountOfNeighbours++
}
if (e.target.Name == d.Name) { //if the target of the link is this node, amountOfNeighbours++
d.amountOfNeighbours++
}
})
})
.attr("r", function(d) {
return d.amountOfNeighbours * 2;
})
基本上浏览所有的链接,并检查有多少链接到所选节点,如下所示:
.each(function(d) {
d.amountOfNeighbours = 0; //set an attribute
link.each(function(e) {
console.log(e)
if (e.source.Name == d.Name) { //if the source of the link is this node, amountOfNeighbours++
d.amountOfNeighbours++
}
if (e.target.Name == d.Name) { //if the target of the link is this node, amountOfNeighbours++
d.amountOfNeighbours++
}
})
})
然后使用这个值:d.amountOfNeighbours
作为半径。我把它乘以2,因为这个值很小:)
.attr("r", function(d) {
return d.amountOfNeighbours * 2;
})
希望对有所帮助
相关文章:
- 如何处理node.js节点mongodb中的连接和查询队列
- jquery在元素中查找文本节点,并使用标记进行连接和包装
- 如何在d3.js图库中基于nodes id连接边和节点
- 解决节点中的“本地主机意外关闭连接”错误
- 如何增加节点中与 Whois 服务器的最大连接数
- AlloyUI图表生成器:按ID而不是名称连接节点
- 节点&MySQL:Can't端连接->异步混淆
- 从显示节点关系的csv文件中获取连接节点的数量
- 使用节点JS连接和断开数据卡
- 有没有什么好的节点模块可以连接google shortener API来缩短长URL
- 节点不是持久的网络连接
- 节点网络套接字:1006远程对等方在谷歌Chrome上丢弃的连接
- 使用节点单元编写带有数据库连接/驱动程序的单元测试
- 从节点连接中引发错误,并在服务器错误处理程序中捕获它
- 节点:建立连接时备份 socket.io 自定义发射器
- 尝试从“平面”JSON连接D3节点以制作公司层次结构图
- 连接到节点服务器自动查找掩码
- 如何检测使用节点.js连接的 USB 设备
- 节点.js + 快速 - 无法连接.ERR_CONNECTION_REFUSED
- 使用AudioContext(Web Audio API)断开节点连接时出现问题