liquid_feedback_frontend
annotate env/ui/bargraph.lua @ 159:5d797c6706d5
implement quorum display
show the initiative quorum as a small 1px line in bargraph
allow to update your support on the diff page
better linked title in diff page
show absolute quorum numbers in detail pages of issue and initiative
show the initiative quorum as a small 1px line in bargraph
allow to update your support on the diff page
better linked title in diff page
show absolute quorum numbers in detail pages of issue and initiative
author | Daniel Poelzleithner <poelzi@poelzi.org> |
---|---|
date | Sat Oct 09 03:42:48 2010 +0200 (2010-10-09) |
parents | 00d1004545f1 |
children | 03c205fc17f0 |
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(" ") end |
poelzi@159 | 30 } |
poelzi@159 | 31 end |
poelzi@159 | 32 ui.container{ |
poelzi@159 | 33 attr = { |
poelzi@159 | 34 style = "width: 1px; background-color: " .. (args.quorum_color or "blue") ..";", |
poelzi@159 | 35 }, |
poelzi@159 | 36 content = function() slot.put(" ") end |
poelzi@159 | 37 } |
poelzi@159 | 38 length = dlength + 1 |
poelzi@159 | 39 value = value - dlength |
poelzi@159 | 40 quorum = nil |
poelzi@159 | 41 end |
poelzi@159 | 42 length = length + value |
bsw@2 | 43 ui.container{ |
bsw@2 | 44 attr = { |
bsw@2 | 45 style = "width: " .. tostring(value) .. "px; background-color: " .. bar.color .. ";", |
bsw@2 | 46 }, |
bsw@2 | 47 content = function() slot.put(" ") end |
bsw@2 | 48 } |
bsw@2 | 49 end |
bsw/jbe@0 | 50 end |
bsw/jbe@19 | 51 if not at_least_one_bar then |
bsw/jbe@19 | 52 slot.put(" ") |
bsw/jbe@19 | 53 end |
bsw/jbe@0 | 54 end |
bsw/jbe@0 | 55 } |
bsw/jbe@0 | 56 end |