This repository has been archived by the owner on Nov 1, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
makeCharts.js
80 lines (73 loc) · 1.78 KB
/
makeCharts.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
import fs from "fs/promises";
import path from "path";
import { fileURLToPath } from "url";
import Chart from "@mgwalker/chartjs-node";
const dir = path.dirname(fileURLToPath(import.meta.url));
const data = JSON.parse(
await fs.readFile(path.join(dir, "output/mo-vid.json"), {
encoding: "utf-8",
})
);
await fs.mkdir(path.join(dir, "docs", "charts"), { recursive: true });
data.forEach(
(
{
new_cases_7_day: weeklyCases,
pcr_positive_7_day_average: pcr,
antigen_positive_7_day_average: antigen,
},
i
) => {
if (pcr) {
data[i].totalPositive = pcr + antigen;
} else {
data[i].totalPositive = Math.round(weeklyCases / 7);
}
}
);
const labels = data.map(({ end }) => end);
await Promise.all(
[
["totalPositive", "0,0,170"],
// ["vaccinations_7_day_average", "0,170,0"],
["hospitalizations", "192,192,0"],
["icu", "255,128,0"],
// ["ventilator", "192,64,0"],
// ["deaths_7_day_average", "192,0,0"],
].map(async ([field, colorRgb]) => {
const chart = new Chart([1200, 800], {
deviceScaleFactor: 3,
type: "line",
data: {
labels,
datasets: [
{
label: "",
data: data.map((d) => d[field]),
backgroundColor: `rgba(${colorRgb},0.2)`,
borderColor: `rgb(${colorRgb})`,
borderWidth: 3,
fill: true,
pointRadius: 0,
},
],
},
options: {
animation: false,
plugins: {
legend: { display: false },
},
responsive: false,
scales: {
x: {
type: "time",
},
y: {
min: 0,
},
},
},
});
chart.save(path.join(dir, `docs/charts/${field}.png`));
})
);