Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
PlotDevice genealogy sparkline
# For PlotDevice (plotdevice.io)
# This code is crappy. It's hastily thrown together prototype code and shouldn't
# be used in anything remotely resembling a production environment.
def draw_sparkline(x, y, data, vital_size=1.5, child_size=0.8, marriage_size=1.5):
reset()
translate(x, y)
death_x = data['death'] - data['birth']
name_y = 0
span_y = 5
base_y = 8.5
# name
if 'name' in data:
fill(0)
font("Minion Pro", size=7, italic=False)
text(data['name'], 0, name_y)
# baseline
stroke(0)
fill(None)
pen(0.25, cap=BUTT)
# 0.2 so it doesn't look like it sticks out
line(0.2, base_y, death_x, base_y)
# birth and death
fill(0)
stroke(None)
rect(0, base_y - (vital_size / 2), vital_size, vital_size)
if 'hide_death' not in data:
rect(death_x, base_y - (vital_size / 2), vital_size, vital_size)
else:
# unknown death, so taper off
stroke(0.5)
for i in range(0, 3):
line(death_x + ((i+0.5)*2), base_y, death_x + ((i+1)*2), base_y)
# children
if 'children' in data:
with fill(0):
with stroke(None):
for child in data['children']:
arc(child - data['birth'], base_y, child_size)
# marriages
if 'marriages' in data:
with fill(1):
with stroke(0):
with pen(0.25):
with rotate(degrees=45):
for marriage in data['marriages']:
rect(marriage - data['birth'], base_y - (marriage_size / 2), marriage_size, marriage_size)
# label
fill(0.6)
font("Minion Pro", size=4, italic=True)
lifespan = "{birth}–".format(birth=data['birth'])
if 'hide_death' not in data:
lifespan = "{lifespan}{death}".format(lifespan=lifespan, death=data['death'])
text(lifespan, -0.3, span_y)
size(200, 200)
draw_sparkline(50, 50, {
'name': 'John Hampton',
'birth': 1805,
'death': 1870,
'marriages': [ 1828 ],
'children': [ 1830, 1832, 1837, 1838, 1841, 1844 ],
})
draw_sparkline(50, 80, {
'name': 'Grazia Parente',
'birth': 1645,
'death': 1685,
'hide_death': True,
'children': [ 1668, 1671, 1679 ],
'marriages': [ 1661, 1673 ],
})
draw_sparkline(50, 110, {
'name': 'Lucas Orlando',
'birth': 1901,
'death': 1909,
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.