simplify util::make_graph
rather than appending the upper limit, use it as the maximum. In the process fixes a display bug when extent == 0, and simplifies the addition of other drawing styles (which need not also work around this values logic).
This commit is contained in:
parent
7c3f545438
commit
5865995d0f
@ -375,19 +375,14 @@ def make_graph(values, upper_limit=100.0):
|
|||||||
"""
|
"""
|
||||||
values = [float(n) for n in values]
|
values = [float(n) for n in values]
|
||||||
|
|
||||||
# Add the upper limit to the end of the array so the graph doesn't distort
|
|
||||||
# as high values drop off the end.
|
|
||||||
values.append(float(upper_limit))
|
|
||||||
|
|
||||||
bar = u'_▁▂▃▄▅▆▇█'
|
bar = u'_▁▂▃▄▅▆▇█'
|
||||||
bar_count = len(bar) - 1
|
bar_count = len(bar) - 1
|
||||||
mn, mx = min(values), max(values)
|
mn, mx = min(values), float(upper_limit)
|
||||||
extent = mx - mn
|
extent = mx - mn
|
||||||
if extent == 0:
|
if extent == 0:
|
||||||
graph = '_' * len(values)
|
graph = '_' * len(values)
|
||||||
else:
|
else:
|
||||||
graph = ''.join(bar[int((n - mn) / extent * bar_count)]
|
graph = ''.join(bar[int((n - mn) / extent * bar_count)] for n in values)
|
||||||
for n in values[:len(values) - 1]) # Don't show the upper limit value.
|
|
||||||
return graph
|
return graph
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user