util::make_graph lower_limit parameter
None is now a choice for lower_limit and upper_limit as well, so that the graph can scale as before. For cpu_usage_graph and network, rather than exposing lower_limit in the interface, 0.0 is used as a default, since it is already used implicitly when choosing colors.
This commit is contained in:
parent
82db7a87a2
commit
ac2b494401
@ -365,18 +365,23 @@ def internet():
|
|||||||
return False
|
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.
|
Draws a graph made of unicode characters.
|
||||||
|
|
||||||
:param values: An array of values to graph.
|
: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').
|
:param style: Drawing style ('blocks', 'braille-fill', 'braille-peak', or 'braille-snake').
|
||||||
:returns: Bar as a string
|
:returns: Bar as a string
|
||||||
"""
|
"""
|
||||||
|
|
||||||
values = [float(n) for n in values]
|
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
|
extent = mx - mn
|
||||||
|
|
||||||
if style == 'blocks':
|
if style == 'blocks':
|
||||||
bar = u'_▁▂▃▄▅▆▇█'
|
bar = u'_▁▂▃▄▅▆▇█'
|
||||||
bar_count = len(bar) - 1
|
bar_count = len(bar) - 1
|
||||||
|
@ -46,7 +46,7 @@ class CpuUsageGraph(CpuUsage, ColorRangeModule):
|
|||||||
self.cpu_readings.insert(0, core_reading)
|
self.cpu_readings.insert(0, core_reading)
|
||||||
self.cpu_readings = self.cpu_readings[:self.graph_width]
|
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})
|
format_options.update({'cpu_graph': graph})
|
||||||
|
|
||||||
color = self.get_gradient(core_reading, self.colors)
|
color = self.get_gradient(core_reading, self.colors)
|
||||||
|
@ -331,7 +331,7 @@ class Network(IntervalModule, ColorRangeModule):
|
|||||||
# Cycle array by inserting at the start and chopping off the last element
|
# Cycle array by inserting at the start and chopping off the last element
|
||||||
self.kbs_arr.insert(0, kbs)
|
self.kbs_arr.insert(0, kbs)
|
||||||
self.kbs_arr = self.kbs_arr[:self.graph_width]
|
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):
|
def run(self):
|
||||||
format_values = dict(kbs="", network_graph="", bytes_sent="", bytes_recv="", packets_sent="", packets_recv="",
|
format_values = dict(kbs="", network_graph="", bytes_sent="", bytes_recv="", packets_sent="", packets_recv="",
|
||||||
|
Loading…
Reference in New Issue
Block a user