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


Python util.cut函数代码示例

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


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

示例1: _compute_margin

    def _compute_margin(self):
        """Compute graph margins from set texts"""
        if self.show_legend and self.series:
            h, w = get_texts_box(
                map(lambda x: truncate(x, self.truncate_legend or 15),
                    cut(self.series, 'title')),
                self.legend_font_size)
            if self.legend_at_bottom:
                h_max = max(h, self.legend_box_size)
                self.margin.bottom += 10 + h_max * round(
                    sqrt(self._order) - 1) * 1.5 + h_max
            else:
                self.margin.right += 10 + w + self.legend_box_size

        if self.title:
            h, _ = get_text_box(self.title[0], self.title_font_size)
            self.margin.top += len(self.title) * (10 + h)

        if self._x_labels:
            h, w = get_texts_box(
                cut(self._x_labels), self.label_font_size)
            self._x_labels_height = 10 + max(
                w * sin(rad(self.x_label_rotation)), h)
            self.margin.bottom += self._x_labels_height
            if self.x_label_rotation:
                self.margin.right = max(
                    w * cos(rad(self.x_label_rotation)),
                    self.margin.right)
        else:
            self._x_labels_height = 0
        if self._y_labels:
            h, w = get_texts_box(
                cut(self._y_labels), self.label_font_size)
            self.margin.left += 10 + max(
                w * cos(rad(self.y_label_rotation)), h)
开发者ID:zicada,项目名称:dokweb,代码行数:35,代码来源:base.py

示例2: _compute_y_labels

 def _compute_y_labels(self):
     y_pos = compute_scale(
         self.min_, self.max_, self.logarithmic,
         self.order_min, self.min_scale, self.max_scale
     )
     if self.y_labels:
         self._y_labels = []
         for i, y_label in enumerate(self.y_labels):
             if isinstance(y_label, dict):
                 pos = self._adapt(y_label.get('value'))
                 title = y_label.get('label', self._y_format(pos))
             elif is_str(y_label):
                 pos = self._adapt(y_pos[i])
                 title = y_label
             else:
                 pos = self._adapt(y_label)
                 title = self._y_format(pos)
             self._y_labels.append((title, pos))
         self.min_ = min(self.min_, min(cut(self._y_labels, 1)))
         self.max_ = max(self.max_, max(cut(self._y_labels, 1)))
         self._box.set_polar_box(
             0, 1,
             self.min_,
             self.max_)
     else:
         self._y_labels = list(zip(map(self._y_format, y_pos), y_pos))
开发者ID:aroraumang,项目名称:pygal,代码行数:26,代码来源:gauge.py

示例3: _compute

    def _compute(self):
        xlen = len(self.series)
        x_pos = [(x + 1) / xlen for x in range(xlen)
        ] if xlen != 1 else [.5]  # Center if only one value

        previous = [[0, 0] for i in range(self._len)]
        for i, serie in enumerate(self.series):
            y_height = - sum(serie.values) / 2
            all_x_pos = [0] + x_pos
            serie.points = []
            for j, value in enumerate(serie.values):
                poly = []
                poly.append((all_x_pos[i], previous[j][0]))
                poly.append((all_x_pos[i], previous[j][1]))
                previous[j][0] = y_height
                y_height = previous[j][1] = y_height + value
                poly.append((all_x_pos[i + 1], previous[j][1]))
                poly.append((all_x_pos[i + 1], previous[j][0]))
                serie.points.append(poly)

        val_max = max(map(sum, cut(self.series, 'values')))
        self._box.ymin = -val_max
        self._box.ymax = val_max

        y_pos = compute_scale(
            self._box.ymin, self._box.ymax, self.logarithmic, self.order_min
        ) if not self.y_labels else map(float, self.y_labels)

        self._x_labels = zip(cut(self.series, 'title'),
                             map(lambda x: x - 1 / (2 * xlen), x_pos))
        self._y_labels = zip(map(self._format, y_pos), y_pos)
