From 263a62c1a4da7f84acb7f22077419f0be15e35e4 Mon Sep 17 00:00:00 2001 From: Pierre Hubert Date: Wed, 23 Aug 2023 11:25:33 +0200 Subject: [PATCH] Add wedding info to tree --- .../complex_family_tree/ComplexFamilyTree.tsx | 40 ++++++++++++++----- .../complex_family_tree/family_chart.d.ts | 4 ++ 2 files changed, 35 insertions(+), 9 deletions(-) diff --git a/geneit_app/src/widgets/complex_family_tree/ComplexFamilyTree.tsx b/geneit_app/src/widgets/complex_family_tree/ComplexFamilyTree.tsx index 603ad7d..a5a3678 100644 --- a/geneit_app/src/widgets/complex_family_tree/ComplexFamilyTree.tsx +++ b/geneit_app/src/widgets/complex_family_tree/ComplexFamilyTree.tsx @@ -3,6 +3,7 @@ import f3, { f3Data } from "family-chart"; import "./family-chart.css"; import { FamilyTreeNode } from "../../utils/family_tree"; import { Member, fmtDate } from "../../api/MemberApi"; +import { Couple } from "../../api/CoupleApi"; export function ComplexFamilyTree(p: { tree: FamilyTreeNode; @@ -24,7 +25,7 @@ export function ComplexFamilyTree(p: { store, svg: view.svg, card_dim: { - w: 220, + w: 230, h: 70, text_x: 75, text_y: 15, @@ -34,8 +35,27 @@ export function ComplexFamilyTree(p: { img_y: 5, }, card_display: [ - (d) => `${d.data.first_name || ""} ${d.data.last_name || ""}`, - (d) => `${d.data["birthday"] || ""}`, + (d) => + `${d.data.first_name || ""} ${d.data.last_name || ""} ${ + d.data.dead ? "✝" : "" + }`, + (d) => { + let s = `${d.data.birthday || ""} ${ + d.data.deathday ? " ✝ " + d.data.deathday : "" + }`; + + if (d.data.wedding_state || d.data.dateOfWedding) { + let weddingInfo = []; + if (d.data.wedding_state) weddingInfo.push(d.data.wedding_state); + if (d.data.dateOfWedding) + weddingInfo.push("Mariage : " + d.data.dateOfWedding); + s += ` ${weddingInfo.join( + " - " + )}`; + } + + return s; + }, ], mini_tree: true, link_break: false, @@ -54,10 +74,8 @@ function treeToF3Data(node: FamilyTreeNode, isUp: boolean): f3Data[] { getAvailableMembers(node, availableMembers); const list: f3Data[] = []; - if (isUp) { - treeToF3DataUpRecurse(node, list, availableMembers); - } else treeToF3DataDownRecurse(node, list, availableMembers); - console.info(list); + if (isUp) treeToF3DataUpRecurse(node, list, availableMembers); + else treeToF3DataDownRecurse(node, list, availableMembers); return list; } @@ -72,13 +90,17 @@ function getAvailableMembers(t: FamilyTreeNode, s: Set) { t.down?.forEach((e) => getAvailableMembers(e, s)); } -function memberData(m: Member): f3.f3DataData { +function memberData(m: Member, c?: Couple): f3.f3DataData { return { first_name: m.first_name ?? "_", last_name: m.last_name ?? "_", gender: m.sex ?? "M", avatar: m.thumbnailURL ?? undefined, + dead: m.dead, birthday: m.dateOfBirth ? fmtDate(m.dateOfBirth) : undefined, + deathday: m.dateOfDeath ? fmtDate(m.dateOfDeath) : undefined, + wedding_state: c?.stateFr, + dateOfWedding: c?.dateOfWedding ? fmtDate(c?.dateOfWedding) : undefined, }; } @@ -158,7 +180,7 @@ function treeToF3DataDownRecurse( if (node.couples) { for (const c of node.couples) { array.push({ - data: memberData(c.member), + data: memberData(c.member, c.couple), id: c.member.id.toString(), rels: { father: diff --git a/geneit_app/src/widgets/complex_family_tree/family_chart.d.ts b/geneit_app/src/widgets/complex_family_tree/family_chart.d.ts index 971620d..9c4ca77 100644 --- a/geneit_app/src/widgets/complex_family_tree/family_chart.d.ts +++ b/geneit_app/src/widgets/complex_family_tree/family_chart.d.ts @@ -12,9 +12,13 @@ declare module "family-chart" { interface f3DataData { gender: "M" | "F"; avatar?: string; + dead: boolean; birthday?: string; + deathday?: string; first_name: string; last_name: string; + dateOfWedding?: string; + wedding_state?: string; } interface f3Data {