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