liquid_feedback_frontend
diff app/main/initiative/_bargraph.lua @ 1045:701a5cf6b067
Imported LiquidFeedback Frontend 3.0 branch
| author | bsw | 
|---|---|
| date | Thu Jul 10 01:19:48 2014 +0200 (2014-07-10) | 
| parents | |
| children | 32cc544d5a5b | 
   line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/app/main/initiative/_bargraph.lua Thu Jul 10 01:19:48 2014 +0200 1.3 @@ -0,0 +1,61 @@ 1.4 +local initiative = param.get("initiative", "table") 1.5 +local batteled_initiative = param.get("battled_initiative", "table") 1.6 + 1.7 +local grey = "#eee" 1.8 + 1.9 +if initiative.issue.fully_frozen and initiative.issue.closed 1.10 + and initiative.negative_votes and initiative.positive_votes and initiative.rank ~= 1 then 1.11 + if not batteled_initiative then 1.12 + return 1.13 + end 1.14 + local battle1 = Battle:getByInitiativeIds(batteled_initiative.id, initiative.id) 1.15 + local battle2 = Battle:getByInitiativeIds(initiative.id, batteled_initiative.id) 1.16 + 1.17 + if not battle1 or not battle2 then 1.18 + return 1.19 + end 1.20 + 1.21 + local positive_votes = battle2.count 1.22 + local negative_votes = battle1.count 1.23 + 1.24 + local max_value = initiative.issue.voter_count 1.25 + if max_value > 0 then 1.26 + ui.bargraph{ 1.27 + max_value = max_value * 2, 1.28 + width = 100, 1.29 + bars = { 1.30 + { color = grey, value = max_value - negative_votes }, 1.31 + { color = "#a00", value = negative_votes }, 1.32 + { color = "#0a0", value = positive_votes }, 1.33 + { color = grey, value = max_value - positive_votes }, 1.34 + } 1.35 + } 1.36 + else 1.37 + ui.bargraph{ 1.38 + max_value = 1, 1.39 + width = 100, 1.40 + bars = { 1.41 + { color = grey, value = 1 }, 1.42 + } 1.43 + } 1.44 + end 1.45 +else 1.46 + local max_value = initiative.issue.population or 0 1.47 + local quorum 1.48 + if initiative.issue.accepted then 1.49 + quorum = initiative.issue.policy.initiative_quorum_num / initiative.issue.policy.initiative_quorum_den 1.50 + else 1.51 + quorum = initiative.issue.policy.issue_quorum_num / initiative.issue.policy.issue_quorum_den 1.52 + end 1.53 + ui.bargraph{ 1.54 + max_value = max_value, 1.55 + width = 100, 1.56 + quorum = max_value * quorum, 1.57 + quorum_color = "#00F", 1.58 + bars = { 1.59 + { color = "#5a5", value = (initiative.satisfied_supporter_count or 0) }, 1.60 + { color = "#fa5", value = (initiative.supporter_count or 0) - (initiative.satisfied_supporter_count or 0) }, 1.61 + { color = grey, value = max_value - (initiative.supporter_count or 0) }, 1.62 + } 1.63 + } 1.64 +end