Browse Source

Fix ZeroDivisionError in sparktext rendering

pull/101/head
Josh Gibbs 11 years ago
parent
commit
9cf62f0b11
  1. 5
      pygal/ghost.py
  2. 10
      pygal/test/test_sparktext.py

5
pygal/ghost.py

@ -146,6 +146,11 @@ class Ghost(object):
vmax = max(values) vmax = max(values)
if relative_to is None: if relative_to is None:
relative_to = min(values) relative_to = min(values)
if (vmax - relative_to) == 0:
chart = bars[0] * len(values)
return chart
divisions = len(bars) - 1 divisions = len(bars) - 1
for value in values: for value in values:
chart += bars[int(divisions * chart += bars[int(divisions *

10
pygal/test/test_sparktext.py

@ -60,3 +60,13 @@ def test_negative_and_float_and_no_data_sparktext():
chart3 = Line() chart3 = Line()
assert chart3.render_sparktext() == u('') assert chart3.render_sparktext() == u('')
def test_same_max_and_relative_values_sparktext():
chart = Line()
chart.add('_', [0, 0, 0, 0, 0])
assert chart.render_sparktext() == u('▁▁▁▁▁')
chart2 = Line()
chart2.add('_', [1, 1, 1, 1, 1])
assert chart2.render_sparktext(relative_to=1) == u('▁▁▁▁▁')

Loading…
Cancel
Save