2019-11-19 14:53:53 +01:00
|
|
|
import {Component, OnInit} from "@angular/core";
|
|
|
|
import {Chart} from "chart.js";
|
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;
|
2019-11-13 18:18:42 +01:00
|
|
|
lineChart: Chart;
|
|
|
|
pollData: any;
|
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
|
|
|
|
|
|
|
constructor() {
|
|
|
|
}
|
2019-10-23 15:39:16 +02:00
|
|
|
|
2019-11-13 18:18:42 +01:00
|
|
|
ngOnInit() {
|
2019-11-19 10:55:56 +01:00
|
|
|
var toto = {
|
|
|
|
step: 0,
|
|
|
|
stepMax: 3,
|
|
|
|
pollType: "special dates",
|
|
|
|
title: "",
|
|
|
|
description: "",
|
|
|
|
myName: "",
|
|
|
|
visibility: "link_only",
|
|
|
|
// date specific poll
|
|
|
|
allowSeveralHours: "true",
|
|
|
|
dateLgfgfgfgist: ["jeudi", "vendredi", "samedi"], // sets of days as strings
|
|
|
|
timeList: ["08:00", "08:30", "09:00"], // ranges of time expressed as strings
|
|
|
|
answers: [
|
|
|
|
{
|
|
|
|
id: 0,
|
|
|
|
text: "no"
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
id: 1,
|
|
|
|
text: "yes"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
id: 2,
|
|
|
|
text: "maybe"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
id: 3,
|
|
|
|
text: "maybe"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
id: 4,
|
|
|
|
text: "maybe"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
id: 5,
|
|
|
|
text: "maybe"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
id: 6,
|
|
|
|
text: "maybe"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
id: 7,
|
|
|
|
text: "maybe"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
id: 8,
|
|
|
|
text: "maybe"
|
|
|
|
}
|
|
|
|
]
|
|
|
|
};
|
2019-10-23 15:39:16 +02:00
|
|
|
|
2019-11-19 10:55:56 +01:00
|
|
|
this.formatDataAnswers(toto);
|
2019-10-23 10:45:30 +02:00
|
|
|
|
2019-11-13 18:18:42 +01:00
|
|
|
this.isColorblind = false;
|
2019-11-18 10:19:28 +01:00
|
|
|
this.pollData = new Chart(document.getElementById("graph"), {
|
2019-11-19 10:55:56 +01:00
|
|
|
type: "horizontalBar",
|
2019-11-13 18:18:42 +01:00
|
|
|
data: {
|
2019-11-19 10:55:56 +01:00
|
|
|
labels: ["jeudi"],
|
|
|
|
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
|
|
|
},
|
|
|
|
options: {
|
2019-11-19 14:53:53 +01:00
|
|
|
legend: {display: false},
|
2019-11-19 10:55:56 +01:00
|
|
|
scales: {
|
|
|
|
xAxes: [
|
|
|
|
{
|
2019-11-19 14:53:53 +01:00
|
|
|
gridLines: {drawBorder: false, display: false},
|
2019-11-19 10:55:56 +01:00
|
|
|
display: false,
|
|
|
|
stacked: true,
|
|
|
|
ticks: {
|
|
|
|
beginAtZero: true,
|
|
|
|
maxRotation: 0,
|
|
|
|
minRotation: 0
|
|
|
|
}
|
|
|
|
}
|
|
|
|
],
|
|
|
|
yAxes: [
|
|
|
|
{
|
2019-11-19 14:53:53 +01:00
|
|
|
gridLines: {drawBorder: true, display: false},
|
2019-11-19 10:55:56 +01:00
|
|
|
display: true,
|
|
|
|
stacked: true
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
2019-11-13 18:18:42 +01:00
|
|
|
}
|
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) {
|
|
|
|
if (poll && poll.pollType === "special dates") {
|
|
|
|
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
|
|
|
}
|