Make awful.widget.graph work with zero values

First, we need to actually draw values which are zero, else the background
"shines through". Since this breaks the border (it draws over the border),
drawing the border needs to be done later.

Signed-off-by: Uli Schlachter <psychon@znc.in>
Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
Uli Schlachter 2009-07-03 17:29:18 +02:00 committed by Julien Danjou
parent 7d143d4d71
commit 855e2b9cdf
1 changed files with 7 additions and 4 deletions

View File

@ -74,9 +74,6 @@ local function update(graph)
local border_width = 0 local border_width = 0
if data[graph].border_color then if data[graph].border_color then
-- Draw border
img:draw_rectangle(0, 0, data[graph].width, data[graph].height,
false, data[graph].border_color or "white")
border_width = 1 border_width = 1
end end
@ -111,7 +108,7 @@ local function update(graph)
-- Draw reverse -- Draw reverse
for i = 0, #values - 1 do for i = 0, #values - 1 do
local value = values[#values - i] local value = values[#values - i]
if value > 0 then if value >= 0 then
value = value / max_value value = value / max_value
img:draw_line(data[graph].width - border_width - i - 1, img:draw_line(data[graph].width - border_width - i - 1,
border_width + ((data[graph].height - 2 * border_width) * (1 - value)), border_width + ((data[graph].height - 2 * border_width) * (1 - value)),
@ -131,6 +128,12 @@ local function update(graph)
true, data[graph].background_color or "#000000aa") true, data[graph].background_color or "#000000aa")
end end
-- Draw the border last so that it overlaps other stuff
if data[graph].border_color then
-- Draw border
img:draw_rectangle(0, 0, data[graph].width, data[graph].height,
false, data[graph].border_color or "white")
end
-- Update the image -- Update the image
graph.widget.image = img graph.widget.image = img