Skip to content

Commit 2a9cbc1

Browse files
authored
Merge pull request #52 from l0drex/beta
Coloring modes
2 parents 7d45a45 + 8a2108b commit 2a9cbc1

32 files changed

+1660
-1156
lines changed

package-lock.json

Lines changed: 716 additions & 352 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
"@types/node": "^18.6.1",
2929
"@types/react": "^18.0.15",
3030
"@types/react-dom": "^18.0.6",
31-
"d3": "4.13.0",
31+
"d3": "7.6.1",
3232
"gedcomx-js": "^2.8.0",
3333
"react": "^18.1.0",
3434
"react-dom": "^18.1.0",

src/App.css

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,18 +39,18 @@ main > * {
3939
@media (orientation: landscape) {
4040
#root {
4141
grid-template-rows: auto 1fr auto;
42-
grid-template-columns: 2fr 1fr;
43-
grid-template-areas:
44-
"header header"
45-
"main sidebar"
46-
"footer sidebar";
47-
}
48-
49-
#root.sidebar-hidden {
5042
grid-template-columns: 1fr;
5143
grid-template-areas:
5244
"header"
5345
"main"
5446
"footer";
5547
}
48+
49+
#root.sidebar-visible {
50+
grid-template-columns: 2fr 1fr;
51+
grid-template-areas:
52+
"header header"
53+
"main sidebar"
54+
"footer sidebar";
55+
}
5656
}

src/App.tsx

Lines changed: 3 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -2,39 +2,30 @@ import * as React from "react";
22
import './App.css';
33
import {localize} from "./main";
44
import config from "./config";
5-
import {GraphPerson} from "./backend/graph";
65
import Header from "./components/Header";
76
import NavigationTutorial from "./components/NavigationTutorial";
87
import Notification from "./components/Notification";
9-
import FamilyPath from "./components/FamilyPath";
108
import Uploader from "./components/Uploader";
11-
import InfoPanel from "./components/InfoPanel";
129
import View from "./components/View";
1310
import {graphModel, loadData} from "./backend/ModelGraph";
1411
import {ReactNode} from "react";
1512

1613
interface State {
1714
notifications: ReactNode[]
18-
focusId: string
19-
focusHidden: boolean
2015
dataAvailable: boolean
2116
}
2217

2318
class App extends React.Component<any, State> {
2419
constructor(props) {
2520
super(props);
26-
27-
let url = new URL(window.location.href);
28-
21+
new URL(window.location.href);
2922
let data = sessionStorage.getItem("familyData");
3023
if (data) {
3124
loadData(JSON.parse(data));
3225
}
3326

3427
this.state = {
3528
notifications: [],
36-
focusId: url.searchParams.get("id"),
37-
focusHidden: graphModel === undefined,
3829
dataAvailable: graphModel !== undefined
3930
};
4031
}
@@ -54,23 +45,11 @@ class App extends React.Component<any, State> {
5445
);
5546
}
5647

57-
let focus;
58-
if (this.state.focusId) {
59-
focus = graphModel.getPersonById(this.state.focusId);
60-
} else {
61-
focus = graphModel.persons[0];
62-
}
63-
if (!focus) {
64-
throw new Error(`No person with id ${this.state.focusId} could be found`)
65-
}
66-
6748
return (
6849
<>
6950
<Header/>
7051
{this.state.notifications}
71-
{!this.state.focusHidden && <InfoPanel person={focus} onRefocus={this.onRefocus.bind(this)}/>}
72-
<View focus={focus} onRefocus={this.onRefocus.bind(this)} focusHidden={this.state.focusHidden}/>
73-
<FamilyPath focus={focus}/>
52+
<View/>
7453
</>
7554
);
7655
}
@@ -79,41 +58,12 @@ class App extends React.Component<any, State> {
7958
sessionStorage.setItem("familyData", fileContent);
8059
loadData(JSON.parse(fileContent));
8160
this.setState({
82-
dataAvailable: true,
83-
focusHidden: false
84-
});
85-
}
86-
87-
onRefocus(newFocus: GraphPerson) {
88-
if (newFocus.data.getId() === this.state.focusId) {
89-
this.setState({
90-
focusHidden: !this.state.focusHidden
91-
})
92-
return;
93-
}
94-
this.setState({
95-
focusHidden: false,
96-
focusId: newFocus.data.getId()
61+
dataAvailable: true
9762
});
9863
}
9964

