refactor
This commit is contained in:
parent
0a6148c73f
commit
e8f1d1db1e
60 changed files with 2417 additions and 612 deletions
|
|
@ -4,36 +4,14 @@ function lineageSplitByActualEdges(component) {
|
|||
const family = lineageEdgeFamily(world.family || {});
|
||||
const nodes = Array.from(new Map(lineageCleanComponent(component, family).filter(Boolean).map(n => [n.id, n])).values());
|
||||
const idSet = new Set(nodes.map(n => n.id));
|
||||
const byId = new Map(nodes.map(n => [n.id, n]));
|
||||
const graph = new Map(nodes.map(n => [n.id, new Set()]));
|
||||
const connect = (a, b) => {
|
||||
if (!a || !b || !idSet.has(a) || !idSet.has(b)) return;
|
||||
graph.get(a).add(b);
|
||||
graph.get(b).add(a);
|
||||
};
|
||||
for (const n of nodes) {
|
||||
for (const p of lineageMutualParentIds(n, family, idSet)) connect(n.id, p);
|
||||
for (const c of lineageMutualChildIds(n, family, idSet)) connect(n.id, c);
|
||||
}
|
||||
const seen = new Set();
|
||||
const parts = [];
|
||||
for (const n of nodes.sort(lineageNodeSort)) {
|
||||
if (seen.has(n.id)) continue;
|
||||
const stack = [n.id];
|
||||
const part = [];
|
||||
seen.add(n.id);
|
||||
while (stack.length) {
|
||||
const id = stack.pop();
|
||||
const node = byId.get(id);
|
||||
if (node) part.push(node);
|
||||
for (const next of graph.get(id) || []) {
|
||||
if (seen.has(next)) continue;
|
||||
seen.add(next);
|
||||
stack.push(next);
|
||||
}
|
||||
}
|
||||
if (part.length && part.some(x => x.alive)) parts.push(part.sort(lineageNodeSort));
|
||||
}
|
||||
const parts = window.TarinaiFamilyGraph.connectedComponents(nodes, {
|
||||
sort: lineageNodeSort,
|
||||
edgesOf: (n) => [
|
||||
...lineageMutualParentIds(n, family, idSet),
|
||||
...lineageMutualChildIds(n, family, idSet),
|
||||
],
|
||||
filter: part => part.length && part.some(x => x.alive),
|
||||
});
|
||||
return parts;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue