Created
July 26, 2023 18:37
-
-
Save LosantGists/bc7e5b41ca8fa2e13e5e617fdb5ab403 to your computer and use it in GitHub Desktop.
build map icon
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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