diff --git a/pygal/ghost.py b/pygal/ghost.py index 585df2a..53f58db 100644 --- a/pygal/ghost.py +++ b/pygal/ghost.py @@ -61,8 +61,13 @@ class Ghost(object): self.series.append( Serie(title, values, len(self.series), self.cls.__value__)) + def _check(self): + if self.config.logarithmic and self.config.zero == 0: + self.config.zero = 1 + def make_instance(self): self.config(**self.__dict__) + self._check() self._last__inst = self.cls(self.config, self.series) return self._last__inst diff --git a/pygal/graph/base.py b/pygal/graph/base.py index 880a409..e97d51d 100644 --- a/pygal/graph/base.py +++ b/pygal/graph/base.py @@ -44,18 +44,10 @@ class BaseGraph(object): self.svg = Svg(self) self._x_labels = None self._y_labels = None - self._box = None self.nodes = {} - self.margin = None - self.view = None - - 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 + self.view = None def __getattr__(self, attr): """Search in config, then in self""" @@ -79,12 +71,12 @@ class BaseGraph(object): if self.show_legend: h, w = get_texts_box( map(lambda x: truncate(x, self.truncate_legend or 15), - cut(self.series, 'title')), + 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 + sqrt(len(self.series)) - 1) * 1.5 + h_max else: self.margin.right += 10 + w + self.legend_box_size @@ -121,7 +113,7 @@ class BaseGraph(object): return [val for serie in self.series for val in serie.values - if val != None] + if val is not None] @cached_property def _len(self): @@ -170,13 +162,11 @@ class BaseGraph(object): serie.metadata += diff * [self.__value__(0)] for metadata in serie.metadata: - if metadata.value == None: + if metadata.value is None: metadata.value = 0 def _render(self): """Make the graph internally""" - self.reinit() - self.svg.reinit() if self._has_data(): self._draw() self.svg.pre_render(False) diff --git a/pygal/svg.py b/pygal/svg.py index 95d560e..c40b9a1 100644 --- a/pygal/svg.py +++ b/pygal/svg.py @@ -25,6 +25,7 @@ from __future__ import division import io import os import json +from datetime import date from lxml import etree from math import cos, sin, pi from urlparse import urlparse @@ -40,19 +41,16 @@ class Svg(object): self.graph = graph self.processing_instructions = [ etree.PI(u'xml', u"version='1.0' encoding='utf-8'")] - self.root = None - self.defs = None - - def reinit(self): - """(Re-)initialization""" self.root = etree.Element( "{%s}svg" % self.ns, nsmap={ None: self.ns, 'xlink': 'http://www.w3.org/1999/xlink', }) - self.root.append(etree.Comment( - u'Generated with pygal %s ©Kozea 2012' % __version__)) + self.root.append( + etree.Comment(u'Generated with pygal %s ©Kozea 2012 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') @@ -135,7 +133,8 @@ class Svg(object): self.node(node, 'path', d=root % (origin, line), **kwargs) - def slice(self, serie_node, node, radius, small_radius, + def slice( + self, serie_node, node, radius, small_radius, angle, start_angle, center, val): """Draw a pie slice""" project = lambda rho, alpha: ( @@ -144,14 +143,14 @@ class Svg(object): fmt = lambda x: '%f %f' % x get_radius = lambda r: fmt(tuple([r] * 2)) absolute_project = lambda rho, theta: fmt( - diff(center, project(rho, theta))) + diff(center, project(rho, theta))) if angle == 2 * pi: self.node(node, 'circle', - cx=center[0], - cy=center[1], - r=radius, - class_='slice reactive tooltip-trigger') + cx=center[0], + cy=center[1], + r=radius, + class_='slice reactive tooltip-trigger') else: to = [absolute_project(radius, start_angle), absolute_project(radius, start_angle + angle), @@ -165,7 +164,7 @@ class Svg(object): get_radius(small_radius), int(angle > pi), to[3]), class_='slice reactive tooltip-trigger') x, y = diff(center, project( - (radius + small_radius) / 2, start_angle + angle / 2)) + (radius + small_radius) / 2, start_angle + angle / 2)) self.graph._tooltip_data(node, val, x, y, classes="centered") self.graph._static_value(serie_node, val, x, y) @@ -181,9 +180,9 @@ class Svg(object): self.root.set('height', str(self.graph.height)) if no_data: no_data = self.node(self.root, 'text', - x=self.graph.width / 2, - y=self.graph.height / 2, - class_='no_data') + x=self.graph.width / 2, + y=self.graph.height / 2, + class_='no_data') no_data.text = self.graph.no_data_text def render(self, is_unicode=False, pretty_print=False):