admin管理员组文章数量:1389754
I have a ton of nodes in a graph, and with some filters I am able to remove some edges by some condition, using cy.remove(myCollection)
.
It happens sometimes that all edges to a node is removed and therefore its sitting alone without edges. Is there any way in Cytoscape to find these nodes without edges?
I was out in something like:
cy.nodes(/*:inside*/).filter(node => node.connectedEdges().size() === 0)
But this returns an empty collection?
I have a ton of nodes in a graph, and with some filters I am able to remove some edges by some condition, using cy.remove(myCollection)
.
It happens sometimes that all edges to a node is removed and therefore its sitting alone without edges. Is there any way in Cytoscape to find these nodes without edges?
I was out in something like:
cy.nodes(/*:inside*/).filter(node => node.connectedEdges().size() === 0)
But this returns an empty collection?
Share Improve this question edited Jan 4, 2018 at 18:32 AlexanderPico 5073 silver badges7 bronze badges asked Dec 6, 2017 at 17:21 janhartmannjanhartmann 15k17 gold badges87 silver badges140 bronze badges2 Answers
Reset to default 6I've had a similar problem: I had to remove nodes without edges from a graph. I solved it by using node.degree() with a function that cycles through nodes of my graph and finds those with degree=0 (both indegree and outdegree, which means that the nodes have neither sources nor targets).
`cy.nodes(function(element){
if( element.isNode() && element.degree()<1){
cy.remove(element)
}
})`
Hope it could be useful to fix your problem
A solution to this (so far) is that instead of manipulating whats inside the graph, I will do the filtering by setting an data property on the node/edge and style with display: "none"
using the data property as a condition. Then this is working:
const nodesWithoutEdges = cy.nodes().filter(node => node.connectedEdges(":visible").size() === 0)
本文标签: javascriptGetting nodes without edgesStack Overflow
版权声明:本文标题:javascript - Getting nodes without edges - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744742241a2622676.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论