开发者ID:rjmcguire,项目名称:pygal,代码行数:31,代码来源:funnel.py

示例4: _compute

    def _compute(self):
        x_pos = [
            (x + 1) / self._order for x in range(self._order)
        ] if self._order != 1 else [.5]  # Center if only one value

        previous = [[self.zero, self.zero] for i in range(self._len)]
        for i, serie in enumerate(self.series):
            y_height = - sum(serie.safe_values) / 2
            all_x_pos = [0] + x_pos
            serie.points = []
            for j, value in enumerate(serie.values):
                poly = []
                poly.append((all_x_pos[i], previous[j][0]))
                poly.append((all_x_pos[i], previous[j][1]))
                previous[j][0] = y_height
                y_height = previous[j][1] = y_height + value
                poly.append((all_x_pos[i + 1], previous[j][1]))
                poly.append((all_x_pos[i + 1], previous[j][0]))
                serie.points.append(poly)

        val_max = max(list(map(sum, cut(self.series, 'values'))) + [self.zero])
        self._box.ymin = -val_max
        self._box.ymax = val_max

        y_pos = compute_scale(
            self._box.ymin, self._box.ymax, self.logarithmic, self.order_min,
            self.min_scale, self.max_scale
        ) if not self.y_labels else list(map(float, self.y_labels))

        self._x_labels = list(
            zip(cut(self.series, 'title'),
                map(lambda x: x - 1 / (2 * self._order), x_pos)))
        self._y_labels = list(zip(map(self._format, y_pos), y_pos))
开发者ID:langelee,项目名称:pygal,代码行数:33,代码来源:funnel.py

示例5: populate

 def populate(self):
     all = self.get_query().order_by(self.criteria).all()
     if self.criteria_name == 'spent_time':
         self.chart.x_labels = [
             "<1s", "1s", "2s", "5s", "10s", "20s",
             "30s", "1min", "2min", "5min",  ">10min"]
     else:
         self.chart.x_labels = list(map(str, map(int, cut(all, 0))))
     self.chart.add(labelize(self.criteria_name, self.lang),
                    list(map(float, cut(all, 1))))
开发者ID:Kozea,项目名称:pystil,代码行数:10,代码来源:charts.py

示例6: _binary_tree

    def _binary_tree(self, data, total, x, y, w, h, parent=None):
        if total == 0:
            return
        if len(data) == 1:
            if parent:
                i, datum = data[0]
                serie, serie_node, rects = parent
                self._rect(serie, serie_node, rects, datum, x, y, w, h, i)
            else:
                datum = data[0]
                serie_node = self.svg.serie(datum)
                self._binary_tree(
                    list(enumerate(datum.values)), total, x, y, w, h, (
                        datum, serie_node,
                        self.svg.node(serie_node['plot'], class_="rects")
                    )
                )
            return

        midpoint = total / 2
        pivot_index = 1
        running_sum = 0
        for i, elt in enumerate(data):
            if running_sum >= midpoint:
                pivot_index = i
                break

            running_sum += elt[1] if parent else sum(elt.values)

        half1 = data[:pivot_index]
        half2 = data[pivot_index:]

        if parent:
            half1_sum = sum(cut(half1, 1))
            half2_sum = sum(cut(half2, 1))
        else:
            half1_sum = sum(map(sum, map(lambda x: x.values, half1)))
            half2_sum = sum(map(sum, map(lambda x: x.values, half2)))
        pivot_pct = half1_sum / total

        if h > w:
            y_pivot = pivot_pct * h
            self._binary_tree(half1, half1_sum, x, y, w, y_pivot, parent)
            self._binary_tree(
                half2, half2_sum, x, y + y_pivot, w, h - y_pivot, parent
            )
        else:
            x_pivot = pivot_pct * w
            self._binary_tree(half1, half1_sum, x, y, x_pivot, h, parent)
            self._binary_tree(
                half2, half2_sum, x + x_pivot, y, w - x_pivot, h, parent
            )
