michelesalvador / FamilyGem

Android app for genealogical trees
https://www.familygem.app
GNU General Public License v3.0
125 stars 34 forks source link

Diagram UI bug: horrible Bond overlap #75

Open Sternbach-Software opened 1 year ago

Sternbach-Software commented 1 year ago

Attached is a picture of my family tree. Notice the horrible pile up at the center of the screen with the Bond mini cards. It happens when the bond mini cards are above the people too. The horizontal line.x seems to be ok, but the line.y is off. This seems to be a tricky case, because how do you determine which bonds should go on top, and which on bottom? Screenshot_2022-11-08-12-20-33-31_6494ae8bcc0f3d697d5f48cc23e6a4d6.jpg

Sternbach-Software commented 1 year ago

I believe this is the relevant loop in GedcomGraph. In my case, it is specifically this line.

Sternbach-Software commented 1 year ago

This looks like a good, short function on stackoverflow to determine whether the groups overlap. Was written for Views, so may need to be adjusted for Groups.

Sternbach-Software commented 1 year ago

Some pseudo code that may help:

int initialPosition = node.y + node.height + PROGENY_DISTANCE;
int finalPosition = initialPosition;
while(isOverlapWithOthers(finalPosition)) {
    finalPosition += findNextOverlappingView(finalPosition).bottom + PROGENY_DISTANCE;
}
youth.setY(finalPosition);

For ancestor bonds, instead of findNextOverlappingView(finalPosition).bottom you would use .top + ANCESTRY_DISTANCE, and -= instead of +=.

To optimize that, you could return null from findNextOverlappingView, and use

View overlappingView;
do { 
    overlappingView = findNextOverlappingView(finalPosition);
   if(overlappingView != null) finalPosition = overlappingView.bottom + PROGENY_DISTANCE;
} while(overlappingView != null);

(or while(true) { ...if(overlappingView != null) {...}else break; }

michelesalvador commented 10 months ago

Thank you for reporting that. I absolutely agree this overlap is unpleasant.

Just a clarification: inside GedcomGraph "bond" refers to the horizontal link between two partners. The little cards below are called "progeny" or "mini children/youth". The little cards above are "ancestry" or "mini origin".

A vertical adjustment risks to produce this:

immagine

IMHO there is an easier (and more effective) solution: let the Y as is, and shift the X until the progenies don't overlap. Progenies width is now ignored, it's because of that they overlap. So the width of each node should be simply Max(Node.width, Progeny.width):

immagine