[reportlab-users] Minor bug in spider.py, with patch
Max M
maxm at mxm.dk
Wed Jun 15 07:25:02 EDT 2005
In <site-packages>/reportlab/graphics/charts/spider.py there is a minor
division
by zero bug.
If all elemnents are 0.0, theMax will also be 0.0. That will make this
line fail
with a zero division error:
scaledRow.append(element / theMax)
Here is the original method:
def normalizeData(self, outer = 0.0):
"""Turns data into normalized ones where each datum is < 1.0,
and 1.0 = maximum radius. Adds 10% at outside edge by default"""
data = self.data
theMax = 0.0
for row in data:
for element in row:
assert element >=0, "Cannot do spider plots of negative
numbers!"
if element > theMax:
theMax = element
theMax = theMax * (1.0+outer)
scaled = []
for row in data:
scaledRow = []
for element in row:
scaledRow.append(element / theMax)
scaled.append(scaledRow)
return scaled
And a patched version:
def normalizeData(self, outer = 0.0):
"""Turns data into normalized ones where each datum is < 1.0,
and 1.0 = maximum radius. Adds 10% at outside edge by default"""
data = self.data
theMax = 0.0
for row in data:
for element in row:
assert element >=0, "Cannot do spider plots of negative
numbers!"
if element > theMax:
theMax = element
theMax = theMax * (1.0+outer)
if theMax == 0.0: # all values are zero
scaled = self.data
else:
scaled = []
for row in data:
scaledRow = []
for element in row:
scaledRow.append(element / theMax)
scaled.append(scaledRow)
return scaled
--
hilsen/regards Max M, Denmark
http://www.mxm.dk/
IT's Mad Science
More information about the reportlab-users
mailing list