From 965530517aeb6113a7b46d978fe65de773be76bc Mon Sep 17 00:00:00 2001 From: Pierre Hubert Date: Wed, 23 Aug 2023 15:42:07 +0200 Subject: [PATCH] Adaptative height --- .../complex_family_tree/ComplexFamilyTree.tsx | 22 +++++++++++++++++-- .../complex_family_tree/family-chart.css | 1 - 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/geneit_app/src/widgets/complex_family_tree/ComplexFamilyTree.tsx b/geneit_app/src/widgets/complex_family_tree/ComplexFamilyTree.tsx index dafe8a7..718620d 100644 --- a/geneit_app/src/widgets/complex_family_tree/ComplexFamilyTree.tsx +++ b/geneit_app/src/widgets/complex_family_tree/ComplexFamilyTree.tsx @@ -74,14 +74,17 @@ export function ComplexFamilyTree(p: { }; const exportPDF = async () => { + const docHeight = treeHeight(p.tree) * 41; + const doc = new jsPDF({ orientation: "l", - format: [351, 351], + format: [docHeight, 351], }); // Clone the SVG to manipulate it const container = document.createElement("div"); container.classList.add("f3", "f3-export"); + container.style.height = docHeight + "px"; document.body.appendChild(container); applyTree(container); @@ -110,7 +113,7 @@ export function ComplexFamilyTree(p: { target.innerHTML = dstSVG; await doc.svg(target, { - height: 351, + height: docHeight, width: 351, }); @@ -136,6 +139,21 @@ export function ComplexFamilyTree(p: { ); } +function treeHeight(node: FamilyTreeNode): number { + let res = + node.down?.reduce((prev, node) => Math.max(prev, treeHeight(node)), 0) ?? 0; + + node.couples?.forEach( + (c) => + (res = Math.max( + res, + c.down.reduce((prev, node) => Math.max(prev, treeHeight(node)), 0) + )) + ); + + return res + 1; +} + function treeToF3Data(node: FamilyTreeNode, isUp: boolean): f3Data[] { const availableMembers = new Set(); getAvailableMembers(node, availableMembers); diff --git a/geneit_app/src/widgets/complex_family_tree/family-chart.css b/geneit_app/src/widgets/complex_family_tree/family-chart.css index c7bf53c..9fab263 100644 --- a/geneit_app/src/widgets/complex_family_tree/family-chart.css +++ b/geneit_app/src/widgets/complex_family_tree/family-chart.css @@ -108,6 +108,5 @@ /*width: 3508px; height: 2480px;*/ width: 351px; - height: 248px; opacity: 0; }