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

wrong position of parent node #15

Closed norflin321 closed 2 years ago

norflin321 commented 2 years ago

My tree looks like this:

Screenshot 2022-01-10 at 19 23 33
json data ![Webp net-resizeimage-3](https://user-images.githubusercontent.com/33498670/148803407-3c859495-c6da-4e8a-a703-2519545156cf.png) `[ { "id": "1", "gender": "male", "parents": [ { "id": "2", "type": "blood" }, { "id": "3", "type": "blood" } ], "siblings": [], "spouses": [], "children": [] }, { "id": "2", "gender": "male", "parents": [{ "id": "4", "type": "blood" }], "children": [{ "id": "1", "type": "blood" }], "siblings": [], "spouses": [{ "id": "3", "type": "married" }] }, { "id": "3", "gender": "female", "parents": [{ "id": "5", "type": "blood" }], "children": [{ "id": "1", "type": "blood" }], "siblings": [], "spouses": [{ "id": "2", "type": "married" }] }, { "id": "4", "gender": "male", "parents": [ { "id": "6", "type": "blood" }, { "id": "7", "type": "blood" } ], "children": [{ "id": "2", "type": "blood" }], "siblings": [], "spouses": [] }, { "id": "5", "gender": "male", "parents": [], "children": [{ "id": "3", "type": "blood" }], "siblings": [], "spouses": [] }, { "id": "6", "gender": "male", "parents": [], "children": [{ "id": "4", "type": "blood" }], "siblings": [], "spouses": [{ "id": "7", "type": "married" }] }, { "id": "7", "gender": "female", "parents": [], "children": [{ "id": "4", "type": "blood" }], "siblings": [], "spouses": [{ "id": "6", "type": "married" }] } ] `

then I wanna add a new parent to node 5. I create new node with id 8, in his array of children add: { "id": "5", "type": "blood" }. In array of parents of node 5 add: { "id": "8", "type": "blood" }. Then tree doesn't look quite right, new node is hidden behind node 7:

Screenshot 2022-01-10 at 19 58 06
json data ![Webp net-resizeimage-4](https://user-images.githubusercontent.com/33498670/148807229-9a2ede7a-d66e-47cb-8e36-92233cf97c16.png) `[ { "id": "1", "gender": "male", "parents": [ { "id": "2", "type": "blood" }, { "id": "3", "type": "blood" } ], "siblings": [], "spouses": [], "children": [] }, { "id": "2", "gender": "male", "parents": [{ "id": "4", "type": "blood" }], "children": [{ "id": "1", "type": "blood" }], "siblings": [], "spouses": [{ "id": "3", "type": "married" }] }, { "id": "3", "gender": "female", "parents": [{ "id": "5", "type": "blood" }], "children": [{ "id": "1", "type": "blood" }], "siblings": [], "spouses": [{ "id": "2", "type": "married" }] }, { "id": "4", "gender": "male", "parents": [ { "id": "6", "type": "blood" }, { "id": "7", "type": "blood" } ], "children": [{ "id": "2", "type": "blood" }], "siblings": [], "spouses": [] }, { "id": "5", "gender": "male", "parents": [{ "id": "8", "type": "blood" }], "children": [{ "id": "3", "type": "blood" }], "siblings": [], "spouses": [] }, { "id": "6", "gender": "male", "parents": [], "children": [{ "id": "4", "type": "blood" }], "siblings": [], "spouses": [{ "id": "7", "type": "married" }] }, { "id": "7", "gender": "female", "parents": [], "children": [{ "id": "4", "type": "blood" }], "siblings": [], "spouses": [{ "id": "6", "type": "married" }] }, { "id": "8", "gender": "male", "parents": [], "children": [{ "id": "5", "type": "blood" }], "siblings": [], "spouses": [] } ] `

Is it possible to add single parent like this? Is it intensional behaviour or a bug? I tried on 3 last version of package.

croonster commented 2 years ago

I have the same issue. Is this something that could be looked at? Having a brief look through at the source code it seems like the "left" calculation goes wrong in this scenario. After you get to the 4th generation and attempt to add a parent on the right hand side of the tree the added node is superimposed on the left hand side.

SanichKotikov commented 2 years ago

@croonster hi. Thanks for the investigation. This lib is always open for pull requests (without changing the code style).

SanichKotikov commented 2 years ago

Fixed in v3.2.0