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:
parent
26f1904bc7
commit
22ac877f46
|
@ -51,14 +51,22 @@ local data = setmetatable({}, { __mode = "k" })
|
||||||
-- @param color The graph background color.
|
-- @param color The graph background color.
|
||||||
|
|
||||||
--- Set the maximum value the graph should handle.
|
--- 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
|
-- @name set_max_value
|
||||||
-- @class function
|
-- @class function
|
||||||
-- @param graph The graph.
|
-- @param graph The graph.
|
||||||
-- @param value The value.
|
-- @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",
|
local properties = { "width", "height", "border_color",
|
||||||
"gradient_colors", "gradient_angle", "color",
|
"gradient_colors", "gradient_angle", "color",
|
||||||
"background_color", "max_value" }
|
"background_color", "max_value", "scale" }
|
||||||
|
|
||||||
local function update(graph)
|
local function update(graph)
|
||||||
-- Create new empty image
|
-- Create new empty image
|
||||||
|
@ -75,6 +83,14 @@ local function update(graph)
|
||||||
local values = data[graph].values
|
local values = data[graph].values
|
||||||
local max_value = data[graph].max_value
|
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 background
|
||||||
-- Draw full gradient
|
-- Draw full gradient
|
||||||
if data[graph].gradient_colors then
|
if data[graph].gradient_colors then
|
||||||
|
@ -128,7 +144,10 @@ local function add_value(graph, value)
|
||||||
|
|
||||||
local value = value or 0
|
local value = value or 0
|
||||||
local max_value = data[graph].max_value
|
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)
|
table.insert(data[graph].values, value)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue