-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsketch.js
101 lines (70 loc) · 2.14 KB
/
sketch.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
/* Alle Befehle für p5js findest du in der Dokumentation: https://p5js.org/reference/ */
let table
let data
let startDate = "2021-12-01"
let dateDE = startDate.split("-")
function preload () {
table = loadTable("https://impfdashboard.de/static/data/germany_vaccinations_timeseries_v2.tsv", "tsv", "header")
}
function setup() {
createCanvas(600, 196)
data = table.getRow(1)
startRow = findStartRow(startDate)
endRow = table.getRowCount("date") - 1
anzahl = countVax(startRow, endRow)
statText(anzahl.toLocaleString())
spritze(anzahl)
}
function draw() {}
function findStartRow(datum) {
for(let i = 0; i < table.getRowCount("date"); i++){
if(table.getRow(i).obj.date === datum){
// let rowNumber = i
// console.log(rowNumber)
return i
}
}
}
function countVax(startRow, endRow){
let anzahlStart = int(table.getRow(startRow).obj.dosen_kumulativ)
let anzahlEnde = int(table.getRow(endRow).obj.dosen_kumulativ)
let total = anzahlEnde - anzahlStart
return total;
}
function checkDate(){}
function statText(total){
noStroke()
fill(17, 19, 20)
textSize(18)
textStyle(BOLD)
text("Was ist aus den \"30 Millionen Impfungen\nbis Weihnachten” geworden?", 40, 40)
fill(17, 19, 20, 20)
rect(36, 96, width, 1)
textSize(12)
fill(17, 19, 20)
text("Impfungen seit " + dateDE[2] + "." + dateDE[1] + "." + dateDE[0], 40, 136)
textStyle(NORMAL)
// fill(157, 204, 229)
text(total, 40, 152)
}
function spritze(total){
let svg = document.createElement("div")
svg.setAttribute("id", "svgContainer")
let main = document.getElementsByTagName("main")
document.body.appendChild(svg)
xhr = new XMLHttpRequest();
xhr.open("GET", "spritze.svg", false);
// Following line is just to be on the safe side;
// not needed if your server delivers SVG with correct MIME type
//xhr.overrideMimeType("image/svg+xml");
xhr.onload = function(e) {
// You might also want to check for xhr.readyState/xhr.status here
document.getElementById("svgContainer")
.appendChild(xhr.responseXML.documentElement);
};
xhr.send("");
let impfe = document.getElementById("impfe")
let w = total / 300000 * 2
impfe.setAttribute("width", w)
console.log(w)
}