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