-
-
Notifications
You must be signed in to change notification settings - Fork 112
/
Copy pathLocationSelector.js
141 lines (125 loc) · 3.46 KB
/
LocationSelector.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
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
import React, {Component} from 'react';
import PropTypes from 'prop-types';
import {connectToContainer} from 'lib';
import Field from './Field';
import Radio from './Radio';
import {UnconnectedDropdown} from './Dropdown';
import DataSelector from './DataSelector';
const LocationmodeVisible = connectToContainer(UnconnectedDropdown, {
modifyPlotProps: (props, context, plotProps) => {
if (!plotProps.fullValue) {
plotProps.isVisible = true;
plotProps.fullValue = plotProps.container.locationmode;
return;
}
},
});
class UnconnectedLocation extends Component {
render() {
const {localize: _} = this.context;
return (
<>
<DataSelector label={_('Locations')} attr="locations" />
<LocationmodeVisible
label={_('Location Format')}
attr="locationmode"
clearable={false}
options={[
{label: _('Country Names'), value: 'country names'},
{label: _('Country Abbreviations (ISO-3)'), value: 'ISO-3'},
{
label: _('USA State Abbreviations (e.g. NY)'),
value: 'USA-states',
},
]}
/>
</>
);
}
}
UnconnectedLocation.propTypes = {
attr: PropTypes.string,
...Field.propTypes,
};
UnconnectedLocation.contextTypes = {
localize: PropTypes.func,
updateContainer: PropTypes.func,
};
const Location = connectToContainer(UnconnectedLocation);
class UnconnectedLocationSelector extends Component {
constructor(props, context) {
super(props, context);
this.state = {
mode: props.container.locations ? 'location' : 'latlon',
};
this.setMode = this.setMode.bind(this);
}
componentWillMount() {
this.setState({
mode: this.props.container.locations ? 'location' : 'latlon',
});
}
setMode(mode) {
this.setState({mode: mode});
this.props.updateContainer(
mode === 'latlon'
? {
locations: null,
locationmode: null,
locationssrc: null,
locationmodesrc: null,
}
: {lat: null, lon: null, latsrc: null, lonsrc: null}
);
}
render() {
const {mode} = this.state;
const {
localize: _,
container: {type: type},
} = this.context;
return type === 'scattergeo' ? (
<>
<Field {...this.props} attr={this.props.attr}>
<Radio
options={[
{value: 'latlon', label: _('Lat/Lon')},
{value: 'location', label: _('Location')},
]}
fullValue={mode}
updatePlot={this.setMode}
attr={this.props.attr}
noDefaultIndicator
/>
</Field>
{mode === 'latlon' ? (
<>
<DataSelector label={_('Latitude')} attr="lat" />
<DataSelector label={_('Longitude')} attr="lon" />
</>
) : (
<Location attr="type" />
)}
</>
) : type === 'choropleth' ? (
<Location attr="type" />
) : (
<>
<DataSelector label={_('Latitude')} attr="lat" />
<DataSelector label={_('Longitude')} attr="lon" />
</>
);
}
}
UnconnectedLocationSelector.propTypes = {
fullValue: PropTypes.any,
updatePlot: PropTypes.func,
attr: PropTypes.string,
...Field.propTypes,
};
UnconnectedLocationSelector.contextTypes = {
container: PropTypes.object,
localize: PropTypes.func,
updateContainer: PropTypes.func,
};
export default connectToContainer(UnconnectedLocationSelector);