Public
Edited
Nov 26
Insert cell
Insert cell
Insert cell
Insert cell
data = FileAttachment("data2-4.json").json()
Insert cell
data2 = FileAttachment("links.json").json()
Insert cell
Insert cell
nodes = data2.map((d) => {
return { data: { id: d.file } };
})
Insert cell
edges = {
const edges = [];
data2.forEach((node) => {
console.log(node);
node.links.forEach((link) => {
if (nodes.find((n) => link.file == n.data.id))
edges.push({
data: {
source: node.file,
target: link.file,
id: node.file + "--" + link
}
});
});
});
return edges;
}
Insert cell
cy = cytoscape({
elements: {
nodes: nodes,
edges: edges
}
})
Insert cell
bc = cy.$().bc()
Insert cell
bc.betweenness("#satipatthaana.htm")
Insert cell
Insert cell
tableBC = {
// Assuming `cy` is your Cytoscape instance

// Calculate betweenness centrality for all nodes
let bc = cy.$().bc();

// Initialize an array to store betweenness centrality values
let betweennessCentralities = [];

// Iterate over all nodes and store their betweenness centrality in the array
cy.nodes().forEach((node) => {
let nodeBc = bc.betweenness(node);
betweennessCentralities.push({ id: node.id(), nodeBc });
});

return betweennessCentralities.sort((a, b) => b.nodeBc - a.nodeBc);

// `betweennessCentralities` now contains the betweenness centrality for each node in the graph
}
Insert cell
Insert cell
Insert cell
Insert cell
// jsnx.edge_betweenness_centrality

Insert cell
G.nodes()
Insert cell
G = {
const G = new jsnx.Graph();
data.forEach((node) => {
G.addNode(node.file);
});
data.forEach((node) => {
G.addNode(node.file);
node.info.links.forEach((link) => {
if (G.nodes().find((n) => link == n)) G.addEdge(node.file, link);
});
});
return G;
}
Insert cell
jsnx.betweennessCentrality(G)
Insert cell
nodeCentralityArray = Object.entries(
jsnx.betweennessCentrality(G)._stringValues
)
.map(([node, centrality]) => ({
node,
centrality
}))
.sort((a, b) => b.centrality - a.centrality)
Insert cell
jsnx.edgeBetweennessCentrality(G)
Insert cell
edgeCentralityArray = Object.entries(jsnx.edgeBetweennessCentrality(G)._values)
.map(([edge, centrality]) => ({
edge: edge.toString(), // Convert tuple to string for consistency
centrality
}))
.sort((a, b) => b.centrality - a.centrality)
Insert cell
Insert cell
Insert cell
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more