"use strict";
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread(); }
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance"); }
function _iterableToArray(iter) { if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter); }
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } }
/**
* This is main plugin loading function
* Feel free to write your own compiler
*/
W.loadPlugin(
/* Mounting options */
{
"name": "windy-plugin-cov",
"version": "0.1.95",
"author": "rittels",
"repository": {
"type": "git",
"url": "git+https://github.com/rittels/"
},
"description": "Covid-19",
"displayName": "Covid-19",
"hook": "contextmenu",
"className": "plugin-lhpane plugin-mobile-fullscreen",
"dependencies": ["https://unpkg.com/windyplugin-module-pickertools/dist/pickerTools.js", "https://unpkg.com/windyplugin-module-infobox/dist/infobox.js"],
"exclusive": "lhpane"
},
/* HTML */
'
',
/* CSS */
'.picker-content.p-empty{background-color:rgba(68,65,65,0.84) !important;width:auto !important;height:auto !important}.picker-content.p-empty .picker-close-button{left:calc(100% + 8px) !important}.little-shy{transition:.7s opacity 0s;-webkit-transition:.7s opacity 0s}.moooving .little-shy{opacity:.9 !important}.onwindy-plugin-cov .left-border{left:400px}.onwindy-plugin-cov #search{display:none}.bottom-shift-down{bottom:-70px}#device-mobile #cov-title{display:none !important}#device-mobile #plugin-content-11{margin-top:11px !important}#device-mobile .bottom-shift-down{bottom:-85px}.infobox-div-inline-block-when-mobile{display:inline-block}.cov-buttons{position:relative;font-size:13px;margin:0px 1px;text-align:center;cursor:pointer;padding:3px;border-radius:3px;border:1px solid black;height:23px;background-color:rgba(0,0,0,0.5);pointer-events:auto;display:inline-block;overflow-y:hidden}.cov-buttons.selected{background-color:#d49500}.cov-buttons.cov-left{width:80px}.cov-buttons.cov-right{width:45px}.cov-buttons:active{background-color:rgba(0,0,0,0.7);padding-top:4px}.cov-transition{transition:opacity .5s}#windy-plugin-cov{width:400px;height:100%}#windy-plugin-cov .plugin-content{padding:3px 5px 3px 5px;border-radius:5px;margin:1.5px;font-size:13px;color:white;line-height:1;background-color:rgba(0,0,0,0.8)}#windy-plugin-cov .plugin-content .header{background-color:rgba(0,0,0,0.8);margin-right:2px;margin-bottom:2px;border:1px solid black;display:inline-block;width:calc(50% - 1px);height:28px;padding:3px;border-radius:5px;color:white;text-shadow:0px 0px 4px black;cursor:pointer}#windy-plugin-cov .plugin-content .header.end{margin-right:0px}#windy-plugin-cov .plugin-content .header#cov-title{width:100%;text-align:center;background-color:#9D0300}#windy-plugin-cov .plugin-content .cov-graph-div{padding:1px;border-radius:3px;border:1px solid rgba(255,255,255,0);text-align:right;margin:.5px;width:calc(26% - 2px);min-height:10px;display:inline-block}#windy-plugin-cov .plugin-content .closing-x-small{font-family:iconfont;font-variant:normal;text-transform:none;line-height:1;color:white;background-color:#9D0300;cursor:pointer;position:sticky;top:2px;float:right;margin:2px 0px 0px 12px;font-size:16px;z-index:10;width:1em;height:1em;border-radius:1em;opacity:.2}#windy-plugin-cov .plugin-content .closing-x-small::before{content:\'\\e013\'}#windy-plugin-cov .plugin-content .cov-div{margin:0px;border:0px;padding:1px;padding-left:4px;padding-right:4px;font-size:13px;opacity:.9;text-shadow:0px 0px 2px black}#windy-plugin-cov .plugin-content .cov-div .cov-div-txt{padding:1px;cursor:pointer;border-radius:5px;width:250px;display:inline-block}#windy-plugin-cov .plugin-content .range-thumb{position:absolute;top:0px;pointer-events:none;background-color:darkorange;margin:1px;width:16px;height:16px;border-radius:7px;border:1px solid rgba(0,0,0,0.8)}#windy-plugin-cov .plugin-content .range-shade{position:absolute;top:0px;pointer-events:none;background-color:#9D0300;opacity:.3;margin:0px;height:18px;border-radius:6px;overflow:hidden}#windy-plugin-cov .plugin-content .range-container{position:relative;display:inline-block;height:20px;border:1px solid rgba(255,255,255,0.3);border-radius:8px;margin:1px;vertical-align:bottom;background-color:rgba(0,0,0,0.1);cursor:pointer}#windy-plugin-cov .plugin-content #datepicker .daydiv{color:white;cursor:pointer;position:relative;margin:0px;border:0px solid green;width:14%;font:11px arial;display:inline-block;text-align:center}#windy-plugin-cov .plugin-content #datepicker .daydiv:hover{font-weight:bold}#windy-plugin-cov .plugin-content #datepicker .selected-date{font-weight:bold;color:darkorange}',
/* Constructor */
function () {
var _this = this;
var rs = W.require('rootScope');
var utils = W.require('utils');
var picker = W.require('picker');
var store = W.require('store');
var bcast = W.require('broadcast');
var interpolator = W.require('interpolator');
var map = W.require('map');
var ib = W.require('windy-plugin-module-infobox');
var pickerT = W.require('windy-plugin-module-pickerTools');
var $ = utils.$;
console.log(W);
var readme = "\n- This Covid-19 plugin displays the dramatic unfolding of the Coronavirus pandemic.\n- The historical data come from Johns Hopkins CSSE's repo on github: https://github.com/CSSEGISandData/COVID-19.\n- The Johns Hopkins github data lag their dashboard by a few hours.\n- The most recent data come from Worldometer: https://www.worldometers.info/coronavirus/#countries.\n- I obtained the geojson files for the region boundaries from various sources, predominantly from here: https://geojson-maps.ash.ms.\n- The population data also come mostly from https://geojson-maps.ash.ms, and Wikipedia.\n- The data are displayed as an interactive chloropleth map, the color shading is logarithmic by default.\n- You can select absolute cases or cases per population, and all cases or new cases over a selected number of days (1-7).\n- Moving the time slider at the bottom, updates the map.\n- The left pane shows the graphs of the country selected with the Picker. If the Picker is closed, the world is shown.\n- I wish you all well!\n\n";
$("#cov-about-content").innerHTML = readme.replace(/- /g, "
- ");
if (rs.isTablet) {
$("#logo").style.left = "100%";
$("#logo").style.marginLeft = "-150px";
}
if ($("#open-in-app")) $("#open-in-app").style.display = "none";
if (rs.isMobile || rs.isTablet) {
this.onopen = function () {
$("#plugin-content-12").appendChild($("#covid-time-range-cont"));
$("#covid-time-range-cont").style.width = "100%";
};
this.onclose = function () {
_this.refs.infobox.appendChild($("#covid-time-range-cont"));
$("#covid-time-range-cont").style.width = "calc(100% - ".concat(rs.isMobile ? 65 : 55, "px)");
};
}
$("#plugins").classList.remove("shy");
$("#plugins").classList.add("little-shy");
var overlayOp = 1;
$(".overlay-layer").classList.add("cov-transition");
map.options.minZoom = 1;
var countryPane = map.createPane('countries');
countryPane.style.zIndex = -100;
function showCovMap() {
overlayOp = 0.2;
if ($(".sea-mask-layer")) {
countryPane.style.zIndex = 200;
overlayOp = 0.5;
} else countryPane.style.zIndex = -100;
W.tileLayer.setOpacity(overlayOp);
hideCal();
}
function hideCovMap() {
overlayOp = 1;
countryPane.style.zIndex = -100;
W.tileLayer.setOpacity(overlayOp);
showCal();
}
var z = map.getZoom();
map.on("zoomend", function (e) {
e = e.target._zoom;
if (e < 3 && z >= 3 || e >= 3 && z < 3) {
z = e;
if (z < 3) continentLayer.addTo(map);else continentLayer.remove();
} else z = e;
});
var contenty = [56, 56, 28];
var moveContent = function moveContent(n, page, move) {
for (var i = n; i > 1; i--) {
contenty[i - 2] += move;
$("#plugin-content-" + page + i).style.top = "calc(100% - ".concat(contenty[i - 2], "px)");
$("#plugin-content-" + page + (i - 1)).style.bottom = contenty[i - 2] + "px";
}
};
moveContent(4, 1, 0);
if (rs.isMobile || rs.isTablet) {
moveContent(2, 1, 45);
$("#plugin-content-12").style.display = "block";
setTimeout(function () {
$("#plugin-content-12").appendChild($("#covid-time-range-cont"));
$("#covid-time-range-cont").style.width = "100%";
}, 500);
}
$("#covid-select-date").addEventListener("click", function () {
if ($("#datepicker").style.display == "none") {
$("#datepicker").style.display = "block";
$("#plugin-content-13").firstElementChild.style.opacity = 1;
moveContent(3, 1, 135);
var dt = new Date(ts2020 + (dayi + 21) * d1);
datePicker.dateSel = dt;
datePicker.fillCal(dt.getTime());
} else {
$("#plugin-content-13").firstElementChild.style.opacity = 0.2;
$("#datepicker").style.display = "none";
moveContent(3, 1, -135);
}
});
$("#plugin-content-13").firstElementChild.addEventListener("click", function (e) {
if ($("#datepicker").style.display == "block") {
e.target.style.opacity = 0.2;
$("#datepicker").style.display = "none";
moveContent(3, 1, -135);
}
});
$("#cov-about").addEventListener("click", function () {
if ($("#cov-about-content").style.display == "none") {
$("#plugin-content-14").firstElementChild.style.opacity = 1;
$("#cov-about-content").style.display = "block";
moveContent(4, 1, 200);
} else {
$("#plugin-content-14").firstElementChild.style.opacity = 0.2;
$("#cov-about-content").style.display = "none";
moveContent(4, 1, -200);
}
});
$("#plugin-content-14").firstElementChild.addEventListener("click", function (e) {
if ($("#cov-about-content").style.display == "block") {
e.target.style.opacity = 0.2;
$("#cov-about-content").style.display = "none";
moveContent(4, 1, -200);
}
});
var _loop = function _loop(i) {
$("#cov-head-" + i).addEventListener("click", function (e) {
if ($("#cov-page-" + i).style.display == "none") {
$("#cov-head-" + i).style.color = "rgba(255,255,255,1)";
$("#cov-head-" + (3 - i)).style.color = "rgba(255,255,255,0.5)";
$("#cov-page-" + i).style.display = "block";
$("#cov-page-" + (3 - i)).style.display = "none";
}
});
};
for (var i = 1; i < 3; i++) {
_loop(i);
}
var regdiv = [],
regtxt = [];
var fetchTries = 0;
var countries = [];
var rules = [];
var polylist = [];
var polyAr = [],
polyAr2 = [];
var curReg = "",
curPoly = "",
curRule = "",
curPop = 0,
curRuleTxt = "",
curOffs = 0,
curRuleContent = false;
var covReg;
var prevReg;
var loaded = false;
var url = "https://www.openaipgeojson.com/covid/";
var ts2020 = new Date(Date.UTC(2020, 0, 1)).getTime();
var doy = Math.floor((Date.now() - ts2020) / (24 * 60 * 60 * 1000));
var dayMax = doy - 21 - 1;
var dayi = dayMax;
var dayiprev;
var d1 = 24 * 60 * 60 * 1000;
var h1 = 60 * 60 * 1000;
var weekdays = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
var mnths = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
var dataSel = "confirmed";
var dataFlds = ["confirmed", "deaths", "recovered"];
var newdays = 7;
var logb = [];
var maxTot = [];
var world = {
"n": "World",
"pop": 7713468000,
"max": []
};
this.refs.infobox = ib("\n \n
Confirmed
\n
Deaths
\n
Recovered
\n
\n
Abs
/ Pop
\n
All
New
\n
Log
Linear
\n
\n \n Hide Windy Cal
\n \n "), "covid-menu", this, false);
var prevInfoBottom;
var toggleCal = this.refs.infobox.querySelector("#hide-windy-cal");
function hideCal() {
$("#bottom").classList.add("bottom-shift-down");
toggleCal.style.bottom = "40px";
toggleCal.innerHTML = "Show Windy Cal";
$("#playpause-mobile").style.display = "none";
}
function showCal() {
$("#bottom").classList.remove("bottom-shift-down");
toggleCal.style.bottom = "-20px";
toggleCal.innerHTML = "Hide Windy Cal";
$("#playpause-mobile").style.display = "block";
}
toggleCal.addEventListener("click", function (e) {
if (e.target.style.bottom == "-20px") {
hideCal();
} else {
showCal();
}
});
this.refs.infobox.querySelector("#" + dataSel).classList.add("selected");
var infobuttons = this.refs.infobox;
function sel(id) {
infobuttons.querySelector("#" + id).classList.add("selected");
}
function desel(id) {
infobuttons.querySelector("#" + id).classList.remove("selected");
}
var opts = {
"abs": {
"val": true,
"ids": ["absolute", "perpop"]
},
"all": {
"val": true,
"ids": ["allcases", "newcases"]
},
"log": {
"val": true,
ids: ["logar", "linear"]
}
};
for (var p in opts) {
sel(opts[p].ids[opts[p].val ? 0 : 1]);
}
infobuttons.querySelectorAll(".data-sel").forEach(function (e) {
e.addEventListener("click", function (ev) {
var id = ev.target.id;
if (dataFlds.includes(id)) {
sel(id);
dataSel = id;
dataFlds.forEach(function (d) {
if (d != id) desel(d);
});
colorLayer = dataSel == "confirmed" ? "greenred" : dataSel == "deaths" ? "lilac" : "green";
} else {
var _loop2 = function _loop2(_p) {
opts[_p].ids.forEach(function (id2, j) {
if (id2 == id) {
opts[_p].val = !j;
sel(id2);
desel(opts[_p].ids[1 - j]);
}
});
};
for (var _p in opts) {
_loop2(_p);
}
}
calcLogB();
fillAllPolys();
updateLegend();
showCovMap();
});
});
$("#covid-play").addEventListener("click", covidPlay);
function covidPlay() {
if (!play) {
play = setInterval(function () {
$("#covid-play").innerHTML = "e";
dayi += 1;
if (dayi > dayMax) dayi = 0;
updateGraph();
showDate();
fillAllPolys();
$("#covid-time-thumb").style.left = 100 * rangeW / (rangeW + 3) * dayi / dayMax + "%";
}, 500);
} else {
$("#covid-play").innerHTML = "f";
clearInterval(play);
play = false;
}
}
var play;
var paneI = 0;
var svgWidth = $("#covid-time-range").parentElement.offsetWidth;
$("#covid-time-svg").setAttribute("viewBox", "0 0 " + svgWidth + " 30");
var pth = document.createElementNS("http://www.w3.org/2000/svg", 'path');
var pthSun = document.createElementNS("http://www.w3.org/2000/svg", 'path');
Object.assign(pth.style, {
"stroke": "white",
"stroke-width": "1px",
"stroke-opacity": 0.5
});
Object.assign(pthSun.style, {
"stroke": "yellow",
"stroke-width": "1px",
"stroke-opacity": 1
});
$("#covid-time-svg").appendChild(pth);
$("#covid-time-svg").appendChild(pthSun);
function drawTimeRange() {
$("#covid-time-range").max = dayMax;
var spc = (svgWidth - 2) / dayMax;
var pthstr = "",
pthstrSun = "";
for (var d = 0; d <= dayMax; d++) {
if (new Date(ts2020 + (d + 21) * d1).getDay() == 0) {
pthstrSun += "M " + (d * spc + 1) + " 1 l0 28 ";
} else {
pthstr += "M " + (d * spc + 1) + " 1 l0 28 ";
}
}
pth.setAttribute("d", pthstr);
pthSun.setAttribute("d", pthstrSun);
}
var rangeReady = true;
var rangeW = $("#covid-time-range-cont").offsetWidth;
function timeRangeInput(v) {
dayi = Number(v);
$("#covid-time-thumb").style.left = 100 * rangeW / (rangeW + 3) * dayi / dayMax + "%";
var TO;
if (rangeReady) {
rangeReady = false;
setTimeout(function () {
rangeReady = true;
clearTimeout(TO);
TO = setTimeout(function () {
if (rangeReady) {
fillAllPolys();
}
}, 300);
}, 300);
fillAllPolys(true);
}
updateGraph();
showDate();
}
$("#covid-time-range").addEventListener("input", function (v) {
return timeRangeInput(v.target.value);
});
function showDate(fromCal) {
var dt = new Date(ts2020 + (dayi + 21) * d1);
var dtstr = dt.getDate() + "-" + mnths[dt.getMonth()];
$("#covid-date").innerHTML = dtstr;
$("#covid-lhpane-date").innerHTML = dtstr;
graphs.forEach(function (e) {
return e.dateDiv.forEach(function (ee) {
ee.innerHTML = dtstr;
});
});
if ($("#datepicker").style.display == "block" && !fromCal) {
datePicker.dateSel = dt;
datePicker.fillCal(dt.getTime());
}
}
setTimeout(showDate, 500);
function numCommas(x) {
return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
}
var gHeight = 120,
gWidth = 380;
if (rs.isMobile) gWidth = window.innerWidth - 20;
var graphs = [{
"id": "graph-container-abs"
}, {
"id": "graph-container-new"
}];
graphs.forEach(function (e) {
var d;
e.title = document.createElement("div");
e.title.innerHTML = e.id == "graph-container-abs" ? "All Cases:" : "New Cases:";
$("#cov-page-2").appendChild(e.title);
e.svg = document.createElementNS("http://www.w3.org/2000/svg", "svg");
Object.assign(e.svg.style, {
"height": gHeight + 2 + "px",
"width": gWidth + "px",
"border": "1px solid rgba(255,255,255,0.2)"
});
e.svg.id = e.id;
e.svg.setAttribute("viewBox", "0 0 ".concat(gWidth, " ").concat(gHeight + 2));
dataFlds.forEach(function (pth, p) {
pth = pth + "pth";
e[pth] = document.createElementNS("http://www.w3.org/2000/svg", 'path');
Object.assign(e[pth].style, {
"fill": "none",
"stroke": pth == "confirmedpth" ? "red" : pth == "deathspth" ? "rgb(322,229,376)" : "green",
"stroke-width": "1px"
});
e.svg.appendChild(e[pth]);
});
$("#cov-page-2").appendChild(e.svg);
e.svg.addEventListener("touch", console.log);
e.timeMrkr = document.createElementNS("http://www.w3.org/2000/svg", "path");
e.timeMrkr.setAttribute("d", "M0 0 L0 ".concat(gHeight));
Object.assign(e.timeMrkr.style, {
"fill": "none",
"stroke": "rgba(255,255,255,0.3)",
"stroke-width": "1px"
});
e.svg.appendChild(e.timeMrkr);
var col = function col(i, o) {
return i == 0 ? "rgba(255,0,0,".concat(o, ")") : i == 1 ? "rgb(200,162,200,".concat(o, ")") : i == 2 ? "rgba(0,255,0,".concat(o, ")") : "transparent";
};
d = document.createElement("div");
d.style.position = "relative";
d.style.left = "15%";
d.style.width = "85%";
for (var _i = -1; _i < 3; _i++) {
var _d = document.createElement("div");
_d.classList.add("cov-graph-div");
if (_i >= 0) {
_d.innerHTML = dataFlds[_i][0].toUpperCase() + dataFlds[_i].slice(1);
_d.style.color = col(_i, 1);
} else _d.style.width = "calc(20% - 2px)";
d.appendChild(_d);
}
$("#cov-page-2").appendChild(d);
e.div = [];
e.dateDiv = [];
for (var _i2 = 0; _i2 < 2; _i2++) {
var _d2 = document.createElement("div");
_d2.style.width = "100%";
if (_i2 == 1) _d2.style.marginBottom = "10px";
$("#cov-page-2").appendChild(_d2);
var _d3 = document.createElement("div");
_d3.style.display = "inline-block";
_d3.style.padding = "2.5px";
_d3.style.verticalAlign = "top";
_d3.style.width = "calc(15%)";
_d3.style.color = "rgba(200,200,200,0.9)";
_d3.innerHTML = _i2 == 0 ? "Absolute" : "Cases
/ Mil";
_d2.appendChild(_d3);
var d2 = document.createElement("div");
d2.style.display = "inline-block";
d2.style.width = "calc(85%)";
_d2.appendChild(d2);
e.div[_i2] = [];
for (var j = 0; j < 2; j++) {
e.div[_i2][j] = [];
for (var k = -1; k < 3; k++) {
var ddd = document.createElement("div");
ddd.classList.add("cov-graph-div");
ddd.style.borderColor = col(k, 0.3);
d2.appendChild(ddd);
if (k >= 0) e.div[_i2][j][k] = ddd;else {
ddd.style.width = "calc(20% - 2px)";
ddd.style.color = "rgba(200,200,200,0.9)";
if (j == 0) {
ddd.innerHTML = "Date";
e.dateDiv.push(ddd);
} else ddd.innerHTML = "Max";
}
}
}
}
});
var testsDiv = document.createElement("div");
$("#cov-page-2").appendChild(testsDiv);
testsDiv.innerHTML = "Total tests done:";
graphs[1].title.style.display = "inline-block";
graphs[1].title.innerHTML = "New cases over ".concat(newdays, " ").concat(newdays == 1 ? "day" : "days", ":");
var newDaysDiv = document.createElement("div");
newDaysDiv.style.width = "140px";
newDaysDiv.style["float"] = "right";
newDaysDiv.classList.add("range-container");
$("#cov-page-2").insertBefore(newDaysDiv, graphs[1].svg);
var ndInput = document.createElement("input");
ndInput.type = "range";
ndInput.max = 6;
ndInput.step = 1;
ndInput.style.width = "100%";
ndInput.style.opacity = 0;
newDaysDiv.appendChild(ndInput);
var ndThumb = document.createElement("div");
ndThumb.classList.add("range-thumb");
ndThumb.style.left = (newdays - 1) / 6 * 120 + "px";
newDaysDiv.appendChild(ndThumb);
var newdaysrangeTO;
ndInput.addEventListener("input", function (e) {
newdays = Number(e.target.value);
ndThumb.style.left = newdays / 6 * 120 + "px";
newdays++;
graphs[1].title.innerHTML = "New cases over ".concat(newdays, " ").concat(newdays == 1 ? "day" : "days", ":");
clearTimeout(newdaysrangeTO);
newdaysrangeTO = setTimeout(function () {
newMax(newdays);
updateGraph(true);
}, 1000);
});
ndInput.addEventListener("change", function (e) {
newMax(newdays);
updateGraph(true);
});
function fetchCountryList() {
return fetch(url + "getfile.php?file=countrylist_med.json").then(function (r) {
return r.json();
}).then(function (r) {
countries = r;
var prevReg = -1;
countries.sort(function (a, b) {
return a.id < b.id ? -1 : 1;
});
countries.forEach(function (e, ii) {
if (!(e.id == "China" || e.id == "Australia" || e.id == "Canada" || e.id == "Hong Kong SAR, China")) {
regdiv[ii] = document.createElement("div");
regdiv[ii].className = "cov-div";
regtxt[ii] = document.createElement("span");
regtxt[ii].innerHTML = e.id.replace("United Kingdom", "UK").replace("Australia", "Aus").replace("External", "Ext");
regtxt[ii].dataset.i = ii;
regtxt[ii].className = "cov-div-txt";
regtxt[ii].addEventListener("click", function (ev) {
var thisN = ev.srcElement;
if (prevReg >= 0) regtxt[prevReg].style.fontWeight = "normal";
prevReg = ii;
thisN.style.fontWeight = "bold";
thisN.style.opacity = 1;
highlightReg(e);
});
regdiv[ii].appendChild(regtxt[ii]);
document.getElementById("country-list-div").appendChild(regdiv[ii]);
}
});
return "country list loaded";
})["catch"](function (error) {
fetchTries++;
if (fetchTries < 10) {
setTimeout(fetchCountryList, 1000);
} else document.getElementById("still-loading").innerHTML = "Failed to load region list.
You can try to reload plugin. " + error;
});
}
var continentLayer;
function getContinents() {
return fetch("".concat(url, "getfile.php?file=continents_bin")).then(function (r) {
return r.blob();
}).then(function (data) {
var reader = new FileReader();
reader.readAsArrayBuffer(data);
reader.onload = function () {
var ar = new Int32Array(reader.result);
var cpg = [];
for (var _i3 = 0, l = ar.length; _i3 < l;) {
var ll = ar[_i3],
pg = [];
for (var j = _i3 + 1; j < _i3 + ll; j += 2) {
pg.push([ar[j + 1] / 1000000, ar[j] / 1000000]);
}
cpg.push(pg);
_i3 = j;
}
continentLayer = L.polygon(cpg, {
color: "black",
fill: false,
weight: 1
});
};
});
}
;
var covid;
function getCovidData() {
return fetch("".concat(url, "update_and_echo_covid.php")).then(function (r) {
return r.json();
}).then(function (data) {
covid = data;
return "covid loaded";
});
}
;
var wom;
function getWOM() {
return fetch("".concat(url, "getfile.php?file=wom.json")).then(function (r) {
return r.json();
}).then(function (data) {
wom = data;
return "wom loaded";
});
}
;
getWOM();
function fetchPolyList() {
return fetch("".concat(url, "getfile.php?file=polylist_med_min.json")).then(function (r) {
return r.json();
}).then(function (r) {
polylist = r;
polyAr = [];
var ii = -1;
polylist.forEach(function (p, i) {
var topleft = L.point([p.mnlt / 1000000, p.mnln / 1000000]);
var btmright = L.point([p.mxlt / 1000000, p.mxln / 1000000]);
polyAr.push({
id: p.id,
km2: p.km2,
cov: p.cov,
bnds: !+p.id.slice(-3) ? L.bounds(topleft, btmright) : false
});
});
return "loading polys";
}).then(function (m) {
polyAr2 = [];
var data = "";
return fetch("".concat(url, "/getfile.php?file=bin"), {
method: "POST",
headers: {
"Content-Type": "application/x-www-form-urlencoded"
},
body: data
}).then(function (r) {
return r.blob();
}).then(function (data) {
var reader = new FileReader();
reader.readAsArrayBuffer(data);
return new Promise(function (res, rej) {
reader.onload = function () {
var ar = new Int32Array(reader.result);
var i = 0,
n = 0,
nn = -1;
var nnn = 0;
for (var _i4 = 0, l = ar.length; _i4 < l;) {
var ll = ar[_i4],
pg = [];
for (var j = _i4 + 1; j < _i4 + ll; j += 2) {
pg.push([ar[j + 1] / 1000000, ar[j] / 1000000]);
}
if (polyAr[n].bnds) {
(function () {
nn++;
var id = polyAr[n].id.slice(0, -6);
var regi = countries.findIndex(function (r) {
return r.id == id;
});
if (countries[regi].polyindx) countries[regi].polyindx.push(nn);else countries[regi].polyindx = [nn];
polyAr2.push({
pg: pg,
km2: polyAr[n].km2,
bnds: polyAr[n].bnds,
id: id,
cov: polyAr[n].cov,
polyid: polyAr[n].id
});
if (nn > 0) {
polyAr2[nn - 1].polygon = L.polygon(polyAr2[nn - 1].pg, {
pane: "countries"
}).addTo(map);
}
})();
} else if (polyAr[n - 1].bnds) {
var tempar = polyAr2[nn].pg;
polyAr2[nn].pg = [tempar, pg];
} else polyAr2[nn].pg.push(pg);
_i4 = j;
n++;
}
polyAr2[nn].polygon = L.polygon(polyAr2[nn].pg, {
pane: "countries"
}).addTo(map);
loaded = true;
$("#still-loading").style.display = "none";
$("#country-list-div").style.display = "block";
res("poly list data loaded");
};
});
})["catch"](function (error) {
document.getElementById("still-loading").innerHTML = "Failed to load custom binary poly list.
You can try to reload plugin. " + error;
});
})["catch"](function (error) {
document.getElementById("still-loading").innerHTML = "Failed to load poly list.
You can try to reload plugin. " + error;
});
}
var prevLegend = {
spans: []
};
var hideCovEl = rs.isMobile || rs.isTablet ? $(".mm-menu") : $("#overlay");
var legendEl = rs.isMobile || rs.isTablet ? $("#legend-mobile") : $("#legend");
hideCovEl.addEventListener("click", function () {
legendEl.style.background = prevLegend.background;
if (prevLegend.spans.length) for (var _i5 = 0; _i5 < legendEl.children.length; _i5++) {
legendEl.children[_i5].innerHTML = prevLegend.spans[_i5];
}
dataFlds.forEach(function (e) {
return $("#" + e).classList.remove("selected");
});
hideCovMap();
});
function updateLegend() {
prevLegend.background = legendEl.style.background;
for (var _i6 = 0; _i6 < legendEl.children.length; _i6++) {
prevLegend.spans[_i6] = legendEl.children[_i6].innerHTML;
}
var cols = W.colors[colorLayer]["default"];
var s = " linear-gradient(to right ";
cols.forEach(function (e, i) {
s += "," + color(i);
});
s += ")";
legendEl.style.background = s;
var children = legendEl.children;
for (var _i7 = 0; _i7 < children.length; _i7++) {
var c = children[_i7];
if (_i7 == 0) {
c.style.textShadow = "0px 0px 5px black";
c.innerHTML = dataSel == "confirmed" ? "Conf'd" : dataSel == "deaths" ? "Deaths" : "Recov'd";
} else {
var k = dataFlds.indexOf(dataSel) + (opts.all.val ? 0 : 3);
var lb = logb[k][opts.abs.val ? "abs" : "pp"];
var x = (cols.length - 1) * (_i7 - 1) / 6;
var y = Math.exp(x * Math.log(lb));
y = y >= 1000 ? Math.round(y / 1000) + "k" : Math.round(y);
c.innerHTML = y;
}
}
}
function calcLogB() {
var cl = W.colors[colorLayer]["default"].length - 2;
for (var t = 0; t < 6; t++) {
logb[t] = {
"abs": Math.exp(Math.log(maxTot[t].abs) / cl),
"pp": Math.exp(Math.log(maxTot[t].pp) / cl)
};
}
}
function movAv(ar, i, d) {
d = i < d ? i : d;
if (d) return ar[i] - ar[i - d];else return 0;
}
function newMax(d) {
for (var _i8 = 3; _i8 < 6; _i8++) {
maxTot[_i8].abs = 0;
maxTot[_i8].pp = 0;
}
covid.forEach(function (c, ii) {
dataFlds.forEach(function (tp, t) {
c.max[t + 3] = {
"abs": 0,
"pp": 0
};
c[tp].forEach(function (cc, i) {
var nw = movAv(c[tp], i, d);
if (nw > c.max[t + 3].abs) c.max[t + 3].abs = nw;
});
if (c.p) c.max[t + 3].pp = c.max[t + 3].abs / c.p;else c.max[t + 3].pp = 0;
["abs", "pp"].forEach(function (n) {
if (c.max[t + 3][n] > maxTot[t + 3][n]) maxTot[t + 3][n] = c.max[t + 3][n];
});
});
});
dataFlds.forEach(function (tp, t) {
world.max[t + 3] = {
"abs": 0,
"pp": 0
};
world[tp].forEach(function (cc, i) {
var nw = movAv(world[tp], i, d);
if (nw > world.max[t + 3].abs) world.max[t + 3].abs = nw;
});
world.max[t + 3].pp = 1000000 * world.max[t + 3].abs / world.pop;
});
}
Promise.all([fetchCountryList(), getCovidData(), getWOM()]).then(function (v) {
dayMax = covid[0].confirmed.length - 1;
var removeLast = covid[0].confirmed[dayMax] == 0 ? true : false;
if (removeLast) dayMax--;
dayi = dayMax;
for (var _i9 = 0; _i9 < 6; _i9++) {
maxTot.push({
"abs": 0,
"pp": 0
});
}
covid.forEach(function (c, ii) {
if (removeLast) {
c.confirmed.splice(dayMax + 1, 1);
c.deaths.splice(dayMax + 1, 1);
c.recovered.splice(dayMax + 1, 1);
}
c.pop = 0;
for (var _i10 = 0; _i10 < countries.length; _i10++) {
if (c.n == countries[_i10].id || countries[_i10].id.indexOf(c.n) === 0 && c.n.indexOf(" ") >= 0) {
c.pop += countries[_i10].pop;
}
}
c.p = c.pop ? c.pop / 1000000 : 0;
});
if (wom) {
covid.forEach(function (c) {
var f = wom.find(function (w) {
return w.n.toUpperCase() === c.n.toUpperCase();
});
dataFlds.forEach(function (tp) {
if (f) {
var ft = tp.slice(0, 1);
c[tp].push(f[ft] > c[tp][dayMax] ? f[ft] : c[tp][dayMax]);
} else {
c[tp].push(c[tp][dayMax]);
}
});
if (f) c.tests = f.t;
});
dayMax++;
dayi++;
}
dataFlds.forEach(function (t) {
world[t] = [];
for (var _i11 = 0; _i11 <= dayMax; _i11++) {
world[t].push(0);
}
});
covid.forEach(function (c, ii) {
c.max = [];
dataFlds.forEach(function (tp, t) {
c.max[t] = {
"abs": 0,
"pp": 0
};
c[tp].forEach(function (cc, i) {
world[tp][i] += isNaN(cc) ? 0 : cc;
if (cc > c.max[t].abs) c.max[t].abs = cc;
});
if (c.p) c.max[t].pp = c.max[t].abs / c.p;else c.max[t].pp = 0;
["abs", "pp"].forEach(function (n) {
if (c.max[t][n] > maxTot[t][n]) maxTot[t][n] = c.max[t][n];
});
});
});
dataFlds.forEach(function (tp, t) {
if (wom) world[tp][dayMax] = wom[0][tp.slice(0, 1)];
world.max[t] = {
"abs": world[tp][dayMax],
"pp": 1000000 * world[tp][dayMax] / world.pop
};
});
newMax(newdays);
covReg = world;
calcLogB();
updateGraph();
updateLegend();
drawTimeRange();
timeRangeInput(dayi);
fetchPolyList().then(fillAllPolys).then(function () {
dayiprev = 0;
setTimeout(function () {
if (picker.getParams) findPoly(picker.getParams());
}, 200);
showCovMap();
});
getContinents();
if (picker.getParams) setTimeout(findPoly, 1000, picker.getParams());
});
W.colors.greenred = {
"default": []
};
for (var _i12 = 0; _i12 <= 128; _i12 += 4) {
W.colors.greenred["default"].push([0, [127 + _i12, 255 - _i12 * 2, 127 - _i12]]);
}
for (var _i13 = 192; _i13 >= 0; _i13 -= 64) {
W.colors.greenred["default"].push([0, [_i13, 0, 0]]);
}
W.colors.lilac = {
"default": []
};
for (var _i14 = 30; _i14 >= 0; _i14--) {
W.colors.lilac["default"].push([0, [322 * _i14 / 30, 229 * _i14 / 30, 376 * _i14 / 30]]);
}
W.colors.green = {
"default": []
};
for (var _i15 = 127; _i15 < 256; _i15 += 8) {
W.colors.green["default"].push([0, [127, _i15, 127]]);
}
for (var _i16 = 120; _i16 >= 0; _i16 -= 8) {
W.colors.green["default"].push([0, [_i16, 256, _i16]]);
}
var colorLayer = "greenred";
function color(x) {
var t = W.colors[colorLayer]["default"];
var l = t.length - 1;
var xb = Math.floor(x);
var xt = xb + 1;
xt = xt > l ? l : xt;
var r = x - xb;
var cl = [];
for (var j = 0; j < 3; j++) {
cl[j] = Math.round(t[xb][1][j] + r * (t[xt][1][j] - t[xb][1][j]));
}
var col = "rgb(".concat(cl[0], ",").concat(cl[1], ",").concat(cl[2], ")");
return col;
}
var firstFill = true;
function fillAllPolys() {
var changed = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
if (polyAr2.length) {
var logVal = function logVal(x, y) {
if (y == 0) return 0;
return Math.log(y) / Math.log(x);
};
var numFilled = 0;
var t = dataFlds.indexOf(dataSel);
t = t + !opts.all.val * 3;
var lb = logb[t][opts.abs.val ? "abs" : "pp"];
var linfac = (W.colors[colorLayer]["default"].length - 1) / maxTot[t][opts.abs.val ? "abs" : "pp"];
countries.forEach(function (cnt) {
if (cnt.polyindx && cnt.polyindx.length) {
if (polyAr2[cnt.polyindx[0]].cov || polyAr2[cnt.polyindx[0]].cov === 0) {
var _polyAr2$cnt$polyindx = polyAr2[cnt.polyindx[0]],
id = _polyAr2$cnt$polyindx.id,
cov = _polyAr2$cnt$polyindx.cov;
var val = 0,
logval;
var _p2 = covid[cov].pop > 0 ? covid[cov].pop / 1000000 : 0;
var ds = dataSel;
if (opts.abs.val) {
if (opts.all.val) {
val = covid[cov][ds][dayi];
} else {
val = movAv(covid[cov][ds], dayi, newdays);
if (val < 0) val = 0;
}
} else if (_p2) {
if (opts.all.val) {
val = covid[cov][ds][dayi] / _p2;
} else {
val = movAv(covid[cov][ds], dayi, newdays) / _p2;
if (val < 0) val = 0;
}
}
if (opts.log.val) {
val = logVal(lb, val);
if (val < 0) val = 0;
} else {
val *= linfac;
}
if (!changed || changed && Math.abs((cnt.val || 0) - val) > 1 || firstFill) {
cnt.val = val;
cnt.polyindx.forEach(function (i) {
polyAr2[i].polygon.setStyle({
fillColor: color(val),
fillOpacity: 1,
color: "black",
weight: 0.3
});
numFilled++;
});
}
} else if (firstFill) {
cnt.polyindx.forEach(function (i) {
return polyAr2[i].polygon.setStyle({
fillOpacity: 0,
color: "black",
weight: 0.3
});
});
}
}
});
firstFill = false;
}
}
function highLightPoly(p) {
var active = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
p.polygon.setStyle({
weight: active ? 3 : 0.2,
color: active ? "white" : "black"
});
}
function highlightReg(region) {
region.polyindx.forEach(function (i) {
layerAr.push(polyAr2[i]);
highLightPoly(polyAr2[i], true);
});
var maxp = layerAr[0];
var minx = Infinity,
miny = Infinity;
var maxx = -Infinity,
maxy = -Infinity;
layerAr.forEach(function (p) {
if (p.km2 > maxp.km2) maxp = p;
if (p.bnds) {
if (p.bnds.max.x > maxx) maxx = p.bnds.max.x;
if (p.bnds.max.y > maxy) maxy = p.bnds.max.y;
if (p.bnds.min.x < minx) minx = p.bnds.min.x;
if (p.bnds.min.y < miny) miny = p.bnds.min.y;
}
});
map.fitBounds([[minx, miny], [maxx, maxy]]);
cancelPrevHighlight();
setTimeout(function () {
bcast.fire("rqstOpen", "picker", {
lon: maxp.bnds.min.y + (maxp.bnds.max.y - maxp.bnds.min.y) / 2,
lat: maxp.bnds.min.x + (maxp.bnds.max.x - maxp.bnds.min.x) / 2
});
}, 1500);
}
function cancelPrevHighlight() {
prevLayerAr = prevLayerAr.filter(function (e) {
if (layerAr.findIndex(function (ee) {
return ee.id == e.id;
}) == -1) {
highLightPoly(e, false);
} else return e;
});
prevLayerAr = _toConsumableArray(new Set(prevLayerAr.concat(layerAr)));
layerAr = [];
}
var checkPoly = function checkPoly(point, vs) {
var x = point[0],
y = point[1];
var inside = false;
for (var i = 0, j = vs.length - 1; i < vs.length; j = i++) {
var xi = vs[i][0],
yi = vs[i][1];
var xj = vs[j][0],
yj = vs[j][1];
var intersect = yi > y != yj > y && x < (xj - xi) * (y - yi) / (yj - yi) + xi;
if (intersect) inside = !inside;
}
return inside;
};
picker.on('pickerOpened', function (c) {
if (rs.isMobile) setTimeout(findPoly, 500, picker.getParams());else findPoly(c);
});
picker.on('pickerMoved', findPoly);
pickerT.drag(findPoly, 350);
picker.on('pickerClosed', function () {
curReg = "";
covReg = world;
layerAr = [];
cancelPrevHighlight();
updateGraph();
});
var prevLayerAr = [];
var layerAr = [];
function updateGraph() {
var newChanged = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
if (dayi != dayiprev || curReg != prevReg || newChanged) {
var i;
(function () {
if (!covReg || !curReg) {
covReg = world;
curReg = covReg.n;
}
var popm = covReg.pop > 0 ? covReg.pop / 1000000 : 0;
var start = covReg.confirmed.findIndex(function (e) {
return e > 0;
});
var l = covReg.confirmed.length - 1,
n = l - start;
var popstr = numCommas(Number(covReg.n == curReg ? covReg.pop : curPop));
if (curReg != prevReg || newChanged) {
(function () {
$("#cov-reg-name").innerHTML = "" + covReg.n + "" + " Pop: " + popstr;
prevReg = curReg;
var drawPth = function drawPth(g, t, mx, ar) {
var str = "";
for (var _i17 = start; _i17 <= l; _i17++) {
var y = ar[_i17];
str += (_i17 == start ? "M" : "L") + (_i17 - start) * gWidth / n + " " + (gHeight + 1 - gHeight * y / mx) + " ";
}
graphs[g][t + "pth"].setAttribute("d", str);
};
covReg.maxnew = [];
var _loop3 = function _loop3(_i18) {
var nw = void 0,
mx = void 0;
if (_i18 == 0) mx = Math.max.apply(Math, _toConsumableArray(covReg.confirmed));
dataFlds.forEach(function (e, j) {
if (_i18 > 0) {
covReg[e + "new"] = covReg[e].map(function (e, i, a) {
return movAv(a, i, newdays);
});
covReg.maxnew[j] = {
abs: Math.max.apply(Math, _toConsumableArray(covReg[e + "new"]))
};
covReg.maxnew[j].pp = covReg.maxnew[j].abs / popm;
}
drawPth(_i18, e, covReg["max" + (_i18 > 0 ? "new" : "")][0].abs, covReg[e + (_i18 > 0 ? "new" : "")]);
});
};
for (var _i18 = 0; _i18 < 2; _i18++) {
_loop3(_i18);
}
graphs.forEach(function (g, k) {
g.div.forEach(function (d, j) {
d[1].forEach(function (dd, i) {
var v = covReg[k == 0 ? "max" : "maxnew"][i][j == 0 ? "abs" : "pp"];
dd.innerHTML = numCommas(Math.round(v * 100) / 100);
});
});
});
})();
}
dayiprev = dayi;
graphs.forEach(function (g, k) {
g.div.forEach(function (d, j) {
d[0].forEach(function (dd, i) {
var v = covReg[dataFlds[i] + (k > 0 ? "new" : "")][dayi] / (j > 0 ? popm : 1);
dd.innerHTML = numCommas(Math.round(v * 100) / 100);
});
});
});
if (covReg.tests) {
testsDiv.innerHTML = "Total tests done: ".concat(numCommas(covReg.tests), ". Positive tests: ").concat(Math.round(1000 * covReg.confirmed[dayMax] / covReg.tests) / 10, "%");
} else {
var w;
if (curReg.indexOf("US") == 0) {
w = wom.find(function (e) {
return e.n == "us";
});
} else if (curReg.indexOf("Australia") == 0) {
w = wom.find(function (e) {
return e.n == "australia";
});
} else if (curReg.indexOf("Canada") == 0) {
w = wom.find(function (e) {
return e.n == "canada";
});
}
if (w) {
testsDiv.innerHTML = "Total tests in ".concat(w.n == "us" ? "US" : w.n[0].toUpperCase() + w.n.slice(1), ": ").concat(numCommas(w.t), ". Pos tests: ").concat(numCommas(w.c), " (").concat(Math.round(1000 * w.c / w.t) / 10, "%)");
} else testsDiv.innerHTML = "No test data";
}
var x = dayi - start;
x = x < 0 ? 0 : x;
x *= gWidth / n;
graphs.forEach(function (e) {
return e.timeMrkr.setAttribute("d", "M".concat(x, " 0 L").concat(x, " ").concat(gHeight));
});
var fontsz = 15;
var curRegT = curReg.replace("United Kingdom", "UK");
if (curRegT.length > 10) {
fontsz = 14;
for (i = 10; i < curRegT.length && curRegT[i] != " "; i++) {
;
}
if (i < curRegT.length) curRegT = curRegT.slice(0, i) + "
" + curRegT.slice(i);
}
var lefttxt = "").concat(curRegT, "
Pop: ").concat(popstr, "
");
var righttxt = "";
if (covReg.n == curReg) {
lefttxt += "Confirmed: " + numCommas(covReg.confirmed[dayi]) + "
" + "Deaths: " + numCommas(covReg.deaths[dayi]) + "
" + (covReg.recovered ? "Recovered: " + numCommas(covReg.recovered[dayi]) + "
" : "");
if (popm > 0) {
righttxt += "Per Million:
").concat(rs.isMobile ? "
" : "") + " Confirmed: " + numCommas(Math.round(10 * covReg.confirmed[dayi] / popm) / 10) + "
" + " Deaths: " + numCommas(Math.round(10 * covReg.deaths[dayi] / popm) / 10) + "
" + (covReg.recovered ? " Recovered: " + numCommas(Math.round(10 * covReg.recovered[dayi] / popm) / 10) + "
" : "");
}
} else {
lefttxt += "No Data";
}
setTimeout(pickerT.showLeftDiv, 250);
if (righttxt) setTimeout(pickerT.showRightDiv, 250);
pickerT.fillLeftDiv(lefttxt, true);
if (righttxt) pickerT.fillRightDiv(righttxt, true);else pickerT.hideRightDiv();
})();
}
}
function findPoly(e) {
if (loaded) {
var c = [e.lon || e.lng, e.lat];
var cc = [e.lat, e.lon || e.lng];
var txt = "";
layerAr = [];
var polyarl = polyAr2.length;
var ii = 0;
for (; ii < polyarl; ii++) {
var _p4 = polyAr2[ii];
if (_p4.bnds && _p4.bnds.contains(cc)) {
if (checkPoly(cc, typeof _p4.pg[0][0][0] == "undefined" ? _p4.pg : _p4.pg[0])) {
layerAr.push({
p: _p4,
i: ii
});
}
}
}
var smallest = Infinity;
var _p3;
for (var _i19 = 0; _i19 < layerAr.length; _i19++) {
if (layerAr[_i19].p.km2 < smallest) {
smallest = layerAr[_i19].p.km2;
_p3 = layerAr[_i19].p;
ii = layerAr[_i19].i;
}
}
if (_p3) {
curReg = _p3.id;
covReg = _p3.cov || _p3.cov === 0 ? covid[_p3.cov] : null;
layerAr = [];
var _c = countries.find(function (e) {
return e.id == curReg;
});
curPop = _c.pop;
_c.polyindx.forEach(function (i) {
layerAr.push(polyAr2[i]);
highLightPoly(polyAr2[i], true);
});
} else {
curReg = "World";
covReg = world;
}
updateGraph();
cancelPrevHighlight();
}
}
;
function str2hr(s) {
return s == "0" ? 0 : Number(s.slice(0, -3)) + Number(s.slice(-2)) / 60;
}
var datePicker = {
createPicker: function createPicker() {
var _this2 = this;
var cbf = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : function () {};
this.cbf = cbf;
this.dateSel = new Date(Math.floor(Date.now() / h1) * h1);
this.h = this.dateSel.getUTCHours();
this.width = 230;
document.getElementById("datepicker").style.width = this.width + "px";
for (var d = 0; d < 3; d++) {
var ddiv = document.createElement("div");
ddiv.classList.add("daydiv");
ddiv.style.fontWeight = "bold";
if (d == 1) {
ddiv.style.width = 14 * 5 + "%";
ddiv.id = "month-year";
}
ddiv.innerHTML = d == 0 ? "<" : d == 2 ? ">" : "";
if (d == 0) ddiv.addEventListener("click", function () {
if (_this2.m > 0) _this2.fillCal(new Date(_this2.y, _this2.m - 1, 3).getTime());
});
if (d == 2) ddiv.addEventListener("click", function () {
if (_this2.m < 11) _this2.fillCal(new Date(_this2.y, _this2.m + 1, 3).getTime());
});
document.getElementById("datepicker").appendChild(ddiv);
}
for (var _d4 = 0; _d4 < 7; _d4++) {
var _ddiv = document.createElement("div");
_ddiv.classList.add("daydiv");
_ddiv.style.fontWeight = "bold";
document.getElementById("datepicker").appendChild(_ddiv);
_ddiv.innerHTML = weekdays[_d4];
}
for (var _d5 = 0; _d5 < 42; _d5++) {
var _ddiv2 = document.createElement("div");
_ddiv2.classList.add("daydiv");
document.getElementById("datepicker").appendChild(_ddiv2);
_ddiv2.innerHTML = _d5;
_ddiv2.id = "daynum" + _d5;
_ddiv2.addEventListener("click", function (e) {
var dd = +e.target.id.slice(6) + 1 - _this2.wd;
_this2.dateSel = new Date(Date.UTC(_this2.y, _this2.m, dd));
var c = document.getElementById("datepicker").children;
for (var _i20 = 0; _i20 < c.length; _i20++) {
c[_i20].classList.remove("selected-date");
}
e.target.classList.add("selected-date");
_this2.update();
});
}
this.timediv = document.createElement("div");
this.timediv.classList.add("daydiv");
this.timediv.style.width = this.width + "px";
this.timediv.style.pointerEvents = "none";
document.getElementById("datepicker").appendChild(this.timediv);
},
wd: -1,
m: -1,
y: -1,
h: -1,
dateSel: new Date(),
tsSel: Date.now(),
fillCal: function fillCal(t) {
var dt = new Date(t);
this.m = dt.getUTCMonth();
this.y = dt.getUTCFullYear();
this.h = 0;
this.wd = new Date(this.y, this.m, 1).getDay();
var daysprevmonth = new Date(this.y, this.m, 0).getDate();
var daysthismonth = new Date(this.y, this.m + 1, 0).getDate();
document.getElementById("month-year").innerHTML = mnths[this.m] + " " + this.y;
for (var d = 0; d < 42; d++) {
var dd = d + 1 - this.wd;
if (Date.UTC(this.y, this.m, dd) == this.dateSel.getTime()) document.getElementById("daynum" + d).classList.add("selected-date");else document.getElementById("daynum" + d).classList.remove("selected-date");
document.getElementById("daynum" + d).style.opacity = dd < 1 || dd > daysthismonth ? 0.7 : 1;
dd = dd < 1 ? daysprevmonth + dd : dd > daysthismonth ? dd - daysthismonth : dd;
document.getElementById("daynum" + d).innerHTML = dd;
}
},
update: function update() {
this.tsSel = this.dateSel.getTime();
this.cbf(this.dateSel, this.tsSel);
}
};
datePicker.createPicker(function (d, t) {
dayi = Math.floor((t - ts2020) / (24 * 60 * 60 * 1000)) - 21;
$("#covid-time-thumb").style.left = 100 * rangeW / (rangeW + 3) * dayi / dayMax + "%";
updateGraph();
fillAllPolys();
showDate(true);
});
datePicker.fillCal(Date.now());
});