开发者ID:Kozea,项目名称:pygal,代码行数:52,代码来源:treemap.py

示例7: get

 def get(data):
     if isinstance(chart, pygal.XY):
         if isinstance(chart, pygal.DateY):
             # Convert to a credible datetime
             return datetime.fromtimestamp(1360000000 + data * 987654)
         return data
     return cut(data)
开发者ID:Qalthos,项目名称:pygal,代码行数:7,代码来源:__init__.py

示例8: _compute_y_labels_major

    def _compute_y_labels_major(self):
        if self.y_labels_major_every:
            self._y_labels_major = [
                self._y_labels[i][1] for i in
                range(0, len(self._y_labels), self.y_labels_major_every)
            ]

        elif self.y_labels_major_count:
            label_count = len(self._y_labels)
            major_count = self.y_labels_major_count
            if (major_count >= label_count):
                self._y_labels_major = [label[1] for label in self._y_labels]
            else:
                self._y_labels_major = [
                    self._y_labels[int(
                        i * (label_count - 1) / (major_count - 1)
                    )][1] for i in range(major_count)
                ]

        elif self.y_labels_major:
            self._y_labels_major = list(map(self._adapt, self.y_labels_major))
        elif self._y_labels:
            self._y_labels_major = majorize(cut(self._y_labels, 1))
        else:
            self._y_labels_major = []
开发者ID:Kozea,项目名称:pygal,代码行数:25,代码来源:graph.py

示例9: _compute

    def _compute(self):
        """Compute y min and max and y scale and set labels"""
        self._x_pos = [
            (x + 1) / self._order for x in range(self._order)
        ] if self._order != 1 else [.5]  # Center if only one value

        previous = [[self.zero, self.zero] for i in range(self._len)]
        for i, serie in enumerate(self.series):
            y_height = - sum(serie.safe_values) / 2
            all_x_pos = [0] + self._x_pos
            serie.points = []
            for j, value in enumerate(serie.values):
                poly = []
                poly.append((all_x_pos[i], previous[j][0]))
                poly.append((all_x_pos[i], previous[j][1]))
                previous[j][0] = y_height
                y_height = previous[j][1] = y_height + value
                poly.append((all_x_pos[i + 1], previous[j][1]))
                poly.append((all_x_pos[i + 1], previous[j][0]))
                serie.points.append(poly)

        val_max = max(list(map(sum, cut(self.series, 'values'))) + [self.zero])
        self._box.ymin = -val_max
        self._box.ymax = val_max

        if self.range and self.range[0] is not None:
            self._box.ymin = self.range[0]

        if self.range and self.range[1] is not None:
            self._box.ymax = self.range[1]
开发者ID:Frankie-666,项目名称:pygal,代码行数:30,代码来源:funnel.py

示例10: test_metadata

def test_metadata(Chart):
    chart = Chart()
    v = range(7)
    if Chart in (pygal.Box,):
        return  # summary charts cannot display per-value metadata
    elif Chart == pygal.XY:
        v = list(map(lambda x: (x, x + 1), v))
    elif issubclass(Chart, BaseMap):
        v = [(i, k) for k, i in enumerate(Chart.x_labels)]

    chart.add('Serie with metadata', [
        v[0],
        {'value': v[1]},
        {'value': v[2], 'label': 'Three'},
        {'value': v[3], 'xlink': 'http://4.example.com/'},
        {'value': v[4], 'xlink': 'http://5.example.com/', 'label': 'Five'},
        {'value': v[5], 'xlink': {
            'href': 'http://6.example.com/'}, 'label': 'Six'},
        {'value': v[6], 'xlink': {
            'href': 'http://7.example.com/',
            'target': '_blank'}, 'label': 'Seven'}
    ])
    q = chart.render_pyquery()
    for md in (
            'Three', 'http://4.example.com/',
            'Five', 'http://7.example.com/', 'Seven'):
        assert md in cut(q('desc'), 'text')

    if Chart in (pygal.Pie, pygal.Treemap):
        # Slices with value 0 are not rendered
        assert len(v) - 1 == len(q('.tooltip-trigger').siblings('.value'))
    elif not issubclass(Chart, BaseMap):

        # Tooltip are not working on maps
        assert len(v) == len(q('.tooltip-trigger').siblings('.value'))
