rems_to_graph = (rems, spacing = 100, jitter = 50, width = 5) => {
const graph = {edges: [], nodes: []}
let idx = 0
let y = 0
let x = 0
for (const rem of Object.values(rems)) {
x = x + spacing
if (idx % width == 0) {
y += spacing
x = 0
}
idx = idx + 1
const node = {
id: rem._id,
x: x + (Math.random() - 0.5) * jitter,
y: y + (Math.random() - 0.5) * jitter,
width: 80,
height: 80,
label: rem.name[0],
}
graph['nodes'].push(node)
for (const child_id of rem.children) {
const edgename = `${rem._id}_${child_id}`
const edge = {
id: edgename,
source: rem._id,
target: child_id,
}
graph['edges'].push(edge)
}
}
return graph
}