liquid_feedback_frontend

changeset 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 78c92775722b
children 160b859e7180
files app/main/initiative/_list_element.lua env/ui/bargraph.lua
line diff
     1.1 --- a/app/main/initiative/_list_element.lua	Wed Mar 21 19:50:58 2012 +0100
     1.2 +++ b/app/main/initiative/_list_element.lua	Wed Mar 21 20:16:19 2012 +0100
     1.3 @@ -24,6 +24,8 @@
     1.4            ui.bargraph{
     1.5              max_value = max_value,
     1.6              width = 100,
     1.7 +            quorum = max_value * initiative.issue.policy.direct_majority_num / initiative.issue.policy.direct_majority_den,
     1.8 +            quorum_color = "#00f",
     1.9              bars = {
    1.10                { color = "#0a0", value = initiative.positive_votes },
    1.11                { color = "#aaa", value = max_value - initiative.negative_votes - initiative.positive_votes },
     2.1 --- a/env/ui/bargraph.lua	Wed Mar 21 19:50:58 2012 +0100
     2.2 +++ b/env/ui/bargraph.lua	Wed Mar 21 20:16:19 2012 +0100
     2.3 @@ -15,16 +15,25 @@
     2.4        local at_least_one_bar = false
     2.5        local quorum = args.quorum and args.quorum * args.width / args.max_value or nil
     2.6        local length = 0
     2.7 +      local rest = 0
     2.8 +      local last_visiable_bar = 0
     2.9 +      for i, bar in ipairs(args.bars) do
    2.10 +        if bar.value > 0 then
    2.11 +          last_visiable_bar = i
    2.12 +        end
    2.13 +      end
    2.14        for i, bar in ipairs(args.bars) do
    2.15          if bar.value > 0 then
    2.16            at_least_one_bar = true
    2.17            local value = bar.value * args.width / args.max_value
    2.18            if quorum and quorum < length + value then
    2.19              local dlength = math.max(quorum - length - 1, 0)
    2.20 +            local dlength_abs = math.floor(dlength)
    2.21 +            local rest = rest + dlength - dlength_abs
    2.22              if dlength > 0 then
    2.23                ui.container{
    2.24                  attr = {
    2.25 -                  style = "width: " .. tostring(dlength) .. "px; background-color: " .. bar.color .. ";",
    2.26 +                  style = "width: " .. tostring(dlength_abs) .. "px; background-color: " .. bar.color .. ";",
    2.27                  },
    2.28                  content = function() slot.put("&nbsp;") end
    2.29                }
    2.30 @@ -40,10 +49,15 @@
    2.31              value = value - dlength
    2.32              quorum = nil
    2.33            end
    2.34 -          length = length + value
    2.35 +          local value_abs = math.floor(value)
    2.36 +          rest = rest + value - value_abs
    2.37 +          if i == last_visiable_bar then
    2.38 +            value_abs = value_abs + rest
    2.39 +          end
    2.40 +          length = length + value_abs
    2.41            ui.container{
    2.42              attr = {
    2.43 -              style = "width: " .. tostring(value) .. "px; background-color: " .. bar.color .. ";",
    2.44 +              style = "width: " .. tostring(value_abs) .. "px; background-color: " .. bar.color .. ";",
    2.45              },
    2.46              content = function() slot.put("&nbsp;") end
    2.47            }

Impressum / About Us