2015-04-23 13:33:29 -04:00
|
|
|
export default Em.Component.extend({
|
|
|
|
tagName: "table",
|
|
|
|
classNames: ["results"],
|
|
|
|
|
|
|
|
options: function() {
|
|
|
|
const totalVotes = this.get("poll.total_votes"),
|
|
|
|
backgroundColor = this.get("poll.background");
|
|
|
|
|
|
|
|
this.get("poll.options").forEach(option => {
|
2015-05-01 19:58:23 -04:00
|
|
|
const percentage = totalVotes == 0 ? 0 : Math.floor(100 * option.get("votes") / totalVotes),
|
2015-04-23 13:33:29 -04:00
|
|
|
styles = ["width: " + percentage + "%"];
|
|
|
|
|
|
|
|
if (backgroundColor) { styles.push("background: " + backgroundColor); }
|
|
|
|
|
|
|
|
option.setProperties({
|
|
|
|
percentage: percentage,
|
|
|
|
title: I18n.t("poll.option_title", { count: option.get("votes") }),
|
|
|
|
style: styles.join(";")
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
return this.get("poll.options");
|
|
|
|
}.property("poll.total_votes", "poll.options.[]")
|
|
|
|
|
|
|
|
});
|