-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstandalone.html
More file actions
1653 lines (1445 loc) · 66 KB
/
Copy pathstandalone.html
File metadata and controls
1653 lines (1445 loc) · 66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Relationship Namer — Node-Based MVP</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', sans-serif;
background: #ffffff;
color: #1a1a1a;
overflow: hidden;
height: 100vh;
}
.app-container {
display: flex;
height: 100vh;
}
.sidebar {
width: 380px;
background: #fafafa;
border-right: 1px solid #e0e0e0;
padding: 24px;
overflow-y: auto;
display: flex;
flex-direction: column;
gap: 24px;
}
.sidebar h2 {
color: #1a1a1a;
font-size: 1.4rem;
font-weight: 600;
margin-bottom: 16px;
border-bottom: 2px solid #1a1a1a;
padding-bottom: 8px;
}
.sidebar h3 {
color: #1a1a1a;
font-size: 1.1rem;
font-weight: 600;
margin-bottom: 12px;
}
.canvas-container {
flex: 1;
position: relative;
background: #ffffff;
overflow: hidden;
border-left: 1px solid #e0e0e0;
}
#graphCanvas {
width: 100%;
height: 100%;
cursor: default;
}
.form-group {
margin-bottom: 16px;
}
.form-group label {
display: block;
margin-bottom: 6px;
color: #666;
font-size: 0.9rem;
font-weight: 500;
}
.form-group input,
.form-group select {
width: 100%;
padding: 10px 12px;
background: #ffffff;
border: 1px solid #d0d0d0;
border-radius: 4px;
color: #1a1a1a;
font-size: 14px;
transition: border-color 0.2s;
}
.form-group input:focus,
.form-group select:focus {
outline: none;
border-color: #1a1a1a;
}
.button {
background: #1a1a1a;
color: white;
border: none;
padding: 10px 20px;
border-radius: 4px;
font-size: 14px;
font-weight: 500;
cursor: pointer;
width: 100%;
transition: background 0.2s;
}
.button:hover {
background: #333;
}
.button:active {
background: #000;
}
.button.secondary {
background: #ffffff;
color: #1a1a1a;
border: 1px solid #1a1a1a;
}
.button.secondary:hover {
background: #f5f5f5;
}
.button.small {
padding: 6px 12px;
font-size: 0.85rem;
width: auto;
}
.error {
color: #d32f2f;
font-size: 0.85rem;
margin-top: 8px;
}
.info-box {
background: #f5f5f5;
border-left: 3px solid #1a1a1a;
padding: 12px;
border-radius: 4px;
font-size: 0.9rem;
line-height: 1.6;
color: #666;
}
.node {
cursor: move;
user-select: none;
}
.node circle {
fill: #ffffff;
stroke: #1a1a1a;
stroke-width: 2;
transition: all 0.2s;
}
.node.selected circle {
fill: #1a1a1a;
stroke: #1a1a1a;
stroke-width: 3;
}
.node.selected text {
fill: #1a1a1a;
font-weight: 600;
}
.node text {
fill: #1a1a1a;
font-size: 12px;
text-anchor: middle;
pointer-events: none;
font-weight: 500;
}
.edge {
stroke: #666;
stroke-width: 2;
fill: none;
}
.edge.parent-child {
stroke: #1a1a1a;
marker-end: url(#arrowhead);
}
.edge.spouse {
stroke: #666;
stroke-dasharray: 5,5;
}
.edge.incest {
stroke: #d32f2f;
stroke-width: 3;
}
.relationship-list {
list-style: none;
margin-top: 12px;
}
.relationship-item {
background: #ffffff;
border: 1px solid #e0e0e0;
border-radius: 4px;
padding: 12px;
margin-bottom: 8px;
font-size: 0.9rem;
line-height: 1.6;
}
.relationship-item strong {
color: #1a1a1a;
font-weight: 600;
}
.relationship-item .type {
color: #666;
font-size: 0.85rem;
margin-top: 4px;
}
.incest-warning {
background: #fff5f5;
border: 1px solid #d32f2f;
border-radius: 4px;
padding: 12px;
margin-top: 12px;
font-size: 0.9rem;
}
.incest-warning h4 {
color: #d32f2f;
margin-bottom: 8px;
font-size: 0.95rem;
}
.incest-warning p {
color: #666;
line-height: 1.6;
}
.add-relationship-section {
margin-top: 16px;
padding-top: 16px;
border-top: 1px solid #e0e0e0;
}
.toolbar {
position: absolute;
top: 20px;
left: 20px;
background: rgba(255, 255, 255, 0.95);
border: 1px solid #e0e0e0;
border-radius: 8px;
padding: 8px;
display: flex;
gap: 8px;
z-index: 100;
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}
.toolbar button {
padding: 8px 16px;
background: #ffffff;
border: 1px solid #d0d0d0;
color: #1a1a1a;
border-radius: 4px;
cursor: pointer;
font-size: 0.9rem;
transition: all 0.2s;
}
.toolbar button:hover {
background: #f5f5f5;
border-color: #1a1a1a;
}
.toolbar button.active {
background: #1a1a1a;
color: #ffffff;
border-color: #1a1a1a;
}
.selected-nodes {
background: #f5f5f5;
border: 1px solid #e0e0e0;
border-radius: 4px;
padding: 12px;
margin-bottom: 16px;
}
.selected-nodes .node-name {
font-weight: 600;
color: #1a1a1a;
margin-bottom: 4px;
}
.selected-nodes .node-label {
font-size: 0.85rem;
color: #666;
}
.info-panel {
position: fixed;
bottom: 20px;
right: 20px;
width: 400px;
max-height: 600px;
background: #ffffff;
border: 1px solid #e0e0e0;
border-radius: 8px;
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
z-index: 1000;
transition: all 0.3s ease;
overflow: hidden;
}
.info-panel.collapsed {
max-height: 60px;
}
.info-panel.collapsed .info-panel-content {
display: none;
}
.info-panel-header {
background: #1a1a1a;
color: #ffffff;
padding: 16px;
border-radius: 8px 8px 0 0;
cursor: pointer;
display: flex;
justify-content: space-between;
align-items: center;
user-select: none;
}
.info-panel-header h3 {
margin: 0;
font-size: 1.1rem;
font-weight: 600;
}
.info-panel-toggle {
background: none;
border: none;
color: #ffffff;
font-size: 1.2rem;
cursor: pointer;
padding: 0;
width: 24px;
height: 24px;
display: flex;
align-items: center;
justify-content: center;
transition: transform 0.3s ease;
}
.info-panel.collapsed .info-panel-toggle {
transform: rotate(180deg);
}
.info-panel-content {
padding: 20px;
max-height: 540px;
overflow-y: auto;
font-size: 0.9rem;
line-height: 1.6;
color: #333;
}
.info-panel-content h4 {
color: #1a1a1a;
font-size: 1rem;
margin-top: 16px;
margin-bottom: 8px;
font-weight: 600;
}
.info-panel-content h4:first-child {
margin-top: 0;
}
.info-panel-content p {
margin-bottom: 12px;
color: #666;
}
.info-panel-content ul {
margin-left: 20px;
margin-bottom: 12px;
color: #666;
}
.info-panel-content li {
margin-bottom: 6px;
}
.info-panel-content .author {
margin-top: 20px;
padding-top: 16px;
border-top: 1px solid #e0e0e0;
font-size: 0.85rem;
color: #999;
text-align: center;
}
</style>
</head>
<body>
<div class="app-container">
<div class="sidebar">
<div>
<h2>Create Node</h2>
<form id="nodeForm">
<div class="form-group">
<label for="nodeName">Name</label>
<input type="text" id="nodeName" placeholder="Enter name" required>
</div>
<button type="submit" class="button">Add Node</button>
<div id="nodeError" class="error" style="display: none;"></div>
</form>
</div>
<div id="selectionSection" style="display: none;">
<h2>Relationship</h2>
<div class="selected-nodes">
<div class="node-name" id="mainPersonName">-</div>
<div class="node-label">Main Person (Point of View)</div>
<div style="margin-top: 12px; padding-top: 12px; border-top: 1px solid #e0e0e0;">
<div class="node-name" id="targetPersonName">-</div>
<div class="node-label">Target Person</div>
</div>
</div>
<div id="relationshipDisplay">
<div class="info-box">No relationships found</div>
</div>
<div class="add-relationship-section">
<h3>Add Relationship</h3>
<form id="relationshipForm">
<div class="form-group">
<label for="relationshipType">Relationship Type</label>
<select id="relationshipType">
<option value="parent">Parent of</option>
<option value="child">Child of</option>
<option value="spouse">Spouse</option>
</select>
</div>
<button type="submit" class="button">Add Relationship</button>
<div id="relationshipError" class="error" style="display: none;"></div>
</form>
</div>
</div>
</div>
<div class="canvas-container">
<div class="toolbar">
<button id="addNodeMode" class="button secondary active">Add Node</button>
<button id="selectMode" class="button secondary">Select Nodes</button>
<button id="panMode" class="button secondary">Pan Canvas</button>
</div>
<svg id="graphCanvas"></svg>
</div>
</div>
<div class="info-panel" id="infoPanel">
<div class="info-panel-header" onclick="toggleInfoPanel()">
<h3>Relationship Identifier Tool</h3>
<button class="info-panel-toggle">▼</button>
</div>
<div class="info-panel-content">
<h4>About</h4>
<p>
The <strong>Relationship Identifier Tool</strong> is a visual graph-based system for mapping
family relationships. Create nodes (people), connect them with parent-child or spouse relationships,
and the system automatically infers all other relationships (siblings, cousins, aunts/uncles, etc.).
</p>
<h4>How to Use</h4>
<ul>
<li><strong>Add Node Mode:</strong> Click anywhere on the canvas to create a new person</li>
<li><strong>Select Nodes Mode:</strong> Click nodes to select them (up to 2). The first selected is your point of view</li>
<li><strong>Pan Canvas Mode:</strong> Drag to move around the canvas</li>
<li><strong>Drag Nodes:</strong> Click and drag nodes to reposition them</li>
</ul>
<h4>Creating Relationships</h4>
<p>
When you select two nodes, you'll see all relationships between them. If no direct relationship
exists, you can add one using the form. The system will automatically show inferred relationships
(siblings, cousins, etc.) even if they're not directly connected.
</p>
<h4>Relationship Types</h4>
<ul>
<li><strong>Parent/Child:</strong> Direct lineage relationships</li>
<li><strong>Spouse:</strong> Marriage/partnership relationships</li>
<li><strong>Inferred:</strong> Automatically calculated (siblings, cousins, aunts/uncles, etc.)</li>
</ul>
<h4>Features</h4>
<ul>
<li>Automatic relationship inference (siblings, cousins with removals, etc.)</li>
<li>Point-of-view system (relationships shown from first selected person's perspective)</li>
<li>Incest detection for spouse relationships (configurable threshold)</li>
<li>Support for complex genealogical relationships (great-grandparents, second cousins, etc.)</li>
</ul>
<h4>Settings</h4>
<div class="form-group" style="margin-top: 12px;">
<label style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px;">
<span>Incest Threshold (generations)</span>
<span class="value" id="thresholdValue" style="color: #1a1a1a; font-weight: 600;">3</span>
</label>
<input type="range" id="incestThreshold" min="1" max="5" value="3" style="width: 100%; margin-bottom: 8px;">
<div class="info-box" style="margin-top: 8px; font-size: 0.85rem;">
Relationships within this many generations are flagged as incestuous (only shown for spouses)
</div>
</div>
<div class="author">
<strong>Relationship Identifier Tool</strong><br>
by Leto-cmd
</div>
</div>
</div>
<script>
// ==================== DATA MODELS ====================
class Node {
constructor(id, name, x, y) {
this.id = id;
this.name = name;
this.x = x;
this.y = y;
}
}
class Edge {
constructor(id, fromNodeId, toNodeId, type) {
this.id = id;
this.fromNodeId = fromNodeId;
this.toNodeId = toNodeId;
this.type = type; // 'parent' or 'spouse'
}
}
// ==================== RELATIONSHIP ENGINE ====================
class RelationshipEngine {
constructor() {
this.nodes = new Map();
this.edges = [];
this.incestThreshold = 3;
}
addNode(node) {
if (this.nodes.has(node.id)) {
throw new Error('Node with this ID already exists');
}
this.nodes.set(node.id, node);
}
addEdge(edge) {
if (!this.nodes.has(edge.fromNodeId) || !this.nodes.has(edge.toNodeId)) {
throw new Error('Both nodes must exist');
}
// Check for cycles in parent-child relationships
if (edge.type === 'parent') {
if (this.wouldCreateCycle(edge.fromNodeId, edge.toNodeId)) {
throw new Error('This would create a cycle in parentage');
}
}
this.edges.push(edge);
}
wouldCreateCycle(fromId, toId) {
return this.isAncestor(toId, fromId);
}
getEdgesBetween(nodeAId, nodeBId) {
return this.edges.filter(e =>
(e.fromNodeId === nodeAId && e.toNodeId === nodeBId) ||
(e.fromNodeId === nodeBId && e.toNodeId === nodeAId) ||
(e.type === 'spouse' && (
(e.fromNodeId === nodeAId && e.toNodeId === nodeBId) ||
(e.fromNodeId === nodeBId && e.toNodeId === nodeAId)
))
);
}
areSpouses(nodeAId, nodeBId) {
return this.edges.some(e =>
e.type === 'spouse' &&
((e.fromNodeId === nodeAId && e.toNodeId === nodeBId) ||
(e.fromNodeId === nodeBId && e.toNodeId === nodeAId))
);
}
// ==================== ANCESTOR MAPPING ====================
getAncestorMap(nodeId) {
const map = new Map();
const visited = new Set();
const traverse = (currentId, depth) => {
if (visited.has(currentId)) return;
visited.add(currentId);
const parentEdges = this.edges.filter(e =>
e.type === 'parent' && e.toNodeId === currentId
);
for (const edge of parentEdges) {
const parentId = edge.fromNodeId;
if (!map.has(parentId) || map.get(parentId) > depth + 1) {
map.set(parentId, depth + 1);
traverse(parentId, depth + 1);
}
}
};
traverse(nodeId, 0);
return map;
}
isAncestor(ancestorId, descendantId) {
const ancestorMap = this.getAncestorMap(descendantId);
return ancestorMap.has(ancestorId);
}
// ==================== NEAREST COMMON ANCESTOR ====================
findNearestCommonAncestor(nodeAId, nodeBId) {
const mapA = this.getAncestorMap(nodeAId);
const mapB = this.getAncestorMap(nodeBId);
let nca = null;
let minMaxDepth = Infinity;
for (const [ancestorId, depthA] of mapA.entries()) {
if (mapB.has(ancestorId)) {
const depthB = mapB.get(ancestorId);
const maxDepth = Math.max(depthA, depthB);
if (maxDepth < minMaxDepth) {
minMaxDepth = maxDepth;
nca = {
ancestorId,
depthA,
depthB,
maxDepth
};
}
}
}
return nca;
}
// ==================== RELATIONSHIP DETERMINATION ====================
getRelationshipFromPerspective(mainPersonId, targetPersonId) {
if (mainPersonId === targetPersonId) {
return { type: 'self', explanation: 'Same person' };
}
// Check if target is a direct ancestor (parent, grandparent, etc.)
const ancestorDistance = this.getAncestorDistance(mainPersonId, targetPersonId);
if (ancestorDistance !== null && ancestorDistance > 0) {
return {
type: 'ancestor',
distance: ancestorDistance,
explanation: this.getAncestorRelationship(mainPersonId, targetPersonId, ancestorDistance)
};
}
// Check if target is a direct descendant (child, grandchild, etc.)
const descendantDistance = this.getAncestorDistance(targetPersonId, mainPersonId);
if (descendantDistance !== null && descendantDistance > 0) {
return {
type: 'descendant',
distance: descendantDistance,
explanation: this.getDescendantRelationship(mainPersonId, targetPersonId, descendantDistance)
};
}
// Check siblings
if (this.areSiblings(mainPersonId, targetPersonId)) {
return {
type: 'sibling',
explanation: `${this.nodes.get(targetPersonId).name} is ${this.nodes.get(mainPersonId).name}'s sibling`
};
}
// Check step-relationships (must come before aunt/uncle)
const stepRelationship = this.getStepRelationship(mainPersonId, targetPersonId);
if (stepRelationship) {
return stepRelationship;
}
// Check aunt/uncle and niece/nephew relationships
const auntUncle = this.getAuntUncleRelationship(mainPersonId, targetPersonId);
if (auntUncle) {
return auntUncle;
}
// Check cousin relationship
const nca = this.findNearestCommonAncestor(mainPersonId, targetPersonId);
if (nca) {
return this.calculateCousinRelationshipFromPerspective(mainPersonId, targetPersonId, nca);
}
return {
type: 'unrelated',
explanation: null
};
}
// ==================== GET ALL RELATIONSHIPS (DIRECT + IN-LAW) ====================
getAllRelationships(mainPersonId, targetPersonId) {
const relationships = [];
// Get direct relationship
const directRel = this.getRelationshipFromPerspective(mainPersonId, targetPersonId);
if (directRel.type !== 'unrelated' && directRel.explanation) {
relationships.push({
...directRel,
isInLaw: false
});
}
// Get in-law relationships through spouses
const inLawRels = this.getInLawRelationships(mainPersonId, targetPersonId);
relationships.push(...inLawRels);
return relationships;
}
// ==================== IN-LAW RELATIONSHIP LOGIC ====================
getInLawRelationships(mainPersonId, targetPersonId) {
const inLawRels = [];
const mainName = this.nodes.get(mainPersonId).name;
const targetName = this.nodes.get(targetPersonId).name;
const mainSpouses = this.getSpouses(mainPersonId);
for (const spouseId of mainSpouses) {
const spouseName = this.nodes.get(spouseId).name;
// Get relationship from spouse's perspective to target
const spouseRel = this.getRelationshipFromPerspective(spouseId, targetPersonId);
if (spouseRel.type !== 'unrelated' && spouseRel.explanation) {
// Convert spouse's relationship to in-law relationship
const inLawRel = this.convertToInLawRelationship(
mainPersonId,
targetPersonId,
spouseId,
spouseRel
);
if (inLawRel) {
inLawRels.push({
...inLawRel,
isInLaw: true,
throughSpouse: spouseName
});
}
}
}
return inLawRels;
}
convertToInLawRelationship(mainPersonId, targetPersonId, spouseId, spouseRelationship) {
const mainName = this.nodes.get(mainPersonId).name;
const targetName = this.nodes.get(targetPersonId).name;
const spouseName = this.nodes.get(spouseId).name;
// Don't show in-law if there's already a direct relationship
const directRel = this.getRelationshipFromPerspective(mainPersonId, targetPersonId);
if (directRel.type !== 'unrelated' && directRel.explanation) {
// Check if it's the same type of relationship (don't duplicate)
if (directRel.type === spouseRelationship.type) {
return null;
}
}
switch (spouseRelationship.type) {
case 'parent':
return {
type: 'in-law-parent',
explanation: `${targetName} is ${mainName}'s parent-in-law (${spouseName}'s parent)`
};
case 'child':
return {
type: 'in-law-child',
explanation: `${targetName} is ${mainName}'s child-in-law (${spouseName}'s child)`
};
case 'sibling':
return {
type: 'in-law-sibling',
explanation: `${targetName} is ${mainName}'s sibling-in-law (${spouseName}'s sibling)`
};
case 'step-parent':
return {
type: 'in-law-step-parent',
explanation: `${targetName} is ${mainName}'s step-parent-in-law (${spouseName}'s step-parent)`
};
case 'step-child':
return {
type: 'in-law-step-child',
explanation: `${targetName} is ${mainName}'s step-child-in-law (${spouseName}'s step-child)`
};
case 'step-sibling':
return {
type: 'in-law-step-sibling',
explanation: `${targetName} is ${mainName}'s step-sibling-in-law (${spouseName}'s step-sibling)`
};
case 'aunt-uncle':
return {
type: 'in-law-aunt-uncle',
explanation: `${targetName} is ${mainName}'s aunt/uncle-in-law (${spouseName}'s aunt/uncle)`
};
case 'niece-nephew':
return {
type: 'in-law-niece-nephew',
explanation: `${targetName} is ${mainName}'s niece/nephew-in-law (${spouseName}'s niece/nephew)`
};
case 'cousin':
return {
type: 'in-law-cousin',
explanation: `${targetName} is ${mainName}'s cousin-in-law (${spouseName}'s ${this.getCousinName(spouseRelationship.cousinDegree)})`
};
case 'ancestor':
const ancestorRel = this.getGenerationName(spouseRelationship.distance, 'ancestor');
return {
type: 'in-law-ancestor',
explanation: `${targetName} is ${mainName}'s ${ancestorRel}-in-law (${spouseName}'s ${ancestorRel})`
};
case 'descendant':
const descendantRel = this.getGenerationName(spouseRelationship.distance, 'descendant');
return {
type: 'in-law-descendant',
explanation: `${targetName} is ${mainName}'s ${descendantRel}-in-law (${spouseName}'s ${descendantRel})`
};
default:
return null;
}
}
getAncestorDistance(descendantId, ancestorId) {
const ancestorMap = this.getAncestorMap(descendantId);
return ancestorMap.has(ancestorId) ? ancestorMap.get(ancestorId) : null;
}
getAncestorRelationship(mainPersonId, targetPersonId, distance) {
const main = this.nodes.get(mainPersonId);
const target = this.nodes.get(targetPersonId);
const relationship = this.getGenerationName(distance, 'ancestor');
return `${target.name} is ${main.name}'s ${relationship}`;
}
getDescendantRelationship(mainPersonId, targetPersonId, distance) {
const main = this.nodes.get(mainPersonId);
const target = this.nodes.get(targetPersonId);
const relationship = this.getGenerationName(distance, 'descendant');
return `${target.name} is ${main.name}'s ${relationship}`;
}
getGenerationName(distance, type) {
if (distance === 1) {
return type === 'ancestor' ? 'parent' : 'child';
} else if (distance === 2) {
return type === 'ancestor' ? 'grandparent' : 'grandchild';
} else if (distance === 3) {
return type === 'ancestor' ? 'great-grandparent' : 'great-grandchild';
} else {
const greats = distance - 2;
const greatPrefix = 'great-'.repeat(greats);
return type === 'ancestor' ? `${greatPrefix}grandparent` : `${greatPrefix}grandchild`;
}
}
getAuntUncleRelationship(mainPersonId, targetPersonId) {
// Check if target is aunt/uncle of main (target is sibling of main's parent)
const mainParents = this.getParents(mainPersonId);
for (const parent of mainParents) {
if (this.areSiblings(parent, targetPersonId)) {
const mainName = this.nodes.get(mainPersonId).name;
const targetName = this.nodes.get(targetPersonId).name;
// Determine if aunt or uncle (would need gender info, but we'll use neutral)
return {
type: 'aunt-uncle',
explanation: `${targetName} is ${mainName}'s aunt/uncle (sibling of ${this.nodes.get(parent).name})`
};
}
}
// Check if target is niece/nephew of main (target's parent is sibling of main)
const targetParents = this.getParents(targetPersonId);
for (const parent of targetParents) {
if (this.areSiblings(mainPersonId, parent)) {
const mainName = this.nodes.get(mainPersonId).name;
const targetName = this.nodes.get(targetPersonId).name;
return {
type: 'niece-nephew',
explanation: `${targetName} is ${mainName}'s niece/nephew (child of ${this.nodes.get(parent).name})`
};
}
}
// Check for great-aunt/uncle and great-niece/nephew
// Great-aunt/uncle: target is sibling of main's grandparent
for (const parent of mainParents) {
const grandParents = this.getParents(parent);
for (const grandParent of grandParents) {
if (this.areSiblings(grandParent, targetPersonId)) {
const mainName = this.nodes.get(mainPersonId).name;
const targetName = this.nodes.get(targetPersonId).name;
return {
type: 'great-aunt-uncle',
explanation: `${targetName} is ${mainName}'s great-aunt/uncle`
};
}
}
}
// Great-niece/nephew: target's grandparent is sibling of main
for (const targetParent of targetParents) {
const targetGrandParents = this.getParents(targetParent);
for (const targetGrandParent of targetGrandParents) {
if (this.areSiblings(mainPersonId, targetGrandParent)) {
const mainName = this.nodes.get(mainPersonId).name;
const targetName = this.nodes.get(targetPersonId).name;
return {
type: 'great-niece-nephew',
explanation: `${targetName} is ${mainName}'s great-niece/nephew`
};
}
}
}
return null;
}
areSiblings(nodeAId, nodeBId) {
const parentsA = this.getParents(nodeAId);
const parentsB = this.getParents(nodeBId);
return parentsA.some(p => parentsB.includes(p));
}
getParents(nodeId) {
return this.edges
.filter(e => e.type === 'parent' && e.toNodeId === nodeId)
.map(e => e.fromNodeId);
}
getChildren(nodeId) {
return this.edges
.filter(e => e.type === 'parent' && e.fromNodeId === nodeId)
.map(e => e.toNodeId);
}
getSpouses(nodeId) {
return this.edges
.filter(e => e.type === 'spouse' &&
(e.fromNodeId === nodeId || e.toNodeId === nodeId))
.map(e => e.fromNodeId === nodeId ? e.toNodeId : e.fromNodeId);
}
// ==================== STEP-RELATIONSHIP LOGIC ====================
getStepRelationship(mainPersonId, targetPersonId) {
const mainName = this.nodes.get(mainPersonId).name;
const targetName = this.nodes.get(targetPersonId).name;
const mainParents = this.getParents(mainPersonId);
const targetParents = this.getParents(targetPersonId);
const mainChildren = this.getChildren(mainPersonId);
const targetChildren = this.getChildren(targetPersonId);
// Check if target is step-parent of main
// Target is married to one of main's parents, but target is not also a parent of main
for (const parent of mainParents) {
if (this.areSpouses(parent, targetPersonId)) {
// Check if target is also a direct parent (if so, not a step-parent)
if (!targetParents.includes(mainPersonId) && !mainParents.includes(targetPersonId)) {
return {
type: 'step-parent',
explanation: `${targetName} is ${mainName}'s step-parent (spouse of ${this.nodes.get(parent).name})`
};
}
}
}
// Check if target is step-child of main