Example #1
0
File: svg.py Project: gsliu/pisar
 def add_styles(self):
     """Add the css to the svg"""
     colors = self.graph.style.get_colors(self.id)
     all_css = []
     for css in ['base.css'] + list(self.graph.css):
         if urlparse(css).scheme:
             self.processing_instructions.append(
                 etree.PI(
                     u('xml-stylesheet'), u('href="%s"' % css)))
         else:
             if not os.path.exists(css):
                 css = os.path.join(
                     os.path.dirname(__file__), 'css', css)
             with io.open(css, encoding='utf-8') as f:
                 css_text = template(
                     f.read(),
                     style=self.graph.style,
                     colors=colors,
                     font_sizes=self.graph.font_sizes(),
                     id=self.id)
                 if not self.graph.pretty_print:
                     css_text = minify_css(css_text)
             all_css.append(css_text)
     self.node(
         self.defs, 'style', type='text/css').text = '\n'.join(all_css)
Example #2
0
File: svg.py Project: gsliu/pisar
    def add_scripts(self):
        """Add the js to the svg"""
        common_script = self.node(self.defs, 'script', type='text/javascript')
        common_script.text = " = ".join(
            ("window.config", json.dumps(self.graph.config.to_dict())))

        for js in self.graph.js:
            if urlparse(js).scheme:
                self.node(
                    self.defs, 'script', type='text/javascript', href=js)
            else:
                script = self.node(self.defs, 'script', type='text/javascript')
                with io.open(js, encoding='utf-8') as f:
                    script.text = f.read()