|
@@ -141,6 +141,24 @@ window.onload = function() {
|
|
|
return levels
|
|
|
}
|
|
|
const levels = calculateLevels(persons)
|
|
|
+
|
|
|
+ function findLevel(person, levels) {
|
|
|
+ const date = +person.birth_date || person.death_date - 3600000 * 24 * 365 * 80
|
|
|
+ if(person.birth_date == null && person.death_date == null) {
|
|
|
+ let minLevel = null
|
|
|
+ for (const child of person.children) {
|
|
|
+ const level = findLevel(child, levels)
|
|
|
+ if ((level !== null && level < minLevel) || minLevel === null)
|
|
|
+ minLevel = level
|
|
|
+ }
|
|
|
+ if (minLevel === null)
|
|
|
+ return null
|
|
|
+ return minLevel - 1
|
|
|
+ } else {
|
|
|
+ return levels.findIndex(l => l >= date)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* calculate position of cards
|
|
|
* @param {*} personList current persons
|
|
@@ -160,14 +178,7 @@ window.onload = function() {
|
|
|
const person = personList[j];
|
|
|
|
|
|
// set y
|
|
|
- const date = +person.birth_date || person.death_date - 3600000 * 24 * 365 * 80
|
|
|
- if(person.birth_date == null && person.death_date == null)
|
|
|
- person.level = level
|
|
|
- else
|
|
|
- person.level = Math.max(level, levels.findIndex(l => l >= date));
|
|
|
- if(person.partner && person.partner.level > person.level) {
|
|
|
- person.level = person.partner.level;
|
|
|
- }
|
|
|
+ person.level = Math.max(level, findLevel(person, levels))
|
|
|
person.y = person.level * (tree.cardHeight + 40);
|
|
|
|
|
|
// set x
|