[英]Is it possible to find out what class an edges source and/or target has?
I have given some nodes a class "hidden" and some a class "visible". 我给了一些节点一个“隐藏”的类和一些给“可见”的类。
I am using the 我正在使用
d3.selectAll(".link")
to select all links in my force directed graph. 选择我的力向图中的所有链接。 These links have both source and target, all linked in a JSON file. 这些链接具有源和目标,都链接在JSON文件中。
I want to go through these links and check the links source node class (and the target) and see if any of the classes = visible/hidden. 我想浏览这些链接并检查链接源节点类(和目标),看看是否有任何类=可见/隐藏。
If both the source and target are "visible" then the link will have a "visible" class else have a "hidden" class. 如果源和目标都“可见”,则链接将具有“可见”类,否则具有“隐藏”类。
How do I see what the links source and target classes are ? 我如何查看链接的源类和目标类?
Here is what I have tried but I do not know what to put in the main 'if' statement. 这是我尝试过的内容,但我不知道要在主“ if”语句中添加什么。
d3.selectAll(".link.visible").attr("class", function(d) {
var c = "link";
if (d.source.visible && d.target.visible) //here this doesnt work, I need to
//find out if source and target of the selected link are visible
{
clog("VISIBLE");
c += " visible";
} else {
clog("HIDDEN");
c += " hidden";
}
return c;
});
Where I apply the visible class to all nodes at the start : 我在一开始将可见类应用于所有节点的地方:
var nodes = inner.selectAll(".node").append("g")
.data(network.network.data.nodes)
nodes.classed("visible", true);
Here is where I show/hide nodes depending if they're selected or not 这是我显示/隐藏节点的位置,具体取决于是否选择了它们
nodes.classed("hidden", function (d)
{
//if()
return d.selected ? false : true;
});
nodes.classed("visible", function (d)
{
return d.selected ? true : false;
});
Since the source
and target
data nodes both have a property selected
that determines the visibility of the associated DOM node, just use that property instead of looking for the CSS classes. 由于source
数据节点和target
数据节点都selected
了确定关联的DOM节点可见性的属性,因此只需使用该属性,而不要查找CSS类。
d3.selectAll(".link")
.attr("class", function(d) {
return d.source.selected && d.target.selected ? "visible" : "hidden";
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.