Layout Graphic Nodes

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 :slight_smile: ) …

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,

If anyone is interested in tackling this :slight_smile:
I have an SQLITE table that should contain enough information…
I’m just not sure how to solve this :frowning:

this schema has more data than required… but it made it easier to see if I was collecting the correct stuff

CREATE TABLE zzzTEMP_TREE ( 
fromGEN Integer DEFAULT 0,
toGEN Integer DEFAULT 0,
fromNODE Text,
toNODE Text,
fromNAME Text,
toNAME Text,
kind Text,
XPOS Integer DEFAULT 0,
YPOS Integer DEFAULT 0)
  • fromGen - the generation coming from (all nodes go DOWN)
  • toGen - the geneation going to (should always be fromGen+1)
  • fromNODE - the nodeID of the start
  • toNODE - the nodeID of the end
  • fromName, toName are the names of the people in each end of the node (toName would be displayed in the NODE)
  • kind - what the relationship between the nodes is
  • xpos,ypos to hold the calculated postions (this is the end result of this exercise)

fromNODE and toNode are the keyValues, the rest should be for “debug” purposes only

in this test table, the fromNode and toNode are just integer numbers, they will be UUID in the final, but that should not make a difference here.

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

I have a similar need for this as well, containing icons.

[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

Thanks… I know the “data” the belongs in each “node”…
and if it were a simple child to parent to grandparent type tree, that is super simple.

This would be more of a “force directed” tree… but all the explanations I can find are either too generic, or require a Phd in math to understand what they are saying

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.

Yes, you have described what NEEDS to be done… what I need is the HOW to do it…