-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtemplate.html
186 lines (165 loc) · 7.72 KB
/
template.html
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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
<!doctype html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>CovidWawa</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/5.0.0-alpha2/css/bootstrap.min.css" integrity="sha384-DhY6onE6f3zzKbjUPRc2hOzGAdEf4/Dz+WJwBvEYL/lkkIsI3ihufq9hk9K4lVoK" crossorigin="anonymous">
<style>
.table {
width: auto;
float: left;
}
.table:first-child {
margin-right: 40px;
}
.table tbody tr td:nth-child(2n) {
border-left: 1px solid;
border-left-color: inherit;
}
div.google-visualization-tooltip {
padding: 10px;
font-size: 100%;
white-space: nowrap;
}
div.google-visualization-tooltip p {
margin: 0;
}
</style>
</head>
<body>
<div id="chart"></div>
<div class="container">
{% for table in [table_data[7:14], table_data[0:7]] %}
<table class="table table-hover">
<thead>
<tr>
<th scope="col">Dzień</th>
<th scope="col">Zakażonych</th>
<th scope="col"><span class="text-muted">nowych</span></th>
<th scope="col">Zgonów</th>
<th scope="col"><span class="text-muted">nowych</span></th>
<th scope="col">Testów</th>
<th scope="col"><span class="text-muted">pozytywnych</span></th>
</tr>
</thead>
<tbody>
{% for row in table|reverse %}
<tr>
<th scope="row" class="day" data-timestamp="{{ (row.day.timestamp() * 1000) | int }}">
{{ row.day.strftime('%d.%m.%Y') }}
</th>
<td>{{ row.positive }}</td>
<td>{{ '%+d' % row.daily.positive }}</td>
<td>{{ row.deaths }}</td>
<td>{{ '%+d' % row.daily.deaths }}</td>
<td>{{ row.daily.tests }}</td>
<td>{{ "{:,.2f}".format(row.daily.positive / row.daily.tests * 100) }}%</td>
</tr>
{% endfor %}
</tbody>
</table>
{% endfor %}
</div>
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<script type="text/javascript">
var dateOptions = { year: 'numeric', month: 'long', day: 'numeric' };
var data = [
{% for row in chart_data %}
[
new Date({{ row.timestamp }}),
`
<p><strong>${new Date({{ row.timestamp }}).toLocaleDateString('pl-PL', dateOptions)}</strong></p>
<p>Zakażenia: <strong>{{ row.positive }}</strong></p>
<p>Zgony: <strong>{{ row.deaths }}</strong></p>
{% if row.tests %}
<p>Testy: <strong>{{ row.tests }}</strong> (<strong>{{ "{:,.2f}".format(row.positive / row.tests * 100) }}%</strong> pozytywnych)</p>
{% endif %}
`,
{{ row.positive_average }},
{{ row.positive }},
'opacity: 0.2'
],
{% endfor %}
];
var viewport_x = data[data.length - 150][0], viewport_y = {{ viewport_y }};
google.charts.load('current', {'packages': ['corechart'], 'language': 'pl'});
function draw() {
var dataTable = new google.visualization.DataTable();
dataTable.addColumn('date', 'Dzień');
dataTable.addColumn({ 'type': 'string', 'role': 'tooltip', 'p': { 'html': true } });
dataTable.addColumn('number', '7-dniowa średnia krocząca zakażeń');
dataTable.addColumn('number', 'Zakażenia');
dataTable.addColumn({ 'type': 'string', 'role': 'style' });
dataTable.addRows(data);
var options = {
title: 'Warszawa: nowe zakażenia',
width: '100%',
height: 800,
curveType: 'function',
theme: 'material',
aggregationTarget: 'category',
tooltip: { trigger: 'hover', isHtml: true },
focusTarget: 'category',
legend: 'none',
chartArea: { 'width': '80%', 'height': '80%' },
explorer: {
axis: 'horizontal',
actions: ['dragToPan']
},
axisTitlesPosition: 'in',
series: {
0: { axis: 'cases', color: 'red' },
1: { axis: 'cases', color: 'red' }
},
vAxes: {
0: { minValue: 0, viewWindow: { min: 0, max: viewport_y } }
},
hAxis: { viewWindow: { min: viewport_x } },
annotations: {
textStyle: {
fontSize: 18,
bold: true,
color: '#000',
opacity: 1
}
}
};
var chart = new google.visualization.LineChart(document.getElementById('chart'));
chart.draw(dataTable, options);
window.addEventListener('resize', debounce(function(){
var chart = new google.visualization.LineChart(document.getElementById('chart'));
chart.draw(dataTable, options);
}));
}
var debounce = function (func, threshold, execAsap) {
var timeout;
return function debounced () {
var obj = this, args = arguments;
function delayed () {
if (!execAsap)
func.apply(obj, args);
timeout = null;
}
if (timeout)
clearTimeout(timeout);
else if (execAsap)
func.apply(obj, args);
timeout = setTimeout(delayed, threshold || 100);
};
}
google.charts.setOnLoadCallback(draw);
for (let element of document.querySelectorAll('.day')) {
let date = new Date(parseInt(element.dataset.timestamp));
if (date.toDateString() === new Date().toDateString()) {
element.innerText = 'dzisiaj';
}
let yesterday = new Date();
yesterday.setDate(yesterday.getDate() - 1);
if (date.toDateString() === yesterday.toDateString()) {
element.innerText = 'wczoraj';
}
}
</script>
</body>
</html>