Browse Source

Refactor some init

pull/8/head
Florian Mounier 12 years ago
parent
commit
bc08708c4c
  1. 5
      pygal/ghost.py
  2. 16
      pygal/graph/base.py
  3. 15
      pygal/svg.py

5
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

16
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"""
@ -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)

15
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: (

Loading…
Cancel
Save