Browse Source

Handle multiple series in bars

pull/8/head
Florian Mounier 13 years ago
parent
commit
14f6320d4e
  1. 7
      pygal/bar.py
  2. 6
      pygal/line.py
  3. 14
      pygal/svg.py

7
pygal/bar.py

@ -1,4 +1,3 @@
from pygal import Margin, Label
from pygal.base import BaseGraph
@ -27,8 +26,8 @@ class Bar(BaseGraph):
self.svg.legend([serie.title for serie in self.series])
self.svg.title()
for serie_index, serie in enumerate(self.series):
serie_node = self.svg.serie(serie_index)
self.svg.bar(serie_node, [
for serie in self.series:
serie_node = self.svg.serie(serie.index)
self.svg.bar(serie_node, serie, [
tuple((x_ranges[i][j], v) for j in range(2))
for i, v in enumerate(serie.values)])

6
pygal/line.py

@ -1,5 +1,3 @@
from pygal import Serie, Margin, Label
from pygal.util import round_to_scale
from pygal.base import BaseGraph
@ -26,8 +24,8 @@ class Line(BaseGraph):
self.svg.legend([serie.title for serie in self.series])
self.svg.title()
for serie_index, serie in enumerate(self.series):
for serie in self.series:
self.svg.line(
self.svg.serie(serie_index), [
self.svg.serie(serie.index), [
(x_pos[i], v)
for i, v in enumerate(serie.values)])

14
pygal/svg.py

@ -146,7 +146,7 @@ class Svg(object):
self.node(serie, 'path',
d='M%s L%s' % (origin, svg_values), class_='line')
def bar(self, serie, values, origin=None):
def bar(self, serie_node, serie, values, origin=None):
"""Draw a bar graph for a serie"""
# value here is a list of tuple range of tuple coord
@ -159,11 +159,15 @@ class Svg(object):
# x and y are left range coords and X, Y right ones
width = X - x
padding = .1 * width
width = width - 2 * padding
self.node(serie, 'rect',
x=x + padding,
inner_width = width - 2 * padding
bar_width = inner_width / len(self.graph.series)
bar_padding = .1 * bar_width
bar_inner_width = bar_width - 2 * bar_padding
offset = serie.index * bar_width + bar_padding
self.node(serie_node, 'rect',
x=x + padding + offset,
y=y,
width=width,
width=bar_inner_width,
height=self.view.y(0) - y,
class_='rect')

Loading…
Cancel
Save