diff --git a/i3pystatus/core/util.py b/i3pystatus/core/util.py index d705b8d..614fd6d 100644 --- a/i3pystatus/core/util.py +++ b/i3pystatus/core/util.py @@ -365,18 +365,23 @@ def internet(): return False -def make_graph(values, upper_limit=100.0, style="blocks"): +def make_graph(values, lower_limit=0.0, upper_limit=100.0, style="blocks"): """ Draws a graph made of unicode characters. :param values: An array of values to graph. - :param upper_limit: Maximum value for the y axis. + :param lower_limit: Minimum value for the y axis (or None for dynamic). + :param upper_limit: Maximum value for the y axis (or None for dynamic). :param style: Drawing style ('blocks', 'braille-fill', 'braille-peak', or 'braille-snake'). :returns: Bar as a string """ + values = [float(n) for n in values] - mn, mx = min(values), max(max(values), float(upper_limit)) + mn, mx = min(values), max(values) + mn = mn if lower_limit == None else min(mn, float(lower_limit)) + mx = mx if upper_limit == None else max(mx, float(upper_limit)) extent = mx - mn + if style == 'blocks': bar = u'_▁▂▃▄▅▆▇█' bar_count = len(bar) - 1 diff --git a/i3pystatus/cpu_usage_graph.py b/i3pystatus/cpu_usage_graph.py index e648db1..4776348 100644 --- a/i3pystatus/cpu_usage_graph.py +++ b/i3pystatus/cpu_usage_graph.py @@ -46,7 +46,7 @@ class CpuUsageGraph(CpuUsage, ColorRangeModule): self.cpu_readings.insert(0, core_reading) self.cpu_readings = self.cpu_readings[:self.graph_width] - graph = make_graph(self.cpu_readings, 100.0, self.graph_style) + graph = make_graph(self.cpu_readings, 0.0, 100.0, self.graph_style) format_options.update({'cpu_graph': graph}) color = self.get_gradient(core_reading, self.colors) diff --git a/i3pystatus/network.py b/i3pystatus/network.py index 303838d..afb9ddb 100644 --- a/i3pystatus/network.py +++ b/i3pystatus/network.py @@ -331,7 +331,7 @@ class Network(IntervalModule, ColorRangeModule): # Cycle array by inserting at the start and chopping off the last element self.kbs_arr.insert(0, kbs) self.kbs_arr = self.kbs_arr[:self.graph_width] - return make_graph(self.kbs_arr, self.upper_limit, self.graph_style) + return make_graph(self.kbs_arr, 0.0, self.upper_limit, self.graph_style) def run(self): format_values = dict(kbs="", network_graph="", bytes_sent="", bytes_recv="", packets_sent="", packets_recv="",