Skip to content

Commit bcf357c

Browse files
Added related individuals
1 parent 86fdac2 commit bcf357c

File tree

5 files changed

+40
-24
lines changed

5 files changed

+40
-24
lines changed

src/gedcom/actions.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { readGedcom } from 'read-gedcom';
2-
import { computeAncestors, computeDescendants, createInitialSettings } from '../util';
2+
import { computeAncestors, computeDescendants, computeRelated, createInitialSettings } from '../util';
33

44
export const LOADING = 'gedcomFile/LOADING';
55
export const SUCCESS = 'gedcomFile/SUCCESS';
@@ -99,13 +99,15 @@ const initializeAllFields = root => {
9999
const computeDependantFields = (root, rootIndividual) => {
100100
const ancestors = rootIndividual ? computeAncestors(root, rootIndividual) : null;
101101
const descendants = rootIndividual ? computeDescendants(root, rootIndividual) : null;
102-
const statistics = computeStatistics(root, ancestors, descendants);
103-
return { ancestors, descendants, statistics };
102+
const related = rootIndividual ? computeRelated(root, ancestors) : null;
103+
const statistics = computeStatistics(root, ancestors, descendants, related);
104+
return { ancestors, descendants, related, statistics };
104105
};
105106

106-
const computeStatistics = (root, ancestors, descendants) => {
107-
const totalIndividuals = root.getIndividualRecord().count();
108-
const totalAncestors = ancestors !== null ? ancestors.size - 1 : null;
107+
const computeStatistics = (root, ancestors, descendants, related) => {
108+
const totalIndividuals = root.getIndividualRecord().count();
109+
const totalAncestors = ancestors !== null ? ancestors.size - 1 : null;
109110
const totalDescendants = descendants !== null ? descendants.size - 1 : null;
110-
return { totalIndividuals, totalAncestors, totalDescendants };
111+
const totalRelated = related !== null ? related.size - 1 : null;
112+
return { totalIndividuals, totalAncestors, totalDescendants, totalRelated };
111113
};

src/i18n/locales/en.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
"page.home.statistics.individuals": "Individuals:",
5555
"page.home.statistics.ancestors": "Ancestors:",
5656
"page.home.statistics.descendants": "Descendants:",
57+
"page.home.statistics.related": "Related:",
5758
"page.home.metadata.title": "File metadata",
5859
"page.home.metadata.name": "Name:",
5960
"page.home.metadata.provider": "Provider:",

src/i18n/locales/fr.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
"page.home.statistics.individuals": "Individus :",
5555
"page.home.statistics.ancestors": "Ancêtres :",
5656
"page.home.statistics.descendants": "Descendants :",
57+
"page.home.statistics.related": "Apparentés :",
5758
"page.home.metadata.title": "Métadonnées du fichier",
5859
"page.home.metadata.name": "Nom :",
5960
"page.home.metadata.provider": "Éditeur :",

src/pages/private/PageHome/PageHome.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,12 @@ export class PageHome extends Component {
112112
<td><strong><FormattedNumber value={statistics.totalDescendants}/></strong></td>
113113
</tr>
114114
)}
115+
{statistics.totalRelated !== null && (
116+
<tr>
117+
<td><FormattedMessage id="page.home.statistics.related"/></td>
118+
<td><strong><FormattedNumber value={statistics.totalRelated}/></strong></td>
119+
</tr>
120+
)}
115121
</tbody>
116122
</Table>
117123
</Col>

src/util/graph.js

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
function breadthFirstSearch(root, initialIndividual, neighboursOf) {
2-
const visited = new Set([initialIndividual.pointer().one()]);
3-
let current = new Set([initialIndividual]);
1+
function breadthFirstSearch(root, initialIndividuals, neighboursOf) {
2+
const visited = new Set(initialIndividuals.map(individual => individual.pointer().one()));
3+
let current = new Set(initialIndividuals);
44
while (current.size > 0) {
55
const next = new Set();
66
for(const individual of current.values()) {
@@ -19,22 +19,28 @@ function breadthFirstSearch(root, initialIndividual, neighboursOf) {
1919
return visited;
2020
}
2121

22+
const ancestorRelation = individual =>
23+
individual
24+
.getFamilyAsChild()
25+
.array()
26+
.flatMap(ind => [ind.getHusband(), ind.getWife()])
27+
.map(ref => ref.getIndividualRecord());
28+
29+
const descendantRelation = individual =>
30+
individual
31+
.getFamilyAsSpouse()
32+
.getChild()
33+
.getIndividualRecord()
34+
.array();
35+
2236
export function computeAncestors(root, initialIndividual) {
23-
return breadthFirstSearch(root, initialIndividual, individual =>
24-
individual
25-
.getFamilyAsChild()
26-
.array()
27-
.flatMap(ind => [ind.getHusband(), ind.getWife()])
28-
.map(ref => ref.getIndividualRecord())
29-
);
37+
return breadthFirstSearch(root, [initialIndividual], ancestorRelation);
3038
}
3139

3240
export function computeDescendants(root, initialIndividual) {
33-
return breadthFirstSearch(root, initialIndividual, individual =>
34-
individual
35-
.getFamilyAsSpouse()
36-
.getChild()
37-
.getIndividualRecord()
38-
.array()
39-
);
41+
return breadthFirstSearch(root, [initialIndividual], descendantRelation);
42+
}
43+
44+
export function computeRelated(root, ancestorsIdSet) {
45+
return breadthFirstSearch(root, Array.from(ancestorsIdSet).map(id => root.getIndividualRecord(id)), descendantRelation);
4046
}

0 commit comments

Comments
 (0)