diff --git a/pleroma-comments.lua b/pleroma-comments.lua index 26c470f..14271d2 100644 --- a/pleroma-comments.lua +++ b/pleroma-comments.lua @@ -135,24 +135,30 @@ function write_comments(pleroma_posts, instance, show_avatars) return "" end local bar_chart = {"
"} - local bar_template = "
$label$
" + local bar_template = [[ +
+ $label$ +
+ ]] local total_votes = math.floor(poll["votes_count"]) + local total_voters = math.floor(poll["voters_count"]) for _, v in pairs(poll["options"]) do - local width = math.floor( - 0.5 + (v["votes_count"]/total_votes) * 100) - vars = { - label = width .. "% " .. v["title"], - pct = width + local percentage = (v["votes_count"]/total_votes) * 100 + local rounded = math.floor(0.5 + percentage) + local vars = { + label = rounded .. "% " .. v["title"], + pct = rounded } local bar = bar_template:gsub("%$(%w+)%$", vars) - print(bar) table.insert(bar_chart, bar) end + -- close chart div table.insert(bar_chart, "
") + local summary = "

$x$ people have cast $y$ votes

" local foo = summary:gsub( "%$(%w+)%$", - {x=math.floor(poll["voters_count"]), y=total_votes} + {x=total_voters, y=total_votes} ) table.insert(bar_chart, foo) return table.concat(bar_chart,"\n")