Skip to content

Instantly share code, notes, and snippets.

@LosantGists
Created July 26, 2023 18:37
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 LosantGists/bc7e5b41ca8fa2e13e5e617fdb5ab403 to your computer and use it in GitHub Desktop.
Save LosantGists/bc7e5b41ca8fa2e13e5e617fdb5ab403 to your computer and use it in GitHub Desktop.
build map icon
const buildIcon = (data,attr) => {
const value = data.attributeValues?.[attr];
const meta = data.attributes?.find(a => a.name === attr);
if(!value || !meta){
throw new TypeError('Missing values'); // value at this point is string, so "0" won't fail
}
const min = meta.attributeTags?.min ? Number(meta.attributeTags.min) : 0;
const max = meta.attributeTags?.max ? Number(meta.attributeTags.max) : 100;
const unit = meta.attributeTags?.unit || '';
const percent = (value - min) / (max - min) * 100;
const status = statusByValue(value,meta);
const colors = colorsByStatus[status];
const icon = document.createElement("div");
icon.innerHTML = iconHTML(attr,percent,value,colors,unit);
if(status === 'critical'){
icon.classList.add('alert-icon');
}
return {
attribute: attr,
value,
meta,
unit,
icon
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment