liquid_feedback_frontend

annotate env/ui/bargraph.lua @ 500:03c205fc17f0

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

Impressum / About Us