本文整理汇总了Python中pygal.svg.Svg.reinit方法的典型用法代码示例。如果您正苦于以下问题:Python Svg.reinit方法的具体用法?Python Svg.reinit怎么用?Python Svg.reinit使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pygal.svg.Svg
的用法示例。
在下文中一共展示了Svg.reinit方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: BaseGraph
# 需要导入模块: from pygal.svg import Svg [as 别名]
# 或者: from pygal.svg.Svg import reinit [as 别名]
class BaseGraph(object):
"""Graphs commons"""
__value__ = Value
def __init__(self, config=None, **kwargs):
"""Init the graph"""
self.config = config or Config()
self.config(**kwargs)
self.horizontal = getattr(self, 'horizontal', False)
self.svg = Svg(self)
self.series = []
self._x_labels = None
self._y_labels = None
self._box = None
self.nodes = {}
self.margin = None
self.view = None
def add(self, title, values):
"""Add a serie to this graph"""
self.series.append(
Serie(title, values, len(self.series), self.__value__))
def reinit(self):
"""(Re-)Init the graph"""
self.margin = Margin(*([20] * 4))
self._box = Box()
if self.logarithmic and self.zero == 0:
# If logarithmic, default zero to 1
self.zero = 1
def __getattr__(self, attr):
"""Search in config, then in self"""
if attr in dir(self.config):
return object.__getattribute__(self.config, attr)
return object.__getattribute__(self, attr)
@property
def _format(self):
"""Return the value formatter for this graph"""
return humanize if self.human_readable else str
def _compute(self):
"""Initial computations to draw the graph"""
def _plot(self):
"""Actual plotting of the graph"""
def _compute_margin(self):
"""Compute graph margins from set texts"""
if self.show_legend:
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(len(self.series)) - 1) * 1.5 + h_max
else:
self.margin.right += 10 + w + self.legend_box_size
if self.title:
h, w = get_text_box(self.title, self.title_font_size)
self.margin.top += 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)
@cached_property
def _legends(self):
"""Getter for series title"""
return [serie.title for serie in self.series]
@cached_property
def _values(self):
"""Getter for series values (flattened)"""
return [val
for serie in self.series
for val in serie.values
if val != None]
@cached_property
def _len(self):
#.........这里部分代码省略.........