liquid_feedback_frontend
view env/ui/bargraph.lua @ 172:165f4bd02cf3
don't show the first draft of a new initiative as a new draft event in the timeline
new draft should only show changes of drafts drafts of new initiatives as they are handled by the new initiative event
new draft should only show changes of drafts drafts of new initiatives as they are handled by the new initiative event
| author | Daniel Poelzleithner <poelzi@poelzi.org> | 
|---|---|
| date | Sun Oct 10 19:40:32 2010 +0200 (2010-10-10) | 
| parents | 5d797c6706d5 | 
| children | 03c205fc17f0 | 
 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(" ") end
    30               }
    31             end
    32             ui.container{
    33               attr = {
    34                 style = "width: 1px; background-color: " .. (args.quorum_color or "blue") ..";",
    35               },
    36               content = function() slot.put(" ") end
    37             }
    38             length = dlength + 1
    39             value = value - dlength
    40             quorum = nil
    41           end
    42           length = length + value
    43           ui.container{
    44             attr = {
    45               style = "width: " .. tostring(value) .. "px; background-color: " .. bar.color .. ";",
    46             },
    47             content = function() slot.put(" ") end
    48           }
    49         end
    50       end
    51       if not at_least_one_bar then
    52         slot.put(" ")
    53       end
    54     end
    55   }
    56 end
