liquid_feedback_frontend

view env/ui/bargraph.lua @ 502:e26b04ef230a

Do not force micro avatars to be quadratic
author bsw
date Wed Mar 21 19:50:24 2012 +0100 (2012-03-21)
parents 03c205fc17f0
children 811bf260f7cf
line source
1 function ui.bargraph(args)
2 local text = ""
3 for i, bar in ipairs(args.bars) do
4 if #text > 0 then
5 text = text .. " / "
6 end
7 text = text .. tostring(bar.value)
8 end
9 ui.container{
10 attr = {
11 class = args.class or "bargraph",
12 title = tostring(text)
13 },
14 content = function()
15 local at_least_one_bar = false
16 local quorum = args.quorum and args.quorum * args.width / args.max_value or nil
17 local length = 0
18 for i, bar in ipairs(args.bars) do
19 if bar.value > 0 then
20 at_least_one_bar = true
21 local value = bar.value * args.width / args.max_value
22 if quorum and quorum < length + value then
23 local dlength = math.max(quorum - length - 1, 0)
24 if dlength > 0 then
25 ui.container{
26 attr = {
27 style = "width: " .. tostring(dlength) .. "px; background-color: " .. bar.color .. ";",
28 },
29 content = function() slot.put("&nbsp;") end
30 }
31 end
32 ui.container{
33 attr = {
34 class = "quorum",
35 style = "width: 1px; background-color: " .. (args.quorum_color or "blue") ..";",
36 },
37 content = function() slot.put("") end
38 }
39 length = dlength + 1
40 value = value - dlength
41 quorum = nil
42 end
43 length = length + value
44 ui.container{
45 attr = {
46 style = "width: " .. tostring(value) .. "px; background-color: " .. bar.color .. ";",
47 },
48 content = function() slot.put("&nbsp;") end
49 }
50 end
51 end
52 if not at_least_one_bar then
53 slot.put("&nbsp;")
54 end
55 end
56 }
57 end

Impressum / About Us