def add_styles(self): """Add the css to the svg""" colors = self.graph.config.style.get_colors(self.id) all_css = [] for css in ['base.css'] + list(self.graph.css): if '://' in css: self.processing_instructions.append( etree.PI( u('xml-stylesheet'), u('href="%s"' % css))) else: if css.startswith('inline:'): css_text = css[len('inline:'):] 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.config.style, colors=colors, font_sizes=self.graph.config.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)
def add_styles(self): """Add the css to the svg""" colors = self.graph.config.style.get_colors(self.id) all_css = [] for css in ['base.css'] + list(self.graph.css): if '://' in css: self.processing_instructions.append( etree.PI(u('xml-stylesheet'), u('href="%s"' % css))) else: if css.startswith('inline:'): css_text = css[len('inline:'):] 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.config.style, colors=colors, font_sizes=self.graph.config.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)
def add_styles(self): """Add the css to the svg""" colors = self.graph.style.get_colors(self.id, self.graph._order) strokes = self.get_strokes() all_css = [] auto_css = ["file://base.css"] if self.graph.style._google_fonts: auto_css.append( "//fonts.googleapis.com/css?family=%s" % quote_plus("|".join(self.graph.style._google_fonts)) ) for css in auto_css + list(self.graph.css): css_text = None if css.startswith("inline:"): css_text = css[len("inline:") :] elif css.startswith("file://"): css = css[len("file://") :] 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, strokes=strokes, id=self.id) if css_text is not None: if not self.graph.pretty_print: css_text = minify_css(css_text) all_css.append(css_text) else: if css.startswith("//") and self.graph.force_uri_protocol: css = "%s:%s" % (self.graph.force_uri_protocol, css) self.processing_instructions.append(etree.PI(u("xml-stylesheet"), u('href="%s"' % css))) self.node(self.defs, "style", type="text/css").text = "\n".join(all_css)
def add_styles(self): """Add the css to the svg""" colors = self.graph.style.get_colors(self.id, self.graph._order) strokes = self.get_strokes() all_css = [] for css in ["base.css"] + list(self.graph.css): if "://" in css: self.processing_instructions.append(etree.PI(u("xml-stylesheet"), u('href="%s"' % css))) else: if css.startswith("inline:"): css_text = css[len("inline:") :] else: if not os.path.exists(css): css = os.path.join(os.path.dirname(__file__), "css", css) class FontSizes(object): """Container for font sizes""" fs = FontSizes() for name in dir(self.graph.state): if name.endswith("_font_size"): setattr(fs, name.replace("_font_size", ""), ("%dpx" % getattr(self.graph, name))) with io.open(css, encoding="utf-8") as f: css_text = template( f.read(), style=self.graph.style, colors=colors, strokes=strokes, font_sizes=fs, 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)
def add_styles(self): """Add the css to the svg""" 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, font_sizes=self.graph.font_sizes()) if not self.graph.pretty_print: css_text = minify_css(css_text) self.node(self.defs, "style", type="text/css").text = css_text
def add_styles(self): """Add the css to the svg""" colors = self.graph.style.get_colors(self.id, self.graph._order) strokes = self.get_strokes() all_css = [] auto_css = ['template://{}'.format(CSS_BASE)] if self.graph.style._google_fonts: auto_css.append( '//fonts.googleapis.com/css?family=%s' % quote_plus('|'.join(self.graph.style._google_fonts))) for css in auto_css + list(self.graph.css): css_text = None if css.startswith('inline:'): css_text = css[len('inline:'):] elif css.startswith('template://'): css = css[len('template://'):] css_text = template(css, style=self.graph.style, colors=colors, strokes=strokes, id=self.id) elif css.startswith('file://'): css = css[len('file://'):] 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, strokes=strokes, id=self.id) if css_text is not None: if not self.graph.pretty_print: css_text = minify_css(css_text) all_css.append(css_text) else: if css.startswith('//') and self.graph.force_uri_protocol: css = '%s:%s' % (self.graph.force_uri_protocol, css) self.processing_instructions.append( etree.PI(u('xml-stylesheet'), u('href="%s"' % css))) self.node(self.defs, 'style', type='text/css').text = '\n'.join(all_css)
def add_styles(self): """Add the css to the svg""" colors = self.graph.style.get_colors(self.id, self.graph._order) strokes = self.get_strokes() all_css = [] auto_css = [base_css] if self.graph.style._google_fonts: auto_css.append( '//fonts.googleapis.com/css?family=%s' % quote_plus( '|'.join(self.graph.style._google_fonts)) ) for css in auto_css + list(self.graph.css): css_text = None if type(css) == str and css.startswith('inline:'): css_text = css[len('inline:'):] elif type(css) == str and css.startswith('file://'): if not os.path.exists(css): css = os.path.join( os.path.dirname(__file__), 'css', css[len('file://'):]) with io.open(css, encoding='utf-8') as f: css_text = template( f.read(), style=self.graph.style, colors=colors, strokes=strokes, id=self.id) elif not type(css) == str: css_text = template( css.data, style=self.graph.style, colors=colors, strokes=strokes, id=self.id) if css_text is not None: if not self.graph.pretty_print: css_text = minify_css(css_text) all_css.append(css_text) else: if type(css) == str and css.startswith('//') and self.graph.force_uri_protocol: css = '%s:%s' % (self.graph.force_uri_protocol, css) self.processing_instructions.append( etree.PI( u('xml-stylesheet'), u('href="%s"' % css))) self.node( self.defs, 'style', type='text/css').text = '\n'.join(all_css)
def add_styles(self): """Add the css to the svg""" 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, font_sizes=self.graph.font_sizes()) if not self.graph.pretty_print: css_text = minify_css(css_text) self.node(self.defs, 'style', type='text/css').text = css_text
def test_minify_css(): css = ''' /* * Font-sizes from config, override with care */ .title { font-family: sans; font-size: 12 ; } .legends .legend text { font-family: monospace; font-size: 14 ;} ''' assert minify_css(css) == ( '.title{font-family:sans;font-size:12}' '.legends .legend text{font-family:monospace;font-size:14}')
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 '://' in css: self.processing_instructions.append( etree.PI( u('xml-stylesheet'), u('href="%s"' % css))) else: if css.startswith('inline:'): css_text = css[len('inline:'):] else: if not os.path.exists(css): css = os.path.join( os.path.dirname(__file__), 'css', css) class FontSizes(object): """Container for font sizes""" fs = FontSizes() for name in dir(self.graph.state): if name.endswith('_font_size'): setattr( fs, name.replace('_font_size', ''), ('%dpx' % getattr(self.graph, name))) with io.open(css, encoding='utf-8') as f: css_text = template( f.read(), style=self.graph.style, colors=colors, font_sizes=fs, 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)
def add_styles(self): """Add the css to the svg""" css_texts = [] 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, font_sizes=self.graph.font_sizes()) if not self.graph.pretty_print: css_text = minify_css(css_text) css_texts.append(css_text) self.node( self.defs, 'style', type='text/css').text = '\n'.join(css_texts)