awful.widget.graph: don't draw bg color over fg color
behavior before: draw fg color everywhere and draw each value inverted as bg color. if not enough values available "remove" the free area (draw a big rectangle with bg color over it). behavior now: draw each value onto background as fg stroke. Signed-off-by: Uli Schlachter <psychon@znc.in>
This commit is contained in:
parent
f41590e19c
commit
cafd28027f
|
@ -77,6 +77,13 @@ function draw(graph, wibox, cr, width, height)
|
||||||
|
|
||||||
cr:set_line_width(1)
|
cr:set_line_width(1)
|
||||||
|
|
||||||
|
-- Draw the background first
|
||||||
|
cr:rectangle(border_width, border_width,
|
||||||
|
width - (2 * border_width),
|
||||||
|
height)
|
||||||
|
cr:set_source(color(data[graph].background_color or "#000000aa"))
|
||||||
|
cr:fill()
|
||||||
|
|
||||||
-- Draw a stacked graph
|
-- Draw a stacked graph
|
||||||
if data[graph].stack then
|
if data[graph].stack then
|
||||||
|
|
||||||
|
@ -90,23 +97,15 @@ function draw(graph, wibox, cr, width, height)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Draw the background first
|
|
||||||
cr:rectangle(border_width, border_width,
|
|
||||||
width - (2 * border_width),
|
|
||||||
height)
|
|
||||||
cr:set_source(color(data[graph].background_color or "#000000aa"))
|
|
||||||
cr:fill()
|
|
||||||
|
|
||||||
for i = 0, width - (2 * border_width) do
|
for i = 0, width - (2 * border_width) do
|
||||||
local rel_i = 0
|
local rel_i = 0
|
||||||
local rel_x = width - border_width - i - 0.5
|
local rel_x = border_width + i
|
||||||
|
|
||||||
if data[graph].stack_colors then
|
if data[graph].stack_colors then
|
||||||
for idx, col in ipairs(data[graph].stack_colors) do
|
for idx, col in ipairs(data[graph].stack_colors) do
|
||||||
local stack_values = values[idx]
|
local stack_values = values[idx]
|
||||||
if stack_values and i < #stack_values then
|
if stack_values and i < #stack_values then
|
||||||
local value = stack_values[#stack_values - i] + rel_i
|
local value = stack_values[#stack_values - i] + rel_i
|
||||||
|
|
||||||
cr:move_to(rel_x, border_width - 0.5 +
|
cr:move_to(rel_x, border_width - 0.5 +
|
||||||
(height - 2 * border_width) * (1 - (rel_i / max_value)))
|
(height - 2 * border_width) * (1 - (rel_i / max_value)))
|
||||||
cr:line_to(rel_x, border_width - 0.5 +
|
cr:line_to(rel_x, border_width - 0.5 +
|
||||||
|
@ -127,12 +126,6 @@ function draw(graph, wibox, cr, width, height)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
cr:rectangle(border_width, border_width,
|
|
||||||
width - (2 * border_width),
|
|
||||||
height - (2 * border_width))
|
|
||||||
cr:set_source(color(data[graph].color or "#ff0000"))
|
|
||||||
cr:fill()
|
|
||||||
|
|
||||||
-- Draw the background on no value
|
-- Draw the background on no value
|
||||||
if #values ~= 0 then
|
if #values ~= 0 then
|
||||||
-- Draw reverse
|
-- Draw reverse
|
||||||
|
@ -140,26 +133,16 @@ function draw(graph, wibox, cr, width, height)
|
||||||
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
|
||||||
cr:move_to(width - border_width - i - 0.5,
|
cr:move_to(border_width + i - 0.5, border_width - 0.5 +
|
||||||
border_width - 0.5 +
|
(height - 2 * border_width) * (1 - value))
|
||||||
(height - 2 * border_width) * (1 - value))
|
cr:line_to(border_width + i - 0.5, border_width +
|
||||||
cr:line_to(width - border_width - i - 0.5,
|
(height - 2 * border_width))
|
||||||
border_width - 1)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
cr:set_source(color(data[graph].background_color or "#000000aa"))
|
cr:set_source(color(data[graph].color or "#ff0000"))
|
||||||
cr:stroke()
|
cr:stroke()
|
||||||
end
|
end
|
||||||
|
|
||||||
-- If we didn't draw values in full length, draw a square
|
|
||||||
-- over the last, left, part to reset everything to 0
|
|
||||||
if #values < width - (2 * border_width) then
|
|
||||||
cr:rectangle(border_width, border_width,
|
|
||||||
width - (2 * border_width) - #values,
|
|
||||||
height - (2 * border_width))
|
|
||||||
cr:set_source(color(data[graph].background_color or "#000000aa"))
|
|
||||||
cr:fill()
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Draw the border last so that it overlaps already drawn values
|
-- Draw the border last so that it overlaps already drawn values
|
||||||
|
|
Loading…
Reference in New Issue