mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-23 23:58:31 -05:00
FIX: don't round up to 100% when using multiple choices poll
This commit is contained in:
parent
4fe1a13bae
commit
9d2128dad3
1 changed files with 8 additions and 3 deletions
|
@ -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];
|
||||
|
|
Loading…
Reference in a new issue