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
const panStateHandler = event => { | |
if (event.nativeEvent.oldState === State.UNDETERMINED) { | |
setLastTranslateX(translateX); | |
setLastTranslateY(translateY); | |
}; | |
}; | |
const panGestureHandler = event => { | |
setTranslateX(-event.nativeEvent.translationX / scale + lastTranslateX); | |
setTranslateY(-event.nativeEvent.translationY / scale + lastTranslateY); |
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
const pinchStateHandler = event => { | |
if (event.nativeEvent.oldState === State.UNDETERMINED) { | |
setLastScaleOffset(-1 + scale); | |
}; | |
}; | |
const pinchGestureHandler = event => { | |
if (event.nativeEvent.scale + lastScaleOffset >= 1 && event.nativeEvent.scale + lastScaleOffset <= 5) { | |
setPrevScale(scale); | |
setScale(event.nativeEvent.scale + lastScaleOffset); |
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
return ( | |
<View style={styles.container}> | |
<PanGestureHandler | |
onGestureEvent={(e) => panGestureHandler(e)} | |
onHandlerStateChange={(e) => panStateHandler(e)} | |
> | |
<PinchGestureHandler | |
onGestureEvent={(e) => pinchGestureHandler(e)} | |
onHandlerStateChange={(e) => pinchStateHandler(e)} | |
> |
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; |
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
//Data Manipulation | |
const covidData = useMemo(() => { | |
const countriesAsArray = Object.keys(covidData_raw).map((country) => ({ | |
name: country, | |
data: covidData_raw[country] | |
})); | |
const windowSize = 7; | |
const countriesWithAvg = countriesAsArray.map(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
export default (data, windowSize) => { | |
newData = []; | |
for (var i = windowSize - 1; i < data.length; i++) { | |
const averages = {}; | |
for (stat of ["confirmed", "deaths"]) { | |
const curWindowData = data.slice(i - windowSize + 1, i + 1); | |
const average = curWindowData.reduce((acc, cur) => cur[stat] + acc, 0) / windowSize; | |
const keyName = "avg_" + stat; | |
averages[keyName] = Math.round(average); | |
} |
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
<!DOCTYPE html> | |
<meta charset="utf-8"> | |
<head> | |
<script src="http://d3js.org/d3.v5.js"></script> | |
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> | |
</head> | |
<body> | |
<style> | |
#svg-div { | |
position: absolute; |