From 06b2d0c8e123034d1490321ee70f81015ff02525 Mon Sep 17 00:00:00 2001 From: ndwarshuis Date: Wed, 10 Nov 2021 12:37:23 -0500 Subject: [PATCH] ENH enhance percent source agreement for timeseries --- drawing/common.lua | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/drawing/common.lua b/drawing/common.lua index d0cbb14..a8ca27e 100644 --- a/drawing/common.lua +++ b/drawing/common.lua @@ -19,6 +19,7 @@ local timeseries = require 'timeseries' local scaled_timeseries = require 'scaled_timeseries' local style = require 'style' local source = require 'source' +local pure = require 'pure' -------------------------------------------------------------------------------- -- constants @@ -133,14 +134,14 @@ local _make_timeseries = function(x, y, w, h, label_config, update_freq) ) end -local _make_tagged_percent_timeseries = function(x, y, w, h, spacing, label, update_freq, format) +local _make_tagged_percent_timeseries = function(x, y, w, h, spacing, label, update_freq, _format) return { label = _left_text(geom.make_point(x, y), label), value = text_threshold.make_formatted( geom.make_point(x + w, y), nil, _right_text_style, - format, + _format, text_threshold.config(theme.CRITICAL_FG, 80) ), plot = M.make_percent_timeseries( @@ -236,17 +237,18 @@ M.tagged_percent_timeseries_draw_dynamic = function(obj, cr) timeseries.draw_dynamic(obj.plot, cr) end -M.tagged_percent_timeseries_set = function(obj, value) - text.set(obj.value, math.floor(value)) - timeseries.update(obj.plot, value * 0.01) +M.tagged_percent_timeseries_set = function(obj, percent) + local _percent = pure.round_percent(percent) + text.set(obj.value, _percent) + timeseries.update(obj.plot, _percent / 100) end -M.tagged_maybe_percent_timeseries_set = function(obj, value) - if value == false then +M.tagged_maybe_percent_timeseries_set = function(obj, percent) + if percent == false then text.set(obj.value, -1) timeseries.update(obj.plot, 0) else - M.tagged_percent_timeseries_set(obj, value) + M.tagged_percent_timeseries_set(obj, percent) end end