From 021ab834343b384468a7a770252095ef08c27ffe Mon Sep 17 00:00:00 2001 From: ndwarshuis Date: Tue, 13 Jul 2021 00:14:04 -0400 Subject: [PATCH] FIX graphics formatting --- drawing/Common.lua | 20 ++++++++++++++++---- drawing/Graphics.lua | 38 ++++++++++++++++++++------------------ 2 files changed, 36 insertions(+), 22 deletions(-) diff --git a/drawing/Common.lua b/drawing/Common.lua index eac4abf..0782c20 100644 --- a/drawing/Common.lua +++ b/drawing/Common.lua @@ -147,14 +147,14 @@ end -------------------------------------------------------------------------------- -- percent plot (label plot with percent signs and some indicator data above it) -M.initPercentPlot = function(x, y, w, h, spacing, label) +M.initPercentPlot_formatted = function(x, y, w, h, spacing, label, format) return { label = _left_text(_G_Widget_.make_point(x, y), label), value = _G_Widget_.formattedThresholdText( _G_Widget_.make_point(x + w, y), nil, M.right_text_style, - '%s%%', + format, _G_Widget_.threshold_text_style(_G_Patterns_.CRITICAL_FG, 80) ), plot = M.initThemedLabelPlot( @@ -167,6 +167,10 @@ M.initPercentPlot = function(x, y, w, h, spacing, label) } end +M.initPercentPlot = function(x, y, w, h, spacing, label) + return M.initPercentPlot_formatted(x, y, w, h, spacing, label, '%s%%') +end + M.percent_plot_draw_static = function(pp, cr) Text.draw(pp.label, cr) LabelPlot.draw_static(pp.plot, cr) @@ -177,9 +181,17 @@ M.percent_plot_draw_dynamic = function(pp, cr) LabelPlot.draw_dynamic(pp.plot, cr) end +-- TODO this is pretty confusing, nil means -1 which gets fed to any text +-- formatting functions M.percent_plot_set = function(pp, cr, value) - Text.set(pp.value, cr, math.floor(value)) - LabelPlot.update(pp.plot, value * 0.01) + local t = -1 + local p = 0 + if value ~= nil then + t = math.floor(value) + p = value * 0.01 + end + Text.set(pp.value, cr, t) + LabelPlot.update(pp.plot, p) end -------------------------------------------------------------------------------- diff --git a/drawing/Graphics.lua b/drawing/Graphics.lua index 96c64ac..bf31dec 100644 --- a/drawing/Graphics.lua +++ b/drawing/Graphics.lua @@ -14,6 +14,12 @@ local _TEXT_SPACING_ = 20 local _PLOT_SEC_BREAK_ = 20 local _PLOT_HEIGHT_ = 56 +local NA = 'N/A' + +local na_percent_format = function(x) + if x == -1 then return NA else return string.format('%s%%', x) end +end + local header = Common.Header( _G_INIT_DATA_.LEFT_X, _MODULE_Y_, @@ -43,7 +49,7 @@ local internal_temp = Common.initTextRowCrit( _INTERNAL_TEMP_Y_, _G_INIT_DATA_.SECTION_WIDTH, 'Internal Temperature', - '%s°C', + function(s) if s == -1 then return NA else return string.format('%s°C', s) end end, 80 ) @@ -75,35 +81,38 @@ local separator3 = Common.initSeparator( local _GPU_UTIL_Y_ = _SEP_Y_3_ + _SEPARATOR_SPACING_ -local gpu_util = Common.initPercentPlot( +local gpu_util = Common.initPercentPlot_formatted( _G_INIT_DATA_.LEFT_X, _GPU_UTIL_Y_, _G_INIT_DATA_.SECTION_WIDTH, _PLOT_HEIGHT_, _PLOT_SEC_BREAK_, - 'GPU Utilization' + 'GPU Utilization', + na_percent_format ) local _MEM_UTIL_Y_ = _GPU_UTIL_Y_ + _PLOT_HEIGHT_ + _PLOT_SEC_BREAK_ * 2 -local mem_util = Common.initPercentPlot( +local mem_util = Common.initPercentPlot_formatted( _G_INIT_DATA_.LEFT_X, _MEM_UTIL_Y_, _G_INIT_DATA_.SECTION_WIDTH, _PLOT_HEIGHT_, _PLOT_SEC_BREAK_, - 'Memory Utilization' + 'Memory Utilization', + na_percent_format ) local _VID_UTIL_Y_ = _MEM_UTIL_Y_ + _PLOT_HEIGHT_ + _PLOT_SEC_BREAK_ * 2 -local vid_util = Common.initPercentPlot( +local vid_util = Common.initPercentPlot_formatted( _G_INIT_DATA_.LEFT_X, _VID_UTIL_Y_, _G_INIT_DATA_.SECTION_WIDTH, _PLOT_HEIGHT_, _PLOT_SEC_BREAK_, - 'Video Utilization' + 'Video Utilization', + na_percent_format ) --[[ @@ -129,21 +138,14 @@ local NV_REGEX = '(%d+)\n'.. '(%d+),(%d+)\n'.. 'graphics=(%d+), memory=%d+, video=(%d+), PCIe=%d+\n' -local NA = 'N/A' - local nvidia_off = function(cr) - Common.text_row_crit_set(internal_temp, cr, NA) + Common.text_row_crit_set(internal_temp, cr, -1) Common.text_rows_set(clock_speed, cr, 1, NA) Common.text_rows_set(clock_speed, cr, 2, NA) - -- TODO refactor this - Text.set(gpu_util.value, cr, NA) - Text.set(mem_util.value, cr, NA) - Text.set(vid_util.value, cr, NA) - - LabelPlot.update(gpu_util.plot, 0) - LabelPlot.update(mem_util.plot, 0) - LabelPlot.update(vid_util.plot, 0) + Common.percent_plot_set(gpu_util, cr, nil) + Common.percent_plot_set(vid_util, cr, nil) + Common.percent_plot_set(mem_util, cr, nil) end local gpu_bus_ctrl = '/sys/bus/pci/devices/0000:01:00.0/power/control'