# HG changeset patch # User bsw # Date 1332357379 -3600 # Node ID 811bf260f7cf0512e98c0678d9440564f87a930b # Parent 78c92775722be82e44cde46bfe19c17a60741cbd Show direct voting majority in bargraph, set all bar elements widths to multiples of 1px diff -r 78c92775722b -r 811bf260f7cf app/main/initiative/_list_element.lua --- a/app/main/initiative/_list_element.lua Wed Mar 21 19:50:58 2012 +0100 +++ b/app/main/initiative/_list_element.lua Wed Mar 21 20:16:19 2012 +0100 @@ -24,6 +24,8 @@ ui.bargraph{ max_value = max_value, width = 100, + quorum = max_value * initiative.issue.policy.direct_majority_num / initiative.issue.policy.direct_majority_den, + quorum_color = "#00f", bars = { { color = "#0a0", value = initiative.positive_votes }, { color = "#aaa", value = max_value - initiative.negative_votes - initiative.positive_votes }, diff -r 78c92775722b -r 811bf260f7cf env/ui/bargraph.lua --- a/env/ui/bargraph.lua Wed Mar 21 19:50:58 2012 +0100 +++ b/env/ui/bargraph.lua Wed Mar 21 20:16:19 2012 +0100 @@ -15,16 +15,25 @@ local at_least_one_bar = false local quorum = args.quorum and args.quorum * args.width / args.max_value or nil local length = 0 + local rest = 0 + local last_visiable_bar = 0 + for i, bar in ipairs(args.bars) do + if bar.value > 0 then + last_visiable_bar = i + end + end for i, bar in ipairs(args.bars) do if bar.value > 0 then at_least_one_bar = true local value = bar.value * args.width / args.max_value if quorum and quorum < length + value then local dlength = math.max(quorum - length - 1, 0) + local dlength_abs = math.floor(dlength) + local rest = rest + dlength - dlength_abs if dlength > 0 then ui.container{ attr = { - style = "width: " .. tostring(dlength) .. "px; background-color: " .. bar.color .. ";", + style = "width: " .. tostring(dlength_abs) .. "px; background-color: " .. bar.color .. ";", }, content = function() slot.put(" ") end } @@ -40,10 +49,15 @@ value = value - dlength quorum = nil end - length = length + value + local value_abs = math.floor(value) + rest = rest + value - value_abs + if i == last_visiable_bar then + value_abs = value_abs + rest + end + length = length + value_abs ui.container{ attr = { - style = "width: " .. tostring(value) .. "px; background-color: " .. bar.color .. ";", + style = "width: " .. tostring(value_abs) .. "px; background-color: " .. bar.color .. ";", }, content = function() slot.put(" ") end }