Skip to content

Issue #147: combine duplicate boxes at the generational level #163

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 29, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 68 additions & 0 deletions projects/GKCore/GKCore/Charts/TreeChartModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,25 @@ private TreeChartPerson DoDescendantsStep(TreeChartPerson parent, GEDCOMIndividu
if (!CheckDescendantFilter(person, level))
return null;

// Kevin Routley (aka fire-eggs, aka KBR). Partially address issue #147.
// Here, multiple instances of the same person _in_a_generation_ are
// combined together. The subsequent changes to the drawing code don't
// cope with connecting people across generations.
if (person.SpouseToFamilyLinks.Count == 1 &&
fPreparedFamilies.IndexOf(person.SpouseToFamilyLinks[0].Family.XRef) >= 0)
{
for (int i = 0; i < fPersons.Count; i++)
{
TreeChartPerson p = fPersons[i];
if (p != null && p.Rec != null && p.Rec.XRef == person.XRef && p.Generation == level)
{
p.Parent = parent;
parent.AddChild(p);
return null;
}
}
}

TreeChartPerson res = AddDescPerson(parent, person, false, level);
result = res;

Expand Down Expand Up @@ -1014,6 +1033,55 @@ private void RecalcDesc(TreeChartPerson person, ExtPoint aPt, bool predef)
if (person.Sex == GEDCOMSex.svNone || person.Sex == GEDCOMSex.svUndetermined) {
fEdges[gen] = person.Rect.Right;
}

// Kevin Routley (aka fire-eggs, aka KBR). Partially address issue #147.
// As a result of combining duplicate people together, there may be overlapping
// boxes. Here, these overlaps are corrected. NOTE: duplicate people _across_generations_
// have not been combined as no adjustment is being made to shift a box down as
// would be necessary.
FixOverlap(person);
}

private void AdjustChildren(TreeChartPerson person, int offset)
{
// Kevin Routley (aka fire-eggs, aka KBR). Partially address issue #147.
// a person has been shifted because of collision. Recursively adjust
// _descendants_ of that person
if (person.GetChildsCount() < 1)
return;
int cMax = person.GetChildsCount();
for (int i = 0; i < cMax; i++)
{
var pp = person.GetChild(i);
pp.PtX += offset;
AdjustChildren(pp, offset);
}
}

private int FixOverlap(TreeChartPerson person)
{
// Kevin Routley (aka fire-eggs, aka KBR). Partially address issue #147.
// Check for, and correct, collisions of boxes in this person's
// generational row.
int shiftAmount = 0;
for (int m = 0; m <= fPersons.Count; m++)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not a mistake by accident?
m <= fPersons.Count

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, it is. Good eye! [There is a loop short-circuit which appears to have prevented it from being an issue in during my testing.]

{
if (fPersons[m].Generation != person.Generation)
continue;
if (person.Rec == null || fPersons[m].Rec.XRef == person.Rec.XRef)
break;

if (!person.Rect.IntersectsWith(fPersons[m].Rect))
continue; // No overlap

int thisShift = fPersons[m].Rect.Right + 25 - person.Rect.Left; // Add a little extra spacing
ShiftDesc(person, thisShift, true); // Note that ShiftDesc moves this person and ANCESTORS; descendants need to be fixed
shiftAmount += thisShift;
}

if (shiftAmount != 0)
AdjustChildren(person, shiftAmount);
return shiftAmount;
}

private void RecalcDescendantsChart(bool predef)
Expand Down