refactor: isBased()

This commit is contained in:
Gigi
2022-04-26 21:02:33 +02:00
parent b00e1049fa
commit b57168154c

View File

@@ -47,15 +47,15 @@ qtip: '/js/jquery.qtip.min.js'
dataType: 'json', dataType: 'json',
success: function (countries) { success: function (countries) {
var orangeCountries = countries.filter(function hasLink(c) { var basedCountries = countries.filter(function hasLink(c) {
var hasLink = c.link ? true : false; var hasLink = c.link ? true : false;
return hasLink; return hasLink;
}); });
var orangeCountryCodes = orangeCountries.map(function(c) { var basedCountryCodes = basedCountries.map(function(c) {
return c.alpha3; return c.alpha3;
}); });
function isOrange(iso) { function isBased(iso) {
return orangeCountryCodes.includes(iso); return basedCountryCodes.includes(iso);
} }
function getColor(iso) { function getColor(iso) {
let country = countries.find(c => c.alpha3 == iso); let country = countries.find(c => c.alpha3 == iso);
@@ -72,13 +72,13 @@ qtip: '/js/jquery.qtip.min.js'
fill: cGray fill: cGray
}, },
mouseenter: function (d, path) { mouseenter: function (d, path) {
if (!isOrange(d.iso)) { if (!isBased(d.iso)) {
path.attr('fill', Math.random() < 0.5 ? cDarkOrange : cDarkWhite ); path.attr('fill', Math.random() < 0.5 ? cDarkOrange : cDarkWhite );
} }
return; return;
}, },
mouseleave: function (d, path) { mouseleave: function (d, path) {
if (!isOrange(d.iso)) { if (!isBased(d.iso)) {
path.animate({ fill: getColor(d.iso) }, 1000); path.animate({ fill: getColor(d.iso) }, 1000);
} }
return; return;