Created
February 6, 2021 03:23
-
-
Save davidar/9be4d33ac58add26b095a4707462b4b4 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env python3 | |
import json | |
import sys | |
import dateutil.parser | |
import gedcom.parser | |
parser = gedcom.parser.Parser() | |
parser.parse_file(sys.argv[1], False) | |
countries = { | |
'Ireland': '#FF893C', | |
'Scotland': '#106FC1', | |
'Australia': 'white', | |
'England': '#CF081F', | |
'Chile': '#0036A8', | |
'Denmark': '#C60C30', | |
'Wales': '#00AD36', | |
} | |
reversals = [10, 14, 16, 17, 21, 22, 37, 1723] | |
def print_date(date): | |
date = date.replace('abt ', '') | |
if len(date.split()) < 3: | |
return date.split()[-1] | |
else: | |
return dateutil.parser.parse(date).date().isoformat().replace('-','.') | |
def print_person(person, indent=0): | |
res = {} | |
first, last = person.get_name() | |
first = first.replace('(', '“').replace(')', '”') | |
res['name'] = f'{first} {last}' | |
#res['name'] += ' (' | |
birth_date, birth_place, _ = person.get_birth_data() | |
birth_country = birth_place.split(', ')[-1] | |
dates = f'{print_date(birth_date)}' | |
if birth_country == 'Germany': | |
birth_country = 'Denmark' | |
if birth_country in ('Denmark', 'Chile'): | |
res['name'] = ' '.join(first.split()[:2] + [last]) | |
if birth_country == 'Australia': | |
birth_country = parser.get_parents(person)[0].get_birth_data()[1].split(', ')[-1] | |
#res['color'] = countries[birth_country] | |
if person.is_deceased(): | |
death_date, death_place, _ = person.get_death_data() | |
dates += f'‒{print_date(death_date)}' | |
print(' ' * indent, person.get_pointer(), res['name'], dates, file=sys.stderr) | |
if indent < 5: | |
father, mother = parser.get_parents(person) | |
assert father.get_gender() == 'M' | |
assert mother.get_gender() == 'F' | |
assert father.get_name()[1] == last | |
res['children'] = [print_person(father, indent+1), print_person(mother, indent+1)] | |
for i in reversals: | |
if person.get_pointer() == f'@P{i}@': | |
res['children'].reverse() | |
else: | |
res['size'] = 1 | |
#res['children'] = [{'name': birth_country + '\n' + birth_country, 'color': countries[birth_country], 'size': 1}] | |
#return {'name': dates, 'children': [res]} | |
res['name'] += '\n' + dates | |
return res | |
me = parser.get_root_child_elements()[1] | |
print(json.dumps(print_person(me))) |
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
<head> | |
<script src="//unpkg.com/d3"></script> | |
<script src="sunburst-chart.js"></script> | |
<style> | |
body { | |
margin: 0; | |
overflow: clip; | |
} | |
.sunburst-viz .main-arc { | |
fill: none; | |
} | |
#chart-bg { | |
width: 100%; | |
height: 100%; | |
position: absolute; | |
top: 0; | |
left: 0; | |
z-index: -1; | |
/*transform: rotate(11.25deg);*/ | |
} | |
#chart-bg .sunburst-viz .main-arc { | |
stroke-width: 0; | |
} | |
</style> | |
</head> | |
<body> | |
<div id="chart-bg"></div> | |
<div id="chart"></div> | |
<script> | |
data = {name: '', children: [ | |
{name: 'England', color: '#ff7961', size: 1}, | |
{name: 'Wales', color: '#80e27e', size: 8}, | |
{name: 'Chile', color: '#6ec6ff', size: 1}, | |
{name: 'Ireland', color: '#ffc947', size: 4}, | |
{name: 'England', color: '#ff7961', size: 4}, | |
{name: 'Scotland', color: '#67daff', size: 2}, | |
{name: 'Denmark', color: '#ff6090', size: 2}, | |
{name: 'England', color: '#ff7961', size: 5}, | |
{name: 'Ireland', color: '#ffc947', size: 2}, | |
{name: 'England', color: '#ff7961', size: 3}, | |
]} | |
Sunburst() | |
.data(data) | |
.label('name2') | |
.size('size') | |
.color('color') | |
.excludeRoot(true) | |
.centerRadius(0) | |
(document.getElementById('chart-bg')); | |
fetch('tree.json').then(res => res.json()).then(data => { | |
Sunburst() | |
.data(data) | |
.label('name') | |
.size('size') | |
.color('color') | |
.radiusScaleExponent(0.7) | |
//.excludeRoot(true) | |
.centerRadius(0) | |
(document.getElementById('chart')); | |
}); | |
</script> | |
</body> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment