-
Notifications
You must be signed in to change notification settings - Fork 4.4k
/
Copy pathGeneralSettings.jsx
214 lines (190 loc) · 6.56 KB
/
GeneralSettings.jsx
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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
import { isArray, map, mapValues, includes, some, each, difference } from "lodash";
import React, { useMemo } from "react";
import { Section, Select, Checkbox } from "@/components/visualizations/editor";
import { UpdateOptionsStrategy } from "@/components/visualizations/editor/createTabbedEditor";
import { EditorPropTypes } from "@/visualizations";
import ChartTypeSelect from "./ChartTypeSelect";
import ColumnMappingSelect from "./ColumnMappingSelect";
function getAvailableColumnMappingTypes(options) {
const result = ["x", "y"];
if (!includes(["custom", "heatmap"], options.globalSeriesType)) {
result.push("series");
}
if (some(options.seriesOptions, { type: "bubble" })) {
result.push("size");
}
if (some(options.seriesOptions, { type: "heatmap" })) {
result.push("zVal");
}
if (!includes(["custom", "heatmap"], options.globalSeriesType)) {
result.push("yError");
}
return result;
}
function getMappedColumns(options, availableColumns) {
const mappedColumns = {};
const availableTypes = getAvailableColumnMappingTypes(options);
each(availableTypes, type => {
mappedColumns[type] = ColumnMappingSelect.MappingTypes[type].multiple ? [] : null;
});
availableColumns = map(availableColumns, c => c.name);
const usedColumns = [];
each(options.columnMapping, (type, column) => {
if (includes(availableColumns, column) && includes(availableTypes, type)) {
const { multiple } = ColumnMappingSelect.MappingTypes[type];
if (multiple) {
mappedColumns[type].push(column);
} else {
mappedColumns[type] = column;
}
usedColumns.push(column);
}
});
return {
mappedColumns,
unusedColumns: difference(availableColumns, usedColumns),
};
}
function mappedColumnsToColumnMappings(mappedColumns) {
const result = {};
each(mappedColumns, (value, type) => {
if (isArray(value)) {
each(value, v => {
result[v] = type;
});
} else {
if (value) {
result[value] = type;
}
}
});
return result;
}
export default function GeneralSettings({ options, data, onOptionsChange }) {
const { mappedColumns, unusedColumns } = useMemo(() => getMappedColumns(options, data.columns), [
options,
data.columns,
]);
function handleGlobalSeriesTypeChange(globalSeriesType) {
onOptionsChange({
globalSeriesType,
showDataLabels: globalSeriesType === "pie",
seriesOptions: mapValues(options.seriesOptions, series => ({
...series,
type: globalSeriesType,
})),
});
}
function handleColumnMappingChange(column, type) {
const columnMapping = mappedColumnsToColumnMappings({
...mappedColumns,
[type]: column,
});
onOptionsChange({ columnMapping }, UpdateOptionsStrategy.shallowMerge);
}
return (
<React.Fragment>
<Section>
<ChartTypeSelect
label="Chart Type"
className="w-100"
data-test="Chart.GlobalSeriesType"
defaultValue={options.globalSeriesType}
onChange={handleGlobalSeriesTypeChange}
/>
</Section>
{map(mappedColumns, (value, type) => (
<ColumnMappingSelect
key={type}
type={type}
value={value}
availableColumns={unusedColumns}
onChange={handleColumnMappingChange}
/>
))}
{includes(["pie"], options.globalSeriesType) && (
<Section>
<Select
label="Direction"
className="w-100"
data-test="Chart.PieDirection"
defaultValue={options.direction.type}
onChange={type => onOptionsChange({ direction: { type } })}>
<Select.Option value="counterclockwise" data-test="Chart.PieDirection.Counterclockwise">
Counterclockwise
</Select.Option>
<Select.Option value="clockwise" data-test="Chart.PieDirection.Clockwise">
Clockwise
</Select.Option>
</Select>
</Section>
)}
{!includes(["custom", "heatmap"], options.globalSeriesType) && (
<Section>
<Checkbox
data-test="Chart.ShowLegend"
defaultChecked={options.legend.enabled}
onChange={event => onOptionsChange({ legend: { enabled: event.target.checked } })}>
Show Legend
</Checkbox>
</Section>
)}
{includes(["box"], options.globalSeriesType) && (
<Section>
<Checkbox
data-test="Chart.ShowPoints"
defaultChecked={options.showpoints}
onChange={event => onOptionsChange({ showpoints: event.target.checked })}>
Show All Points
</Checkbox>
</Section>
)}
{!includes(["custom", "heatmap"], options.globalSeriesType) && (
<Section>
<Select
label="Stacking"
className="w-100"
data-test="Chart.Stacking"
defaultValue={options.series.stacking}
disabled={!includes(["line", "area", "column"], options.globalSeriesType)}
onChange={stacking => onOptionsChange({ series: { stacking } })}>
<Select.Option value={null} data-test="Chart.Stacking.Disabled">
Disabled
</Select.Option>
<Select.Option value="stack" data-test="Chart.Stacking.Stack">
Stack
</Select.Option>
</Select>
</Section>
)}
{includes(["line", "area", "column"], options.globalSeriesType) && (
<Section>
<Checkbox
data-test="Chart.NormalizeValues"
defaultChecked={options.series.percentValues}
onChange={event => onOptionsChange({ series: { percentValues: event.target.checked } })}>
Normalize values to percentage
</Checkbox>
</Section>
)}
{!includes(["custom", "heatmap", "bubble", "scatter"], options.globalSeriesType) && (
<Section>
<Select
label="Missing and NULL values"
className="w-100"
data-test="Chart.MissingValues"
defaultValue={options.missingValuesAsZero ? 1 : 0}
onChange={value => onOptionsChange({ missingValuesAsZero: !!value })}>
<Select.Option value={0} data-test="Chart.MissingValues.Keep">
Do not display in chart
</Select.Option>
<Select.Option value={1} data-test="Chart.MissingValues.Zero">
Convert to 0 and display in chart
</Select.Option>
</Select>
</Section>
)}
</React.Fragment>
);
}
GeneralSettings.propTypes = EditorPropTypes;