liquid_feedback_frontend
diff env/ui/bargraph.lua @ 504:811bf260f7cf
Show direct voting majority in bargraph, set all bar elements widths to multiples of 1px
author | bsw |
---|---|
date | Wed Mar 21 20:16:19 2012 +0100 (2012-03-21) |
parents | 03c205fc17f0 |
children | 701a5cf6b067 |
line diff
1.1 --- a/env/ui/bargraph.lua Wed Mar 21 19:50:58 2012 +0100 1.2 +++ b/env/ui/bargraph.lua Wed Mar 21 20:16:19 2012 +0100 1.3 @@ -15,16 +15,25 @@ 1.4 local at_least_one_bar = false 1.5 local quorum = args.quorum and args.quorum * args.width / args.max_value or nil 1.6 local length = 0 1.7 + local rest = 0 1.8 + local last_visiable_bar = 0 1.9 + for i, bar in ipairs(args.bars) do 1.10 + if bar.value > 0 then 1.11 + last_visiable_bar = i 1.12 + end 1.13 + end 1.14 for i, bar in ipairs(args.bars) do 1.15 if bar.value > 0 then 1.16 at_least_one_bar = true 1.17 local value = bar.value * args.width / args.max_value 1.18 if quorum and quorum < length + value then 1.19 local dlength = math.max(quorum - length - 1, 0) 1.20 + local dlength_abs = math.floor(dlength) 1.21 + local rest = rest + dlength - dlength_abs 1.22 if dlength > 0 then 1.23 ui.container{ 1.24 attr = { 1.25 - style = "width: " .. tostring(dlength) .. "px; background-color: " .. bar.color .. ";", 1.26 + style = "width: " .. tostring(dlength_abs) .. "px; background-color: " .. bar.color .. ";", 1.27 }, 1.28 content = function() slot.put(" ") end 1.29 } 1.30 @@ -40,10 +49,15 @@ 1.31 value = value - dlength 1.32 quorum = nil 1.33 end 1.34 - length = length + value 1.35 + local value_abs = math.floor(value) 1.36 + rest = rest + value - value_abs 1.37 + if i == last_visiable_bar then 1.38 + value_abs = value_abs + rest 1.39 + end 1.40 + length = length + value_abs 1.41 ui.container{ 1.42 attr = { 1.43 - style = "width: " .. tostring(value) .. "px; background-color: " .. bar.color .. ";", 1.44 + style = "width: " .. tostring(value_abs) .. "px; background-color: " .. bar.color .. ";", 1.45 }, 1.46 content = function() slot.put(" ") end 1.47 }