Public
Edited
Mar 11, 2023
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
function get_neighList(nodes, links){
// build the list of neighbours for each nodes of the graph
// returns an array of indexed by nodes
let neighList = new Array(nodes.length);
for (let node in nodes) {
let neighbours = new Array();
neighbours.push(parseInt(nodes[node].node.index));
for (let i=0; i<links.length; i++) {
// console.log(nodes[node].node.index)
if (links[i].link.sourceId === nodes[node].node.index) {
neighbours.push(parseInt(links[i].link.targetId));
}
// if (links[i].link.targetId === nodes[node].node.index) {
// neighbours.push(parseInt(links[i].link.sourceId));
// }
}
// console.log(neighbours);
// filter out empty
if (neighbours.length > 1)
neighList[node] = neighbours;
}
return neighList;
}
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