Hello, awesome developers! I'm out of awesome development business for quite a long time, as far as I've chosen user's role (there're a lot of other job to do here, so I've got no time to work on awesome), but I've updated recently to awesome v3.4 from git and noticed new stack mode for awful.widget.graph. I also noticed it doesn't scale data up to max_value setting, but I needed it as I want to output graph for inbound and outbound network traffic with different colors on the same graph, data are feed in bytes-per-second.
So I prepared some simple and straighforward patch to make stacked mode graph widget support max_value setting. Hope it will be useful and rest in main awesome git repo one day. -- Best regards, Konstantin Stepanov
From dd656a8e86613c53146bae4271722393d022fbee Mon Sep 17 00:00:00 2001 From: Konstantin Stepanov <[email protected]> Date: Sun, 25 Jul 2010 14:48:14 +0300 Subject: [PATCH] stack graph mode works with max_value --- lib/awful/widget/graph.lua.in | 25 ++++++++++++++++++------- 1 files changed, 18 insertions(+), 7 deletions(-) diff --git a/lib/awful/widget/graph.lua.in b/lib/awful/widget/graph.lua.in index d5e2b81..53ec732 100644 --- a/lib/awful/widget/graph.lua.in +++ b/lib/awful/widget/graph.lua.in @@ -85,6 +85,8 @@ local properties = { "width", "height", "border_color", "stack", local function update(graph) -- Create new empty image local img = capi.image.argb32(data[graph].width, data[graph].height, nil) + local max_value = data[graph].max_value + local values = data[graph].values local border_width = 0 if data[graph].border_color then @@ -93,6 +95,17 @@ local function update(graph) -- Draw a stacked graph if data[graph].stack then + + if data[graph].scale then + for _, v in ipairs(values) do + for __, sv in ipairs(v) do + if sv > max_value then + max_value = sv + end + end + end + end + -- Draw the background first img:draw_rectangle(border_width, border_width, data[graph].width - (2 * border_width), @@ -105,14 +118,14 @@ local function update(graph) if data[graph].stack_colors then for idx, color in ipairs(data[graph].stack_colors) do - local values = data[graph].values[idx] - if values and i < #values then - local value = values[#values - i] + rel_i + local stack_values = values[idx] + if stack_values and i < #stack_values then + local value = stack_values[#stack_values - i] + rel_i img:draw_line(rel_x, border_width - 1 + - math.ceil((data[graph].height - 2 * border_width) * (1 - rel_i)), + math.ceil((data[graph].height - 2 * border_width) * (1 - (rel_i / max_value))), rel_x, border_width - 1 + - math.ceil((data[graph].height - 2 * border_width) * (1 - value)), + math.ceil((data[graph].height - 2 * border_width) * (1 - (value / max_value))), color or "red") rel_i = value end @@ -120,8 +133,6 @@ local function update(graph) end end else - local values = data[graph].values - local max_value = data[graph].max_value if data[graph].scale then for _, v in ipairs(values) do -- 1.7.1
signature.asc
Description: Digital signature
