Draw couples links

This commit is contained in:
Pierre HUBERT 2023-08-26 13:39:32 +02:00
parent e07b093dfc
commit 1c15fd17db
2 changed files with 32 additions and 9 deletions

View File

@ -26,6 +26,5 @@ export function getTextWidth(text: string, font: string) {
if (!ref.has(c)) ref.set(c, computeTextWidth(c, font)); if (!ref.has(c)) ref.set(c, computeTextWidth(c, font));
size += ref.get(c)!; size += ref.get(c)!;
} }
console.log(text, size);
return size; return size;
} }

View File

@ -48,7 +48,7 @@ function buildSimpleDownTreeNode(
): SimpleTreeNode { ): SimpleTreeNode {
if (depth === 0) throw new Error("Too much recursion reached!"); if (depth === 0) throw new Error("Too much recursion reached!");
const lastCouple = tree.couples?.[tree.couples?.length ?? 0]; const lastCouple = tree.couples?.[tree.couples?.length - 1 ?? 0];
// Preprocess children // Preprocess children
let childrenToProcess = tree.down; let childrenToProcess = tree.down;
@ -137,9 +137,11 @@ export function SimpleFamilyTree(p: {
function NodeArea(p: { function NodeArea(p: {
x: number; x: number;
y: number; y: number;
parentLinkDestX?: number;
parentLinkDestY?: number;
node: SimpleTreeNode; node: SimpleTreeNode;
}): React.ReactElement { }): React.ReactElement {
const couple_x_offset = const parent_x_offset =
p.x + p.x +
Math.floor( Math.floor(
(p.node.width - (p.node.width -
@ -152,16 +154,38 @@ function NodeArea(p: {
let downXOffset = p.x; let downXOffset = p.x;
let endFirstFaceX =
parent_x_offset +
Math.floor((memberCardWidth(p.node.member) - FACE_WIDTH) / 2) +
FACE_WIDTH;
let beginingOfSecondCardX =
parent_x_offset + memberCardWidth(p.node.member) + SPOUSE_SPACING;
let middleParentFaceY = p.y + Math.floor(FACE_HEIGHT / 2);
return ( return (
<> <>
<MemberCard x={couple_x_offset} y={p.y} member={p.node.member} /> <MemberCard x={parent_x_offset} y={p.y} member={p.node.member} />
{p.node.spouse && ( {p.node.spouse && (
<MemberCard <>
x={couple_x_offset + memberCardWidth(p.node.member) + SPOUSE_SPACING} {/* Couple link */}
y={p.y} <path
member={p.node.spouse.member} className="link"
/> fill="none"
stroke="#000"
d={`M${endFirstFaceX} ${middleParentFaceY} H ${
beginingOfSecondCardX + memberCardWidth(p.node.spouse.member) / 2
}`}
></path>
<MemberCard
x={beginingOfSecondCardX}
y={p.y}
member={p.node.spouse.member}
/>
</>
)} )}
{p.node.down.map((n) => { {p.node.down.map((n) => {