Skip to content

Commit 47e38f1

Browse files
committed
fix bug causing argentina to crash
1 parent 74526fd commit 47e38f1

File tree

3 files changed

+33
-33
lines changed

3 files changed

+33
-33
lines changed

components/widgets/index.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,11 @@ class WidgetsContainer extends PureComponent {
104104
(mapSettingsChanged || activeWidgetChanged)
105105
) {
106106
this.syncWidgetWithMap();
107-
} else if (!datasets && activeWidgetChanged) {
107+
} else if (
108+
!datasets &&
109+
activeWidgetChanged &&
110+
!isEqual(settings, prevSettings)
111+
) {
108112
this.clearMap();
109113
}
110114
}

components/world-map/component.jsx

+27-31
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@ import {
44
ComposableMap,
55
Geographies,
66
Geography,
7-
Lines,
87
ZoomableGroup,
9-
Line
8+
Line,
109
} from 'react-simple-maps';
1110
import { Tooltip } from 'react-tippy';
1211

@@ -24,14 +23,14 @@ class WorldMap extends React.PureComponent {
2423
const y1 = end[1];
2524
const curve = {
2625
forceUp: `${x1} ${y0}`,
27-
forceDown: `${x0} ${y1}`
26+
forceDown: `${x0} ${y1}`,
2827
}[arc.curveStyle];
2928

3029
return `M ${start.join(' ')} Q ${curve} ${end.join(' ')}`;
3130
}
3231

3332
static isDestinationCountry(iso, countries) {
34-
return countries.map(f => f.geoId).includes(iso);
33+
return countries.map((f) => f.geoId).includes(iso);
3534
}
3635

3736
static getDerivedStateFromProps(nextProps, prevState) {
@@ -40,7 +39,7 @@ class WorldMap extends React.PureComponent {
4039
return {
4140
flows: nextProps.flows,
4241
originGeoId: nextProps.originGeoId,
43-
originCoordinates: nextProps.originCoordinates
42+
originCoordinates: nextProps.originCoordinates,
4443
};
4544
}
4645
return prevState;
@@ -50,10 +49,10 @@ class WorldMap extends React.PureComponent {
5049
flows: [],
5150
originGeoId: null,
5251
tooltipConfig: null,
53-
originCoordinates: []
52+
originCoordinates: [],
5453
};
5554

56-
onMouseMove = (geometry, e) => {
55+
onMouseMove = (e, geometry) => {
5756
const { flows } = this.state;
5857
const geoId = geometry.properties
5958
? geometry.properties.iso2
@@ -66,17 +65,17 @@ class WorldMap extends React.PureComponent {
6665
const unit = 't';
6766
const volume =
6867
geometry.value ||
69-
(flows.find(flow => flow.geoId === geoId) || {}).value;
68+
(flows.find((flow) => flow.geoId === geoId) || {}).value;
7069
const height =
7170
geometry.height ||
72-
(flows.find(flow => flow.geoId === geoId) || {}).height;
71+
(flows.find((flow) => flow.geoId === geoId) || {}).height;
7372
const value = formatNumber({ num: volume, unit: 't' });
7473
const percentage = formatNumber({ num: height * 100, unit: '%' });
7574
const tooltipConfig = {
7675
x,
7776
y,
7877
text,
79-
items: [{ title, value, unit, percentage }]
78+
items: [{ title, value, unit, percentage }],
8079
};
8180
this.setState(() => ({ tooltipConfig }));
8281
}
@@ -90,7 +89,7 @@ class WorldMap extends React.PureComponent {
9089
const { flows, originGeoId } = this.state;
9190

9291
return geographies.map(
93-
geography =>
92+
(geography) =>
9493
geography.properties.iso2 !== 'AQ' && (
9594
<Geography
9695
key={geography.properties.cartodb_id}
@@ -100,13 +99,13 @@ class WorldMap extends React.PureComponent {
10099
'-dark': WorldMap.isDestinationCountry(
101100
geography.properties.iso2,
102101
flows
103-
)
102+
),
104103
},
105104
{ '-pink': originGeoId === geography.properties.iso2 }
106105
)}
107106
geography={geography}
108107
projection={projection}
109-
onMouseMove={this.onMouseMove}
108+
onMouseMove={(e) => this.onMouseMove(e, geography)}
110109
onMouseLeave={this.onMouseLeave}
111110
/>
112111
)
@@ -116,20 +115,14 @@ class WorldMap extends React.PureComponent {
116115
renderLines = () => {
117116
const { originCoordinates, flows } = this.state;
118117

119-
return flows.map(flow => (
118+
return flows.map((flow) => (
120119
<Line
121120
key={flow.geoId}
122121
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}
131124
strokeWidth={flow.strokeWidth}
132-
onMouseMove={this.onMouseMove}
125+
onMouseMove={(e) => this.onMouseMove(e, flow)}
133126
onMouseLeave={this.onMouseLeave}
134127
/>
135128
));
@@ -143,28 +136,28 @@ class WorldMap extends React.PureComponent {
143136
<Tooltip
144137
className={className}
145138
theme="tip"
146-
html={
139+
html={(
147140
<div className="c-world-map-tooltip">
148141
<p>{text && text.toLowerCase()}</p>
149142
<p>{items && items[0].value}</p>
150143
<p>{items && items[0].percentage}</p>
151144
</div>
152-
}
145+
)}
153146
followCursor
154147
animateFill={false}
155148
open={!!tooltipConfig}
156149
>
157150
<ComposableMap
158151
className={cx('c-world-map')}
159-
projection="robinson"
160152
style={{ width: '100%', height: 'auto' }}
161153
projectionConfig={{ scale: 145 }}
162154
>
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)}
166159
</Geographies>
167-
<Lines>{this.renderLines()}</Lines>
160+
{this.renderLines()}
168161
</ZoomableGroup>
169162
</ComposableMap>
170163
</Tooltip>
@@ -173,7 +166,10 @@ class WorldMap extends React.PureComponent {
173166
}
174167

175168
WorldMap.propTypes = {
176-
className: PropTypes.string
169+
flows: PropTypes.array,
170+
originCoordinates: PropTypes.array,
171+
originGeoId: PropTypes.string,
172+
className: PropTypes.string,
177173
};
178174

179175
export default WorldMap;

services/trase.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import request from 'utils/request';
22

3-
const { TRASE_API } = 'utils/constants';
3+
import { TRASE_API } from 'utils/constants';
44

55
export const fetchTraseContexts = () => request.get(`${TRASE_API}/contexts`);
66

0 commit comments

Comments
 (0)