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 badges
Add a ment  | 

2 Answers 2

Reset to default 6

I'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