From 5865995d0fb2790d19fb8daf34ea0d36b8ac447b Mon Sep 17 00:00:00 2001 From: Matus Telgarsky Date: Tue, 27 Jan 2015 13:42:04 -0500 Subject: [PATCH] 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). --- i3pystatus/core/util.py | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/i3pystatus/core/util.py b/i3pystatus/core/util.py index 098644c..1f7410f 100644 --- a/i3pystatus/core/util.py +++ b/i3pystatus/core/util.py @@ -375,19 +375,14 @@ def make_graph(values, upper_limit=100.0): """ 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_count = len(bar) - 1 - mn, mx = min(values), max(values) + mn, mx = min(values), float(upper_limit) extent = mx - mn if extent == 0: graph = '_' * len(values) else: - graph = ''.join(bar[int((n - mn) / extent * bar_count)] - for n in values[:len(values) - 1]) # Don't show the upper limit value. + graph = ''.join(bar[int((n - mn) / extent * bar_count)] for n in values) return graph