Adaptative height

This commit is contained in:
Pierre HUBERT 2023-08-23 15:42:07 +02:00
parent e97814586e
commit 965530517a
2 changed files with 20 additions and 3 deletions

View File

@ -74,14 +74,17 @@ export function ComplexFamilyTree(p: {
}; };
const exportPDF = async () => { const exportPDF = async () => {
const docHeight = treeHeight(p.tree) * 41;
const doc = new jsPDF({ const doc = new jsPDF({
orientation: "l", orientation: "l",
format: [351, 351], format: [docHeight, 351],
}); });
// Clone the SVG to manipulate it // Clone the SVG to manipulate it
const container = document.createElement("div"); const container = document.createElement("div");
container.classList.add("f3", "f3-export"); container.classList.add("f3", "f3-export");
container.style.height = docHeight + "px";
document.body.appendChild(container); document.body.appendChild(container);
applyTree(container); applyTree(container);
@ -110,7 +113,7 @@ export function ComplexFamilyTree(p: {
target.innerHTML = dstSVG; target.innerHTML = dstSVG;
await doc.svg(target, { await doc.svg(target, {
height: 351, height: docHeight,
width: 351, 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[] { function treeToF3Data(node: FamilyTreeNode, isUp: boolean): f3Data[] {
const availableMembers = new Set<number>(); const availableMembers = new Set<number>();
getAvailableMembers(node, availableMembers); getAvailableMembers(node, availableMembers);

View File

@ -108,6 +108,5 @@
/*width: 3508px; /*width: 3508px;
height: 2480px;*/ height: 2480px;*/
width: 351px; width: 351px;
height: 248px;
opacity: 0; opacity: 0;
} }