0

I want to list all the nodes that are connected to a node that I rollover with a mouse in a text field, been trying to use the filter function and it sort of does what I need since it affects the stroke width of the linked objects but I'd like to also output the node names too.

 .on("mouseover", function(da) {
  link.filter(function(db) { return da.group == db.groupColor; })
  .transition()
  .style("stroke-width", 8);  

 selectedText.text("Currently Selected: "+da.name+"is connecting to sensors: "+link.filter(function(db) { return da.group == db.groupColor; }) ); 

right now I am getting an output of "bike brian is connected to sensors: [object svgline element]"

but what I want is to be able to return all the names of the other nodes... does that make sense? so that it might say "bike brian is connected to sensors: accelerometer, gps, etc..."

4

1 回答 1

0

假设您的链接使用标准网络语法,您可以执行以下操作:

var filteredLinks = link.filter(function(db) { return da.group == db.groupColor; });
var sensorList = '';
for (x in filteredLinks) {
    if (filteredLinks[x]) {
    filteredLinks[x].source.id == originalSensorID ? sensorList += filteredLinks[x].target.id : sensorList += filteredLinks[x].source.id
    }
}

您可能需要在 sensorList 变量中添加逗号和空格。这有点麻烦,但我无法使 .each() 方法与过滤器一起使用,所以这是我能想到的最好的方法。

于 2013-01-08T15:07:51.167 回答