Last active
July 23, 2020 04:38
-
-
Save JoBerkner/2081846406ed92c1925a54e7a90ffb9d to your computer and use it in GitHub Desktop.
useEffect hook to create SVG paths for each country
This file contains 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
useEffect(() => { | |
setCountryList( | |
countryPaths.map((path, i) => { | |
const curCountry = COUNTRIES[i].properties.name; | |
const isCountryNameInData = data.some(country => country.name === curCountry); | |
const curCountryData = isCountryNameInData | |
? data.find(country => country.name === curCountry)["data"] | |
: null; | |
const isDataAvailable = isCountryNameInData | |
? curCountryData.some(data => data.date === date) | |
: false; | |
const dateIndex = isDataAvailable | |
? curCountryData.findIndex(x => x.date === date) | |
: null; | |
return ( | |
<Path | |
key={curCountry} | |
d={path} | |
stroke={"#aaa"} | |
strokeOpacity={0.3} | |
strokeWidth={0.6} | |
fill={ | |
isDataAvailable | |
? colorScale(curCountryData[dateIndex][stat]) | |
: "#aaa" | |
} | |
opacity={isDataAvailable ? 1 : 0.4} | |
/> | |
) | |
}) | |
) | |
}, []) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment