@@ -2,12 +2,21 @@ import GedcomX, {setReferenceAge} from "./gedcomx-extensions";
22import viewGraph , { ViewMode } from "./ViewGraph" ;
33import config from "../config" ;
44import { PersonFactTypes } from "./gedcomx-enums" ;
5+ import { filterLang } from "../main" ;
56
67let lastViewGraphBuildParams : { id : string , view : ViewMode | string }
78
89class ModelGraph extends GedcomX . Root {
910 constructor ( data ) {
1011 super ( data )
12+
13+ // localize
14+ this . persons = ( this . persons ?? [ ] ) . filter ( filterLang ) ;
15+ this . relationships = ( this . relationships ?? [ ] ) . filter ( filterLang ) ;
16+ this . events = ( this . events ?? [ ] ) . filter ( filterLang ) ;
17+ this . documents = ( this . documents ?? [ ] ) . filter ( filterLang ) ;
18+ this . places = ( this . places ?? [ ] ) . filter ( filterLang ) ;
19+
1120 if ( ! data || data . persons . length < 0 || data . relationships . length < 0 ) {
1221 throw new Error ( "The calculated graph is empty! Please check if your files are empty. If not, please file a bug report!" ) ;
1322 }
@@ -24,7 +33,14 @@ class ModelGraph extends GedcomX.Root {
2433 }
2534
2635 getSourceDescriptionById ( id : string ) : GedcomX . SourceDescription {
27- return this . getSourceDescriptions ( ) . find ( d => d . getId ( ) === id ) ;
36+ return this . getSourceDescriptions ( ) . find ( d => d . id === id ) ;
37+ }
38+
39+ getAgentById ( id : string | GedcomX . ResourceReference ) : GedcomX . Agent {
40+ if ( id instanceof GedcomX . ResourceReference ) {
41+ id = id . getResource ( ) . substring ( 1 ) ;
42+ }
43+ return this . agents . find ( a => ( id as string ) in a . getIdentifiers ( ) . getValues ( ) ) ;
2844 }
2945
3046 getPersonByName = ( name : string ) : GedcomX . Person => {
@@ -195,12 +211,12 @@ class ModelGraph extends GedcomX.Root {
195211 private setAgeGen0 = ( startPerson : GedcomX . Person ) => {
196212 let personWithKnownAge = this . persons
197213 . filter ( p => {
198- let generationStartFacts = startPerson . getFactsByType ( PersonFactTypes . Generation ) ;
214+ let generationStartFacts = startPerson . getFactsByType ( PersonFactTypes . GenerationNumber ) ;
199215 if ( generationStartFacts . length < 1 ) {
200216 return false ;
201217 }
202218 let generationStart = generationStartFacts [ 0 ] . getValue ( ) ;
203- let generationPFacts = p . getFactsByType ( PersonFactTypes . Generation )
219+ let generationPFacts = p . getFactsByType ( PersonFactTypes . GenerationNumber )
204220 if ( generationPFacts . length < 1 ) {
205221 return false ;
206222 }
@@ -215,7 +231,7 @@ class ModelGraph extends GedcomX.Root {
215231 }
216232 setReferenceAge ( personWithKnownAge . getAgeToday ( ) ,
217233 // get generation from generation fact
218- Number ( personWithKnownAge . getFactsByType ( PersonFactTypes . Generation ) [ 0 ] . getValue ( ) ) ) ;
234+ Number ( personWithKnownAge . getFactsByType ( PersonFactTypes . GenerationNumber ) [ 0 ] . getValue ( ) ) ) ;
219235 }
220236
221237 private getAncestors ( person : GedcomX . Person ) : GedcomX . Person [ ] {
0 commit comments