Browse Source

Merge pull request #78 from sirlark/xml_filters

ADDS HOOK FOR XML MODIFICATION PRE-RENDERING
pull/82/head
Mounier Florian 11 years ago
parent
commit
3f999628fa
  1. 7
      pygal/ghost.py
  2. 8
      pygal/graph/base.py
  3. 2
      pygal/svg.py

7
pygal/ghost.py

@ -60,6 +60,7 @@ class Ghost(object):
self.config = config
self.raw_series = []
self.raw_series2 = []
self.xml_filters = []
def add(self, title, values, secondary=False):
"""Add a serie to this graph"""
@ -70,6 +71,9 @@ class Ghost(object):
else:
self.raw_series.append((title, values))
def add_xml_filter(self, callback):
self.xml_filters.append(callback)
def make_series(self, series):
return prepare_values(series, self.config, self.cls)
@ -79,7 +83,8 @@ class Ghost(object):
series = self.make_series(self.raw_series)
secondary_series = self.make_series(self.raw_series2)
self._last__inst = self.cls(
self.config, series, secondary_series, self.uuid)
self.config, series, secondary_series, self.uuid,
self.xml_filters)
return self._last__inst
# Rendering

8
pygal/graph/base.py

@ -35,13 +35,14 @@ class BaseGraph(object):
_adapters = []
def __init__(self, config, series, secondary_series, uuid):
def __init__(self, config, series, secondary_series, uuid, xml_filters):
"""Init the graph"""
self.uuid = uuid
self.__dict__.update(config.to_dict())
self.config = config
self.series = series or []
self.secondary_series = secondary_series or []
self.xml_filters = xml_filters or []
self.horizontal = getattr(self, 'horizontal', False)
self.svg = Svg(self)
self._x_labels = None
@ -252,4 +253,7 @@ class BaseGraph(object):
def render_tree(self):
"""Render the graph, and return lxml tree"""
return self.svg.root
svg = self.svg.root
for f in self.xml_filters:
svg = f(svg)
return svg

2
pygal/svg.py

@ -217,6 +217,8 @@ class Svg(object):
def render(self, is_unicode=False, pretty_print=False):
"""Last thing to do before rendering"""
for f in self.graph.xml_filters:
self.root = f(self.root)
svg = etree.tostring(
self.root, pretty_print=pretty_print,
xml_declaration=False,

Loading…
Cancel
Save