-
Notifications
You must be signed in to change notification settings - Fork 0
/
common.js
124 lines (120 loc) · 3.46 KB
/
common.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
function getRandomColor() {
return "hsl(" + 360 * Math.random() + ',' +
(60 + 40 * Math.random()) + '%,' +
(60 + 5 * Math.random()) + '%)'
}
function getMostCommon(object) {
let mostCommon = "", mostCommonQnt = 0;
for(let o in object) {
if(!object.hasOwnProperty(o)) continue;
if(object[o] > mostCommonQnt) {
mostCommonQnt = object[o]
mostCommon = o
}
}
return [mostCommon, mostCommonQnt]
}
function createPie(elementId, data, color, labels) {
const ctx = document.getElementById(elementId).getContext('2d');
const chart = new Chart(ctx, {
type: 'doughnut',
data: {
datasets: [{
data: data,
backgroundColor: color,
borderColor: color,
label: 'Dados'
}],
labels: labels
},
options: {
legend: {
labels: {
fontColor: "#BBBBBB"
}
},
responsive: true,
maintainAspectRatio: false
}
})
}
function createFlightGraph(elementId, xs, mean_ys, day_ys) {
const ctx = document.getElementById(elementId).getContext('2d');
const chart = new Chart(ctx, {
type: 'line',
responsive: true,
data: {
labels: xs,
datasets: [
{
label: 'Média de voos por 7 dias',
data: mean_ys,
backgroundColor: 'rgba(0, 0, 0, 0)',
borderColor: 'rgb(219, 130, 75)',
borderWidth: 2,
fill: false,
pointRadius: 0,
pointHitRadius: 3
},
{
label: 'Voos por dia',
data: day_ys,
backgroundColor: 'rgba(0, 0, 0, 0)',
borderColor: 'rgb(75, 183, 219)',
borderWidth: 2,
fill: false,
pointRadius: 0,
pointHitRadius: 3
}
]
},
options: {
legend: {
labels: {
fontColor: "#BBBBBB"
}
},
scales: {
xAxes: [{
type: "time",
time: {
unit: 'month',
tooltipFormat: 'dddd, MMMM Do YYYY'
},
gridLines: {
color: "#BBBBBB"
},
scaleLabel: {
display: true,
labelString: 'Período',
fontColor: "#BBBBBB"
},
ticks: {
fontColor: "#BBBBBB",
}
}],
yAxes: [{
gridLines: {
color: "#BBBBBB"
},
scaleLabel: {
display: true,
labelString: 'Quantidade de Voos',
fontColor: "#BBBBBB"
},
ticks: {
fontColor: "#BBBBBB"
}
}]
}
}
});
}
function collapseTopNav() {
var x = document.getElementById("topnav");
if (x.className === "topnav") {
x.className += " responsive";
} else {
x.className = "topnav";
}
}