# HG changeset patch # User bsw # Date 1437230815 -7200 # Node ID 7e48d429389f25209f4eda8c2e35595d952e27e6 # Parent fede09736f2b4aeb9d5f7e51cacaebf1f3751505 Unified rendering of vote percentages (floor instead of round) diff -r fede09736f2b -r 7e48d429389f app/main/initiative/_list_element.lua --- a/app/main/initiative/_list_element.lua Sat Jul 18 16:20:30 2015 +0200 +++ b/app/main/initiative/_list_element.lua Sat Jul 18 16:46:55 2015 +0200 @@ -65,13 +65,6 @@ and initiative.negative_votes ~= nil and not for_event then - local function percent(p, q) - if q > 0 then - return math.floor(p / q * 100) .. "%" - else - return "0%" - end - end local result = "" if initiative.eligible then result = _("Reached #{sign}#{num}/#{den}", { @@ -94,11 +87,11 @@ result_text = _("#{result}: #{yes_count} Yes (#{yes_percent}), #{no_count} No (#{no_percent}), #{neutral_count} Abstention (#{neutral_percent})", { result = result, yes_count = initiative.positive_votes, - yes_percent = percent(initiative.positive_votes, issue.voter_count), + yes_percent = format.percent_floor(initiative.positive_votes, issue.voter_count), neutral_count = neutral_count, - neutral_percent = percent(neutral_count, issue.voter_count), + neutral_percent = format.percent_floor(neutral_count, issue.voter_count), no_count = initiative.negative_votes, - no_percent = percent(initiative.negative_votes, issue.voter_count) + no_percent = format.percent_floor(initiative.negative_votes, issue.voter_count) }) else result_text = _("#{result}: No votes (0)", { result = result }) diff -r fede09736f2b -r 7e48d429389f app/main/initiative/_sidebar_state.lua --- a/app/main/initiative/_sidebar_state.lua Sat Jul 18 16:20:30 2015 +0200 +++ b/app/main/initiative/_sidebar_state.lua Sat Jul 18 16:46:55 2015 +0200 @@ -14,10 +14,6 @@ local abstention_votes = max_value - negative_votes - positive_votes - local function perc(votes, sum) - if sum > 0 then return string.format( "%.f", votes * 100 / sum ) .. "%" end - return "" - end local head_text if initiative.winner then head_text = _"Approved" @@ -38,7 +34,7 @@ } ui.tag { tag = "th", content = _"Yes" } ui.tag { tag = "td", content = - perc(positive_votes, max_value) + format.percent_floor(positive_votes, max_value) } ui.tag { tag = "th", content = _"Yes" } end } @@ -48,7 +44,7 @@ } ui.tag { tag = "th", content = _"Abstention" } ui.tag { tag = "td", content = - perc(abstention_votes, max_value) + format.percent_floor(abstention_votes, max_value) } ui.tag { tag = "th", content = _"Abstention" } end } @@ -58,7 +54,7 @@ } ui.tag { tag = "th", content = _"No" } ui.tag { tag = "td", content = - perc(negative_votes, max_value) + format.percent_floor(negative_votes, max_value) } ui.tag { tag = "th", content = _"No" } end } diff -r fede09736f2b -r 7e48d429389f env/format/percent_floor.lua --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/env/format/percent_floor.lua Sat Jul 18 16:46:55 2015 +0200 @@ -0,0 +1,7 @@ +function format.percent_floor(p, q) + if q > 0 then + return math.floor(100 * p / q) .. "%" + else + return "0%" + end +end