Debian Codegraph @

obvious/lib/widget/graph.lua

raw symbols SCIP
1 -----------------------------------
2 -- Author: Uli Schlachter --
3 -- Copyright 2009 Uli Schlachter --
4 -----------------------------------
5
6 local beautiful = require("beautiful")
7 local awful = {
8 widget = require("awful.widget")
9 }
10 local setmetatable = setmetatable
11
12 local function graph(layout, scale)
13 local theme = beautiful.get()
14 local color = theme.graph_fg_color or theme.widget_fg_color or theme.fg_normal
15 local back = theme.graph_bg_color or theme.widget_bg_color or theme.bg_normal
16 local border= theme.graph_border or theme.widget_border or theme.border_normal
17 local width = theme.graph_width or theme.widget_width
18
19 local widget = awful.widget.graph({ layout = layout })
20 widget:set_color(color)
21 widget:set_border_color(border)
22 widget:set_background_color(back)
23
24 if width then
25 widget:set_width(width)
26 end
27
28 if scale then
29 widget:set_scale(true)
30 end
31
32 return widget
33 end
34
35 local function create(data, layout)
36 local scale = true
37 if data.max then
38 scale = false
39 end
40
41 local widget = graph(layout, scale)
42
43 widget.update = function(widget)
44 local max = widget.data.max or 1
45 local val = widget.data:get() or max
46 widget:add_value(val / max)
47 end
48
49 widget.data = data
50
51 return widget
52 end
53
54 return setmetatable({
55 create = create,
56 }, { __call = function (_, ...) return graph(...) end })
57
58 -- vim:ft=lua:ts=2:sw=2:sts=2:tw=80:et