-
-
Notifications
You must be signed in to change notification settings - Fork 229
/
Copy pathEditorMarimekkoTab.tsx
62 lines (56 loc) · 1.98 KB
/
EditorMarimekkoTab.tsx
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
import { Grapher } from "@ourworldindata/grapher"
import lodash from "lodash"
import { action, IReactionDisposer, observable, reaction } from "mobx"
import { observer } from "mobx-react"
import { Component } from "react"
import { NumberField, Section, Toggle } from "./Forms.js"
@observer
export class EditorMarimekkoTab extends Component<{ grapher: Grapher }> {
@observable xOverrideTimeInputField: number | undefined
constructor(props: { grapher: Grapher }) {
super(props)
this.xOverrideTimeInputField = props.grapher.xOverrideTime
}
@action.bound onXOverrideYear(value: number | undefined) {
this.xOverrideTimeInputField = value
}
render() {
const { grapher } = this.props
return (
<div className="EditorMarimekkoTab">
<Section name="Filtering">
<NumberField
label="Override X axis target year"
value={this.xOverrideTimeInputField}
onValue={this.onXOverrideYear}
allowNegative
/>
<Toggle
label="Exclude entities that do not belong in any color group"
value={!!grapher.matchingEntitiesOnly}
onValue={action(
(value: boolean) =>
(grapher.matchingEntitiesOnly =
value || undefined)
)}
/>
</Section>
</div>
)
}
dispose!: IReactionDisposer
componentDidMount() {
this.dispose = reaction(
() => this.xOverrideTimeInputField,
lodash.debounce(
() =>
(this.props.grapher.xOverrideTime =
this.xOverrideTimeInputField),
800
)
)
}
componentWillUnmount() {
this.dispose()
}
}