示例#1
0
    def __init__(self, graph):
        """Create the svg helper with the chart instance"""
        self.graph = graph
        if not graph.no_prefix:
            self.id = '#chart-%s ' % graph.uuid
        else:
            self.id = ''
        self.processing_instructions = []
        if etree.lxml:
            attrs = {'nsmap': {None: self.ns, 'xlink': self.xlink_ns}}
        else:
            attrs = {'xmlns': self.ns}
            if hasattr(etree, 'register_namespace'):
                etree.register_namespace('xlink', self.xlink_ns)
            else:
                etree._namespace_map[self.xlink_ns] = 'xlink'

        self.root = etree.Element('svg', **attrs)
        self.root.attrib['id'] = self.id.lstrip('#').rstrip()
        self.root.attrib['class'] = 'pygal-chart'
        self.root.append(
            etree.Comment(
                u('Generated with pygal %s (%s) ©Kozea 2011-2015 on %s' %
                  (__version__, 'lxml' if etree.lxml else 'etree',
                   date.today().isoformat()))))
        self.root.append(etree.Comment(u('http://pygal.org')))
        self.root.append(etree.Comment(u('http://github.com/Kozea/pygal')))
        self.defs = self.node(tag='defs')
        self.title = self.node(tag='title')
        self.title.text = graph.title or 'Pygal'

        for def_ in self.graph.defs:
            self.defs.append(etree.fromstring(def_))
示例#2
0
文件: svg.py 项目: regzhuce/pygal
    def __init__(self, graph):
        """Create the svg helper with the chart instance"""
        self.graph = graph
        if not graph.no_prefix:
            self.id = "#chart-%s " % graph.uuid
        else:
            self.id = ""
        self.processing_instructions = [etree.ProcessingInstruction(u("xml"), u("version='1.0' encoding='utf-8'"))]
        if etree.lxml:
            attrs = {"nsmap": {None: self.ns, "xlink": self.xlink_ns}}
        else:
            attrs = {"xmlns": self.ns}
            if hasattr(etree, "register_namespace"):
                etree.register_namespace("xlink", self.xlink_ns)
            else:
                etree._namespace_map[self.xlink_ns] = "xlink"

        self.root = etree.Element("svg", **attrs)
        self.root.attrib["id"] = self.id.lstrip("#").rstrip()
        self.root.attrib["class"] = "pygal-chart"
        self.root.append(
            etree.Comment(
                u(
                    "Generated with pygal %s (%s) ©Kozea 2011-2015 on %s"
                    % (__version__, "lxml" if etree.lxml else "etree", date.today().isoformat())
                )
            )
        )
        self.root.append(etree.Comment(u("http://pygal.org")))
        self.root.append(etree.Comment(u("http://github.com/Kozea/pygal")))
        self.defs = self.node(tag="defs")
        self.title = self.node(tag="title")
        self.title.text = graph.title or "Pygal"
示例#3
0
    def __init__(self, graph):
        """Create the svg helper with the chart instance"""
        self.graph = graph
        if not graph.no_prefix:
            self.id = '#chart-%s ' % graph.uuid
        else:
            self.id = ''
        self.processing_instructions = [
            etree.ProcessingInstruction(
                u('xml'), u("version='1.0' encoding='utf-8'"))]
        if etree.lxml:
            attrs = {
                'nsmap': {
                    None: self.ns,
                    'xlink': self.xlink_ns
                }
            }
        else:
            attrs = {
                'xmlns': self.ns
            }
            if hasattr(etree, 'register_namespace'):
                etree.register_namespace('xlink', self.xlink_ns)
            else:
                etree._namespace_map[self.xlink_ns] = 'xlink'

        self.root = etree.Element('svg', **attrs)
        self.root.attrib['id'] = self.id.lstrip('#').rstrip()
        self.root.attrib['class'] = 'pygal-chart'
        self.root.append(
            etree.Comment(u(
                'Generated with pygal %s (%s) ©Kozea 2011-2015 on %s' % (
                    __version__,
                    'lxml' if etree.lxml else 'etree',
                    date.today().isoformat()))))
        self.root.append(etree.Comment(u('http://pygal.org')))
        self.root.append(etree.Comment(u('http://github.com/Kozea/pygal')))
        self.defs = self.node(tag='defs')
        self.title = self.node(tag='title')
        self.title.text = graph.title or 'Pygal'

        for def_ in self.graph.defs:
            self.defs.append(etree.fromstring(def_))