|
|
|
@ -24,12 +24,15 @@ from math import cos, sin, pi
|
|
|
|
|
class Pie(Graph): |
|
|
|
|
"""Pie graph""" |
|
|
|
|
|
|
|
|
|
def slice(self, serie_node, start_angle, angle, perc): |
|
|
|
|
def slice(self, serie_node, start_angle, angle, perc, |
|
|
|
|
small=False): |
|
|
|
|
slices = self.svg.node(serie_node, class_="slices") |
|
|
|
|
slice_ = self.svg.node(slices, class_="slice") |
|
|
|
|
center = ((self.width - self.margin.x) / 2., |
|
|
|
|
(self.height - self.margin.y) / 2.) |
|
|
|
|
r = min(center) |
|
|
|
|
if small: |
|
|
|
|
r *= .8 |
|
|
|
|
center_str = '%f %f' % center |
|
|
|
|
rxy = '%f %f' % tuple([r] * 2) |
|
|
|
|
to = '%f %f' % (r * sin(angle), r * (1 - cos(angle))) |
|
|
|
@ -51,19 +54,28 @@ class Pie(Graph):
|
|
|
|
|
|
|
|
|
|
def _compute(self): |
|
|
|
|
for serie in self.series: |
|
|
|
|
serie.values = [max(serie.values[0], 0)] |
|
|
|
|
serie.values = map(lambda x: max(x, 0), serie.values) |
|
|
|
|
return super(Pie, self)._compute() |
|
|
|
|
|
|
|
|
|
def _plot(self): |
|
|
|
|
total = float(sum(serie.values[0] for serie in self.series)) |
|
|
|
|
total = float(sum(map(sum, map(lambda x: x.values, self.series)))) |
|
|
|
|
|
|
|
|
|
if total == 0: |
|
|
|
|
return |
|
|
|
|
current_angle = 0 |
|
|
|
|
for serie in self.series: |
|
|
|
|
val = serie.values[0] |
|
|
|
|
angle = 2 * pi * val / total |
|
|
|
|
angle = 2 * pi * sum(serie.values) / total |
|
|
|
|
self.slice( |
|
|
|
|
self._serie(serie.index), |
|
|
|
|
current_angle, |
|
|
|
|
angle, val / total) |
|
|
|
|
angle, sum(serie.values) / total) |
|
|
|
|
if len(serie.values) > 1: |
|
|
|
|
small_current_angle = current_angle |
|
|
|
|
for val in serie.values: |
|
|
|
|
small_angle = 2 * pi * val / total |
|
|
|
|
self.slice( |
|
|
|
|
self._serie(serie.index), |
|
|
|
|
small_current_angle, |
|
|
|
|
small_angle, val / total, True) |
|
|
|
|
small_current_angle += small_angle |
|
|
|
|
current_angle += angle |
|
|
|
|