forceGraph = {
const graph = new ForceGraph3D(domEl)
.graphData(getFabricData());
graph
.cooldownTicks(350)
.d3AlphaDecay(0.001)
.d3Force('link').iterations(30);
return graph;
function getFabricData() {
const perimeter = 12, length = 30;
const getId = (col, row) => `${col},${row}`;
let nodes = [], links = [];
for (let colIdx=0; colIdx<perimeter; colIdx++) {
for (let rowIdx=0; rowIdx<length; rowIdx++) {
const id = getId(colIdx, rowIdx);
nodes.push({id});
if (rowIdx>0) {
links.push({ source: getId(colIdx, rowIdx-1), target: id });
}
links.push({ source: getId((colIdx || perimeter) - 1, rowIdx), target: id });
}
}
return { nodes, links };
}
}