awful.widget.graph: Add a "scale" property

If this is set to true (default is false), then the graph widget automatically
scales its content to make it fit exactly. If "max_value" is also set, this is
the minimum "height" the graph will use.

This can be useful for graphes which monitor things like network bandwidth
which can vary a lot.

Signed-off-by: Uli Schlachter <psychon@znc.in>
Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
Uli Schlachter 2009-06-08 19:13:44 +02:00 committed by Julien Danjou
parent 26f1904bc7
commit 22ac877f46
1 changed files with 21 additions and 2 deletions

View File

@ -51,14 +51,22 @@ local data = setmetatable({}, { __mode = "k" })
-- @param color The graph background color.
--- Set the maximum value the graph should handle.
-- If "scale" is also set, the graph never scales up below this value, but it
-- automatically scales down to make all data fit.
-- @name set_max_value
-- @class function
-- @param graph The graph.
-- @param value The value.
--- Set the graph to automatically scale its values. Default is false.
-- @name set_scale
-- @class function
-- @param graph The graph.
-- @param scale A boolean value
local properties = { "width", "height", "border_color",
"gradient_colors", "gradient_angle", "color",
"background_color", "max_value" }
"background_color", "max_value", "scale" }
local function update(graph)
-- Create new empty image
@ -75,6 +83,14 @@ local function update(graph)
local values = data[graph].values
local max_value = data[graph].max_value
if data[graph].scale then
for _, v in ipairs(values) do
if v > max_value then
max_value = v
end
end
end
-- Draw background
-- Draw full gradient
if data[graph].gradient_colors then
@ -128,7 +144,10 @@ local function add_value(graph, value)
local value = value or 0
local max_value = data[graph].max_value
value = math.min(max_value, math.max(0, value))
value = math.max(0, value)
if not data[graph].scale then
value = math.min(max_value, value)
end
table.insert(data[graph].values, value)