Position nodes along a grid:
let nodeCoords = []
let edges = []
let nodes = []
for (let i = 0; i < 5; i++) {
for (let j = 0; j < 5; j++) {
nodeCoords.push([i, j])
nodes.push(`${i},${j}`)
if (i < 4) edges.push([`${i},${j}`, `${i+1},${j}`])
if (j < 4) edges.push([`${i},${j}`, `${i},${j+1}`])
}
}
canvas.nodes(nodes).data(nodeCoords).add({
pos: ([i, j]) => [(i - 2) * 35, (j - 2) * 35],
fixed: true,
labels: { 0: { remove: true } }
})
canvas.edges(edges).add()