UNPKG

covid19-dashboard

Version:

Dashboard App displaying COVID-19 numbers by country

167 lines (146 loc) 6.51 kB
import Base from '../../node_modules/neo.mjs/src/core/Base.mjs'; /** * Static utility class * @class Covid.Util * @extends Neo.core.Base */ class Util extends Base { static getStaticConfig() {return { /** * A regex to replace blank chars * @member {RegExp} flagRegEx=/ /gi * @protected * @static */ flagRegEx: / /gi, /** * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toLocaleString * Change this config to enforce a county specific formatting (e.g. 'de-DE') * @member {String} locales='default' * @protected * @static */ locales: 'default' }} static getConfig() {return { /** * @member {String} className='Covid.Util' * @protected */ className: 'Covid.Util' }} /** * Used for the casesPerOneMillion column to show % of population * @param {Object} data * @param {Number} data.value * @returns {String} */ static formatInfected(data) { let value = data.value; if (!Neo.isNumber(value)) { return value || 'N/A'; } value = Math.round(value / 100); value /= 100; value = value.toFixed(2) + ' %'; return value.toLocaleString(Util.locales); } /** * This method will get used as a grid renderer, so the 2nd param is an overload (would be {Object} record) * @param {Object} data * @param {Number} data.value * @param {String} [color] * @returns {String} */ static formatNumber(data, color) { let value = data.value; if (!Neo.isNumber(value)) { return value || 'N/A'; } value = value.toLocaleString(Util.locales); return typeof color !== 'string' ? value : `<span style="color:${color};">${value}</span>`; } /** * * @param {String} name * @returns {String} url */ static getCountryFlagUrl(name) { const map = { 'bosnia' : 'bosnia-and-herzegovina', 'cabo-verde' : 'cape-verde', 'car' : 'central-african-republic', 'caribbean-netherlands' : 'netherlands', 'channel-islands' : 'jersey', 'côte-d\'ivoire' : 'ivory-coast', 'congo' : 'republic-of-the-congo', 'congo,-the-democratic-republic-of-the': 'democratic-republic-of-congo', 'curaçao' : 'curacao', 'czechia' : 'czech-republic', 'diamond-princess' : 'japan', // cruise ship 'drc' : 'democratic-republic-of-congo', 'el-salvador' : 'salvador', 'eswatini' : 'swaziland', 'faeroe-islands' : 'faroe-islands', 'falkland-islands-(malvinas)' : 'falkland-islands', 'french-guiana' : 'france', // ? 'guadeloupe' : 'france', // ? 'holy-see-(vatican-city-state)' : 'vatican-city', 'iran,-islamic-republic-of' : 'iran', 'lao-people\'s-democratic-republic' : 'laos', 'libyan-arab-jamahiriya' : 'libya', 'macedonia' : 'republic-of-macedonia', 'marshall-islands' : 'marshall-island', 'mayotte' : 'france', // ? 'moldova,-republic-of' : 'moldova', 'ms-zaandam' : 'netherlands', // cruise ship 'new-caledonia' : 'france', 'palestinian-territory,-occupied' : 'palestine', 'poland' : 'republic-of-poland', 'réunion' : 'france', 's.-korea' : 'south-korea', 'st.-barth' : 'st-barts', 'saint-helena' : 'united-kingdom', // sorry, icon not included 'saint-lucia' : 'st-lucia', 'saint-martin' : 'sint-maarten', 'saint-pierre-miquelon' : 'france', 'saint-vincent-and-the-grenadines' : 'st-vincent-and-the-grenadines', 'syrian-arab-republic' : 'syria', 'tanzania,-united-republic-of' : 'tanzania', 'timor-leste' : 'east-timor', 'turks-and-caicos-islands' : 'turks-and-caicos', 'u.s.-virgin-islands' : 'virgin-islands', 'uae' : 'united-arab-emirates', 'uk' : 'united-kingdom', 'usa' : 'united-states-of-america', 'uzbekistan' : 'uzbekistn', 'venezuela,-bolivarian-republic-of' : 'venezuela', 'viet-nam' : 'vietnam', 'wallis-and-futuna' : 'france' }; let imageName = name.toLowerCase().replace(Util.flagRegEx, '-'); imageName = map[imageName] || imageName; if (Neo.config.isGitHubPages) { let path = '../../../../resources/images/flaticon/country_flags/png/' + imageName + '.png'; if (Neo.config.environment !== 'development') { path = '../../' + path; } return path; } return 'https://raw.githubusercontent.com/neomjs/pages/master/resources/images/flaticon/country_flags/png/' + imageName + '.png'; } /** * * @param {Object} data * @param {Number} data.index * @returns {Object} */ static indexRenderer(data) { return { cls : ['neo-index-column', 'neo-table-cell'], html: data.index + 1 }; } } Neo.applyClassConfig(Util); export default Util;