Javascript D3JS高亮显示包含给定字符串的节点
我愿意搜索并突出显示包含给定字符串的节点。 为此,我调用set_focus方法Javascript D3JS高亮显示包含给定字符串的节点,javascript,jquery,asp.net,d3.js,Javascript,Jquery,Asp.net,D3.js,我愿意搜索并突出显示包含给定字符串的节点。 为此,我调用set_focus方法 function set_focus(d) { text.style("opacity", function(o) { return isConnected(d.id, o.id) ? 1 : null; }); img.style("opacity", function(o) { return isConnec
function set_focus(d)
{
text.style("opacity", function(o) {
return isConnected(d.id, o.id) ? 1 : null;
});
img.style("opacity", function(o) {
return isConnected(d.id, o.id) ? 1 : null;
});
link.style("opacity", function(o) {
return o.source.index == d.index || o.target.index == d.index ? 1 : null;
});
}
上述函数有条件地设置元素的不透明度。我想设置相互连接的节点的不透明度。但是我不想干扰那些没有连接的节点的不透明性
如需进一步澄清:
return isConnected(d.id, o.id) ? 1 : null;
如果isConnected==false,我不想返回不透明度
必需:返回是否已连接(d.id、o.id)?1:“此处返回当前不透明度值”代码>
发生:返回未连接(d.id,o.id)?1:“返回零或空”代码>您可以使用getter获取当前元素的不透明度值:
d3.select(this).style("opacity");
然后,您可以在三元运算符中使用它:
text.style("opacity", function(o) {
var current = d3.select(this).style("opacity");
return isConnected(d.id, o.id) ? 1 : current;
});
谢谢Gerardo,我已经试过你说的了…但是var current=d3.select(this.attr(“不透明”);正在返回null。我需要在创建文本时设置文本的不透明度吗?好的,var current=d3。选择(this).style(“不透明度”);用样式替换attr。。。。非常感谢。