Programmatically generate SVG (vector) images, animations, and interactive Jupyter widgets
1import dataclasses 2 3from . import url_encode 4 5 6@dataclasses.dataclass 7class JupyterSvgInline: 8 '''Jupyter-displayable SVG displayed inline on the Jupyter web page.''' 9 svg: str 10 def _repr_html_(self): 11 return self.svg 12 13@dataclasses.dataclass 14class JupyterSvgImage: 15 '''Jupyter-displayable SVG displayed within an img tag on the Jupyter web 16 page. 17 ''' 18 svg: str 19 def _repr_html_(self): 20 uri = url_encode.svg_as_utf8_data_uri(self.svg) 21 return '<img src="{}">'.format(uri) 22 23@dataclasses.dataclass 24class JupyterSvgFrame: 25 '''Jupyter-displayable SVG displayed within an HTML iframe.''' 26 svg: str 27 width: float 28 height: float 29 def _repr_html_(self): 30 uri = url_encode.svg_as_utf8_data_uri(self.svg) 31 return (f'<iframe src="{uri}" width="{self.width}" ' 32 f'height="{self.height}" style="border:0" />')