-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
684cc85
commit 02f6098
Showing
9 changed files
with
321 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { SelectionIndividualRecord } from 'read-gedcom'; | ||
import { IndividualTree } from './types.ts'; | ||
|
||
export const buildIndividualTree = <D extends object>( | ||
root: SelectionIndividualRecord, | ||
// eslint-disable-next-line no-unused-vars | ||
dataForIndividual: (individual: SelectionIndividualRecord, depth: number) => D, | ||
depthLimit: number, | ||
): IndividualTree<D> => { | ||
if (root.length !== 1) { | ||
throw new Error(); | ||
} | ||
const visit = (individual: SelectionIndividualRecord, depth: number): IndividualTree<D> => { | ||
const family = individual.getFamilyAsChild(); | ||
const husband = family.getHusband().getIndividualRecord().arraySelect()[0]; | ||
const wife = family.getWife().getIndividualRecord().arraySelect()[0]; | ||
const newDepth = depth + 1; | ||
return { | ||
...(depth < depthLimit - 1 | ||
? { | ||
father: husband ? visit(husband, newDepth) : undefined, | ||
mother: wife ? visit(wife, newDepth) : undefined, | ||
} | ||
: {}), | ||
data: dataForIndividual(individual, depth), | ||
}; | ||
}; | ||
return visit(root, 0); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import React, { useState } from 'react'; | ||
import { interpolateSinebow } from 'd3-scale-chromatic'; | ||
import { DiskVisualization, DiskVisualizationType } from './DiskVisualization.tsx'; | ||
import { GeographyDiskData } from '../scripts/types.ts'; | ||
import { Box, Slider, Stack } from '@mui/joy'; | ||
|
||
interface DiskGeographyVisualizationProps { | ||
data: GeographyDiskData['tree']; | ||
} | ||
|
||
export const DiskGeographyVisualization: React.FC<DiskGeographyVisualizationProps> = ({ data }) => { | ||
const [level, setLevel] = useState(1); | ||
const formatPlace = (place: (string | null)[] | null, strict: boolean): string | null => { | ||
if (place === null) { | ||
return null; | ||
} | ||
const parts = place.slice(level); | ||
const joinChar = ', '; | ||
if (parts.every((v): v is string => v !== null)) { | ||
return parts.join(joinChar); | ||
} else if (strict) { | ||
return null; | ||
} else { | ||
return parts.filter((v): v is string => v !== null).join(joinChar); | ||
} | ||
}; | ||
return ( | ||
<Box> | ||
<DiskVisualization | ||
data={data} | ||
color={interpolateSinebow} | ||
tooltip={(d) => ( | ||
<Stack alignItems="center"> | ||
<Box>Sosa {d.sosa}</Box> | ||
<Box>{formatPlace(d.place, false)}</Box> | ||
</Stack> | ||
)} | ||
type={DiskVisualizationType.CATEGORY} | ||
category={(d) => formatPlace(d.place, true)} | ||
/> | ||
<Slider | ||
step={1} | ||
min={0} | ||
max={2} | ||
valueLabelDisplay="off" | ||
marks={[ | ||
{ value: 0, label: 'Town' }, | ||
{ value: 1, label: 'Department' }, | ||
{ value: 2, label: 'Country' }, | ||
]} | ||
track={false} | ||
onChange={(e) => setLevel(parseInt((e.target as any).value))} | ||
value={level} | ||
/> | ||
</Box> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import React, { useState } from 'react'; | ||
import { interpolateReds } from 'd3-scale-chromatic'; | ||
import { DiskVisualization, DiskVisualizationType } from './DiskVisualization'; | ||
import { LongevityDiskData } from '../scripts/types'; | ||
import { Box, ButtonGroup, IconButton, Stack } from '@mui/joy'; | ||
import { Female, JoinFull, Male } from '@mui/icons-material'; | ||
|
||
interface DiskLongevityVisualizationProps { | ||
data: LongevityDiskData['tree']; | ||
} | ||
|
||
export const DiskLongevityVisualization: React.FC<DiskLongevityVisualizationProps> = ({ data }) => { | ||
const [gender, setGender] = useState<boolean | null>(null); | ||
return ( | ||
<Box> | ||
<DiskVisualization | ||
data={data} | ||
color={interpolateReds} | ||
tooltip={(d) => ( | ||
<Stack alignItems="center"> | ||
<Box>Sosa {d.sosa}</Box> | ||
<Box>{d.longevity !== null ? `${d.longevity} years` : d.sosa >= 1 << 3 ? 'Unknown' : 'Still alive'}</Box> | ||
</Stack> | ||
)} | ||
type={DiskVisualizationType.SCALE} | ||
scale={(d) => (gender === null ? d.longevity : !!(d.sosa % 2) === gender ? d.longevity : null)} | ||
/> | ||
<ButtonGroup sx={{ '--ButtonGroup-radius': '40px', justifyContent: 'center', mt: 1 }}> | ||
<IconButton onClick={() => setGender(false)} variant={gender === false ? 'solid' : 'soft'} color="primary"> | ||
<Male /> | ||
</IconButton> | ||
<IconButton onClick={() => setGender(null)} variant={gender === null ? 'solid' : 'soft'} color="primary"> | ||
<JoinFull /> | ||
</IconButton> | ||
<IconButton onClick={() => setGender(true)} variant={gender === true ? 'solid' : 'soft'} color="primary"> | ||
<Female /> | ||
</IconButton> | ||
</ButtonGroup> | ||
</Box> | ||
); | ||
}; |
Oops, something went wrong.