graph = {
const children_ = name => componentDeps.get(name).components || [];
const filter = (ids1, ids2) => ids1.filter(id => ids2.includes(id));
const unique = values => [...new Set(values)];
const allNames = [...componentDeps.keys()];
const filterSubs = (name, names) => filter(children_(name), names);
const walk = name => [name, ...filterSubs(name, allNames).map(walk)].flat();
const names = root == ' none' ? allNames : unique(walk(root));
const edgeId = (id, from, to) => ({ id, sources: [from], targets: [to] });
const edge = (from, to) => edgeId(`${from}->${to}`, from, to);
const edgesFrom = name => filterSubs(name, names).map(sub => edge(name, sub));
const edges = names.map(edgesFrom).flat();
const splitlines = (ids, mapper, width) => {
const reducer = ({ lines, count }, id) => {
const str = mapper(id);
const length = str.length;
const [line, newCount] =
10 + (count + length) * 6.4 > width
? [[], length]
: [lines.pop() || [], count + length];
line.push(str);
lines.push(line);
return { lines, count: newCount };
};
const lines = (ids || []).reduce(reducer, { lines: [], count: 0 }).lines;
return lines.map(line => line.join(','));
};
const children = names.map(name => {
const { props, events, color } = componentDeps.get(name);
const width = Math.max(120, name.length * 8.4 + 10);
const proplines = splitlines(props || [], id => id, width);
const eventlines = splitlines(events, id => `@${id}`, width);
const lines = [...proplines, ...eventlines];
const height = 25 + lines.length * 15;
const info = { label: name, text: lines.join('\n'), color };
return { id: name, width, height, info };
});
const layoutOptions = { 'elk.algorithm': 'layered' };
return { id: "root", layoutOptions, children, edges };
}