2016-03-08 64 views

回答

1

您的僞代碼是一個好的開始。您可以使用filter來實現選擇中的if條件。需要注意的是.source和鏈接.target由D3編輯,他們不再是節點的ID,但該節點本身:

thisNode = nodeObject; // where nodeObject is the javascript object for the node, it's probably called "d" in your function. 
d3.selectAll(".link") 
    .filter(function(d) { 
    return (d.source === thisNode) || (d.target === thisNode); 
    }) 
    .style("stroke", "red") 
+0

謝謝你和Mehdi El Fadil這麼多。作爲像我這樣的初學者的附加信息,當append()使用SelectAll()時,必須設置attr(class)作爲鏈接。我浪費了那麼多時間 –

3

擴大對@ Laurent的回答之上,「重啓」的鏈接顏色可能在之前的互動中被塗成紅色:

thisNode = nodeObject; // where nodeObject is the javascript object for the node, it's probably called "d" in your function. 
d3.selectAll(".link") 
    .style("stroke",function(d) { 
    return d.source === thisNode || d.target === thisNode ? "red" : "#888888"; 
    })