Skip to content

Instantly share code, notes, and snippets.

@carmoreira
Created March 30, 2020 14:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save carmoreira/3330a89e76007662b5c44c161c329262 to your computer and use it in GitHub Desktop.
Save carmoreira/3330a89e76007662b5c44c161c329262 to your computer and use it in GitHub Desktop.
Callback function to get Australia COVID-19 confirmed cases for Interactive Geo Maps WordPress plugin
function igm_custom_filter_20921(data) {
let auRegions = [];
let codes = [
{
"region": "Australian Capital Territory",
"code": "AU-ACT"
},
{
"region": "New South Wales",
"code": "AU-NSW"
},
{
"region": "Victoria",
"code": "AU-VIC"
},
{
"region": "Queensland",
"code": "AU-QLD"
},
{
"region": "South Australia",
"code": "AU-SA"
},
{
"region": "Western Australia",
"code": "AU-WA"
},
{
"region": "Tasmania",
"code": "AU-TAS"
},
{
"region": "Northern Territory",
"code": "AU-NT"
},
{
"region": "Australian Capital Territory",
"code": "AU-ACT"
}
];
jQuery.ajax({
url: "https://raw.githubusercontent.com/CSSEGISandData/COVID-19/301c88ffc4b0baeccc6dbeb10ba306ab1ae8544b/csse_covid_19_data/csse_covid_19_time_series/time_series_19-covid-Confirmed.csv",
type: 'get',
async: false,
dataType: 'text',
success: function (response) {
const lines = response.split('\n');
for (let line of lines) {
const items = line.match(/(".*?"|[^",]+)(?=\s*,|\s*$)/g);
if (!Array.isArray(items)) { continue; }
if (items[1] !== 'Australia') { continue; }
const peopleArr = items.slice(4);
const value = parseInt(peopleArr[peopleArr.length - 1]);
const name = items[0];
const code = codes.filter(function (code) {
return code.region == items[0];
});
if (code.length === 0) {
continue;
}
// ranges
/* #feedde
#fdbe85
#fd8d3c
#e6550d
#a63603
*/
let color = '#feedde';
if (value > 0 && value <= 100) {
color = '#fdbe85';
}
else if (value > 100 && value <= 1000) {
color = '#fd8d3c';
}
else if (value > 1000 && value <= 10000) {
color = '#e6550d';
}
else if (value > 10000) {
color = '#a63603';
}
const doc = {
'id': code[0].code,
'name': name,
'value': value,
'fill': color,
'hover': '#d94701',
'useDefaults': '0'
};
auRegions.push({ ...doc });
}
}
});
data.regions = auRegions;
return data;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment