Browse Source

- fix specifying a value_formatter, needed to be excluded from the json dictionary

- Pie graphs do now support a value_formatter as well
pull/218/head
never-eat-yellow-snow 10 years ago
parent
commit
636aecea04
  1. 13
      pygal/graph/pie.py
  2. 4
      pygal/svg.py

13
pygal/graph/pie.py

@ -33,6 +33,15 @@ class Pie(Graph):
_adapters = [positive, none_to_zero]
@property
def _format(self):
"""Return the value formatter for this graph"""
def percentage_formatter(y, self=self):
total = sum(map(sum, map(lambda x: x.values, self.series)))
perc = y/total
return '{0:.2%}'.format(perc)
return self.value_formatter or percentage_formatter
def slice(self, serie, start_angle, total):
"""Make a serie slice"""
serie_node = self.svg.serie(serie)
@ -57,7 +66,7 @@ class Pie(Graph):
else:
angle = 2 * pi * perc
serie_angle += angle
val = '{0:.2%}'.format(perc)
val = self._format(val)
metadata = serie.metadata.get(i)
slice_ = decorate(
self.svg,
@ -77,7 +86,7 @@ class Pie(Graph):
total_perc += perc
if dual:
val = '{0:.2%}'.format(total_perc)
val = self._format(total_perc*total)
self.svg.slice(serie_node,
self.svg.node(slices, class_="big_slice"),
radius * .9, 0, serie_angle,

4
pygal/svg.py

@ -127,7 +127,9 @@ class Svg(object):
return dict((k, getattr(self.graph.state, k))
for k in dir(self.graph.config)
if not k.startswith('_') and not hasattr(
getattr(self.graph.config, k), '__call__'))
getattr(self.graph.config, k), '__call__')
and not hasattr(getattr(self.graph.state, k), '__call__')
)
def json_default(o):
if isinstance(o, (datetime, date)):

Loading…
Cancel
Save