-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpoolchart.js
171 lines (163 loc) · 3.06 KB
/
poolchart.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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
function new_poolchart(canvas) {
let labels = [];
let load_series = [];
let running_series = [];
let starting_and_running_series = [];
let desired_series = [];
let load_ds = {
label: 'Load',
data: load_series,
steppedLine: 'after',
fill: false,
showLine: true,
//
pointRadius: 3,
borderWidth: 0,
borderColor: 'pink',
backgroundColor: 'pink',
};
// Running: darker green;
// starting: lighter green on top of that
let running_ds = {
label: 'Running',
data: running_series,
steppedLine: 'before',
fill: true,
//
pointRadius: 0,
borderWidth: 0,
borderColor: '#afc',
backgroundColor: '#afc',
};
let starting_and_running_ds = {
label: 'Starting + Running',
data: starting_and_running_series,
steppedLine: 'before',
fill: true,
//
pointRadius: 0,
borderWidth: 0,
borderColor: '#dfe',
backgroundColor: '#dfe'
};
// Desired: dotted line
let desired_ds = {
label: 'Desired',
data: desired_series,
steppedLine: 'before',
fill: false,
//
pointRadius: 0,
borderWidth: 1,
borderDash: [5, 5],
borderColor: 'black',
backgroundColor: 'black',
};
let options = {
responsive: false,
animation: {
duration: 0,
},
legend: {
display: false,
},
scales: {
xAxes: [{
type: 'linear',
display: true,
scaleLabel: {
display: true,
labelString: 'minutes ago',
},
ticks: {
suggestedMin: -5,
suggestedMax: 0,
},
}],
yAxes: [
{
type: 'linear',
ticks: {
stepSize: 0.5,
beginAtZero: true,
suggestedMin: 0,
suggestedMax: 4,
},
// display: true,
// scaleLabel: {
// display: true,
// labelString: 'pear',
// }
},
],
}
}
let config = {
type: 'line',
options: options,
data: {
labels: labels,
datasets: [
running_ds,
starting_and_running_ds,
desired_ds,
load_ds,
]
}
};
let ctx = canvas.getContext('2d');
let chart = new Chart(ctx, config);
return {
canvas: canvas,
chart: chart,
raw_stats: [],
labels: labels,
load_series: load_series,
running_series: running_series,
starting_and_running_series: starting_and_running_series,
desired_series: desired_series,
};
}
function add_to_poolchart(poolchart, now, stats) {
poolchart.raw_stats.push({
timestamp: now,
...stats
})
}
function refresh_poolchart(poolchart, now) {
function process(name, arr, f, labels=null) {
arr.length = 0;
if (labels != null) {
labels.length = 0;
}
for (let entry of poolchart.raw_stats) {
let t = (entry.timestamp - now) / 60000;
arr.push({
x: t,
y: f(entry)
})
if (labels != null) {
labels.push(t);
}
}
console.log(name + " " + JSON.stringify(arr));
}
process("load",
poolchart.load_series,
entry => entry.load,
poolchart.labels);
process("running",
poolchart.running_series,
entry => entry.up
);
process("starting",
poolchart.starting_and_running_series,
entry => entry.up + entry.starting
);
process("desired",
poolchart.desired_series,
entry => entry.desired
);
poolchart.chart.update();
console.log(".")
}