开发者ID:Mengxinqian,项目名称:pygal,代码行数:35,代码来源:test_graph.py

示例11: adapt

def adapt(chart, data):
    if isinstance(chart, pygal.DateY):
        # Convert to a credible datetime
        return list(map(
            lambda t:
            (datetime.fromtimestamp(1360000000 + t[0] * 987654)
             if t[0] is not None else None, t[1]), data))

    if isinstance(chart, pygal.XY):
        return data

    data = cut(data)
    if isinstance(chart, pygal.Worldmap):
        return list(
            map(lambda x: list(
                COUNTRIES.keys())[
                    int(x) % len(COUNTRIES)]
                if x is not None else None, data))
    elif isinstance(chart, pygal.FrenchMap_Regions):
        return list(
            map(lambda x: list(
                REGIONS.keys())[
                    int(x) % len(REGIONS)]
                if x is not None else None, data))
    elif isinstance(chart, pygal.FrenchMap_Departments):
        return list(
            map(lambda x: list(
                DEPARTMENTS.keys())[
                    int(x) % len(DEPARTMENTS)]
                if x is not None else None, data))
    return data
开发者ID:AlanRun,项目名称:UiAutoTest,代码行数:31,代码来源:__init__.py

示例12: _plot

    def _plot(self):
        map = etree.fromstring(MAP)
        map.set('width', str(self.view.width))
        map.set('height', str(self.view.height))

        for i, serie in enumerate(self.series):
            safe_vals = list(filter(
                lambda x: x is not None, cut(serie.values, 1)))
            if not safe_vals:
                continue
            min_ = min(safe_vals)
            max_ = max(safe_vals)
            for j, (country_code, value) in enumerate(serie.values):
                if value is None:
                    continue
                if max_ == min_:
                    ratio = 1
                else:
                    ratio = .3 + .7 * (value - min_) / (max_ - min_)

                try:
                    country = map.find('.//*[@id="%s"]' % country_code)
                except SyntaxError:
                    # Python 2.6 (you'd better install lxml)
                    country = None
                    for e in map:
                        if e.attrib.get('id', '') == country_code:
                            country = e

                if country is None:
                    continue
                cls = country.get('class', '').split(' ')
                cls.append('color-%d' % i)
                country.set('class', ' '.join(cls))
                country.set(
                    'style', 'fill-opacity: %f' % (
                        ratio))

                metadata = serie.metadata.get(j)
                if metadata:
                    node = decorate(self.svg, country, metadata)
                    if node != country:
                        country.remove(node)
                        index = list(map).index(country)
                        map.remove(country)
                        node.append(country)
                        map.insert(index, node)

                last_node = len(country) > 0 and country[-1]
                if last_node is not None and last_node.tag == 'title':
                    title_node = last_node
                    text = title_node.text + '\n'
                else:
                    title_node = self.svg.node(country, 'title')
                    text = ''
                title_node.text = text + '[%s] %s: %s' % (
                    serie.title,
                    self.country_names[country_code], self._format(value))

        self.nodes['plot'].append(map)
开发者ID:AlanRun,项目名称:UiAutoTest,代码行数:60,代码来源:worldmap.py

示例13: test_metadata

