From 9d2128dad30aaa96a0b13be666daabbbba2993f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9gis=20Hanol?= Date: Mon, 23 Nov 2015 11:34:24 +0100 Subject: [PATCH] FIX: don't round up to 100% when using multiple choices poll --- .../components/poll-results-standard.js.es6 | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/plugins/poll/assets/javascripts/components/poll-results-standard.js.es6 b/plugins/poll/assets/javascripts/components/poll-results-standard.js.es6 index f9b62769a..e0ae0071a 100644 --- a/plugins/poll/assets/javascripts/components/poll-results-standard.js.es6 +++ b/plugins/poll/assets/javascripts/components/poll-results-standard.js.es6 @@ -5,13 +5,18 @@ export default Em.Component.extend({ tagName: "ul", classNames: ["results"], - @computed("poll.voters", "poll.options.[]") + @computed("poll.voters", "poll.options.[]", "poll.isMultiple") options() { const options = this.get("poll.options"); const voters = this.get("poll.voters"); - const percentages = voters === 0 ? + let percentages = voters === 0 ? Array(options.length).fill(0) : - evenRound(_.map(options, o => 100 * o.get("votes") / voters)); + _.map(options, o => 100 * o.get("votes") / voters); + + // fix percentages to add up to 100 when the poll is single choice only + if (!this.get("poll.isMultiple")) { + percentages = evenRound(percentages); + } options.forEach((option, i) => { const percentage = percentages[i];