Skip to content Skip to sidebar Skip to footer

Perform Centrality Functions On All Nodes Using Cytoscape.js

I need to calculate degree, closeness and betweenness centrality for every node on a graph. I'm currently using the functions built into Cytoscape.js on each node after the cy.read

Solution 1:

Run the algorithm once, rather than running it N times. Then just query the result:

let ccn = cy.elements().closenessCentralityNormalized({ /* my options */ });

cy.nodes().forEach( n => {
  n.data({
    ccn: ccn.closeness( n )
  });
} );

Use normalised versions of centrality algorithms unless you have a good reason to do otherwise. Only the normalised versions really mean anything if you compare results in one graph to results in another graph, for example.


Post a Comment for "Perform Centrality Functions On All Nodes Using Cytoscape.js"