-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutil.js
65 lines (51 loc) · 1.61 KB
/
util.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import React from "react";
import numeral from "numeral";
import {Circle, Popup} from "react-leaflet";
const casesTypeColors ={
cases: {
hex:"#CC1034",
multiplier:800,
},
recovered: {
hex:"#7dd71d",
multiplier:1200,
},
deaths:{
hex:"#fb443",
multiplier:2000,
},
};
export const sortData =(data) => {
const sortedData = [...data];
return sortedData.sort((a,b) =>
(a.cases >b.cases ? -1 :1 ))
};
export const prettyPrintStat =(stat) =>
stat ?`+${numeral(stat).format("0.0a")}`:"+0";
//draw circle on the map interective tootltip
export const showDataOnMap=(data,casesType='cases') => (
data.map(country => (
<Circle
center ={[country.countryInfo.lat, country.countryInfo.long]}
fillOpacity ={0.4}
color={casesTypeColors[casesType].hex}
fillColor={casesTypeColors[casesType].hex}
radius={
Math.sqrt(country[casesType]) * casesTypeColors[casesType].multiplier
}
>
<Popup>
<div className="info-container">
<div
className="info-flag"
style={{backgroundImage:`url(${country.countryInfo.flag})`}}
/>
<div className="info-name">{country.country}</div>
<div className="info-confirmed">Cases: {numeral(country.cases).format("0,0")}</div>
<div className="info-recovered">Recovered: {numeral(country.recovered).format("0,0")}</div>
<div className="info-deaths">Deaths: {numeral(country.deaths).format("0,0")}</div>
</div>
</Popup>
</Circle>
))
)