4
4
ComposableMap ,
5
5
Geographies ,
6
6
Geography ,
7
- Lines ,
8
7
ZoomableGroup ,
9
- Line
8
+ Line ,
10
9
} from 'react-simple-maps' ;
11
10
import { Tooltip } from 'react-tippy' ;
12
11
@@ -24,14 +23,14 @@ class WorldMap extends React.PureComponent {
24
23
const y1 = end [ 1 ] ;
25
24
const curve = {
26
25
forceUp : `${ x1 } ${ y0 } ` ,
27
- forceDown : `${ x0 } ${ y1 } `
26
+ forceDown : `${ x0 } ${ y1 } ` ,
28
27
} [ arc . curveStyle ] ;
29
28
30
29
return `M ${ start . join ( ' ' ) } Q ${ curve } ${ end . join ( ' ' ) } ` ;
31
30
}
32
31
33
32
static isDestinationCountry ( iso , countries ) {
34
- return countries . map ( f => f . geoId ) . includes ( iso ) ;
33
+ return countries . map ( ( f ) => f . geoId ) . includes ( iso ) ;
35
34
}
36
35
37
36
static getDerivedStateFromProps ( nextProps , prevState ) {
@@ -40,7 +39,7 @@ class WorldMap extends React.PureComponent {
40
39
return {
41
40
flows : nextProps . flows ,
42
41
originGeoId : nextProps . originGeoId ,
43
- originCoordinates : nextProps . originCoordinates
42
+ originCoordinates : nextProps . originCoordinates ,
44
43
} ;
45
44
}
46
45
return prevState ;
@@ -50,10 +49,10 @@ class WorldMap extends React.PureComponent {
50
49
flows : [ ] ,
51
50
originGeoId : null ,
52
51
tooltipConfig : null ,
53
- originCoordinates : [ ]
52
+ originCoordinates : [ ] ,
54
53
} ;
55
54
56
- onMouseMove = ( geometry , e ) => {
55
+ onMouseMove = ( e , geometry ) => {
57
56
const { flows } = this . state ;
58
57
const geoId = geometry . properties
59
58
? geometry . properties . iso2
@@ -66,17 +65,17 @@ class WorldMap extends React.PureComponent {
66
65
const unit = 't' ;
67
66
const volume =
68
67
geometry . value ||
69
- ( flows . find ( flow => flow . geoId === geoId ) || { } ) . value ;
68
+ ( flows . find ( ( flow ) => flow . geoId === geoId ) || { } ) . value ;
70
69
const height =
71
70
geometry . height ||
72
- ( flows . find ( flow => flow . geoId === geoId ) || { } ) . height ;
71
+ ( flows . find ( ( flow ) => flow . geoId === geoId ) || { } ) . height ;
73
72
const value = formatNumber ( { num : volume , unit : 't' } ) ;
74
73
const percentage = formatNumber ( { num : height * 100 , unit : '%' } ) ;
75
74
const tooltipConfig = {
76
75
x,
77
76
y,
78
77
text,
79
- items : [ { title, value, unit, percentage } ]
78
+ items : [ { title, value, unit, percentage } ] ,
80
79
} ;
81
80
this . setState ( ( ) => ( { tooltipConfig } ) ) ;
82
81
}
@@ -90,7 +89,7 @@ class WorldMap extends React.PureComponent {
90
89
const { flows, originGeoId } = this . state ;
91
90
92
91
return geographies . map (
93
- geography =>
92
+ ( geography ) =>
94
93
geography . properties . iso2 !== 'AQ' && (
95
94
< Geography
96
95
key = { geography . properties . cartodb_id }
@@ -100,13 +99,13 @@ class WorldMap extends React.PureComponent {
100
99
'-dark' : WorldMap . isDestinationCountry (
101
100
geography . properties . iso2 ,
102
101
flows
103
- )
102
+ ) ,
104
103
} ,
105
104
{ '-pink' : originGeoId === geography . properties . iso2 }
106
105
) }
107
106
geography = { geography }
108
107
projection = { projection }
109
- onMouseMove = { this . onMouseMove }
108
+ onMouseMove = { ( e ) => this . onMouseMove ( e , geography ) }
110
109
onMouseLeave = { this . onMouseLeave }
111
110
/>
112
111
)
@@ -116,20 +115,14 @@ class WorldMap extends React.PureComponent {
116
115
renderLines = ( ) => {
117
116
const { originCoordinates, flows } = this . state ;
118
117
119
- return flows . map ( flow => (
118
+ return flows . map ( ( flow ) => (
120
119
< Line
121
120
key = { flow . geoId }
122
121
className = "world-map-arc"
123
- line = { {
124
- ...flow ,
125
- coordinates : {
126
- start : flow . coordinates ,
127
- end : originCoordinates
128
- }
129
- } }
130
- buildPath = { WorldMap . buildCurves }
122
+ from = { originCoordinates }
123
+ to = { flow . coordinates }
131
124
strokeWidth = { flow . strokeWidth }
132
- onMouseMove = { this . onMouseMove }
125
+ onMouseMove = { ( e ) => this . onMouseMove ( e , flow ) }
133
126
onMouseLeave = { this . onMouseLeave }
134
127
/>
135
128
) ) ;
@@ -143,28 +136,28 @@ class WorldMap extends React.PureComponent {
143
136
< Tooltip
144
137
className = { className }
145
138
theme = "tip"
146
- html = {
139
+ html = { (
147
140
< div className = "c-world-map-tooltip" >
148
141
< p > { text && text . toLowerCase ( ) } </ p >
149
142
< p > { items && items [ 0 ] . value } </ p >
150
143
< p > { items && items [ 0 ] . percentage } </ p >
151
144
</ div >
152
- }
145
+ ) }
153
146
followCursor
154
147
animateFill = { false }
155
148
open = { ! ! tooltipConfig }
156
149
>
157
150
< ComposableMap
158
151
className = { cx ( 'c-world-map' ) }
159
- projection = "robinson"
160
152
style = { { width : '100%' , height : 'auto' } }
161
153
projectionConfig = { { scale : 145 } }
162
154
>
163
- < ZoomableGroup disablePanning center = { [ 20 , 0 ] } >
164
- < Geographies geography = { WORLD_GEOGRAPHIES } disableOptimization >
165
- { this . renderGeographies }
155
+ < ZoomableGroup center = { [ 0 , 0 ] } >
156
+ < Geographies geography = { WORLD_GEOGRAPHIES } >
157
+ { ( { geographies, projection } ) =>
158
+ this . renderGeographies ( geographies , projection ) }
166
159
</ Geographies >
167
- < Lines > { this . renderLines ( ) } </ Lines >
160
+ { this . renderLines ( ) }
168
161
</ ZoomableGroup >
169
162
</ ComposableMap >
170
163
</ Tooltip >
@@ -173,7 +166,10 @@ class WorldMap extends React.PureComponent {
173
166
}
174
167
175
168
WorldMap . propTypes = {
176
- className : PropTypes . string
169
+ flows : PropTypes . array ,
170
+ originCoordinates : PropTypes . array ,
171
+ originGeoId : PropTypes . string ,
172
+ className : PropTypes . string ,
177
173
} ;
178
174
179
175
export default WorldMap ;
0 commit comments