liquid_feedback_frontend
changeset 1210:7e48d429389f
Unified rendering of vote percentages (floor instead of round)
author | bsw |
---|---|
date | Sat Jul 18 16:46:55 2015 +0200 (2015-07-18) |
parents | fede09736f2b |
children | 513c36865ac9 |
files | app/main/initiative/_list_element.lua app/main/initiative/_sidebar_state.lua env/format/percent_floor.lua |
line diff
1.1 --- a/app/main/initiative/_list_element.lua Sat Jul 18 16:20:30 2015 +0200 1.2 +++ b/app/main/initiative/_list_element.lua Sat Jul 18 16:46:55 2015 +0200 1.3 @@ -65,13 +65,6 @@ 1.4 and initiative.negative_votes ~= nil 1.5 and not for_event 1.6 then 1.7 - local function percent(p, q) 1.8 - if q > 0 then 1.9 - return math.floor(p / q * 100) .. "%" 1.10 - else 1.11 - return "0%" 1.12 - end 1.13 - end 1.14 local result = "" 1.15 if initiative.eligible then 1.16 result = _("Reached #{sign}#{num}/#{den}", { 1.17 @@ -94,11 +87,11 @@ 1.18 result_text = _("#{result}: #{yes_count} Yes (#{yes_percent}), #{no_count} No (#{no_percent}), #{neutral_count} Abstention (#{neutral_percent})", { 1.19 result = result, 1.20 yes_count = initiative.positive_votes, 1.21 - yes_percent = percent(initiative.positive_votes, issue.voter_count), 1.22 + yes_percent = format.percent_floor(initiative.positive_votes, issue.voter_count), 1.23 neutral_count = neutral_count, 1.24 - neutral_percent = percent(neutral_count, issue.voter_count), 1.25 + neutral_percent = format.percent_floor(neutral_count, issue.voter_count), 1.26 no_count = initiative.negative_votes, 1.27 - no_percent = percent(initiative.negative_votes, issue.voter_count) 1.28 + no_percent = format.percent_floor(initiative.negative_votes, issue.voter_count) 1.29 }) 1.30 else 1.31 result_text = _("#{result}: No votes (0)", { result = result })
2.1 --- a/app/main/initiative/_sidebar_state.lua Sat Jul 18 16:20:30 2015 +0200 2.2 +++ b/app/main/initiative/_sidebar_state.lua Sat Jul 18 16:46:55 2015 +0200 2.3 @@ -14,10 +14,6 @@ 2.4 local abstention_votes = max_value - 2.5 negative_votes - 2.6 positive_votes 2.7 - local function perc(votes, sum) 2.8 - if sum > 0 then return string.format( "%.f", votes * 100 / sum ) .. "%" end 2.9 - return "" 2.10 - end 2.11 local head_text 2.12 if initiative.winner then 2.13 head_text = _"Approved" 2.14 @@ -38,7 +34,7 @@ 2.15 } 2.16 ui.tag { tag = "th", content = _"Yes" } 2.17 ui.tag { tag = "td", content = 2.18 - perc(positive_votes, max_value) 2.19 + format.percent_floor(positive_votes, max_value) 2.20 } 2.21 ui.tag { tag = "th", content = _"Yes" } 2.22 end } 2.23 @@ -48,7 +44,7 @@ 2.24 } 2.25 ui.tag { tag = "th", content = _"Abstention" } 2.26 ui.tag { tag = "td", content = 2.27 - perc(abstention_votes, max_value) 2.28 + format.percent_floor(abstention_votes, max_value) 2.29 } 2.30 ui.tag { tag = "th", content = _"Abstention" } 2.31 end } 2.32 @@ -58,7 +54,7 @@ 2.33 } 2.34 ui.tag { tag = "th", content = _"No" } 2.35 ui.tag { tag = "td", content = 2.36 - perc(negative_votes, max_value) 2.37 + format.percent_floor(negative_votes, max_value) 2.38 } 2.39 ui.tag { tag = "th", content = _"No" } 2.40 end }