10065
componentDidMount() {
10166
localize(config.browserLang);
102-
let root = document.querySelector<HTMLDivElement>("#root");
103-
if (this.state.focusHidden) {
104-
root.classList.add("sidebar-hidden");
105-
} else {
106-
root.classList.remove("sidebar-hidden");
107-
}
108-
}
109-
110-
componentDidUpdate(prevProps: Readonly<any>, prevState: Readonly<State>, snapshot?: any) {
111-
let root = document.querySelector<HTMLDivElement>("#root");
112-
if (this.state.focusHidden) {
113-
root.classList.add("sidebar-hidden");
114-
} else {
115-
root.classList.remove("sidebar-hidden");
116-
}
11767
}
11868

11969
componentDidCatch(error: Error, errorInfo: React.ErrorInfo) {

src/backend/Date.test.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
import {Date as GDate} from "gedcomx-js";
1+
import GedcomX from "./gedcomx-extensions";
22
import config from "../config";
3-
require("./gedcomx-extensions")
43

54
test("toDateObject works", () => {
6-
let gDate = new GDate();
5+
let gDate = new GedcomX.Date();
76
let date = gDate.toDateObject();
87
expect(date).toBeUndefined();
98

@@ -50,7 +49,7 @@ test("toDateObject works", () => {
5049
test("toString works", () => {
5150
config.browserLang = "en";
5251

53-
let date = new GDate();
52+
let date = new GedcomX.Date();
5453
expect(date.toString()).toBe("")
5554

5655
date.setFormal("+2022")

src/backend/Fact.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
import {Date, Fact} from "gedcomx-js";
2-
import {PersonFactTypes} from "./gedcomx-extensions";
1+
import GedcomX from "./gedcomx-extensions";
32
import config from "../config";
3+
import {PersonFactTypes} from "./gedcomx-enums";
44

55
test("toString works", () => {
66
config.browserLang = "en";
7-
let fact = new Fact().setType(PersonFactTypes.Birth);
7+
let fact = new GedcomX.Fact().setType(PersonFactTypes.Birth);
88
expect(fact.toString()).toBe("born")
99

10-
fact.setDate(new Date().setFormal("+2022-01-25T06:55"))
10+
fact.setDate(new GedcomX.Date().setFormal("+2022-01-25T06:55"))
1111
expect(fact.toString()).toBe("born on 01/25/2022 at 06:55 AM")
1212
})

src/backend/ModelGraph.test.ts

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,44 @@
11
import {graphModel, loadData} from "./ModelGraph";
22
import * as data from "./test-data.json";
3-
import {RelationshipTypes} from "./gedcomx-extensions";
3+
import {ViewMode} from "./ViewGraph";
4+
import {RelationshipTypes} from "./gedcomx-enums";
45

56
test("loads data", () => {
67
// load the data
78
loadData(data);
8-
expect(graphModel.getPersons().length).toBe(16+1);
9-
expect(graphModel.getRelationships().length).toBe(26);
10-
expect(graphModel.getRelationships().filter(r => r.getType() === RelationshipTypes.Couple).length).toBe(6);
9+
10+
expect(graphModel.getPersons().length)
11+
.toBe(16 + 1); // persons + unknown persons
12+
expect(graphModel.getRelationships().length)
13+
.toBe(26);
14+
expect(graphModel.getRelationships().filter(r => r.getType() === RelationshipTypes.Couple).length)
15+
.toBe(6);
1116
expect(graphModel.getRelationships().filter(r => r.getType() === RelationshipTypes.ParentChild).length)
1217
.toBe(20);
1318
})
19+
20+
test.each([
21+
[ViewMode.DEFAULT,
22+
2 + 2 + 2 + 2 + 2 + 1, // persons + couples
23+
2 * 2 + 5 + 1], // 2 * couples + parent-child / 2
24+
[ViewMode.ALL, 17 + 6, 2 * 6 + 20 / 2],
25+
[ViewMode.DESCENDANTS, 4+2, 5],
26+
[ViewMode.ANCESTORS, 12+6, 17]
27+
])("Builds view graph: %s", (viewMode: ViewMode, nodes: number, links: number) => {
28+
loadData(data);
29+
let viewGraph = graphModel.buildViewGraph("1", viewMode);
30+
expect(viewGraph.nodes.length).toBe(nodes);
31+
expect(viewGraph.links.length).toBe(links);
32+
})
33+
34+
test.each([
35+
[ViewMode.DEFAULT, "15", 4+2, 5],
36+
[ViewMode.DEFAULT, "7", 4+2, 5],
37+
[ViewMode.ANCESTORS, "15", 2, 1],
38+
[ViewMode.DESCENDANTS, "7", 2, 1]
39+
])("Build in edge case: %s", (viewMode: ViewMode, id: string, nodes: number, links: number) => {
40+
loadData(data);
41+
let viewGraph = graphModel.buildViewGraph(id, viewMode);
42+
expect(viewGraph.nodes.length).toBe(nodes);
43+
expect(viewGraph.links.length).toBe(links);
44+
})

0 commit comments

Comments
 (0)