-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmapa.js
330 lines (303 loc) · 12.4 KB
/
mapa.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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
/**
* Mapa COVID
*/
var map, zonas, dataTotal, idprovincias, seleccion = "1";
var queryString = window.location.search, urlParams = new URLSearchParams(queryString);
TOSHOW = "" != urlParams ? "departamentos" : "provincias";
GEOJSONTOSHOW = "departamentos" != TOSHOW ? "departamento.geojson" : "provincia.geojson";
DATAJSONTOSHOW = "data_zonas.json";
DATAJSONTOTALES = "data_totales.json";
DEFUNCIONES_PAIS = "defunciones_argentina.json";
var settings;
google.charts.load('current', {'packages':['corechart'], 'callback': cargaTotales } );
var chart;
var defunciones = {};
function drawChartCurves(contagios, fallecidos) {
var now = new Date();
var nanio = settings["Fecha actualizacion"]["Datos"].substring(6, 10);
var nmes = settings["Fecha actualizacion"]["Datos"].substring(3, 5);
var ndia = settings["Fecha actualizacion"]["Datos"].substring(0, 2);
var dias = [ ['día', 'contagios (x1)', 'fallecidos (x10)'] ];
for (var d = new Date(2020, 3, 3); d <= new Date(nanio, nmes - 1, ndia); d.setDate(d.getDate() + 1)) {
fecha = d.toLocaleDateString('en-GB').substring(0,5);
ncontagios = 0;
nfallecidos = 0;
if ((contagios != null) && (contagios[fecha] != null))
{
ncontagios = contagios[fecha];
}
if ((fallecidos != null) && (fallecidos[fecha] != null))
{
nfallecidos = fallecidos[fecha] * 10;
}
registro = [fecha, ncontagios, nfallecidos];
dias.push( registro );
}
var data = google.visualization.arrayToDataTable(dias);
var options = {
'height':360,
'width':666,
'fontSize': 14,
'title':'Líneas de tiempo de contagios y fallecidos del COVID19',
};
options.chartArea = { left: '10%', top: '10%', width: "95%", height: "66%"};
var chart = new google.visualization.LineChart(document.getElementById('chart_curva'));
chart.draw(data, options);
}
function drawDefunciones(in1) {
panel = document.getElementById('chart_defunciones');
mensaje = "";
mensaje = mensaje + '<table class="table table-hover table-dark"><thead><tr><th scope="col">defunciones</th><th scope="col">causa</th><tr></thead><tbody>'
try {
keys = Object.keys(defunciones[in1]);
for (causa in keys) {
nombre = (keys[causa] != "COVID19")? defunciones["codigos"][keys[causa]] : keys[causa];
cantidad = defunciones[in1][keys[causa]]
mensaje = mensaje + "<tr> <td>" + cantidad.toLocaleString() + " </td><td>" + nombre.substring(0, 100) + "</td></tr>";
}
mensaje = mensaje + " </tbody></table>"
mensaje = mensaje + "<center> <a href = 'https://datos.gob.ar/dataset/salud-defunciones-ocurridas-registradas-republica-argentina/archivo/salud_75621151-2d67-4535-9b69-0f99c6a8cf52'>dataset</a></center> "
} catch(e){
mensaje = "";
}
panel.innerHTML = mensaje;
}
function drawChartVelas(poblacion, contagiados, ncontagiados, curados, ncurados, cuidados, ncuidados, fallecidos, nfallecidos, respiradoresp, nrespiradoresp, respiradoresn, nrespiradoresn) {
respiradoresp.splice(0,0,nrespiradoresp + "\nRespiradores\nCOVID +");
respiradoresn.splice(0,0,nrespiradoresn + "\nRespiradores\nCOVID -");
contagiados.splice(0,0,ncontagiados + "\nCOVID+");
curados.splice(0,0,ncurados + "\ncurados");
fallecidos.splice(0,0,nfallecidos +"\nfallecidos");
cuidados.splice(0,0,ncuidados +"\ncuidados intensivos");
var dataInfo = [ contagiados, curados, fallecidos, cuidados, respiradoresp, respiradoresn ]
var data = google.visualization.arrayToDataTable(dataInfo, true);
var porcien = ncontagiados*100 ;
porcien = (porcien / poblacion).toFixed(2);
var titulo = (poblacion == 0)? '\n Gráfico edades min, max y cuartiles': formatMoney(poblacion) + ' población total \nEdades min, max y cuartiles';
var options = {
'height':360,
'width':666,
'fontSize': 14,
'title':titulo,
legend:'none'
};
options.chartArea = { left: '5%', top: '20%', width: "95%", height: "66%"};
chart = new google.visualization.CandlestickChart(document.getElementById('chart_velas'));
chart.draw(data, options);
}
function cargaTotales() {
$.getJSON(DATAJSONTOTALES, function(a) {
if (seleccion != "") {
settings = a;
document.getElementById("mapa_titulo").innerHTML = "Argentina";
showData(a);
}
}).fail(function() {
console.log("An error has occurred.")
});
}
function formatMoney(amount, decimalCount = 0, decimal = ".", thousands = ",") {
try {
decimalCount = Math.abs(decimalCount);
decimalCount = isNaN(decimalCount) ? 2 : decimalCount;
const negativeSign = amount < 0 ? "-" : "";
let i = parseInt(amount = Math.abs(Number(amount) || 0).toFixed(decimalCount)).toString();
let j = (i.length > 3) ? i.length % 3 : 0;
return negativeSign + (j ? i.substr(0, j) + thousands : '') + i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + thousands) + (decimalCount ? decimal + Math.abs(amount - i).toFixed(decimalCount).slice(2) : "");
} catch (e) {
console.log(e)
}
};
function getColorByIn1(in1) {
pormil = 0;
try {
var pintura = document.getElementById("pintura");
if ((zonas!= null) && (zonas[in1] != null) && (typeof(zonas[in1]["pormil"]) != "undefined") && (typeof(zonas[in1]["pormil"]["COVID+"]) != "undefined") )
{
pormil = zonas[in1]["pormil"]["COVID+"];
if ( zonas[in1]["totales"]["COVID+"] > 0)
{
pormil = pormil + 80;
if ( zonas[in1]["totales"]["COVID+"] > 30)
pormil = 255 < pormil ? 255 : 25 * pormil;
} else {
pormil = 0;
}
} else {
pormil = 0;
}
} catch(e) {
pormil = 0;
}
r = pormil;
g = 255 - r;
b = 255 - r;
color = "rgb(" + r + "," + g + ", " + b + ")";
return color;
}
function printData(a) {
text = "";
for (var c in a) {
if ((c != "pormil")&&(c != "nombre"))
a.hasOwnProperty(c) && ("object" != typeof a[c] ? text = text + " " + c + ": " + a[c] + "<br/>" : (subobj = a[c],
text = text + "<br/>" + c + "<br/>",
text += getTextFromJSON(subobj)));
}
return text;
}
function acercade() {
alert('Se muestra en el mapa los datos publicados por el Ministerio de Salud de la Nación Argentia actualizados al día ' + settings["Fecha actualizacion"]["Datos"] + ' y disponibles para descargar en el link de abajo a la derecha. El mapa de COVID Argentina es un desarrollo sin fines de lucro realizado por Carlos Miguens ([email protected]) Por favor notificar toda idea o solicitud de correción, gracias! ');
}
function showData(a) {
if ((a != null) && (a["edad"]!=null)) {
nvivos = (a["totales"]==null)||(a["totales"]["COVID+"]==null) ?0:a["totales"]["COVID+"];
ncurados = (a["totales"]==null)||(a["totales"]["curados"]==null) ?0:a["totales"]["curados"];
ncuidados = (a["totales"]==null)||(a["totales"]["Cuidados"]==null) ?0:a["totales"]["Cuidados"];
nfallecidos = (a["totales"]==null)||(a["totales"]["Fallecidos"]==null) ?0:a["totales"]["Fallecidos"];
nrespiradoresp =(a["respitador"]==null)||(a["respitador"]["+"]==null) ?0:a["respitador"]["+"];
nrespiradoresn = (a["respitador"]==null)||(a["respitador"]["-"]==null) ?0:a["respitador"]["-"];
var contagiados = [a["edad"]["COVID+"].min, a["edad"]["COVID+"].q1, a["edad"]["COVID+"].q2, a["edad"]["COVID+"].max];
var curados = [a["edad"]["curados"].min, a["edad"]["curados"].q1, a["edad"]["curados"].q2, a["edad"]["curados"].max];
var cuidados = [a["edad"]["cuidados"].min, a["edad"]["cuidados"].q1, a["edad"]["cuidados"].q2, a["edad"]["cuidados"].max];
var fallecidos = [a["edad"]["fallecidos"].min, a["edad"]["fallecidos"].q1, a["edad"]["fallecidos"].q2, a["edad"]["fallecidos"].max];
var respiradoresp = 0;
var respiradoresn = 0;
if (a["edad"]["respirador+"] != null) {
respiradoresp = [a["edad"]["respirador+"].min, a["edad"]["respirador+"].q1, a["edad"]["respirador+"].q2, a["edad"]["respirador+"].max];
respiradoresn = [a["edad"]["respirador-"].min, a["edad"]["respirador-"].q1, a["edad"]["respirador-"].q2, a["edad"]["respirador-"].max];
}
poblacion = 0;
if (a["poblacion"] != null)
{
poblacion =a["poblacion"]["T"];
}
drawChartVelas(poblacion, contagiados, nvivos, curados, ncurados, cuidados, ncuidados, fallecidos, nfallecidos, respiradoresp, nrespiradoresp, respiradoresn, nrespiradoresn);
}
if ((a["curvaf"] != null) || (a["curvac"] != null))
{
drawChartCurves(a["curvac"], a["curvaf"]);
}
if ((settings != null) && (settings["Fecha actualizacion"] != null)) {
fecha = (settings["Fecha actualizacion"]["Datos"] != null) ? "<a href='https://sisa.msal.gov.ar/datos/descargas/covid-19/files/Covid19Casos.csv'>Datos actualizados al " + settings["Fecha actualizacion"]["Datos"] + "</a>" : "";
document.getElementById("fecha_actualizacion").innerHTML = fecha;
}
}
function resolverNombre(a) {
nombreKey = a;
"Tierra del Fuego, Ant\u00e1rtida e Islas del Atl\u00e1ntico Sur" === a && (nombreKey = "Tierra del Fuego");
"Ciudad Aut\u00f3noma de Buenos Aires" === a && (nombreKey = "CABA");
return nombreKey
}
$(document).ready(function() {
$.getJSON(DATAJSONTOSHOW, function(a) {
zonas = a
initMap();
showData(zonas);
}).fail(function() {
console.log("An error has occurred.")
})
});
$(document).ready(function() {
$.getJSON(DEFUNCIONES_PAIS, function(data) {
defunciones = data
drawDefunciones(0);
}).fail(function() {
console.log("An error has occurred.")
})
});
var getCircularReplacer = function() {
var a = new WeakSet;
return function(c, d) {
if ("object" === typeof d && null !== d) {
if (a.has(d))
return;
a.add(d)
}
return d
}
};
function reselecciona(a) {
map.data.revertStyle();
map.data.overrideStyle(a.feature, {
strokeWeight: 5
});
nombre = a.feature.getProperty("nam");
in1 = a.feature.getProperty("in1");
document.getElementById("mapa_titulo").innerHTML = nombre;
if(zonas[in1] == null) {
document.getElementById("fallecidos").innerHTML = "sin datos";
drawChartVelas(0,[0, 0, 0, 0],0,[0, 0, 0, 0], 0, [0, 0, 0, 0], 0, [0, 0, 0, 0], 0, [0, 0, 0, 0], 0, [0, 0, 0, 0], 0);
} else {
drawDefunciones(in1)
showData(zonas[in1]);
}
}
function initMap() {
map = new google.maps.Map(document.getElementById("mapa"),{
center: {
lat: -50,
lng: -62
},
zoom: 3.8
});
map.data.loadGeoJson(GEOJSONTOSHOW);
map.data.setStyle(function(a) {
in1 = a.getProperty("in1");
nombre = a.getProperty("nam");
color = getColorByIn1(in1);
return {
fillColor: color,
strokeWeight: 1
}
});
map.data.addListener("click", function(a) {
seleccion = (seleccion == "") ?"1":"";
if (seleccion == "1") reselecciona(a);
});
map.data.addListener("mouseover", function(a) {
if (seleccion == "1") {
reselecciona(a);
}
});
map.data.addListener("mouseout", function(a) {
if (seleccion != "") {
map.data.revertStyle();
document.getElementById("mapa_titulo").innerHTML = "Argentina";
drawDefunciones("0") ;
showData(settings);
}
});
}
sw = 0;
function refreshMapa()
{
if (sw == 1) {
sw = 0;
this.TOSHOW = "provincias";
} else {
sw = 1;
this.TOSHOW = "departamentos";
}
GEOJSONTOSHOW = "departamentos" != TOSHOW ? "departamento.geojson" : "provincia.geojson";
$.getJSON(DATAJSONTOSHOW, function(a) {
zonas = a
initMap();
showData(zonas);
}).fail(function() {
console.log("An error has occurred.")
})
}
function myPeriodicMethod() {
$.ajax({
success: function(data) {
for (i = 0; i < 33;i++)
console.log(i%2 == 0 ? ".: CmIgUeNs :. " : ".: cMiGuEnS :. ");
},
complete: function() {
// schedule the next request *only* when the current one is complete:
setTimeout(myPeriodicMethod, 1000);
}
});
}
// schedule the first invocation:
// setTimeout(myPeriodicMethod, 1500);