-
-
Save lawrencegripper/b2c31fc910b88353debc202e61426905 to your computer and use it in GitHub Desktop.
labella
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
def timeline(name, data): | |
from labella.timeline import TimelineSVG, TimelineTex | |
from labella.utils import COLOR_10 | |
from labella.scale import TimeScale, LinearScale | |
import pyvips | |
import os | |
def color_selector(data): | |
colors = { | |
"meds": "#FEA443", | |
"meds_amoxicillin": "#705E78", | |
"meds_paracetamol": "#A5AAA3", | |
"meds_ibrufen": "#812F33", | |
"sleep": "#EB722A", | |
"inhaler_blue": "#1E24E3", | |
"inhaler_brown": "#B61D28", | |
"note": "#BCBF50", | |
} | |
return colors[data['type']] | |
options = { | |
"scale": LinearScale(), | |
"initialWidth": 350, | |
"initialHeight": 580, | |
"direction": 'right', | |
"dotColor": color_selector, | |
"labelBgColor": color_selector, | |
"linkColor": color_selector, | |
"textFn": lambda x: f'{x["timeobj"].strftime("%H:%M")} - {x["message"]}' , | |
"labelPadding": {"left": 0, "right": 0, "top": 1, "bottom": 1}, | |
"margin": {"left": 20, "right": 20, "top": 30, "bottom": 20}, | |
"layerGap": 40, | |
"labella": { | |
"maxPos": 500, | |
}, | |
"latex": {"reproducible": True}, | |
} | |
items = data.to_dict('records') | |
tl = TimelineSVG(items, options=options) | |
svg_filename = f'timeline{name}.svg' | |
tl.export(svg_filename) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment