(function($) {
'use strict';
function removeData(chart) {
chart.data.labels.pop();
chart.data.datasets.forEach((dataset) => {
dataset.data.pop();
});
chart.update();
}
function funcionAjax(pais,pais_nombre){
try {
filtrar_tabla(pais_nombre);
}
catch{}
try {
$.ajax({
type: "POST",
url: "https://covid19.lemonpot.ai/ajaxPHP/backend.php",
data: {Pais:pais},
beforeSend: function(){
$('#graficoConfirmados').remove();
$("#contGrafico1").append('
');
$('#graficoFallecidos').remove();
$("#contGrafico2").append('');
$('#graficoRecuperados').remove();
$("#contGrafico3").append('');
$('#graficoArea').remove();
$("#contGrafico4").append('');
$('#graficoActivos').remove();
$("#contGrafico5").append('');
$("#totalConfirmados").html('');
$("#totalFallecidos").html('');
$("#totalRecuperados").html('');
$("#activosTotales").html('');
},
success: function(data){
var json = JSON.parse(data);
$("#record_confirmados").html(json.RecordC);
$("#record_muertes").html(json.RecordM);
$("#record_recuperados").html(json.RecordR);
$("#record_activos").html(json.RecordA);
$("#cantidad_dias_confirmados").html(json.cantidad_dias_confirmados);
var labelsFechas = json.fecha;
var dataRecuperados = json.rec;
var arrRecuperados = [];
var dataConfirmados = json.conf;
var arrConfirmados = [];
var dataMuertos = json.muer;
var arrMuertos = [];
var dataActivos = json.act;
var arrActivos = [];
var index = 0;
for (index = 0; index < labelsFechas.length; index++) {
var dictMuertos = {};
dictMuertos["t"] = moment(labelsFechas[index]['date'],"YYYYMMDD");
dictMuertos["y"] = dataMuertos[index];
arrMuertos.push(dictMuertos);
var dictConfirmados = {};
dictConfirmados["t"] = moment(labelsFechas[index]['date'],"YYYYMMDD");
dictConfirmados["y"] = dataConfirmados[index];
arrConfirmados.push(dictConfirmados);
var dictRecuperados = {};
dictRecuperados["t"] = moment(labelsFechas[index]['date'],"YYYYMMDD");
dictRecuperados["y"] = dataRecuperados[index];
arrRecuperados.push(dictRecuperados);
var dictActivos = {};
dictActivos["t"] = moment(labelsFechas[index]['date'],"YYYYMMDD");
dictActivos["y"] = dataActivos[index];
arrActivos.push(dictActivos);
labelsFechas[index] = labelsFechas[index]['date'];
}
var confirmadosTotales = json.confTotales;
var recuperadosTotales = json.recTotales;
var fallecidosTotales = json.muerTotales;
var ultimoConfirmados = json.ultimosConfirmados;
var ultimoFallecidos = json.ultimosFallecidos;
var ultimoRecuperados = json.ultimoRecuperados;
var activosTotales = json.activosTotales;
var inf = json.inf;
var sup = json.sup;
var arrFechasPrediccion = json.fechaPre;
var arrSupPrediccion = json.arrSup;
var arrInfPrediccion = json.arrInf;
var arrInf = [];
var arrSup = [];
for (index = 0; index < arrFechasPrediccion.length; index++) {
var dictInf = {};
dictInf["t"] = moment(arrFechasPrediccion[index],"YYYYMMDD");
dictInf["y"] = arrInfPrediccion[index];
arrInf.push(dictInf);
var dictSup = {};
dictSup["t"] = moment(arrFechasPrediccion[index],"YYYYMMDD");
dictSup["y"] = arrSupPrediccion[index];
arrSup.push(dictSup);
arrFechasPrediccion[index] = arrFechasPrediccion[index];
}
$("#bandera_dashboard").attr("src",json.srcBandera);
$("#pais_dashboard").text(json.nombrePais2);
$("#totalConfirmados").text(confirmadosTotales);
$("#ultimoDiaConfirmados").text(ultimoConfirmados);
$("#totalFallecidos").text(fallecidosTotales);
$("#ultimoDiaFallecidos").text(ultimoFallecidos);
$("#totalRecuperados").text(recuperadosTotales);
$("#ultimoDiaRecuperados").text(ultimoRecuperados);
$("#activosTotales").text(activosTotales);
$("#estimacionInf").text(inf);
$("#estimacionSup").text(sup);
$("#porcentajeConfirmadosNuevos").text(json.porcentajeConfirmados);
$("#porcentajeRecuperadosNuevos").text(json.porcentajeRecuperados);
$("#porcentajeFallecidosNuevos").text(json.porcentajeFallecidos);
if (json.ultimosActivos < 0) {
$("#ultimosActivos").text(json.ultimosActivos);
$("#colorUltimosActivos").removeClass("bg-red");
$("#colorUltimosActivos").addClass("bg-success");
}else {
$("#colorUltimosActivos").removeClass("bg-success");
$("#colorUltimosActivos").addClass("bg-red");
$("#ultimosActivos").text("+"+json.ultimosActivos);
}
if (json.porcentajeActivos[0]=="-") {
$("#porcentajeActivos").text(json.porcentajeActivos);
}else {
$("#porcentajeActivos").text("+"+json.porcentajeActivos);
}
$("#tasaMortalidad").text(json.tasaMortalidad);
$(".nombre_pais").text(json.nombrePais);
$("#duplicadosReal").text(json.duplicadosReal);
$("#duplicadosPrediccion").text(json.duplicadosPrediccion);
if (json.controlCurva == 0) {
var pa = ''+json.nombrePais+'SI ha logrado estabilizar su curva de contagios.';
$("#texto_estabilizacion").html(pa);
}else if (json.controlCurva == 1) {
$("#texto_estabilizacion").html(''+json.nombrePais+'NO ha logrado estabilizar su curva de contagios.');
}
else{
$("#texto_estabilizacion").html(''+json.nombrePais+'está en vias de estabilizar su curva de contagios.');
}
var configActivos = {
type: 'line',
data: {
labels: labelsFechas,
datasets: [{
pointRadius: 0,
label: 'Activos',
backgroundColor: $.constants.primary,
borderColor: $.constants.primary,
data: arrActivos,
fill: true,
}]
},
options: {
plugins: {
p1: false // disable plugin 'p1' for this instance
},
responsive: true,
maintainAspectRatio: false,
title: {
display: false,
text: 'Total Confirmados',
},
legend:{
display:false
},
tooltips: {
mode: 'index',
intersect: false,
},
hover: {
mode: 'nearest',
intersect: true
},
scales: {
xAxes: [{
gridLines: {
display:false
},
type: 'time',
time: {
unit: 'month'
},
display: true,
//scaleLabel: {
// display: true,
// labelString: 'Date'
//}
}],
yAxes: [{
ticks: {
callback: function(label, index, labels) {
return label/1000+'k';
}
},
gridLines: {
display:false
},
display: true,
scaleLabel: {
display: false,
labelString: 'Value'
}
}]
}
}
}; // fin configActivos
var configConfirmados = {
type: 'line',
data: {
labels: labelsFechas,
datasets: [{
pointRadius: 0,
label: 'Confirmados',
backgroundColor: $.constants.primary,
borderColor: $.constants.primary,
data: arrConfirmados,
fill: true,
}]
},
options: {
responsive: true,
maintainAspectRatio: false,
title: {
display: false,
text: 'Total Confirmados',
},
legend:{
display:false
},
tooltips: {
mode: 'index',
intersect: false,
},
hover: {
mode: 'nearest',
intersect: true
},
scales: {
xAxes: [{
gridLines: {
display:false
},
type: 'time',
time: {
unit: 'month'
},
display: true,
//scaleLabel: {
// display: true,
// labelString: 'Date'
//}
}],
yAxes: [{
ticks: {
callback: function(label, index, labels) {
return label/1000+'k';
}
},
gridLines: {
display:false
},
display: true,
scaleLabel: {
display: false,
labelString: 'Value'
}
}]
}
}
}; // fin configConfirmados
var configRecuperados = {
type: 'line',
data: {
labels: labelsFechas,
datasets: [{
pointRadius: 0,
label: 'Recuperados',
backgroundColor: $.constants.success,
borderColor: $.constants.success,
data: arrRecuperados,
fill: true,
}]
},
options: {
responsive: true,
maintainAspectRatio: false,
title: {
display: false,
text: 'Total Recuperados',
},
legend:{
display:false
},
tooltips: {
mode: 'index',
intersect: false,
},
hover: {
mode: 'nearest',
intersect: true
},
scales: {
xAxes: [{
gridLines: {
display:false
},
type: 'time',
time: {
unit: 'month'
},
display: true,
//scaleLabel: {
// display: true,
// labelString: 'Date'
//}
}],
yAxes: [{
ticks: {
callback: function(label, index, labels) {
return label/1000+'k';
}
},
gridLines: {
display:false
},
display: true,
scaleLabel: {
display: false,
labelString: 'Value'
}
}]
}
}
};
var configMuertos = {
type: 'line',
data: {
labels: labelsFechas,
datasets: [{
pointRadius: 0,
label: 'Muertes',
backgroundColor: $.constants.danger,
borderColor: $.constants.danger,
data: arrMuertos,
fill: true,
}]
},
options: {
responsive: true,
maintainAspectRatio: false,
title: {
display: false,
text: 'Muertes Confirmadas',
},
legend:{
display:false
},
tooltips: {
mode: 'index',
intersect: false,
},
hover: {
mode: 'nearest',
intersect: true
},
scales: {
xAxes: [{
gridLines: {
display:false
},
type: 'time',
time: {
unit: 'month'
},
display: true,
//scaleLabel: {
// display: true,
// labelString: 'Date'
//}
}],
yAxes: [{
ticks: {
callback: function(label, index, labels) {
return label/1000+'k';
}
},
gridLines: {
display:false
},
display: true,
scaleLabel: {
display: false,
labelString: 'Value'
}
}]
}
}
};
var configArea = {
type: 'line',
data: {
labels: arrFechasPrediccion,
datasets: [{
pointRadius: 0,
label: 'Inferior',
backgroundColor: $.constants.primary,
borderColor: $.constants.primary,
data: arrInf,
fill: false,
},
{
pointRadius: 0,
label: 'Superior',
backgroundColor: $.constants.info,
borderColor: $.constants.info,
data: arrSup,
fill: "-1",
}]
},
options: {
responsive: true,
maintainAspectRatio: false,
title: {
display: false,
text: 'Grafico Prediccion',
},
legend:{
display:false
},
tooltips: {
mode: 'index',
intersect: false,
itemSort: function(a, b) {
return b.datasetIndex - a.datasetIndex;
},
},
hover: {
mode: 'nearest',
intersect: true
},
scales: {
xAxes: [{
gridLines: {
display:false
},
type: 'time',
time: {
unit: 'month'
},
display: true,
}],
yAxes: [{
ticks: {
callback: function(label, index, labels) {
return label/1000+'k';
}
},
gridLines: {
display:false
},
display: true,
scaleLabel: {
display: false,
labelString: 'Value'
}
}]
}
}
}; // fin
$('#graficoActivos').remove();
$("#contGrafico5").append('');
$('#graficoConfirmados').remove();
$("#contGrafico1").append('');
$('#graficoFallecidos').remove();
$("#contGrafico2").append('');
$('#graficoRecuperados').remove();
$("#contGrafico3").append('');
$('#graficoArea').remove();
$("#contGrafico4").append('');
var ctx5 = document.getElementById('graficoActivos').getContext('2d');
var chart5 = new Chart(ctx5, configActivos);
var ctx1 = document.getElementById('graficoConfirmados').getContext('2d');
var chart1 = new Chart(ctx1, configConfirmados);
console.log(chart1);
var ctx2 = document.getElementById('graficoFallecidos').getContext('2d');
window.myLine2 = new Chart(ctx2, configMuertos);
var ctx3 = document.getElementById('graficoRecuperados').getContext('2d');
window.myLine3 = new Chart(ctx3, configRecuperados);
var ctx4 = document.getElementById('graficoArea').getContext('2d');
window.myLine4 = new Chart(ctx4, configArea);
}, // fin success
error: function(xhr) { // if error occured
console.log("Error en ajax home");
},
}); // fin ajax
}
catch
{}
}
function updateGrafico(grafico, dias){
var pais = $(".paisSeleccionado").attr("id");
// graficos 1,2,3,4,5
// dias (hacia atras) 0=todos, 7, 30
$.ajax({
type: "POST",
url: "https://covid19.lemonpot.ai/ajaxPHP/backend.php",
data: {actualizarGraficos:1,grafico:grafico,dias:dias,Pais2:pais},
beforeSend: function(){
if (grafico == 1) {
$('#graficoConfirmados').remove();
$("#contGrafico1").append('');
}else if ( grafico == 2 ) {
$('#graficoFallecidos').remove();
$("#contGrafico2").append('');
}else if ( grafico == 3 ) {
$('#graficoRecuperados').remove();
$("#contGrafico3").append('');
}else if ( grafico == 4 ) {
$('#graficoArea').remove();
$("#contGrafico4").append('');
}else {
$('#graficoActivos').remove();
$("#contGrafico5").append('');
}
},
success: function(data){
var json = JSON.parse(data);
if(dias > 0){
var diaOmes = 'day';
}else{
var diaOmes = 'month';
}
var arrFechas = json.fechas;
console.log(arrFechas);
console.log(json.cont);
console.log(grafico);
console.log(pais);
console.log(dias);
if (grafico == 1) {
var arrDatos = json.arrDatos;
console.log(json.arrDatos);
$('#graficoConfirmados').remove();
$("#contGrafico1").append('');
var configConfirmados = {
type: 'line',
data: {
labels: arrFechas,
datasets: [{
pointRadius: 0,
label: 'Confirmados',
backgroundColor: $.constants.primary,
borderColor: $.constants.primary,
data: arrDatos,
fill: true,
}]
},
options: {
responsive: true,
maintainAspectRatio: false,
title: {
display: false,
text: 'Total Confirmados',
},
legend:{
display:false
},
tooltips: {
mode: 'index',
intersect: false,
},
hover: {
mode: 'nearest',
intersect: true
},
scales: {
xAxes: [{
gridLines: {
display:false
},
type: 'time',
time: {
unit: diaOmes
},
display: true,
//scaleLabel: {
// display: true,
// labelString: 'Date'
//}
}],
yAxes: [{
ticks: {
callback: function(label, index, labels) {
return label/1000+'k';
}
},
gridLines: {
display:false
},
display: true,
scaleLabel: {
display: false,
labelString: 'Value'
}
}]
}
}
}; // fin configConfirmados
var ctx1 = document.getElementById('graficoConfirmados').getContext('2d');
var chart1 = new Chart(ctx1, configConfirmados);
}else if (grafico == 2) {
var arrDatos = json.arrDatos;
$('#graficoFallecidos').remove();
$("#contGrafico2").append('');
var configMuertos = {
type: 'line',
data: {
labels: arrFechas,
datasets: [{
pointRadius: 0,
label: 'Muertes',
backgroundColor: $.constants.danger,
borderColor: $.constants.danger,
data: arrDatos,
fill: true,
}]
},
options: {
responsive: true,
maintainAspectRatio: false,
title: {
display: false,
text: 'Muertes Confirmadas',
},
legend:{
display:false
},
tooltips: {
mode: 'index',
intersect: false,
},
hover: {
mode: 'nearest',
intersect: true
},
scales: {
xAxes: [{
gridLines: {
display:false
},
type: 'time',
time: {
unit: diaOmes
},
display: true,
//scaleLabel: {
// display: true,
// labelString: 'Date'
//}
}],
yAxes: [{
ticks: {
callback: function(label, index, labels) {
return label/1000+'k';
}
},
gridLines: {
display:false
},
display: true,
scaleLabel: {
display: false,
labelString: 'Value'
}
}]
}
}
};
var ctx2 = document.getElementById('graficoFallecidos').getContext('2d');
window.myLine2 = new Chart(ctx2, configMuertos);
}else if (grafico == 3) {
var arrDatos = json.arrDatos;
$('#graficoRecuperados').remove();
$("#contGrafico3").append('');
var configRecuperados = {
type: 'line',
data: {
labels: arrFechas,
datasets: [{
pointRadius: 0,
label: 'Recuperados',
backgroundColor: $.constants.success,
borderColor: $.constants.success,
data: arrDatos,
fill: true,
}]
},
options: {
responsive: true,
maintainAspectRatio: false,
title: {
display: false,
text: 'Total Recuperados',
},
legend:{
display:false
},
tooltips: {
mode: 'index',
intersect: false,
},
hover: {
mode: 'nearest',
intersect: true
},
scales: {
xAxes: [{
gridLines: {
display:false
},
type: 'time',
time: {
unit: diaOmes
},
display: true,
//scaleLabel: {
// display: true,
// labelString: 'Date'
//}
}],
yAxes: [{
ticks: {
callback: function(label, index, labels) {
return label/1000+'k';
}
},
gridLines: {
display:false
},
display: true,
scaleLabel: {
display: false,
labelString: 'Value'
}
}]
}
}
};
var ctx3 = document.getElementById('graficoRecuperados').getContext('2d');
window.myLine3 = new Chart(ctx3, configRecuperados);
}else if (grafico == 4) {
var arrInf = json.arrInf;
var arrSup = json.arrSup;
$('#graficoArea').remove();
$("#contGrafico4").append('');
var configArea = {
type: 'line',
data: {
labels: arrFechas,
datasets: [{
pointRadius: 0,
label: 'Inferior',
backgroundColor: $.constants.primary,
borderColor: $.constants.primary,
data: arrInf,
fill: false,
},
{
pointRadius: 0,
label: 'Superior',
backgroundColor: $.constants.info,
borderColor: $.constants.info,
data: arrSup,
fill: "-1",
}]
},
options: {
responsive: true,
maintainAspectRatio: false,
title: {
display: false,
text: 'Grafico Prediccion',
},
legend:{
display:false
},
tooltips: {
mode: 'index',
intersect: false,
itemSort: function(a, b) {
return b.datasetIndex - a.datasetIndex;
},
},
hover: {
mode: 'nearest',
intersect: true
},
scales: {
xAxes: [{
gridLines: {
display:false
},
type: 'time',
time: {
unit: diaOmes
},
display: true,
}],
yAxes: [{
ticks: {
callback: function(label, index, labels) {
return label/1000+'k';
}
},
gridLines: {
display:false
},
display: true,
scaleLabel: {
display: false,
labelString: 'Value'
}
}]
}
}
}; // fin
var ctx4 = document.getElementById('graficoArea').getContext('2d');
window.myLine4 = new Chart(ctx4, configArea);
}else {
var arrDatos = json.arrDatos;
$('#graficoActivos').remove();
$("#contGrafico5").append('');
var configActivos = {
type: 'line',
data: {
labels: arrFechas,
datasets: [{
pointRadius: 0,
label: 'Activos',
backgroundColor: $.constants.primary,
borderColor: $.constants.primary,
data: arrDatos,
fill: true,
}]
},
options: {
responsive: true,
maintainAspectRatio: false,
title: {
display: false,
text: 'Total Confirmados',
},
legend:{
display:false
},
tooltips: {
mode: 'index',
intersect: false,
},
hover: {
mode: 'nearest',
intersect: true
},
scales: {
xAxes: [{
gridLines: {
display:false
},
type: 'time',
time: {
unit: diaOmes
},
display: true,
//scaleLabel: {
// display: true,
// labelString: 'Date'
//}
}],
yAxes: [{
ticks: {
callback: function(label, index, labels) {
return label/1000+'k';
}
},
gridLines: {
display:false
},
display: true,
scaleLabel: {
display: false,
labelString: 'Value'
}
}]
}
}
}; // fin configActivos
var ctx5 = document.getElementById('graficoActivos').getContext('2d');
var chart5 = new Chart(ctx5, configActivos);
}
},error: function(){
console.log("ERROR");
}
});
}
$('.tiempoGrafico1').click(function () {
var id = $(this).attr("id");
$(".p1Seleccionado").removeClass("p1Seleccionado");
$(this).addClass("p1Seleccionado");
if ((id.localeCompare("7grafico1"))==0) {
updateGrafico(1, 7);
}else if ((id.localeCompare("30grafico1"))==0) {
updateGrafico(1, 30)
}else {
updateGrafico(1, 0)
}
});
$('.tiempoGrafico2').click(function () {
var id = $(this).attr("id");
$(".p2Seleccionado").removeClass("p2Seleccionado");
$(this).addClass("p2Seleccionado");
if ((id.localeCompare("7grafico2"))==0) {
updateGrafico(2, 7);
}else if ((id.localeCompare("30grafico2"))==0) {
updateGrafico(2, 30)
}else {
updateGrafico(2, 0)
}
});
$('.tiempoGrafico3').click(function () {
var id = $(this).attr("id");
$(".p3Seleccionado").removeClass("p3Seleccionado");
$(this).addClass("p3Seleccionado");
if ((id.localeCompare("7grafico3"))==0) {
updateGrafico(3, 7);
}else if ((id.localeCompare("30grafico3"))==0) {
updateGrafico(3, 30)
}else {
updateGrafico(3, 0)
}
});
$('.tiempoGrafico4').click(function () {
var id = $(this).attr("id");
$(".p4Seleccionado").removeClass("p4Seleccionado");
$(this).addClass("p4Seleccionado");
if ((id.localeCompare("7grafico4"))==0) {
updateGrafico(4, 7);
}else if ((id.localeCompare("30grafico4"))==0) {
updateGrafico(4, 30)
}else {
updateGrafico(4, 0)
}
});
$('.tiempoGrafico5').click(function () {
var id = $(this).attr("id");
$(".p5Seleccionado").removeClass("p5Seleccionado");
$(this).addClass("p5Seleccionado");
if ((id.localeCompare("7grafico5"))==0) {
updateGrafico(5, 7);
}else if ((id.localeCompare("30grafico5"))==0) {
updateGrafico(5, 30)
}else {
updateGrafico(5, 0)
}
});
$( document ).ready(function() {
funcionAjax("global");});
$('.Filtrar_Pais_li').click(function () {
$(".paisSeleccionado").removeClass("paisSeleccionado");
$(this).addClass("paisSeleccionado");
var obj1 = { Title: 'Estadisticas COVID19 para '+this.title+' - LEMONPOT', Url: 'https://covid19.lemonpot.ai/dashboard/'+this.getAttribute("data-name") };
history.pushState(obj1, obj1.Title, obj1.Url);
document.getElementById('titulo_dashboard').innerHTML = obj1.Title;
_paq.push(['setCustomUrl', obj1.Url]);
_paq.push(['setDocumentTitle', obj1.Title]);
// remove all previously assigned custom variables, requires Matomo (formerly Piwik) 3.0.2
_paq.push(['deleteCustomVariables', 'page']);
_paq.push(['setGenerationTimeMs', 0]);
_paq.push(['trackPageView']);
gtag('config', 'UA-6855864-11', {'page_location':obj1.Url,'page_title':obj1.Title,'page_path': 'dashboard/'+this.getAttribute("data-name")});
gtag('js', new Date());
funcionAjax(this.id,this.title);
});
})(jQuery);