Browse Source

Fixed failing test case in Pie.add_data. Tests now pass on Python 3

pull/8/head
Jason R. Coombs 13 years ago
parent
commit
46a8dc70ad
  1. 26
      svg/charts/pie.py

26
svg/charts/pie.py

@ -1,5 +1,5 @@
import math
from operator import add
import itertools
from lxml import etree
from svg.charts.graph import Graph
@ -90,9 +90,25 @@ class Pie(Graph):
is the same as:
graph.add_data({data:[3,5,8,11]}) # doctest: +SKIP
>>> graph.add_data({data:[3,5,8,11]}) # doctest: +SKIP
If data is added of with differing lengths, the corresponding
values will be assumed to be zero.
>>> graph.add_data({data:[1,2,3,4]}) # doctest: +SKIP
>>> graph.add_data({data:[5,7]}) # doctest: +SKIP
is the same as:
>>> graph.add_data({data:[5,7]}) # doctest: +SKIP
>>> graph.add_data({data:[1,2,3,4]}) # doctest: +SKIP
and
>>> graph.add_data({data:[6,9,3,4]}) # doctest: +SKIP
"""
self.data = map(robust_add, self.data, data_descriptor['data'])
pairs = itertools.izip_longest(self.data, data_descriptor['data'])
self.data = list(itertools.starmap(robust_add, pairs))
def add_defs(self, defs):
"Add svg definitions"
@ -123,7 +139,7 @@ class Pie(Graph):
return ['']
def keys(self):
total = reduce(add, self.data)
total = sum(self.data)
percent_scale = 100.0 / total
def key(field, value):
result = [field]
@ -157,7 +173,7 @@ class Pie(Graph):
wedge_text_pad = 5
wedge_text_pad = 20 * int(self.show_percent) * int(self.show_data_labels)
total = reduce(add, self.data)
total = sum(self.data)
max_value = max(self.data)
percent_scale = 100.0 / total

Loading…
Cancel
Save