graph = {
const roleNames = ['CEO', 'CFO', 'CTO', 'COO', 'CMO'];
const roles = roleNames.map((name, id) => ({id: id + 1, name, type: 'role', color: 'orange'}));
const userNames = ['John', 'Tom', 'Jack', 'Pam', 'Jill', 'Chad', 'Bill', 'Mike', 'Dana', 'Mary'];
const users = userNames.map((name, id) => ({id: id + 10, name, type: 'user', color: 'red' }));
const nodes = [...roles, ...users];
const n = (name) => nodes.find(n => n.name === name).id;
const l = (source, target, access, value = 1) =>
({
access,
source: n(source),
target: n(target),
value,
is: accessHash[access].is,
color: accessHash[access].color,
});
const links = roleNames.flatMap(role => {
const shuffled = shuffle(userNames).slice(Math.trunc(Math.random()*3));
const own = shuffled[0];
const part = Math.trunc(Math.random()*(shuffled.length-2)) + 1;
const vis = shuffled.slice(1, part);
const hid = shuffled.slice(part);
return [
l(own, role, 'owner'),
...vis.map(usr => l(usr, role, 'visible')),
...hid.map(usr => l(usr, role, 'hidden')),
];
});
return { nodes, links}
}