forked from owid/owid-grapher
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEditorFeatures.tsx
152 lines (125 loc) · 4.02 KB
/
EditorFeatures.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
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
142
143
144
145
146
147
148
149
150
151
152
import { computed } from "mobx"
import { ChartEditor } from "./ChartEditor.js"
// Responsible for determining what parts of the editor should be shown, based on the
// type of chart being edited
export class EditorFeatures {
editor: ChartEditor
constructor(editor: ChartEditor) {
this.editor = editor
}
@computed get grapher() {
return this.editor.grapher
}
@computed get canCustomizeYAxisScale() {
return !this.grapher.isStackedArea && !this.grapher.isStackedBar
}
@computed get canCustomizeXAxisScale() {
return this.grapher.isScatter || this.grapher.isMarimekko
}
@computed get canCustomizeYAxisLabel() {
return this.grapher.isScatter || this.grapher.isMarimekko
}
@computed get canCustomizeXAxisLabel() {
return (
this.grapher.isLineChart ||
this.grapher.isScatter ||
this.grapher.isMarimekko ||
this.grapher.isStackedArea
)
}
@computed get canCustomizeYAxis() {
return this.canCustomizeYAxisScale || this.canCustomizeYAxisLabel
}
@computed get canCustomizeXAxis() {
return this.canCustomizeXAxisScale || this.canCustomizeXAxisLabel
}
@computed get canRemovePointsOutsideAxisDomain() {
return this.grapher.isScatter
}
@computed get timeDomain() {
return !this.grapher.isDiscreteBar
}
@computed get timelineRange() {
return !this.grapher.isDiscreteBar
}
@computed get showYearLabels() {
return this.grapher.isDiscreteBar
}
@computed get hideLegend() {
return (
this.grapher.isLineChart ||
this.grapher.isStackedArea ||
this.grapher.isStackedDiscreteBar
)
}
@computed get stackedArea() {
return this.grapher.isStackedArea
}
@computed get relativeModeToggle() {
return (
this.grapher.isStackedArea ||
this.grapher.isStackedBar ||
this.grapher.isStackedDiscreteBar ||
this.grapher.isLineChart ||
this.grapher.isScatter ||
this.grapher.isMarimekko
)
}
@computed get comparisonLine() {
return this.grapher.isLineChart || this.grapher.isScatter
}
@computed get canSpecifySortOrder() {
return (
this.grapher.isStackedDiscreteBar ||
this.grapher.isLineChart ||
this.grapher.isDiscreteBar ||
this.grapher.isMarimekko
)
}
@computed get canSortByColumn() {
return this.grapher.isStackedDiscreteBar || this.grapher.isMarimekko
}
@computed get canHideTotalValueLabel() {
return this.grapher.isStackedDiscreteBar
}
@computed get canCustomizeVariableType() {
return this.grapher.hasMultipleYColumns
}
@computed get canSpecifyMissingDataStrategy() {
if (!this.grapher.hasMultipleYColumns) return false
if (this.grapher.isStackedArea || this.grapher.isStackedBar) {
return true
}
// for line charts, specifying a missing data strategy only makes sense
// if there are multiple entities
if (this.grapher.isLineChart) {
return (
this.grapher.canChangeEntity ||
this.grapher.canSelectMultipleEntities
)
}
return false
}
@computed get showChangeInPrefixToggle() {
return (
this.grapher.isLineChart &&
(this.grapher.isRelativeMode || this.grapher.canToggleRelativeMode)
)
}
@computed get showEntityAnnotationInTitleToggle() {
return (
!this.grapher.canChangeEntity &&
!this.grapher.canSelectMultipleEntities
)
}
@computed get showTimeAnnotationInTitleToggle() {
return (
!this.grapher.hasTimeline ||
!(
this.grapher.isDiscreteBar ||
this.grapher.isStackedDiscreteBar ||
this.grapher.isMarimekko
)
)
}
}