A similar discussion took place years ago, but the requirements that the user posted were quite simplistic compared to what I need.
I am creating a family tree app (per my mothers request [She is 83]).
I have a database structure that holds all the relavant data (Names, Parents, Siblings, Children)… but would like to display a tree… but here is the catch… it needs to be more than just person->parents->grandparents … that type is easy.
What I need to show is given the ID of a single person… Show that person, their parents, any and all partners (not just a single spouse), all their children (connected to both parents, or only to central person if other parent isn’t known) and any/all partners of central persons parent
The layout of those nodes would be dependant on how many nodes ended up in the collection, and what relationships were involved… As it should not create any overlaps or crossing line…
Something like this (example only… trust me my family looks nothing like this ) …
after staring at the above drawing… I determined that the “Y” value of each node is “easy”
central person (Dave), all of his sibilings (direct or step) are Y=0
direct parents (and any "Ex"s) are Y= -1
grandparents are Y= -2
Children and the children of Siblings are Y = +1
GrandChildren (not shown) would be Y= +2
Therefore the problem is to determine the proper “X” coordinate (order, spacing etc)
For my purposes the data for “drawing” would be pruned to grandparents thru grandchildren,
You -definitely- need some complex math here. What you try to achieve has its roots in graph theory. Have a look at it, maybe there is something you can use. I think social media like LinkedIn use these models to construct a tree of your connections. It’s called a sociogram.
How to do it will depend on how much of the family tree that you want to display at a time. Do you want to display the entire thing, or just the parts that branch away from one individual? And just that individual’s ancestors or just that individual’s descendants, or both?
5 generations… from a focus person, their parents and grandparents, their children and grandchildren…
but it also has to include all current/ex partners of the focus person, as well as any current/ex partners of the parents (as their could be 1/2 siblings)… Basically the diagram in the OP
[quote=443594:@Dave S]5 generations… from a focus person, their parents and grandparents, their children and grandchildren…
but it also has to include all current/ex partners of the focus person, as well as any current/ex partners of the parents (as their could be 1/2 siblings)… Basically the diagram in the OP[/quote]
There are established standards for how you diagram such things
While it doesn’t tell you how to lay things out it might give you some additional inspiration if you follow the std layout guidelines for nodes etc
While your database contains all of the necessary information, and probably in the most compact form, it’s probably not in the optimum form for easy generation of a node diagram. This may be stating the obvious, but I think you need to extract the pertinent node info and create a linked list data structure in memory with additional properties as necessary in each node object to hold temporary data to aid in positioning the nodes in the output. For example you’ll need a property to group the siblings and half-siblings according to whether they have the same two parents, or only one parent in common, and which parent is the common parent. Once you have this data structure built, it should be straightforward to group the siblings, half-siblings and cousins at each generation level, and then position them accordingly.
As you previously mentioned, if you know the generation of the person, then you know the Y coordinate. Once you assign a generation number to each person, then you can add up how many people there are at each generation level, and that will be the number of people that need to be displayed in each horizontal row. Obviously, there are added complications because the varying number of siblings or parents at each generation level will cause things to get out of vertical alignment, but that’s where you’ll have to traverse the linked list and adjust the max and min values of the leftmost and rightmost siblings. This may require multiple iterations to get everything adjusted correctly.