Skip to content

Commit

Permalink
Avoid ZeroDivisionError and IndexError; Fixes #51 (#52)
Browse files Browse the repository at this point in the history
* Avoid ZeroDivisionError and IndexError; Refs #51
  • Loading branch information
bvacaliuc authored and sethoscope committed Jun 29, 2018
1 parent e3f2123 commit b735bd9
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions heatmap.py
Expand Up @@ -575,7 +575,10 @@ def __init__(self, hsva_min=None, hsva_max=None, image=None, steps=256):
self.values.append(rgba)

def get(self, floatval):
return self.values[int(floatval * (len(self.values) - 1))]
try:
return self.values[int(floatval * (len(self.values) - 1))]
except IndexError:
return self.values[0 if floatval<0 else -1]


class ImageMaker():
Expand Down Expand Up @@ -624,7 +627,7 @@ def make_image(self, matrix):
x = int(coord.x - extent.min.x)
y = int(coord.y - extent.min.y)
if extent.is_inside(coord):
color = self.config.colormap.get(val / maxval)
color = self.config.colormap.get(val / maxval) if maxval > 0 else self.config.colormap.get(0)
if self.background:
pixels[x, y] = ImageMaker._blend_pixels(color,
self.background)
Expand Down

0 comments on commit b735bd9

Please sign in to comment.