2020-01-15 11:40:39 +01:00
|
|
|
import {Component, Inject, OnInit} from "@angular/core";
|
2019-11-19 14:53:53 +01:00
|
|
|
import {Chart} from "chart.js";
|
2020-01-15 11:40:39 +01:00
|
|
|
import {DOCUMENT} from '@angular/common';
|
2020-01-16 10:33:05 +01:00
|
|
|
import {mockGraphConfig} from "../config/mock-graph";
|
2020-01-16 16:25:40 +01:00
|
|
|
import {graphOptions} from "../config/graph-canevas-options";
|
|
|
|
import {ConfigService} from "../services/config.service";
|
|
|
|
import {mockPoll3} from "../config/mock-poll3";
|
2019-10-23 10:45:30 +02:00
|
|
|
|
|
|
|
@Component({
|
2019-11-13 18:18:42 +01:00
|
|
|
selector: "framadate-poll-graphic",
|
|
|
|
templateUrl: "./poll-graphic.component.html",
|
|
|
|
styleUrls: ["./poll-graphic.component.scss"]
|
2019-10-23 10:45:30 +02:00
|
|
|
})
|
|
|
|
export class PollGraphicComponent implements OnInit {
|
2019-11-19 14:53:53 +01:00
|
|
|
isColorblind: boolean = false;
|
2020-01-16 16:25:40 +01:00
|
|
|
pollConfigRetrieved: any = mockPoll3;
|
|
|
|
graphicConfig: any = mockGraphConfig;
|
2020-01-16 10:20:15 +01:00
|
|
|
preferred: any = "rien";
|
2019-11-19 10:55:56 +01:00
|
|
|
yesList: number[] = [];
|
|
|
|
maybeList: number[] = [];
|
|
|
|
noList: number[] = [];
|
|
|
|
nbPoll: number = 0;
|
|
|
|
dateList: string[] = [];
|
2019-11-19 14:53:53 +01:00
|
|
|
|
2020-01-16 16:25:40 +01:00
|
|
|
constructor(@Inject(DOCUMENT) private document: any,
|
|
|
|
private config: ConfigService) {
|
2019-11-19 14:53:53 +01:00
|
|
|
}
|
2019-10-23 15:39:16 +02:00
|
|
|
|
2019-11-13 18:18:42 +01:00
|
|
|
ngOnInit() {
|
2020-01-16 16:25:40 +01:00
|
|
|
this.formatDataAnswers(this.graphicConfig);
|
2019-11-13 18:18:42 +01:00
|
|
|
this.isColorblind = false;
|
2020-01-16 16:25:40 +01:00
|
|
|
this.pollConfigRetrieved = new Chart(this.document.getElementById("graph"), {
|
2019-11-19 10:55:56 +01:00
|
|
|
type: "horizontalBar",
|
2019-11-13 18:18:42 +01:00
|
|
|
data: {
|
2020-01-16 16:25:40 +01:00
|
|
|
labels: this.pollConfigRetrieved.choices.map(choice => choice.name),
|
2019-11-19 10:55:56 +01:00
|
|
|
datasets: [
|
|
|
|
{
|
|
|
|
type: "horizontalBar",
|
|
|
|
stack: "Yes",
|
|
|
|
backgroundColor: "#429a00",
|
|
|
|
data: this.yesList
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: "horizontalBar",
|
|
|
|
stack: "Yes",
|
|
|
|
backgroundColor: "#f5a623",
|
|
|
|
data: this.maybeList
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: "horizontalBar",
|
|
|
|
stack: "No",
|
|
|
|
backgroundColor: "#cd0000",
|
|
|
|
data: this.noList
|
|
|
|
}
|
|
|
|
]
|
2019-11-13 18:18:42 +01:00
|
|
|
},
|
2020-01-16 16:25:40 +01:00
|
|
|
options: graphOptions
|
2019-11-19 10:55:56 +01:00
|
|
|
});
|
|
|
|
}
|
2019-11-13 18:18:42 +01:00
|
|
|
|
2019-11-19 14:53:53 +01:00
|
|
|
toggleColorblind() {
|
2019-11-13 18:18:42 +01:00
|
|
|
this.isColorblind = !this.isColorblind;
|
|
|
|
}
|
|
|
|
|
2019-11-19 10:55:56 +01:00
|
|
|
formatDataAnswers(poll) {
|
2020-01-16 16:25:40 +01:00
|
|
|
// if (poll && poll.pollType === "date") {
|
|
|
|
this.initPollCounter();
|
|
|
|
poll.answers.forEach(response => {
|
|
|
|
switch (response.text) {
|
|
|
|
case "yes":
|
|
|
|
this.yesList[this.nbPoll - 1]++;
|
|
|
|
break;
|
|
|
|
case "maybe":
|
|
|
|
this.maybeList[this.nbPoll - 1]++;
|
|
|
|
break;
|
|
|
|
case "no":
|
|
|
|
this.noList[this.nbPoll - 1]++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
// }
|
2019-11-13 18:18:42 +01:00
|
|
|
}
|
|
|
|
|
2019-11-19 10:55:56 +01:00
|
|
|
initPollCounter() {
|
|
|
|
this.nbPoll++;
|
2019-11-19 14:53:53 +01:00
|
|
|
this.dateList[this.nbPoll - 1] = "jeudi";
|
2019-11-19 10:55:56 +01:00
|
|
|
this.maybeList[this.nbPoll - 1] = 0;
|
|
|
|
this.yesList[this.nbPoll - 1] = 0;
|
|
|
|
this.noList[this.nbPoll - 1] = 0;
|
|
|
|
}
|
2019-10-23 10:45:30 +02:00
|
|
|
}
|