-
-
Notifications
You must be signed in to change notification settings - Fork 112
/
Copy pathMarkerSize.js
106 lines (94 loc) · 2.9 KB
/
MarkerSize.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
import Field from './Field';
import PropTypes from 'prop-types';
import React, {Component} from 'react';
import {connectToContainer} from 'lib';
import RadioBlocks from '../widgets/RadioBlocks';
import Numeric from './Numeric';
import DataSelector from './DataSelector';
import {MULTI_VALUED} from 'lib/constants';
class UnconnectedMarkerSize extends Component {
constructor(props, context) {
super(props, context);
let type = null;
if (!props.container.marker || (props.container.marker && !props.container.marker.sizesrc)) {
type = 'constant';
} else if (
props.container.marker &&
Array.isArray(props.container.marker.size) &&
props.fullContainer.marker &&
Array.isArray(props.fullContainer.marker.size)
) {
type = 'variable';
}
this.state = {
type,
value: {
constant: type === 'constant' ? props.fullValue : '6',
variable: type === 'variable' ? props.fullValue : null,
},
};
this.setType = this.setType.bind(this);
this.setValue = this.setValue.bind(this);
}
setType(type) {
this.setState({type: type});
this.props.updatePlot(this.state.value[type]);
if (type === 'constant') {
this.context.updateContainer({['marker.sizesrc']: null});
} else {
this.context.updateContainer({
['marker.size']: null,
['marker.sizesrc']: null,
});
}
}
setValue(inputValue) {
const {type} = this.state;
this.setState(
type === 'constant' ? {value: {constant: inputValue}} : {value: {variable: inputValue}}
);
this.props.updatePlot(inputValue);
}
render() {
const {attr, fullValue} = this.props;
const {localize: _} = this.context;
const {type, value} = this.state;
const options = [
{label: _('Constant'), value: 'constant'},
{label: _('Variable'), value: 'variable'},
];
const multiValued =
this.props.multiValued || (Array.isArray(fullValue) && fullValue.includes(MULTI_VALUED));
return (
<Field {...this.props} multiValued={multiValued} attr={attr}>
<RadioBlocks options={options} activeOption={type} onOptionChange={this.setType} />
{type === 'constant' ? (
<Numeric
suppressMultiValuedMessage
attr="marker.size"
updatePlot={this.setValue}
fullValue={value.constant}
noDefaultIndicator
/>
) : multiValued ? null : (
<DataSelector
suppressMultiValuedMessage
attr="marker.size"
updatePlot={this.setValue}
noDefaultIndicator
/>
)}
</Field>
);
}
}
UnconnectedMarkerSize.propTypes = {
fullValue: PropTypes.any,
updatePlot: PropTypes.func,
...Field.propTypes,
};
UnconnectedMarkerSize.contextTypes = {
localize: PropTypes.func,
updateContainer: PropTypes.func,
};
export default connectToContainer(UnconnectedMarkerSize);