Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 26 additions & 5 deletions src/ancestor-chart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,7 @@ export class AncestorChart<IndiT extends Indi, FamT extends Fam>
if (!fam) {
continue;
}
const [father, mother] =
entry.family!.id === this.options.startFam &&
this.options.swapStartSpouses
? [fam.getMother(), fam.getFather()]
: [fam.getFather(), fam.getMother()];
const [father, mother] = this.getParents(fam, entry);
if (!father && !mother) {
continue;
}
Expand Down Expand Up @@ -134,4 +130,29 @@ export class AncestorChart<IndiT extends Indi, FamT extends Fam>
this.util.updateSvgDimensions(info);
return Object.assign(info, { animationPromise });
}

private getParents(fam: Fam, entry: TreeNode) {
let [father, mother] = [fam.getFather(), fam.getMother()];
if(!father && !mother) {
// get indis whose FAMS contains this family
const res: any[] = Array.from((this.options.data as any).indis.entries())
.filter((e: any[]) => e[1]?.json?.fams && e[1].json.fams.includes(entry.family?.id));
const getFromRes = function(pRes: any, sex: "M" | "F") {
const r = pRes.find((e: any) => e[1].json.sex === sex);
return r.length === 2
? r[1].json?.id || null
: null;
}
father = getFromRes(res, "M");
mother = getFromRes(res, "F");
}

if(this.options.swapStartSpouses) {
const pivot = father;
father = mother;
mother = pivot;
}

return [father || null, mother];
Comment thread
lezhumain marked this conversation as resolved.
Outdated
}
}
34 changes: 33 additions & 1 deletion tests/ancestor-chart.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,42 @@ describe('Ancestor chart', () => {
const data = new JsonDataProvider(json);
const chart = new AncestorChart({
data,
startFam: 'F1',
startFam: json.fams[0].id,
renderer: new FakeRenderer(),
svgSelector: 'svg',
});
chart.render();
});

it('should work with FAM values only', () => {
// I5+I6
// F3
// |
// I3+I4
// F2
// |
// +-++
// | |
// I1+I2
// F1
Comment thread
lezhumain marked this conversation as resolved.
Outdated
const json: JsonGedcomData = {
fams: [
{id: 'F1', children: []},
],
indis: [
{id: 'I1', fams: ['F1'], sex: "M"},
{id: 'I2', fams: ['F1'], sex: "F"},
{id: 'I3', famc: 'F1', sex: "F"},
],
};
const data = new JsonDataProvider(json);
const chart = new AncestorChart({
data,
startFam: json.fams[0].id,
renderer: new FakeRenderer(),
svgSelector: 'svg',
});
chart.render();
});

});