def test_metadata(Chart):
    chart = Chart()
    v = range(7)
    if Chart == pygal.XY:
        v = list(map(lambda x: (x, x + 1), v))
    elif Chart == pygal.Worldmap or Chart == pygal.SupranationalWorldmap:
        v = list(map(lambda x: x, i18n.COUNTRIES))

    chart.add('Serie with metadata', [
        v[0],
        {'value': v[1]},
        {'value': v[2], 'label': 'Three'},
        {'value': v[3], 'xlink': 'http://4.example.com/'},
        {'value': v[4], 'xlink': 'http://5.example.com/', 'label': 'Five'},
        {'value': v[5], 'xlink': {
            'href': 'http://6.example.com/'}, 'label': 'Six'},
        {'value': v[6], 'xlink': {
            'href': 'http://7.example.com/',
            'target': '_blank'}, 'label': 'Seven'}
    ])
    q = chart.render_pyquery()
    for md in (
            'Three', 'http://4.example.com/',
            'Five', 'http://7.example.com/', 'Seven'):
        assert md in cut(q('desc'), 'text')

    if Chart == pygal.Pie:
        # Slices with value 0 are not rendered
        assert len(v) - 1 == len(q('.tooltip-trigger').siblings('.value'))
    elif Chart != pygal.Worldmap and Chart != pygal.SupranationalWorldmap:
        # Tooltip are not working on worldmap
        assert len(v) == len(q('.tooltip-trigger').siblings('.value'))
开发者ID:Bouska,项目名称:pygal,代码行数:32,代码来源:test_graph.py

示例14: all

    def all(style='default', color=None, interpolate=None, base_style=None):
        width, height = 600, 400
        data = random.randrange(1, 10)
        order = random.randrange(1, 10)
        if color is None:
            style = styles[style]
        else:
            style = parametric_styles[style](
                color, base_style=styles[base_style or 'default'])
        xy_series = _random(data, order)
        other_series = []
        for title, values in xy_series:
            other_series.append(
                (title, cut(values, 1)))
        xy_series = b64encode(pickle.dumps(xy_series))
        other_series = b64encode(pickle.dumps(other_series))
        config = Config()
        config.width = width
        config.height = height
        config.fill = bool(random.randrange(0, 2))
        config.human_readable = True
        config.interpolate = interpolate
        config.style = style
        config.x_labels = [random_label() for i in range(data)]
        svgs = []
        for chart in pygal.CHARTS:
            type = chart.__name__
            svgs.append({'type': type,
                         'series': xy_series if type == 'XY' else other_series,
                         'config': b64encode(pickle.dumps(config))})

        return render_template('svgs.jinja2',
                               svgs=svgs,
                               width=width,
                               height=height)
开发者ID:Bouska,项目名称:pygal,代码行数:35,代码来源:__init__.py

示例15: test_metadata

def test_metadata(Chart):
    chart = Chart()
    v = range(7)
    if Chart in (pygal.Box,):
        return  # summary charts cannot display per-value metadata
    elif Chart == pygal.XY:
        v = list(map(lambda x: (x, x + 1), v))
    elif Chart == pygal.Worldmap or Chart == pygal.SupranationalWorldmap:
        v = list(map(lambda x: x, i18n.COUNTRIES))

    chart.add(
        "Serie with metadata",
        [
            v[0],
            {"value": v[1]},
            {"value": v[2], "label": "Three"},
            {"value": v[3], "xlink": "http://4.example.com/"},
            {"value": v[4], "xlink": "http://5.example.com/", "label": "Five"},
            {"value": v[5], "xlink": {"href": "http://6.example.com/"}, "label": "Six"},
            {"value": v[6], "xlink": {"href": "http://7.example.com/", "target": "_blank"}, "label": "Seven"},
        ],
    )
    q = chart.render_pyquery()
    for md in ("Three", "http://4.example.com/", "Five", "http://7.example.com/", "Seven"):
        assert md in cut(q("desc"), "text")

    if Chart == pygal.Pie:
        # Slices with value 0 are not rendered
        assert len(v) - 1 == len(q(".tooltip-trigger").siblings(".value"))
    elif Chart != pygal.Worldmap and Chart != pygal.SupranationalWorldmap:
        # Tooltip are not working on worldmap
        assert len(v) == len(q(".tooltip-trigger").siblings(".value"))
开发者ID:prakashnsm,项目名称:pygal,代码行数:32,代码来源:test_graph.py


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