"""Core objects for visualization."""frommicom.loggerimportloggerfromosimportpathfromjinja2importEnvironment,PackageLoader,select_autoescapeimportwebbrowser
[docs]classVisualization(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):
[docs]defview(self):"""Open the visualization in a browser. Parameters ---------- None. Returns ------- nothing """webbrowser.open("file://%s"%path.realpath(self.filename),new=2)
[docs]defsave(self,**kwargs):"""Render and and save the visualization."""out=self.filenamefiles={k:d.to_csv(index=False)fork,dinself.data.items()}logger.info("Writing visualization to %s."%out)self.template.stream(files=files,**kwargs).dump(out)