refactor
This commit is contained in:
parent
0a6148c73f
commit
e8f1d1db1e
60 changed files with 2417 additions and 612 deletions
|
|
@ -112,35 +112,14 @@ function liveFamilyComponents(family) {
|
|||
const relatedIds = lineageRelatedIdSet(family);
|
||||
const nodes = Array.from(relatedIds).map(id => family[id]).filter(Boolean);
|
||||
const ids = new Set(nodes.map(n => n.id));
|
||||
const graph = new Map(nodes.map(n => [n.id, new Set()]));
|
||||
const addEdge = (a, b) => {
|
||||
if (!a || !b || !ids.has(a) || !ids.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, ids)) addEdge(n.id, p);
|
||||
for (const c of lineageMutualChildIds(n, family, ids)) addEdge(n.id, c);
|
||||
}
|
||||
const seen = new Set();
|
||||
const comps = [];
|
||||
for (const n of nodes.sort(lineageNodeSort)) {
|
||||
if (seen.has(n.id)) continue;
|
||||
const stack = [n.id];
|
||||
const comp = [];
|
||||
seen.add(n.id);
|
||||
while (stack.length) {
|
||||
const id = stack.pop();
|
||||
const item = family[id];
|
||||
if (item) comp.push(item);
|
||||
for (const next of graph.get(id) || []) {
|
||||
if (seen.has(next)) continue;
|
||||
seen.add(next);
|
||||
stack.push(next);
|
||||
}
|
||||
}
|
||||
if (comp.some(x => x.alive)) comps.push(comp);
|
||||
}
|
||||
const comps = window.TarinaiFamilyGraph.connectedComponents(nodes, {
|
||||
sort: lineageNodeSort,
|
||||
edgesOf: (n) => [
|
||||
...lineageMutualParentIds(n, family, ids),
|
||||
...lineageMutualChildIds(n, family, ids),
|
||||
],
|
||||
filter: comp => comp.some(x => x.alive),
|
||||
});
|
||||
comps.sort((a, b) => {
|
||||
const ag = Math.min(...a.map(n => n.generation || 1));
|
||||
const bg = Math.min(...b.map(n => n.generation || 1));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue