diff --git a/core b/core index 760beff..1f4d9a5 160000 --- a/core +++ b/core @@ -1 +1 @@ -Subproject commit 760beffe2710d863e2e18063fff50556fa1c054c +Subproject commit 1f4d9a574c8887e084bb1acbde3dc99392da084c diff --git a/drawing/Common.lua b/drawing/Common.lua index bfb370c..8f69a12 100644 --- a/drawing/Common.lua +++ b/drawing/Common.lua @@ -134,7 +134,7 @@ M.default_plot_style = Startup.plot_style( M.percent_label_style = Startup.label_style( Theme.INACTIVE_TEXT_FG, M.label_font_spec, - function(z) return Util.round_to_string(z * 100)..'%' end + function(_) return function(z) return Util.round_to_string(z * 100)..'%' end end ) M.initThemedLabelPlot = function(x, y, w, h, label_style, update_freq) @@ -200,6 +200,34 @@ end -------------------------------------------------------------------------------- -- scaled plot +-- Generate a format string for labels on y axis of plots. If the max of the +-- plot if numerically less than the number of grid lines, this means that +-- some number of decimal places are necessary to accurately display the number. +-- Note that this for now only works when the number of y grid lines if 4, as +-- it gives enough resolution for 1, 0.75, 0.5, and 0.25 but no more +M.y_label_format_string = function(plot_max, unit) + local num_fmt + if plot_max < 2 then + num_fmt = '%.2f' + elseif plot_max < 4 then + num_fmt = '%.1f' + else + num_fmt = '%.0f' + end + return string.format('%s %s', num_fmt, unit) +end + +M.converted_y_label_format_generator = function(unit) + return function(plot_max) + local new_prefix, new_max = Util.convert_data_val(plot_max) + local conversion_factor = plot_max / new_max + local fmt = M.y_label_format_string(new_max, new_prefix..unit..'/s') + return function(bytes) + return string.format(fmt, bytes / conversion_factor) + end + end +end + M.base_2_scale_data = function(m) return Startup.scale_data(2, m, 0.9) end diff --git a/drawing/Network.lua b/drawing/Network.lua index d343e95..1a3e269 100644 --- a/drawing/Network.lua +++ b/drawing/Network.lua @@ -5,10 +5,9 @@ local Geometry = require 'Geometry' return function(update_freq) local PLOT_SEC_BREAK = 20 local PLOT_HEIGHT = 56 + -- TODO ensure these interfaces actually exist local INTERFACES = {'enp7s0f1', 'wlp0s20f3'} - local __math_floor = math.floor - ----------------------------------------------------------------------------- -- header @@ -22,11 +21,6 @@ return function(update_freq) ----------------------------------------------------------------------------- -- download plot - local network_label_function = function(bits) - local new_unit, new_value = Util.convert_data_val(bits) - return __math_floor(new_value)..' '..new_unit..'b/s' - end - local value_format_function = function(bits) local unit, value = Util.convert_data_val(bits) return Util.precision_round_to_string(value, 3)..' '..unit..'b/s' @@ -39,7 +33,7 @@ return function(update_freq) Geometry.SECTION_WIDTH, PLOT_HEIGHT, value_format_function, - network_label_function, + Common.converted_y_label_format_generator('b'), PLOT_SEC_BREAK, label, 2, diff --git a/drawing/Power.lua b/drawing/Power.lua index b203f1c..893771a 100644 --- a/drawing/Power.lua +++ b/drawing/Power.lua @@ -23,10 +23,13 @@ return function(update_freq) ----------------------------------------------------------------------------- -- package 0 power plot - local power_label_function = function(watts) return watts..' W' end + local power_label_function = function(plot_max) + local fmt = Common.y_label_format_string(plot_max, 'W') + return function(watts) return string.format(fmt, watts) end + end local power_format_function = function(watts) - return Util.precision_round_to_string(watts, 3).." W" + return Util.precision_round_to_string(watts, 3)..' W' end local build_plot = function(y, label, format_fun) diff --git a/drawing/ReadWrite.lua b/drawing/ReadWrite.lua index 6496f55..041c9f8 100644 --- a/drawing/ReadWrite.lua +++ b/drawing/ReadWrite.lua @@ -31,10 +31,14 @@ return function(update_freq) ----------------------------------------------------------------------------- -- reads - local io_label_function = function(bytes) - local new_unit, new_value = Util.convert_data_val(bytes) - return __math_floor(new_value)..' '..new_unit..'B/s' - end + -- local io_label_format_fun_generator = function(plot_max) + -- local new_unit, new_max = Util.convert_data_val(plot_max) + -- local conversion_factor = plot_max / new_max + -- local fmt = Common.y_label_format_string(new_max, new_unit..'B/s') + -- return function(bytes) + -- return string.format(fmt, bytes / conversion_factor) + -- end + -- end local format_value_function = function(bps) local unit, value = Util.convert_data_val(bps) @@ -48,7 +52,7 @@ return function(update_freq) Geometry.SECTION_WIDTH, PLOT_HEIGHT, format_value_function, - io_label_function, + Common.converted_y_label_format_generator('B'), PLOT_SEC_BREAK, label, 2,