Browse Source

Fix stacked lines

pull/8/head
Florian Mounier 13 years ago
parent
commit
f72e2a7446
  1. 2
      demo/simple_test.py
  2. 4
      pygal/graph/base.py
  3. 11
      pygal/graph/line.py
  4. 5
      pygal/graph/stackedline.py
  5. 8
      pygal/style.py

2
demo/simple_test.py

@ -156,7 +156,7 @@ stackedline = StackedLine(fill=True)
stackedline.add('test1u euirset uriets ur itseruie uriset uriest u', [1, 3, 2, None, 2, 13, 2, 5, 8]) stackedline.add('test1u euirset uriets ur itseruie uriset uriest u', [1, 3, 2, None, 2, 13, 2, 5, 8])
stackedline.add('test2', [4, 1, 1, 3, 12, 3]) stackedline.add('test2', [4, 1, 1, 3, 12, 3])
stackedline.add('test3', [9, 3, 2, lnk(10, '!'), 8, 2]) stackedline.add('test3', [9, 3, 2, lnk(10, '!'), 8, 2])
stackedline.x_labels = ['aaisaruistarsitauritaria', 'bsruie trstie rusiet ruetsru', 'cuasitaruisrnauciuestuirue uiretsu iersut irasui', 'd', 'e', 'f', 'g'] stackedline.x_labels = ['aaisaruistarsitauritaria', 'bsruie trstie rusiet ruetsru', 'cuasitaruisrnauciuestuirue uiretsu iersut irasui', 'd', 'e', 'f', 'g']
stackedline.title = "Stackedline ine uisernuis enuir esnue sunres nuise nuires uinsre auin ruist arusit arst ierustie ruiset uriest uirest test" stackedline.title = "Stackedline ine uisernuis enuir esnue sunres nuise nuires uinsre auin ruist arusit arst ierustie ruiset uriest uirest test"
# stackedline.interpolate = "cubic"xb # stackedline.interpolate = "cubic"xb

4
pygal/graph/base.py

@ -177,6 +177,10 @@ class BaseGraph(object):
diff = self._len - len(serie.values) diff = self._len - len(serie.values)
serie.metadata += diff * [self.__value__(0)] serie.metadata += diff * [self.__value__(0)]
for metadata in serie.metadata:
if metadata.value == None:
metadata.value = 0
def _render(self): def _render(self):
"""Make the graph internally""" """Make the graph internally"""
self.reinit() self.reinit()

11
pygal/graph/line.py

@ -99,11 +99,12 @@ class Line(Graph):
] if self._len != 1 else [.5] # Center if only one value ] if self._len != 1 else [.5] # Center if only one value
for serie in self.series: for serie in self.series:
serie.points = [ if not hasattr(serie, 'points'):
(x_pos[i], v) serie.points = [
for i, v in enumerate(serie.values)] (x_pos[i], v)
if self.interpolate: for i, v in enumerate(serie.values)]
serie.interpolated = self._interpolate(serie.values, x_pos) if self.interpolate:
serie.interpolated = self._interpolate(serie.values, x_pos)
if self.include_x_axis: if self.include_x_axis:
self._box.ymin = min(self._min, 0) self._box.ymin = min(self._min, 0)

5
pygal/graph/stackedline.py

@ -46,10 +46,7 @@ class StackedLine(Line):
] if self._len != 1 else [.5] # Center if only one value ] if self._len != 1 else [.5] # Center if only one value
accumulation = [0] * self._len accumulation = [0] * self._len
for serie in self.series: for serie in self.series:
accumulation = map(sum, izip_longest( accumulation = map(sum, zip(accumulation, serie.values))
accumulation, [val
if val != None else 0
for val in serie.values], fillvalue=0))
serie.points = [ serie.points = [
(x_pos[i], v) (x_pos[i], v)
for i, v in enumerate(accumulation)] for i, v in enumerate(accumulation)]

8
pygal/style.py

@ -34,10 +34,10 @@ class Style(object):
opacity_hover='.9', opacity_hover='.9',
transition='250ms', transition='250ms',
colors=( colors=(
'#ff5995', '#b6e354', '#feed6c', '#8cedff', '#9e6ffe', '#ff5995', '#b6e354', '#feed6c', '#8cedff', '#9e6ffe',
'#899ca1', '#f8f8f2', '#808384', '#bf4646', '#516083', '#899ca1', '#f8f8f2', '#bf4646', '#516083', '#f92672',
'#f92672', '#82b414', '#fd971f', '#56c2d6', '#8c54fe', '#82b414', '#fd971f', '#56c2d6', '#808384', '#8c54fe',
'#465457')): '#465457')):
self.background = background self.background = background
self.plot_background = plot_background self.plot_background = plot_background
self.foreground = foreground self.foreground = foreground

Loading…
Cancel
Save