liquid_feedback_frontend
view app/main/initiative/_bargraph.lua @ 1115:b9364e1b7994
merge
| author | bsw | 
|---|---|
| date | Mon Nov 10 19:02:21 2014 +0100 (2014-11-10) | 
| parents | 701a5cf6b067 | 
| children | 32cc544d5a5b | 
 line source
     1 local initiative = param.get("initiative", "table")
     2 local batteled_initiative = param.get("battled_initiative", "table")
     4 local grey = "#eee"
     6 if initiative.issue.fully_frozen and initiative.issue.closed
     7    and initiative.negative_votes and initiative.positive_votes and initiative.rank ~= 1 then
     8     if not batteled_initiative then
     9       return
    10     end
    11     local battle1 = Battle:getByInitiativeIds(batteled_initiative.id, initiative.id)
    12     local battle2 = Battle:getByInitiativeIds(initiative.id, batteled_initiative.id)
    14     if not battle1 or not battle2 then
    15       return
    16     end
    18     local positive_votes = battle2.count
    19     local negative_votes = battle1.count
    21     local max_value = initiative.issue.voter_count
    22     if max_value > 0 then
    23       ui.bargraph{
    24         max_value = max_value * 2,
    25         width = 100,
    26         bars = {
    27           { color = grey, value = max_value - negative_votes },
    28           { color = "#a00", value = negative_votes },
    29           { color = "#0a0", value = positive_votes },
    30           { color = grey, value = max_value - positive_votes },
    31         }
    32       }
    33     else
    34       ui.bargraph{
    35         max_value = 1,
    36         width = 100,
    37         bars = {
    38           { color = grey, value = 1 },
    39         }
    40       }
    41     end
    42 else
    43   local max_value = initiative.issue.population or 0
    44   local quorum
    45   if initiative.issue.accepted then
    46     quorum = initiative.issue.policy.initiative_quorum_num / initiative.issue.policy.initiative_quorum_den
    47   else
    48     quorum = initiative.issue.policy.issue_quorum_num / initiative.issue.policy.issue_quorum_den
    49   end
    50   ui.bargraph{
    51     max_value = max_value,
    52     width = 100,
    53     quorum = max_value * quorum,
    54     quorum_color = "#00F",
    55     bars = {
    56       { color = "#5a5", value = (initiative.satisfied_supporter_count or 0) },
    57       { color = "#fa5", value = (initiative.supporter_count or 0) - (initiative.satisfied_supporter_count or 0) },
    58       { color = grey, value = max_value - (initiative.supporter_count or 0) },
    59     }
    60   }
    61 end
