-
-
Notifications
You must be signed in to change notification settings - Fork 229
/
Copy pathEditorScatterTab.tsx
93 lines (84 loc) · 3.38 KB
/
EditorScatterTab.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
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
import {
ComparisonLineConfig,
ScatterPointLabelStrategy,
} from "@ourworldindata/types"
import { Grapher } from "@ourworldindata/grapher"
import { debounce } from "@ourworldindata/utils"
import { action, observable } from "mobx"
import { observer } from "mobx-react"
import { Component } from "react"
import { NumberField, Section, SelectField, Toggle } from "./Forms.js"
@observer
export class EditorScatterTab extends Component<{ grapher: Grapher }> {
@observable comparisonLine: ComparisonLineConfig = { yEquals: undefined }
constructor(props: { grapher: Grapher }) {
super(props)
}
@action.bound onToggleHideTimeline(value: boolean) {
this.props.grapher.hideTimeline = value || undefined
}
@action.bound onToggleHideScatterLabels(value: boolean) {
this.props.grapher.hideScatterLabels = value || undefined
}
@action.bound onXOverrideYear(value: number | undefined) {
this.props.grapher.xOverrideTime = value
}
@action.bound onToggleConnection(value: boolean) {
const { grapher } = this.props
grapher.hideConnectedScatterLines = value
}
@action.bound onChangeScatterPointLabelStrategy(value: string) {
this.props.grapher.scatterPointLabelStrategy =
value as ScatterPointLabelStrategy
}
render() {
const { grapher } = this.props
return (
<div className="EditorScatterTab">
<Section name="Timeline">
<Toggle
label="Hide timeline"
value={!!grapher.hideTimeline}
onValue={this.onToggleHideTimeline}
/>
<Toggle
label="Hide connected scatter lines"
value={!!grapher.hideConnectedScatterLines}
onValue={this.onToggleConnection}
/>
<NumberField
label="Override X axis target year"
value={grapher.xOverrideTime}
onValue={debounce(this.onXOverrideYear, 300)}
allowNegative
/>
</Section>
<Section name="Point Labels">
<SelectField
value={grapher.scatterPointLabelStrategy}
onValue={this.onChangeScatterPointLabelStrategy}
options={Object.keys(ScatterPointLabelStrategy).map(
(entry) => ({ value: entry })
)}
/>
<Toggle
label="Hide point labels (except when hovering)"
value={!!grapher.hideScatterLabels}
onValue={this.onToggleHideScatterLabels}
/>
</Section>
<Section name="Filtering">
<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>
)
}
}