Show always couples in same order in simple tree
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Pierre HUBERT 2023-08-26 17:05:31 +02:00
parent 137b7422cf
commit 4e22455f46

View File

@ -241,6 +241,17 @@ function NodeArea(p: {
}): React.ReactElement {
let parent_x_offset: number;
let pers1 = p.node.member;
let pers2 = p.node.spouse?.member;
let didSwap = false;
if (pers2?.sex === "M") {
let s = pers1;
pers1 = pers2;
pers2 = s;
didSwap = true;
}
parent_x_offset = p.x + center(p.node.width, p.node.parentWidth);
let unusedChildrenWidth = p.node.width - p.node.childrenWidth;
@ -248,24 +259,22 @@ function NodeArea(p: {
let endFirstFaceX =
parent_x_offset +
Math.floor((memberCardWidth(p.node.member) - FACE_WIDTH) / 2) +
Math.floor((memberCardWidth(pers1) - FACE_WIDTH) / 2) +
FACE_WIDTH;
let beginingOfSecondCardX =
parent_x_offset +
p.node.parentWidth -
memberCardWidth(p.node.spouse?.member);
parent_x_offset + p.node.parentWidth - memberCardWidth(pers2);
let beginSecondFaceX =
p.node.spouse &&
beginingOfSecondCardX +
(memberCardWidth(p.node.spouse.member) - FACE_WIDTH) / 2;
beginingOfSecondCardX + (memberCardWidth(pers2) - FACE_WIDTH) / 2;
let middleParentFaceY = p.y + Math.floor(FACE_HEIGHT / 2);
// Compute points for link between children and parent
let parentLinkX =
parent_x_offset + Math.floor(memberCardWidth(p.node.member) / 2);
let parentLinkX = didSwap
? beginSecondFaceX! + Math.floor(FACE_WIDTH / 2)
: parent_x_offset + Math.floor(memberCardWidth(pers1) / 2);
let parentLinkY = p.y;
// Remove ugly little shifts
@ -279,8 +288,7 @@ function NodeArea(p: {
childrenLinkX = Math.floor((endFirstFaceX + beginSecondFaceX!) / 2);
childrenLinkY = middleParentFaceY;
} else {
childrenLinkX =
parent_x_offset + Math.floor(memberCardWidth(p.node.member) / 2);
childrenLinkX = parent_x_offset + Math.floor(memberCardWidth(pers1) / 2);
childrenLinkY = p.y + CARD_HEIGHT + 2;
}
@ -298,7 +306,7 @@ function NodeArea(p: {
></path>
)}
<MemberCard x={parent_x_offset} y={p.y} member={p.node.member} />
<MemberCard x={parent_x_offset} y={p.y} member={pers1} />
{p.node.spouse && (
<>
@ -310,11 +318,7 @@ function NodeArea(p: {
d={`M${endFirstFaceX} ${middleParentFaceY} H ${beginSecondFaceX}`}
></path>
<MemberCard
x={beginingOfSecondCardX}
y={p.y}
member={p.node.spouse.member}
/>
<MemberCard x={beginingOfSecondCardX} y={p.y} member={pers2!} />
</>
)}