SanichKotikov / relatives-tree

A tiny library for calculating specific JSON data to family tree nodes and connectors 🌳
https://sanichkotikov.github.io/react-family-tree-example/
MIT License
45 stars 21 forks source link

Missing/misplaced children of remarried parents #24

Open Phen-Ro opened 4 months ago

Phen-Ro commented 4 months ago

I found a rendering issue with situations regarding children of one side of a couple or children of a parent with multiple spouse. In all of the following examples, the rootId is "Mother".

This can be imagined as a story of a divorced couple with a child, where the mother remarries, and the child's father is removed from the family tree.

Standard unit, renders correctly:

[
  { "id": "Mother", "gender": "female", "spouses": [{ "id": "Father", "type": "divorced" }], "siblings": [], "parents": [], "children": [{ "id": "Child", "type": "blood" }] },
  { "id": "Father", "gender": "male", "spouses": [{ "id": "Mother", "type": "divorced" }], "siblings": [], "parents": [], "children": [{ "id": "Child", "type": "blood" }] },
  { "id": "Child", "gender": "male", "spouses": [], "siblings": [], "parents": [{ "id": "Mother", "type": "blood" }, { "id": "Father", "type": "blood" }], "children": [] }
]

Actual & Expected:

[Mother]---[Father]
         |
      [Child]

When the mother remarries, the child is now linked only to the father:

[
  { "id": "Mother", "gender": "female", "spouses": [{ "id": "Father", "type": "divorced" }, { "id": "Husband", "type": "married" }], "siblings": [], "parents": [], "children": [{ "id": "Child", "type": "blood" }] },
  { "id": "Father", "gender": "male", "spouses": [{ "id": "Mother", "type": "divorced" }], "siblings": [], "parents": [], "children": [{ "id": "Child", "type": "blood" }] },
  { "id": "Husband", "gender": "male", "spouses": [{ "id": "Mother", "type": "married" }], "siblings": [], "parents": [], "children": [] },
  { "id": "Child", "gender": "male", "spouses": [], "siblings": [], "parents": [{ "id": "Mother", "type": "blood" }, { "id": "Father", "type": "blood" }], "children": [] }
]

Actual:

[Father]---[Mother]---[Husband]
   |
[Child]

Expected:

[Father]---[Mother]---[Husband]
         |
      [Child]

If the father is removed, the child disappears:

[
  { "id": "Mother", "gender": "female", "spouses": [{ "id": "Husband", "type": "married" }], "siblings": [], "parents": [], "children": [{ "id": "Child", "type": "blood" }] },
  { "id": "Husband", "gender": "male", "spouses": [{ "id": "Mother", "type": "married" }], "siblings": [], "parents": [], "children": [] },
  { "id": "Child", "gender": "male", "spouses": [], "siblings": [], "parents": [{ "id": "Mother", "type": "blood" }], "children": [] }
]

Actual:

[Mother]---[Husband]

Expected:

[Mother]---[Husband]
   |
[Child]

When the 2nd husband is removed, the child reappears:

[
  { "id": "Mother", "gender": "female", "spouses": [{ "id": "Husband", "type": "married" }], "siblings": [], "parents": [], "children": [{ "id": "Child", "type": "blood" }] },
  { "id": "Child", "gender": "male", "spouses": [], "siblings": [], "parents": [{ "id": "Mother", "type": "blood" }], "children": [] }
]

Actual & Expected:

[Mother]
   |
[Child]

Here's a similar situation, the one that got me investigating this. This is a single mother of one who (re)marries and has another kid with the new guy:

[
  { "id": "Mother", "gender": "female", "spouses": [{ "id": "New Guy", "type": "married" }], "siblings": [], "parents": [], "children": [{ "id": "First Child", "type": "blood" }, { "id": "New Baby", "type": "blood" }] },
  { "id": "New Guy", "gender": "male", "spouses": [{ "id": "Mother", "type": "married" }], "siblings": [], "parents": [], "children": [{ "id": "New Baby", "type": "blood" }] },
  { "id": "First Child", "gender": "male", "spouses": [], "siblings": [{ "id": "New Baby", "type": "half" }], "parents": [{ "id": "Mother", "type": "blood" }], "children": [] },
  { "id": "New Baby", "gender": "female", "spouses": [], "siblings": [{ "id": "First Child", "type": "half" }], "parents": [{ "id": "Mother", "type": "blood" }, { "id": "New Guy", "type": "blood" }], "children": [] }
]

Actual:

[Mother]---[New Guy]
         |
     [New Baby]

Expected:

  [Mother]---[New Guy]
    |      |
 [Child] [New Baby]

Are my expectations off, or is the code?

If it is the code, I have a feeling it has to do with createChildUnitsFunc and/or getSpouseNodesFunc. I haven't been able to dig too far into it, but it seems that the way Units are created pushes out children that aren't the full offspring of the computed parents, and parents who are couples aren't offered to createChildUnits as potential single parents. Or something like that. I'll see if I can do more research, but no promises. This might be related to #12.

SanichKotikov commented 4 months ago

Hi. All the actual renders look as intended at the beginning. But this dosn't mean it can't be changed.

Yes, it's inside createFamilyFunc > getChildUnitsFunc > createChildUnitsFunc.