Skip to content

Commit

Permalink
Fix ZeroDivisionError in sparktext rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
Josh Gibbs committed Mar 3, 2014
1 parent 4b45750 commit 9cf62f0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
5 changes: 5 additions & 0 deletions pygal/ghost.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,11 @@ def render_sparktext(self, relative_to=None):
vmax = max(values)
if relative_to is None:
relative_to = min(values)

if (vmax - relative_to) == 0:
chart = bars[0] * len(values)
return chart

divisions = len(bars) - 1
for value in values:
chart += bars[int(divisions *
Expand Down
10 changes: 10 additions & 0 deletions pygal/test/test_sparktext.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,13 @@ def test_negative_and_float_and_no_data_sparktext():

chart3 = Line()
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('▁▁▁▁▁')

0 comments on commit 9cf62f0

Please sign in to comment.