如何通過d3提示顯示所選(並且我的意思是盤旋在節點上)的第一度鄰居?d3工具提示中的第一個節點鄰居
這裏是我的d3.tip部分
var tip = d3.tip()
.attr('class', 'd3-tip')
.html(function(d) {return [name of neighbors];});
我怎麼會改變後續幫我通過我的小費返回文本,而不是改變透明度?
var linkedByIndex = {};
var toggle = 0;
for (i = 0; i < nodes.length; i++) {
linkedByIndex[i + "," + i] = 1;
};
links.forEach(function (d) {
linkedByIndex[d.source.index + "," + d.target.index] = 1;
});
//This function looks up whether a pair are neighbours
function neighboring(a, b) {
return linkedByIndex[a.index + "," + b.index];
}
function connectedNodes() {
if (toggle == 0) {
//Reduce the opacity of all but the neighbouring nodes
d = d3.select(this).node().__data__;
circle.style("opacity", function (o) {
return neighboring(d, o) | neighboring(o, d) ? 1 : 0.1;
});
path.style("opacity", function (o) {
return d.index==o.source.index | d.index==o.target.index ? 1 : 0.1;
});
//Reduce the op
toggle = 1;
} else {
//Put them back to opacity=1
circle.style("opacity", 1);
path.style("opacity", 1);
toggle = 0;
}}
你可以把你的代碼放在工作小提琴中嗎? – Cyril
@omicronAlpha是否可以解決您的問題? – thatOneGuy
@thisOneGuy是的!謝謝,抱歉,遲交回復 – OmicronAlpha