{ id: "8", source: "1", target: "4", types: "marriage", type: edgeType }, // связь брака от мужа к жене
{ id: "1", source: "1", target: "2", types: "children", type: edgeType }, // связь от одного родителя к ребёнку
{ id: "2", source: "4", target: "2", types: "children", type: edgeType }, // связь от другого родителя к ребёнку
{ id: "5", source: "5", target: "4", types: "marriage", type: edgeType }, // связь брака от мужа к жене (второй брак жены)
{ id: "6", source: "5", target: "1", types: "children", type: edgeType }, // связь от одного родителя к ребёнку
{ id: "7", source: "4", target: "1", types: "children", type: edgeType } // связь от другого родителя к ребёнку
const position = { x: 0, y: 0 };
const edgeType = "smoothstep";
export const initialNodes = [
{
id: "1",
type: 'person',
data: {
lastName: "Метельский",
firstName: "Геннадий",
middleName: "Георгиевич",
birthdate: '1992-04-25',
birthPlace: "г. Киев, Украина",
religion: "Orthodoxy",
nationality: "Russian",
isAlive: false,
deathDate: '1292-04-25',
deathPlace: "г. Киев, Украина",
burialPlace: "Киевское кладбище",
causeOfDeath: "тяжелое заболевание",
photoUrl: 'https://www.geeksvgs.com/files/2019/02/dd85b_grandfather.thumb.png',
event: ["vov", "plen", "rep"],
sex: "m"
},
position: { x: 0, y: 0 },
},
{
id: "2",
type: 'person',
data: {
lastName: "Метельский",
firstName: "Богдан",
middleName: "Геннадьевич",
birthdate: '25.04.1992',
birthPlace: "г. Киев, Украина",
religion: "Orthodoxy",
nationality: "Ukrainian",
isAlive: true,
photoUrl: 'https://www.geeksvgs.com/files/2019/02/dd85b_grandfather.thumb.png',
sex: "m"
},
position: { x: 0, y: 0 },
},
{
id: "3",
type: 'person',
data: {
lastName: "Метельская",
firstName: "Алина",
middleName: "Геннадьевна",
birthdate: '25.04.1992',
birthPlace: "г. Киев, Украина",
religion: "Orthodoxy",
nationality: "Ukrainian",
isAlive: true,
photoUrl: 'https://www.geeksvgs.com/files/2019/02/dd85b_grandfather.thumb.png',
sex: "f"
},
position: { x: 0, y: 0 },
},
{
id: "4",
type: 'person',
data: {
lastName: "Метельская",
firstName: "Татьяна",
middleName: "Васильевна",
birthdate: '24.02.1991',
birthPlace: "г. Одесса, Украина",
religion: "Catholicism",
nationality: "Ukrainian",
isAlive: true,
photoUrl: 'https://www.geeksvgs.com/files/2019/02/dd85b_grandfather.thumb.png',
sex: "f"
},
position: { x: 0, y: 0 }
},
{
id: "5",
type: 'person',
data: {
lastName: "Метельский",
firstName: "Георгий",
middleName: "Ясонович",
birthdate: '24.02.1991',
birthPlace: "г. Одесса, Украина",
religion: "Catholicism",
nationality: "Ukrainian",
isAlive: true,
photoUrl: 'https://www.geeksvgs.com/files/2019/02/dd85b_grandfather.thumb.png',
sex: "m"
},
position: { x: 0, y: 0 },
}
];
export const initialEdges = [
{ id: "8", source: "1", target: "4", types: "marriage", type: edgeType },
{ id: "1", source: "1", target: "2", types: "children", type: edgeType },
{ id: "4", source: "4", target: "2", types: "children", type: edgeType },
{ id: "5", source: "5", target: "4", types: "marriage", type: edgeType },
{ id: "6", source: "4", target: "3", types: "children", type: edgeType },
{ id: "7", source: "5", target: "3", types: "children", type: edgeType },
];
const getLayoutedElements = (nodes, edges/*, direction = "TB"*/) => {
/*dagreGraph.setGraph({ rankdir: direction });*/
//nodes.forEach((node) => {
// dagregraph.setnode(node.id, { width: nodewidth, height: nodeheight });
//});
const childMarriages = {};
edges.forEach((edge) => {
if (edge.types === "marriage") {
const marriageId = `${edge.source}-marriage-${edge.target}`;
const marriageNode = {
id: marriageId,
types: "marriage",
position,
data: {
husband: edge.source,
wife: edge.target,
children: [],
},
};
const husbandToMarriage = {
id: `${edge.source}-to-${marriageId}`,
source: edge.source,
target: marriageId,
type: edgeType,
};
const wifeToMarriage = {
id: `${edge.target}-to-${marriageId}`,
source: edge.target,
target: marriageId,
type: edgeType,
};
// Переносим фильтрацию связей типа "children" внутрь map
const childrenFromMarriage = edges
.filter((childEdge) => childEdge.types === "children")
.map((childEdge) => {
const childNode = nodes.find((node) => node.id === childEdge.target);
if (childNode) {
const childId = childNode.id;
// Проверяем, принадлежит ли ребенок к данному браку
if (
(childEdge.source === edge.source ||
childEdge.source === edge.target) &&
childMarriages[childId] === undefined // Проверяем, что у ребенка еще нет браков
) {
childMarriages[childId] = marriageId;
marriageNode.data.children.push(childId);
return {
id: `${marriageId}-to-${childId}`,
source: marriageId,
target: childId,
type: "smoothstep",
};
}
}
return null;
})
.filter(Boolean);
nodes.push(marriageNode);
edges.push(husbandToMarriage);
edges.push(wifeToMarriage);
childrenFromMarriage.forEach((edge) => edges.push(edge));
}
});
edges = edges.filter((edge) => edge.types !== "children");
edges = edges.filter((edge) => edge.types !== "marriage");
return { nodes, edges };
};
{ id: "8", source: "1", target: "4", types: "marriage", type: edgeType },
{ id: "1", source: "1", target: "2", types: "Father", type: edgeType },
{ id: "3", source: "4", target: "2", types: "Mother", type: edgeType}