2

I've been trying to loop through each of the nodes in my network chart to calculate the degree centrality of the nodes. Have been able to do so for other normalized centrality measures, but did not get any success with the unnormalized ones. Below are my code:

This works:

let dcn = cy.elements().degreeCentralityNormalized();
cy.nodes().forEach(n => {
    n.data({
       dcn: dcn.degree(n)
    });
});

However, this doesn't work:

let dc = cy.elements().degreeCentrality();
cy.nodes().forEach(n => {
    n.data({
       dc: dc.degree(n)
    });
});

Have been getting the following error message: Uncaught TypeError: Cannot read property 'connectedEdges' of undefined at ca.degreeCentrality

Not sure why this is the case. Appreciate any help here!

ZPeh
  • 592
  • 1
  • 7
  • 18

1 Answers1

0

For degreeCentrality function the docs says.

For options.directed: false, this function returns an object of the following form:

{ degree /* the degree centrality of the root node */ }

For degreeCentralityNormalized function the docs says

For options.directed: false, this function returns an object of the following form:

{ /* the normalised degree centrality of the specified node */
degree: function( node ){ /* impl */ } }

I wish it supported typescript so that we can see what they return.

canbax
  • 3,432
  • 1
  • 27
  • 44