not bad
This commit is contained in:
parent
2741b93dea
commit
434f07cc4e
103 changed files with 8387 additions and 8152 deletions
|
|
@ -1,9 +1,4 @@
|
|||
"use strict";
|
||||
|
||||
function buildArchiveRows(family) {
|
||||
return liveFamilyComponents(family);
|
||||
}
|
||||
|
||||
function lineageEdgeFamily(family = world.family || {}) {
|
||||
return family || {};
|
||||
}
|
||||
|
|
@ -85,47 +80,3 @@ function lineageMutualChildIds(n, family = world.family || {}, idSet = null) {
|
|||
children.sort((a, b) => lineageNodeSort(family[a], family[b]));
|
||||
return children;
|
||||
}
|
||||
|
||||
function lineageHasActualRelation(n, family = world.family || {}) {
|
||||
return lineageMutualParentIds(n, family).length > 0 || lineageMutualChildIds(n, family).length > 0;
|
||||
}
|
||||
|
||||
function lineageRelatedIdSet(family) {
|
||||
family = lineageEdgeFamily(family);
|
||||
const relationIndex = lineageRelationIndex(family);
|
||||
const ids = new Set();
|
||||
for (const n of Object.values(family || {}).filter(Boolean)) {
|
||||
const parents = relationIndex.parentsByChild.get(n.id) || [];
|
||||
const children = relationIndex.childrenByParent.get(n.id) || [];
|
||||
if (parents.size || children.size) ids.add(n.id);
|
||||
for (const id of parents) ids.add(id);
|
||||
for (const id of children) ids.add(id);
|
||||
}
|
||||
return ids;
|
||||
}
|
||||
|
||||
function liveFamilyComponents(family) {
|
||||
// Childless pairs, including pairs currently performing the birth ritual, are
|
||||
// intentionally excluded. A \u5bb6\u7cfb\u56f3 node is created only after an actual parent/child
|
||||
// relation exists; otherwise ritual participants become isolated pseudo-families.
|
||||
family = lineageEdgeFamily(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 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));
|
||||
const at = Math.min(...a.map(n => n.birthTime || 0));
|
||||
const bt = Math.min(...b.map(n => n.birthTime || 0));
|
||||
return ag - bg || at - bt || b.length - a.length;
|
||||
});
|
||||
return comps;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue