Source code for micom.viz.core

"""Core objects for visualization."""

from micom.logger import logger
from os import path
from jinja2 import Environment, PackageLoader, select_autoescape
import webbrowser

[docs]env = Environment( loader=PackageLoader("micom", "data/templates"), autoescape=select_autoescape(["html"]), )
[docs]class Visualization(object): """A visualization object. Attributes ---------- filename : str The filename of trhe saved visualization. data : dict The data used to create the Visualization. template : jinja2.Template The jinja template used to render the visualization. """ def __init__(self, filename, data, template): self.filename = filename = data self.template = env.get_template(template)
[docs] def view(self): """Open the visualization in a browser. Parameters ---------- None. Returns ------- nothing """"file://%s" % path.realpath(self.filename), new=2)
[docs] def save(self, **kwargs): """Render and and save the visualization.""" out = self.filename files = {k: d.to_csv(index=False) for k, d in}"Writing visualization to %s." % out), **kwargs).dump(out)