2014-04-14 28 views
0

它的鄰居節點,我創建使用D3.JS庫力向圖,突出的一個節點,在力向圖

mouseover我想要做的是要突出一個節點和它的鄰居節點和消失都其他節點。

mouseout事件我想重新設置圖形的方式。

我曾嘗試下面的代碼爲亮點的一部分,但它不工作:

.on("mouseover", function(d) { 

d3.select(this).select("circle").style("stroke-width", 6); 
var nodeNeighbors = graph.links.filter(function(link) { 

return link.source.index === d.index || link.target.index === d.index;}) 
         .map(function(link) { 

return link.source.index === d.index ? link.target.index : link.source.index; }); 

以下是link for my force directed graph

+1

[This question](http://stackoverflow.com/questions/8739072/highlight-selected-node-its-links-and-its-children-in-a-d3-force-directed-grap)and [這個問題](http://stackoverflow.com/questions/19154129/d3js-force-directed-graph-advanced-highlighting-of-neigbour-nodes-and-links)可能會有所幫助。 –

+0

@LarsKotthoff我用下面的例子更新了我的代碼,但仍然沒有工作。 http://plnkr.co/edit/d3a92HOodd7lQdPr6wQd?p=preview – analyticalpicasso

回答

2

這幾乎是從this question的完整複製和粘貼,請參閱此處以瞭解詳細信息。

我改變的唯一的事情是通過轉換淡入/出鏈接的節點/鏈接,並在用於確定鄰居的數據結構的兩個方向上添加連接。完整演示here

2

它可能如果你叉這個plunker和研究的主要部分轉出容易:

var linkedByIndex = {}; 
    json.links.forEach(function(d) { 
    linkedByIndex[d.source.index + "," + d.target.index] = 1; 
}); 

function isConnected(a, b) { 
    return linkedByIndex[a.index + "," + b.index] || linkedByIndex[b.index + "," + a.index] || a.index == b.index; 
} 
相關問題