MapChart.js
2.7 KB
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import React, { memo } from "react";
import {
ComposableMap,
Geographies,
Geography
} from "react-simple-maps";
import { useTranslation, Trans } from 'react-i18next';
const geoUrl =
// "http://arreport.test/world-110m.json";
"https://yearinreview.cbvinstitute.com/world-110m.json";
const MapChart = ({ setTooltipContent, countries }) => {
const { t } = useTranslation();
return (
<>
<ComposableMap data-tip="" projection="geoMercator" >
<Geographies geography={geoUrl}>
{({ geographies }) =>
geographies.map(geo => {
var found = false;
for(var i = 0;i < countries.length;++i) {
for(const cprop in geo.properties) {
if(typeof geo.properties[cprop].indexOf == 'function' && geo.properties[cprop].indexOf(countries[i].name) !== -1) {
geo.properties.NICENAME = countries[i].name
found = true;
break;
}
}
}
var style = {};
if(found) {
style = {
default: {
fill: "#5CBFBC",
outline: "#0F1647",
stroke: "#0F1647",
strokeWidth: "0.25px"
},
hover: {
fill: "white",
outline: "none"
}
}
} else {
style = {
default: {
fill: "#594D78",
outline: "none",
},
hover: {
fill: "#594D78",
outline: "none"
},
pressed: {
fill: "#594D78",
outline: "none"
}
}
}
return (
<Geography
key={geo.rsmKey}
geography={geo}
onMouseEnter={() => {
if(found) {
const { NICENAME } = geo.properties;
setTooltipContent(`${NICENAME}`);
}
}}
onMouseLeave={() => {
setTooltipContent("");
}}
style={style}
/>
) } )
}
</Geographies>
</ComposableMap>
</>
);
};
export default memo(MapChart);