GeneIT/geneit_app/src/widgets/complex_family_tree/ComplexFamilyTree.tsx

240 lines
5.4 KiB
TypeScript
Raw Normal View History

2023-08-22 14:12:55 +00:00
import React from "react";
2023-08-22 15:17:36 +00:00
import f3, { f3Data } from "family-chart";
2023-08-22 14:12:55 +00:00
import "./family-chart.css";
export function ComplexFamilyTree(): React.ReactElement {
const refCb = (container: HTMLDivElement) => {
if (!container) return;
2023-08-22 14:12:55 +00:00
const store = f3.createStore({
data: data(),
node_separation: 250,
level_separation: 150,
}),
view = f3.d3AnimationView({
store,
cont: document.querySelector("#FamilyChart"),
}),
Card = f3.elements.Card({
store,
svg: view.svg,
card_dim: {
w: 220,
h: 70,
text_x: 75,
text_y: 15,
img_w: 60,
img_h: 60,
img_x: 5,
img_y: 5,
},
card_display: [
2023-08-22 15:17:36 +00:00
(d) => `${d.data.first_name || ""} ${d.data.last_name || ""}`,
2023-08-22 14:12:55 +00:00
(d) => `${d.data["birthday"] || ""}`,
],
mini_tree: true,
link_break: false,
});
view.setCard(Card);
store.setOnUpdate((props) => view.update(props || {}));
store.update.tree({ initial: true });
};
2023-08-22 14:12:55 +00:00
return <div className="f3" id="FamilyChart" ref={refCb}></div>;
}
2023-08-22 14:57:41 +00:00
2023-08-22 15:17:36 +00:00
const data: () => f3Data[] = () => [
{
id: "0",
rels: {
spouses: ["8c92765f-92d3-4120-90dd-85a28302504c"],
father: "0c09cfa0-5e7c-4073-8beb-94f6c69ada19",
mother: "0fa5c6bc-5b58-40f5-a07e-d787e26d8b56",
children: [
"ce2fcb9a-6058-4326-b56a-aced35168561",
"f626d086-e2d6-4722-b4f3-ca4f15b109ab",
],
},
data: {
first_name: "Agnus",
last_name: "",
birthday: "1970",
avatar:
"https://static8.depositphotos.com/1009634/988/v/950/depositphotos_9883921-stock-illustration-no-user-profile-picture.jpg",
gender: "M",
},
},
{
id: "8c92765f-92d3-4120-90dd-85a28302504c",
data: {
gender: "F",
first_name: "Andrea",
last_name: "",
birthday: "",
avatar: "",
},
rels: {
spouses: ["0"],
children: [
"ce2fcb9a-6058-4326-b56a-aced35168561",
"f626d086-e2d6-4722-b4f3-ca4f15b109ab",
],
},
},
{
id: "0c09cfa0-5e7c-4073-8beb-94f6c69ada19",
data: {
gender: "M",
first_name: "Zen",
last_name: "",
birthday: "",
avatar: "",
},
rels: {
children: ["0"],
spouses: ["0fa5c6bc-5b58-40f5-a07e-d787e26d8b56"],
},
},
{
id: "0fa5c6bc-5b58-40f5-a07e-d787e26d8b56",
data: {
gender: "F",
first_name: "Zebra",
last_name: "",
birthday: "",
avatar: "",
},
rels: {
spouses: ["0c09cfa0-5e7c-4073-8beb-94f6c69ada19"],
children: ["0"],
father: "12a9bddf-855a-4583-a695-c73fa8c0e9b2",
mother: "bd56a527-b613-474d-9f38-fcac0aae218b",
},
},
{
id: "ce2fcb9a-6058-4326-b56a-aced35168561",
data: {
gender: "M",
first_name: "Ben",
last_name: "",
birthday: "",
avatar: "",
},
rels: {
mother: "8c92765f-92d3-4120-90dd-85a28302504c",
father: "0",
spouses: ["b4e33c68-20a7-47ba-9dcc-1168a07d5b52"],
children: [
"eabd40c9-4518-4485-af5e-e4bc3ffd27fb",
"240a3f71-c921-42d7-8a13-dec5e1acc4fd",
],
},
},
{
id: "f626d086-e2d6-4722-b4f3-ca4f15b109ab",
data: {
gender: "F",
first_name: "Becky",
last_name: "",
birthday: "",
avatar: "",
},
rels: {
mother: "8c92765f-92d3-4120-90dd-85a28302504c",
father: "0",
},
},
{
id: "eabd40c9-4518-4485-af5e-e4bc3ffd27fb",
data: {
gender: "M",
first_name: "Carlos",
last_name: "",
birthday: "",
avatar: "",
},
rels: {
mother: "b4e33c68-20a7-47ba-9dcc-1168a07d5b52",
father: "ce2fcb9a-6058-4326-b56a-aced35168561",
},
},
{
id: "b4e33c68-20a7-47ba-9dcc-1168a07d5b52",
data: {
gender: "F",
first_name: "Branka",
last_name: "",
birthday: "",
avatar: "",
},
rels: {
spouses: ["ce2fcb9a-6058-4326-b56a-aced35168561"],
children: [
"eabd40c9-4518-4485-af5e-e4bc3ffd27fb",
"240a3f71-c921-42d7-8a13-dec5e1acc4fd",
],
},
},
{
id: "240a3f71-c921-42d7-8a13-dec5e1acc4fd",
data: {
gender: "F",
first_name: "Carla",
last_name: "",
birthday: "",
avatar: "",
},
rels: {
mother: "b4e33c68-20a7-47ba-9dcc-1168a07d5b52",
father: "ce2fcb9a-6058-4326-b56a-aced35168561",
},
},
{
id: "12a9bddf-855a-4583-a695-c73fa8c0e9b2",
data: {
gender: "M",
first_name: "Yvo",
last_name: "",
birthday: "",
avatar: "",
},
rels: {
children: ["0fa5c6bc-5b58-40f5-a07e-d787e26d8b56"],
spouses: ["bd56a527-b613-474d-9f38-fcac0aae218b"],
},
},
{
id: "bd56a527-b613-474d-9f38-fcac0aae218b",
data: {
gender: "F",
first_name: "Yva",
last_name: "",
birthday: "",
avatar: "",
},
rels: {
spouses: ["12a9bddf-855a-4583-a695-c73fa8c0e9b2"],
children: ["0fa5c6bc-5b58-40f5-a07e-d787e26d8b56"],
},
},
];
/*
import { jsPDF } from "jspdf";
import "svg2pdf.js";
setTimeout(() => {
2023-08-22 14:57:41 +00:00
const doc = new jsPDF({
orientation: "l",
format: [1000, 1000],
});
const element = document.getElementById("FamilyChart");
console.log(element);
doc.svg(element!.children[0], { height: 1000, width: 1000 }).then(() => {
// save the created pdf
//doc.save("myPDF.pdf");
2023-08-22 14:57:41 +00:00
});
}, 6000);*/