当前位置: 首页>>代码示例>>Python>>正文


Python _compat.u函数代码示例

本文整理汇总了Python中pygal._compat.u函数的典型用法代码示例。如果您正苦于以下问题:Python u函数的具体用法?Python u怎么用?Python u使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了u函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_no_data

def test_no_data():
    line = Line()
    q = line.render_pyquery()
    assert q(".text-overlay text").text() == "No data"
    line.no_data_text = u("þæ®þ怀&ij¿’€")
    q = line.render_pyquery()
    assert q(".text-overlay text").text() == u("þæ®þ怀&ij¿’€")
开发者ID:AllanDaemon,项目名称:pygal,代码行数:7,代码来源:test_config.py

示例2: test_value_formatter

def test_value_formatter():
    line = Line(value_formatter=lambda x: str(x) + u('‰'))
    line.add('_', [10 ** 4, 10 ** 5, 23 * 10 ** 4])
    q = line.render_pyquery()
    assert len(q(".y.axis .guides")) == 11
    assert q(".axis.y text").map(texts) == list(map(
        lambda x: str(x) + u('‰'), map(float, range(20000, 240000, 20000))))
开发者ID:AllanDaemon,项目名称:pygal,代码行数:7,代码来源:test_config.py

示例3: test_render_data_uri

def test_render_data_uri(Chart):
    """Test the render data uri"""
    chart = Chart(fill=True)
    chart.add(u('ééé'), [1, 2, 3])
    chart.add(u('èèè'), [10, 21, 5])
    assert chart.render_data_uri().startswith(
        'data:image/svg+xml;charset=utf-8;base64,')
开发者ID:ConnorMooreLUC,项目名称:pygal,代码行数:7,代码来源:test_config.py

示例4: add_styles

    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)
开发者ID:Kozea,项目名称:pygal,代码行数:34,代码来源:svg.py

示例5: __init__

    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"
开发者ID:regzhuce,项目名称:pygal,代码行数:33,代码来源:svg.py

示例6: render_sparktext

    def render_sparktext(self, relative_to=None):
        """Make a mini text sparkline from chart"""
        bars = u('▁▂▃▄▅▆▇█')
        if len(self.raw_series) == 0:
            return u('')
        values = list(self.raw_series[0][1])
        if len(values) == 0:
            return u('')

        chart = u('')
        values = list(map(lambda x: max(x, 0), values))

        vmax = max(values)
        if relative_to is None:
            relative_to = min(values)

        if (vmax - relative_to) == 0:
            chart = bars[0] * len(values)
            return chart

        divisions = len(bars) - 1
        for value in values:
            chart += bars[int(divisions *
                              (value - relative_to) / (vmax - relative_to))]
        return chart
开发者ID:andreiSaw,项目名称:analyticsserver-1359,代码行数:25,代码来源:public.py

示例7: add_styles

 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)
开发者ID:AlanRun,项目名称:UiAutoTest,代码行数:28,代码来源:svg.py

示例8: __init__

 def __init__(self, graph):
     self.graph = graph
     if not graph.no_prefix:
         self.id = '#chart-%s ' % graph.uuid
     else:
         self.id = ''
     self.processing_instructions = [
         etree.PI(u('xml'), u("version='1.0' encoding='utf-8'"))]
     self.root = etree.Element(
         "{%s}svg" % self.ns,
         nsmap={
             None: self.ns,
             'xlink': 'http://www.w3.org/1999/xlink',
         })
     self.root.attrib['id'] = self.id.lstrip('#').rstrip()
     self.root.attrib['class'] = 'pygal-chart'
     self.root.append(
         etree.Comment(u(
             'Generated with pygal %s ©Kozea 2011-2014 on %s' % (
                 __version__, 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'
开发者ID:HanderLo,项目名称:pygal,代码行数:25,代码来源:svg.py

示例9: add_styles

    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)
开发者ID:langelee,项目名称:pygal,代码行数:31,代码来源:svg.py

示例10: test_truncate

def test_truncate():
    assert truncate('1234567890', 50) == '1234567890'
    assert truncate('1234567890', 5) == u('1234…')
    assert truncate('1234567890', 1) == u('…')
    assert truncate('1234567890', 9) == u('12345678…')
    assert truncate('1234567890', 10) == '1234567890'
    assert truncate('1234567890', 0) == '1234567890'
    assert truncate('1234567890', -1) == '1234567890'
开发者ID:Bouska,项目名称:pygal,代码行数:8,代码来源:test_util.py

示例11: test_same_max_and_relative_values_sparktext

def test_same_max_and_relative_values_sparktext():
    chart = Line()
    chart.add('_', [0, 0, 0, 0, 0])
    assert chart.render_sparktext() == u('▁▁▁▁▁')

    chart2 = Line()
    chart2.add('_', [1, 1, 1, 1, 1])
    assert chart2.render_sparktext(relative_to=1) == u('▁▁▁▁▁')
开发者ID:AlanRun,项目名称:UiAutoTest,代码行数:8,代码来源:test_sparktext.py

示例12: test_no_data_sparktext

def test_no_data_sparktext():
    """Test no data sparktext"""
    chart2 = Line()
    chart2.add('_', [])
    assert chart2.render_sparktext() == u('')

    chart3 = Line()
    assert chart3.render_sparktext() == u('')
开发者ID:aroraumang,项目名称:pygal,代码行数:8,代码来源:test_sparktext.py

示例13: test_truncate

def test_truncate():
    """Test truncate function"""
    assert truncate('1234567890', 50) == '1234567890'
    assert truncate('1234567890', 5) == u('1234…')
    assert truncate('1234567890', 1) == u('…')
    assert truncate('1234567890', 9) == u('12345678…')
    assert truncate('1234567890', 10) == '1234567890'
    assert truncate('1234567890', 0) == '1234567890'
    assert truncate('1234567890', -1) == '1234567890'
开发者ID:madaiz11,项目名称:pygal,代码行数:9,代码来源:test_util.py

示例14: test_negative_and_float_and_no_data_sparktext

def test_negative_and_float_and_no_data_sparktext():
    chart = Line()
    chart.add('_', [0.1, 0.2, 0.9, -0.5])
    assert chart.render_sparktext() == u('▁▂█▁')

    chart2 = Line()
    chart2.add('_', [])
    assert chart2.render_sparktext() == u('')

    chart3 = Line()
    assert chart3.render_sparktext() == u('')
开发者ID:Bouska,项目名称:pygal,代码行数:11,代码来源:test_sparktext.py

示例15: add_styles

    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)
开发者ID:never-eat-yellow-snow,项目名称:pygal,代码行数:49,代码来源:svg.py


注:本文中的pygal._compat.u函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。