@qrvey/utils 1.11.0 → 1.12.0-0-chart-v2-0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. package/dist/charts/adapters/chartBuilderAdapter.d.ts +35 -0
  2. package/dist/charts/adapters/chartBuilderAdapter.js +647 -0
  3. package/dist/charts/adapters/chartBuilderDefinitions.d.ts +568 -0
  4. package/dist/charts/adapters/chartBuilderDefinitions.js +31 -0
  5. package/dist/charts/adapters/chartBuilderParse.d.ts +9 -0
  6. package/dist/charts/adapters/chartBuilderParse.js +416 -0
  7. package/dist/charts/adapters/index.d.ts +1 -0
  8. package/dist/charts/adapters/index.js +1 -0
  9. package/dist/charts/helpers/chartBuilder.d.ts +53 -0
  10. package/dist/charts/helpers/chartBuilder.js +190 -0
  11. package/dist/cjs/charts/adapters/chartBuilderAdapter.d.ts +35 -0
  12. package/dist/cjs/charts/adapters/chartBuilderAdapter.js +654 -0
  13. package/dist/cjs/charts/adapters/chartBuilderDefinitions.d.ts +568 -0
  14. package/dist/cjs/charts/adapters/chartBuilderDefinitions.js +34 -0
  15. package/dist/cjs/charts/adapters/chartBuilderParse.d.ts +9 -0
  16. package/dist/cjs/charts/adapters/chartBuilderParse.js +421 -0
  17. package/dist/cjs/charts/adapters/index.d.ts +1 -0
  18. package/dist/cjs/charts/adapters/index.js +1 -0
  19. package/dist/cjs/charts/helpers/chartBuilder.d.ts +53 -0
  20. package/dist/cjs/charts/helpers/chartBuilder.js +212 -0
  21. package/dist/cjs/globalization/interfaces/chart_builder/II18nChartBuilderAxisStyle.d.ts +4 -0
  22. package/dist/cjs/globalization/interfaces/common/II18nRelativeDates.d.ts +8 -0
  23. package/dist/cjs/globalization/interfaces/common/II18nRelativeDates.js +2 -0
  24. package/dist/cjs/globalization/interfaces/common/II18nUnits.d.ts +6 -0
  25. package/dist/cjs/globalization/labels/chart_builder/I18N_CHART_BUILDER_STYLE_OPTIONS.js +4 -0
  26. package/dist/cjs/globalization/labels/common/I18N_COMMON.js +2 -10
  27. package/dist/cjs/globalization/labels/common/I18N_RELATIVE_DATES.d.ts +2 -0
  28. package/dist/cjs/globalization/labels/common/I18N_RELATIVE_DATES.js +11 -0
  29. package/dist/globalization/interfaces/chart_builder/II18nChartBuilderAxisStyle.d.ts +4 -0
  30. package/dist/globalization/interfaces/common/II18nRelativeDates.d.ts +8 -0
  31. package/dist/globalization/interfaces/common/II18nRelativeDates.js +1 -0
  32. package/dist/globalization/interfaces/common/II18nUnits.d.ts +6 -0
  33. package/dist/globalization/labels/chart_builder/I18N_CHART_BUILDER_STYLE_OPTIONS.js +4 -0
  34. package/dist/globalization/labels/common/I18N_COMMON.js +2 -10
  35. package/dist/globalization/labels/common/I18N_RELATIVE_DATES.d.ts +2 -0
  36. package/dist/globalization/labels/common/I18N_RELATIVE_DATES.js +8 -0
  37. package/package.json +1 -1
@@ -0,0 +1,35 @@
1
+ /**
2
+ * The function `buildChartBodyV1` checks if the input body is already in version 2 format, and if not,
3
+ * converts it from version 2 to version 1.
4
+ * @param {any} body - The `body` parameter is of type `any`, which means it can be any data type.
5
+ * @returns either the original `body` if it has a property `v2`, or the result of calling the
6
+ * `fromV2ToV1` function with `body` as the argument and `false` as the second argument.
7
+ */
8
+ export declare function buildChartBodyV1(body: any): any;
9
+ /**
10
+ * The function `fromV2ToV1` converts a V2 chart object to a V1 chart object in TypeScript.
11
+ * @param {any} opts - The `opts` parameter is an object that contains various settings and
12
+ * configurations for a chart. It is optional and has a default value of an empty object `{}`.
13
+ * @param [inPreviewMode=true] - The `inPreviewMode` parameter is a boolean value that indicates
14
+ * whether the function is being called in preview mode or not. It is set to `true` by default.
15
+ * @returns the variable `data`.
16
+ */
17
+ export declare function fromV2ToV1(opts?: any, inPreviewMode?: boolean): any;
18
+ export declare function getPanelConfig(config?: any, opts?: any): any;
19
+ export declare function getTrendsChartsConfig(trendInfo: any): {
20
+ fields: any;
21
+ isGrouped?: undefined;
22
+ conditions?: undefined;
23
+ visualization?: undefined;
24
+ totals?: undefined;
25
+ isMultipleSorted?: undefined;
26
+ trendsChart?: undefined;
27
+ } | {
28
+ fields: any;
29
+ isGrouped: boolean;
30
+ conditions: any;
31
+ visualization: any;
32
+ totals: any;
33
+ isMultipleSorted: any;
34
+ trendsChart: any;
35
+ };
@@ -0,0 +1,647 @@
1
+ import { _cloneDeep, _get, _isEmpty, _pick, randomKey, allowTableCalculation, hasReferenceLayer, hasSmallMultiple, hasTrendLayer, isChartBasic, isChartMap, isChartMetric, isChartMultiserie, isChartMinMax, isColumnDate, columnKey, timePeriod, timePeriodCustomRange, isTimeColumn, } from "../helpers/chartBuilder";
2
+ import { parseGlobalSettingByType, parseStyleSettingByType, } from "./chartBuilderParse";
3
+ /**
4
+ * The function `buildChartBodyV1` checks if the input body is already in version 2 format, and if not,
5
+ * converts it from version 2 to version 1.
6
+ * @param {any} body - The `body` parameter is of type `any`, which means it can be any data type.
7
+ * @returns either the original `body` if it has a property `v2`, or the result of calling the
8
+ * `fromV2ToV1` function with `body` as the argument and `false` as the second argument.
9
+ */
10
+ export function buildChartBodyV1(body) {
11
+ if (body.v2)
12
+ return body;
13
+ return fromV2ToV1(body, false);
14
+ }
15
+ /**
16
+ * The function `fromV2ToV1` converts a V2 chart object to a V1 chart object in TypeScript.
17
+ * @param {any} opts - The `opts` parameter is an object that contains various settings and
18
+ * configurations for a chart. It is optional and has a default value of an empty object `{}`.
19
+ * @param [inPreviewMode=true] - The `inPreviewMode` parameter is a boolean value that indicates
20
+ * whether the function is being called in preview mode or not. It is set to `true` by default.
21
+ * @returns the variable `data`.
22
+ */
23
+ export function fromV2ToV1(opts = {}, inPreviewMode = true) {
24
+ var _a, _b;
25
+ if (!(opts === null || opts === void 0 ? void 0 : opts.stylesSettings) ||
26
+ ((isChartMetric(opts.type) || isChartMinMax(opts.type)) &&
27
+ _isEmpty(opts.dimensions.values))) {
28
+ return;
29
+ }
30
+ const objCopy = _cloneDeep(opts);
31
+ const chart_ms = [
32
+ "BAR_CHART_MS" /* CHART_TYPE.BAR_CHART_MS */,
33
+ "LINE_CHART_MS" /* CHART_TYPE.LINE_CHART_MS */,
34
+ "SYMBOL_CHART_MS" /* CHART_TYPE.SYMBOL_CHART_MS */,
35
+ ];
36
+ const chart_cb = [...chart_ms, "COMBO_CHART" /* CHART_TYPE.COMBO_CHART */];
37
+ const chart_base = [
38
+ "BAR_CHART" /* CHART_TYPE.BAR_CHART */,
39
+ "LINE_CHART" /* CHART_TYPE.LINE_CHART */,
40
+ "SYMBOL_CHART" /* CHART_TYPE.SYMBOL_CHART */,
41
+ "MINMAX_CHART" /* CHART_TYPE.MINMAX_CHART */,
42
+ "FUNNEL_CHART" /* CHART_TYPE.FUNNEL_CHART */,
43
+ ];
44
+ const bar_type = objCopy.stylesSettings.bar_type;
45
+ objCopy.bar_width = objCopy.stylesSettings.bar_width;
46
+ objCopy.isMulti = isChartMultiserie(objCopy.type);
47
+ objCopy.isChartOptions = [...chart_base, ...chart_cb].includes(objCopy.type);
48
+ objCopy.isCombolayer = [
49
+ "COMBO_CHART" /* CHART_TYPE.COMBO_CHART */,
50
+ "COMBINED_CHART" /* CHART_TYPE.COMBINED_CHART */,
51
+ ].includes(objCopy.type);
52
+ objCopy.isReference = hasReferenceLayer((_a = opts === null || opts === void 0 ? void 0 : opts.dimensions) === null || _a === void 0 ? void 0 : _a.reference);
53
+ objCopy.isTrend =
54
+ objCopy.type !== "MINMAX_CHART" /* CHART_TYPE.MINMAX_CHART */ &&
55
+ hasTrendLayer((_b = opts === null || opts === void 0 ? void 0 : opts.dimensions) === null || _b === void 0 ? void 0 : _b.trend);
56
+ const isBarMs = objCopy.isMulti && objCopy.type === "BAR_CHART_MS" /* CHART_TYPE.BAR_CHART_MS */;
57
+ objCopy.is100 = isBarMs && bar_type === "h100" /* BAR_TYPE.FULL */;
58
+ objCopy.isCombo =
59
+ objCopy.isTrend ||
60
+ objCopy.isMulti ||
61
+ objCopy.isCombolayer ||
62
+ objCopy.isReference;
63
+ objCopy.isComboCalc = objCopy.isCombolayer;
64
+ objCopy.isStakedBar =
65
+ (isBarMs || objCopy.isCombo) &&
66
+ (objCopy.is100 || bar_type === "Stacked" /* BAR_TYPE.STACKED */) &&
67
+ objCopy.type !== "BAR_CHART" /* CHART_TYPE.BAR_CHART */;
68
+ objCopy.isSmallMultiples =
69
+ [...chart_base, ...chart_cb].includes(objCopy.type) &&
70
+ objCopy.type !== "FUNNEL_CHART" /* CHART_TYPE.FUNNEL_CHART */ &&
71
+ hasSmallMultiple(opts.dimensions.smallmultiple);
72
+ const layerList = getLayerList(objCopy);
73
+ if (!layerList)
74
+ return;
75
+ const data = getPanelBodyByChart(objCopy.type, objCopy, layerList, inPreviewMode);
76
+ data.v2 = opts;
77
+ return data;
78
+ }
79
+ function getPanelBodyByChart(chart, obj, layerList, inPreviewMode) {
80
+ let panelBody = Object.assign(Object.assign({}, _pick(obj, [
81
+ "title",
82
+ "name",
83
+ "metricid",
84
+ "chartid",
85
+ "type",
86
+ "position",
87
+ "createDate",
88
+ "modifyDate",
89
+ "dataSet",
90
+ "isOldChart",
91
+ "isMulti",
92
+ "bar_width",
93
+ "isComboCalc",
94
+ ])), { globalSettings: getGlobalSettings(obj.type, obj), preFilters: obj.preFilters || [], defaultFilters: obj.defaultFilters || {}, oldInternalFilters: obj.oldInternalFilters, dateGroup: _get(layerList[0], "dateGroup"), timeGroup: _get(layerList[0], "timeGroup"), layerList });
95
+ panelBody.name = obj.name || obj.title; // Retro for metrics
96
+ panelBody.dataset = obj.dataset; // AT Retro
97
+ switch (chart) {
98
+ case "BOXWHISKER_CHART" /* CHART_TYPE.BOXWHISKER_CHART */:
99
+ panelBody.globalSettings.sortX = {
100
+ type: "Label" /* ACTION_SORT.LABEL */,
101
+ order: "Asc" /* ACTION_SORT_DIR.ASC */,
102
+ }; // remove when box and whishker support sorting by UI settings
103
+ break;
104
+ case "CROSSTAB_CHART" /* CHART_TYPE.CROSSTAB_CHART */:
105
+ panelBody = Object.assign(Object.assign({}, panelBody), { chart: getCrosstabConfig(obj) });
106
+ break;
107
+ case "EXPANDABLE_TABLE_CHART" /* CHART_TYPE.EXPANDABLE_TABLE_CHART */:
108
+ case "TABLE_CHART" /* CHART_TYPE.TABLE_CHART */: {
109
+ const isSimpleTable = !obj.dimensions["categories" /* CHART_DIMENSION.CATEGORIES */].length;
110
+ const attrMax = isSimpleTable
111
+ ? "globalSettings.max_rows.value"
112
+ : "globalSettings.max_groups.value";
113
+ const maxRecords = _get(obj, attrMax);
114
+ panelBody = Object.assign(Object.assign({}, panelBody), { globalSettings: Object.assign(Object.assign({}, panelBody.globalSettings), { maxRecords }), chart: getTableConfig(obj, inPreviewMode) });
115
+ break;
116
+ }
117
+ case "INDICATOR" /* CHART_TYPE.INDICATOR_METRIC */:
118
+ case "DIAL" /* CHART_TYPE.DIAL_METRIC */:
119
+ case "BULLET" /* CHART_TYPE.BULLET_METRIC */: {
120
+ const { comparison } = _cloneDeep(obj.dimensions);
121
+ panelBody = Object.assign(Object.assign(Object.assign({}, panelBody), { globalSettings: Object.assign(Object.assign({}, panelBody.globalSettings), {
122
+ // TODO: Rebase this implementation to refactor
123
+ comparisonType: _get(comparison, "[0].comparison.type", "CHANGE" /* COMPARISON_TYPE.CHANGE */) }) }), getMetricConfigData(chart, obj));
124
+ break;
125
+ }
126
+ case "GEO_CHART_DOT" /* CHART_TYPE.GEO_CHART_DOT */:
127
+ case "GEO_CHART_BUBBLE" /* CHART_TYPE.GEO_CHART_BUBBLE */:
128
+ case "GEO_CHART_CHOROPLETH" /* CHART_TYPE.GEO_CHART_CHOROPLETH */:
129
+ panelBody = Object.assign(Object.assign({}, panelBody), { isSmallMultiples: obj.isSmallMultiples, chart: getGeoMapConfig(obj) });
130
+ break;
131
+ default:
132
+ panelBody = Object.assign(Object.assign({}, panelBody), { isChartOptions: true, isCombolayer: obj.isCombolayer, isReference: obj.isReference, isMulti: obj.isMulti, isCombo: obj.isCombo, isSmallMultiples: obj.isSmallMultiples, isTrend: obj.isTrend, is100: obj.is100, isStakedBar: obj.isStakedBar, isSplit: false });
133
+ break;
134
+ }
135
+ return panelBody;
136
+ }
137
+ export function getPanelConfig(config = {}, opts = {}) {
138
+ return Object.assign(Object.assign({}, config), { type: getPanelType(opts.type), inBuilder: true, editable: true, panel: {
139
+ header: { visible: false },
140
+ body: { hasOverlay: false },
141
+ }, previewFilters: _get(config, "filterData.logic"), data: fromV2ToV1(Object.assign(Object.assign({}, opts), { appid: config.app_id || config.appid })) });
142
+ }
143
+ function getPanelType(chart) {
144
+ return [
145
+ "INDICATOR" /* CHART_TYPE.INDICATOR_METRIC */,
146
+ "DIAL" /* CHART_TYPE.DIAL_METRIC */,
147
+ "BULLET" /* CHART_TYPE.BULLET_METRIC */,
148
+ ].includes(chart)
149
+ ? "METRIC"
150
+ : "CHART";
151
+ }
152
+ function getMetricConfigData(chart, obj) {
153
+ const { values, thresholds, comparison } = _cloneDeep(obj.dimensions);
154
+ let data = {
155
+ value: Object.assign(Object.assign({}, values[0]), { property: parsePropertyComplexData(values[0]) }),
156
+ dataSet: {},
157
+ valueAggregate: values[0] && values[0].aggregate,
158
+ };
159
+ if (_get(comparison, "[0]")) {
160
+ const dateColumn = Object.assign({}, comparison[0]);
161
+ const config = dateColumn.comparison;
162
+ delete dateColumn.comparison;
163
+ data = Object.assign(Object.assign({}, data), { dateColumn, timePeriod: timePeriod.find((tp) => tp.label === config.time_period.value), comparison: timePeriod.find((tp) => tp.label === config.time_comparison.value) });
164
+ if (config.time_period.value === "CUSTOM_RANGE" /* TIME_PERIOD.CUSTOM_RANGE */) {
165
+ data = Object.assign(Object.assign({}, data), { timePeriodCustomRange: timePeriodCustomRange.find((tpc) => tpc.label === config.time_period.range), timePeriodDate: config.time_period.start, timePeriodEndDate: config.time_period.end });
166
+ }
167
+ if (config.time_comparison.value === "CUSTOM_RANGE" /* TIME_PERIOD.CUSTOM_RANGE */) {
168
+ data = Object.assign(Object.assign({}, data), { comparisonCustomRange: timePeriodCustomRange.find((tpc) => tpc.label === config.time_comparison.range), comparisonDate: config.time_comparison.start, comparisonEndDate: config.time_comparison.end });
169
+ }
170
+ }
171
+ return {
172
+ appid: obj.appid,
173
+ type: { label: chart },
174
+ thresholdsList: thresholds === null || thresholds === void 0 ? void 0 : thresholds.map((thr) => ({
175
+ label: thr.custom_label || thr.label,
176
+ color: thr.color,
177
+ operator: { label: thr.operator },
178
+ value: thr.value,
179
+ initValue: thr.value,
180
+ endValue: thr.max_value,
181
+ })),
182
+ data,
183
+ individualSettings: parseStyleSettingByType(chart, obj),
184
+ dataset: data.dataSet,
185
+ };
186
+ }
187
+ function getLayerList(opts) {
188
+ if (!isValidData(opts)) {
189
+ return;
190
+ }
191
+ const dimensions = _cloneDeep(opts.dimensions);
192
+ let list = [];
193
+ /** ******* Categort/Value based charts **********/
194
+ const category = getCategory(dimensions, opts);
195
+ const valueColumn = getValue(category, dimensions, opts);
196
+ const dateGroup = category && isColumnDate(category) && category.dateGroup
197
+ ? category.dateGroup
198
+ : undefined;
199
+ const timeGroup = category && isTimeColumn(category) && category.timeGroup
200
+ ? category.timeGroup
201
+ : undefined;
202
+ const scaleType = category &&
203
+ (isColumnDate(category) || isTimeColumn(category)) &&
204
+ category.scaleType
205
+ ? category.scaleType
206
+ : undefined;
207
+ const valueLayer = Object.assign(Object.assign({}, parseLayer(category, valueColumn, 0, opts)), parseAxisLabels(valueColumn, opts));
208
+ list = [valueLayer];
209
+ if (dateGroup) {
210
+ list[0] = Object.assign(Object.assign({}, list[0]), { dateGroup });
211
+ }
212
+ if (timeGroup) {
213
+ list[0] = Object.assign(Object.assign({}, list[0]), { timeGroup });
214
+ }
215
+ if (scaleType) {
216
+ list[0] = Object.assign(Object.assign({}, list[0]), { scaleType });
217
+ }
218
+ if (opts.isMulti) {
219
+ const seriesValue = dimensions.series.length
220
+ ? dimensions.series[0]
221
+ : valueColumn;
222
+ list[0].multiserie = {
223
+ maxDataPoints: _get(opts, "globalSettings.max_series_point.value", true),
224
+ maxNumDataPoints: _get(opts, "globalSettings.max_series_point.option", 50),
225
+ type: opts.stylesSettings.bar_type,
226
+ serie: Object.assign(Object.assign({}, seriesValue), { property: parsePropertyComplexData(seriesValue) }),
227
+ };
228
+ }
229
+ if (opts.isCombolayer) {
230
+ const dimensionProp = opts.type === "COMBINED_CHART" /* CHART_TYPE.COMBINED_CHART */ ? "values" : "series";
231
+ list = [
232
+ ...list,
233
+ ...getComboLayers(category, dimensions, opts, dimensionProp),
234
+ ];
235
+ }
236
+ if (opts.isTrend) {
237
+ list = [...list, getTrendLayer(dimensions.trend[0])];
238
+ }
239
+ if (opts.isSmallMultiples) {
240
+ list = [...list, getSmallMultipleLayer(dimensions.smallmultiple[0])];
241
+ }
242
+ if (opts.isReference) {
243
+ list = [...list, ...getReferenceLayers(dimensions.reference)];
244
+ }
245
+ if (opts.type === "HEATMAP_CHART" /* CHART_TYPE.HEATMAP_CHART */ && dimensions.pivots.length) {
246
+ list[0].pivot = Object.assign(Object.assign({}, dimensions.pivots[0]), { property: parsePropertyComplexData(dimensions.pivots[0]) });
247
+ list[0].pivotLabel = _get(opts.stylesSettings, "pivot_axis.custom_label");
248
+ }
249
+ if (opts.type === "TABLE_CHART" /* CHART_TYPE.TABLE_CHART */ ||
250
+ opts.type === "EXPANDABLE_TABLE_CHART" /* CHART_TYPE.EXPANDABLE_TABLE_CHART */ ||
251
+ opts.type === "CROSSTAB_CHART" /* CHART_TYPE.CROSSTAB_CHART */) {
252
+ list = [{ type: opts.type }];
253
+ }
254
+ if (opts.type === "BOXWHISKER_CHART" /* CHART_TYPE.BOXWHISKER_CHART */ && dimensions.pivots.length) {
255
+ list[0].distribution = Object.assign(Object.assign({}, dimensions.pivots[0]), { property: parsePropertyComplexData(dimensions.pivots[0]) });
256
+ }
257
+ if (opts.type === "GEO_CHART_BUBBLE" /* CHART_TYPE.GEO_CHART_BUBBLE */) {
258
+ list[0].mapType = { label: "BUBBLE" };
259
+ }
260
+ if (opts.type === "GEO_CHART_DOT" /* CHART_TYPE.GEO_CHART_DOT */) {
261
+ list[0].mapType = { label: "DOT" };
262
+ list[0].value = Object.assign(Object.assign({}, list[0].category), { property: parsePropertyComplexData(list[0].category) }); // fix https://qrveydev.atlassian.net/browse/CB-689
263
+ }
264
+ if (opts.type === "GEO_CHART_CHOROPLETH" /* CHART_TYPE.GEO_CHART_CHOROPLETH */) {
265
+ list[0].mapType = { label: "CHOROPLETH" };
266
+ }
267
+ /** ******* Tabular/multicolum based charts **********/
268
+ // logic here
269
+ return list;
270
+ }
271
+ function parseAxisLabels(valueColumn, opts) {
272
+ const Y_AXIS_ATTR = "y_axis.custom_label";
273
+ const X_AXIS_ATTR = "x_axis.custom_label";
274
+ const axisLabels = {
275
+ chartValuLabelTemp: _get(opts.stylesSettings, Y_AXIS_ATTR),
276
+ chartLabelTemp: _get(opts.stylesSettings, X_AXIS_ATTR),
277
+ };
278
+ if (opts.type === "COMBO_CHART" /* CHART_TYPE.COMBO_CHART */ ||
279
+ opts.type === "COMBINED_CHART" /* CHART_TYPE.COMBINED_CHART */) {
280
+ const valueStyleObj = opts.isCombolayer
281
+ ? valueColumn.comboLayer
282
+ : opts.stylesSettings;
283
+ if (opts.type === "COMBO_CHART" /* CHART_TYPE.COMBO_CHART */)
284
+ axisLabels.chartValuLabelTemp = _get(valueStyleObj, Y_AXIS_ATTR);
285
+ }
286
+ return axisLabels;
287
+ }
288
+ function parseLayer(category, value, index, opts) {
289
+ const isCombinedMainLayer = opts.type === "COMBINED_CHART" /* CHART_TYPE.COMBINED_CHART */ && index === 0;
290
+ const isCombinedOtherLayer = opts.type === "COMBINED_CHART" /* CHART_TYPE.COMBINED_CHART */ && index > 0;
291
+ const layerType = isCombinedMainLayer
292
+ ? _get(opts, "stylesSettings.combined_type")
293
+ : opts.type === "COMBO_CHART" /* CHART_TYPE.COMBO_CHART */ && opts.isStakedBar
294
+ ? "BAR_CHART" /* CHART_TYPE.BAR_CHART */
295
+ : _get(value, "comboLayer.layer_type");
296
+ const getOptions = () => isCombinedMainLayer
297
+ ? _get(opts, "stylesSettings")
298
+ : _get(value, "comboLayer");
299
+ const visualizationType = opts.type === "COMBINED_CHART" /* CHART_TYPE.COMBINED_CHART */
300
+ ? isCombinedMainLayer
301
+ ? layerType
302
+ : "COMBO_CHART"
303
+ : opts.type;
304
+ return {
305
+ category: Object.assign(Object.assign({}, category), { property: parsePropertyComplexData(category) }),
306
+ value: Object.assign(Object.assign({}, value), { property: parsePropertyComplexData(value), calculation: allowTableCalculation(opts.type) &&
307
+ parseCalculation(value, opts, isCombinedOtherLayer) }),
308
+ aggregate: value ? value.aggregate : { label: "COUNT" },
309
+ type: getOldChartType(opts.type, opts.previousType, layerType),
310
+ visualization: parseStyleSettingByType(visualizationType, opts, getOptions()),
311
+ property: parsePropertyComplexData(category),
312
+ index,
313
+ };
314
+ }
315
+ function parsePropertyComplexData(column) {
316
+ return _get(column, "property.value", null);
317
+ }
318
+ function parseCalculation(column = {}, chart, ignoreReset = false) {
319
+ const reset = getResetCalculation(column, chart, ignoreReset);
320
+ return (column.calculation && {
321
+ aggregate: _get(column, "calculation.value", "SUM"),
322
+ abbreviation: _get(column, "calculation.abbreviation"),
323
+ reset,
324
+ direction: chart.isMulti && !ignoreReset ? "vertical" : null,
325
+ });
326
+ }
327
+ function getResetCalculation(column = {}, chart, ignoreReset = false) {
328
+ if (chart &&
329
+ ((chart.type === "HEATMAP_CHART" /* CHART_TYPE.HEATMAP_CHART */ &&
330
+ chart.dimensions.pivots.length) ||
331
+ chart.isSmallMultiples ||
332
+ (chart.isMulti && !ignoreReset)))
333
+ return 0;
334
+ if (column.calculation &&
335
+ chart &&
336
+ (chart.type === "TABLE_CHART" /* CHART_TYPE.TABLE_CHART */ ||
337
+ chart.type === "EXPANDABLE_TABLE_CHART" /* CHART_TYPE.EXPANDABLE_TABLE_CHART */))
338
+ return chart.dimensions.categories.length > 1 &&
339
+ column.calculation.levels &&
340
+ column.calculation.levels.id !== "TABLE"
341
+ ? column.calculation.levels.colIndex
342
+ : null;
343
+ return null;
344
+ }
345
+ function parseSortOrder(chartType, column = {}) {
346
+ const sortDirection = column.sortOrder || typeof column.sorting !== "string"
347
+ ? _get(column, "sorting.order")
348
+ : column.sorting;
349
+ if (chartType === "CROSSTAB_CHART" /* CHART_TYPE.CROSSTAB_CHART */) {
350
+ // parse from simple string sorting-option to Crosstab (dateGroup) sorting-option object
351
+ const isDategroupSortOpt = typeof sortDirection === "string" && column.dateGroup;
352
+ return Object.assign(Object.assign({}, (typeof column.sorting !== "string" ? column.sorting : {})), { order: isDategroupSortOpt
353
+ ? {
354
+ [column.dateGroup.text]: sortDirection || "asc",
355
+ }
356
+ : sortDirection });
357
+ }
358
+ // parse from Crosstab (dateGroup) sorting-option object to simple string sortion-option
359
+ const isDategroupSortOpt = column.dateGroup && typeof sortDirection !== "string";
360
+ return Object.assign(Object.assign({}, (typeof column.sorting !== "string" ? column.sorting : {})), { order: isDategroupSortOpt
361
+ ? sortDirection && _get(column, `sorting.order.${column.dateGroup.text}`)
362
+ : sortDirection });
363
+ }
364
+ function getValue(category, dimensions, opts) {
365
+ if (opts.type === "BOXWHISKER_CHART" /* CHART_TYPE.BOXWHISKER_CHART */ ||
366
+ opts.type === "MINMAX_CHART" /* CHART_TYPE.MINMAX_CHART */)
367
+ return dimensions.values[0];
368
+ const value = dimensions.values[0] || category;
369
+ return getColumnFromDimension(value, dimensions, opts);
370
+ }
371
+ function getCategory(dimensions, opts) {
372
+ if (opts.type === "BOXWHISKER_CHART" /* CHART_TYPE.BOXWHISKER_CHART */ ||
373
+ opts.type === "MINMAX_CHART" /* CHART_TYPE.MINMAX_CHART */)
374
+ return dimensions.categories[0];
375
+ if ([
376
+ "GEO_CHART_DOT" /* CHART_TYPE.GEO_CHART_DOT */,
377
+ "GEO_CHART_BUBBLE" /* CHART_TYPE.GEO_CHART_BUBBLE */,
378
+ "GEO_CHART_CHOROPLETH" /* CHART_TYPE.GEO_CHART_CHOROPLETH */,
379
+ ].includes(opts.type))
380
+ return dimensions.categories[0];
381
+ const category = _get(dimensions, "categories[0]") || dimensions.values[0];
382
+ if (category && category.calculation)
383
+ delete category.calculation;
384
+ return getColumnFromDimension(category, dimensions, opts);
385
+ }
386
+ function getColumnFromDimension(column, dimensions, { isCombolayer, isMulti }) {
387
+ let _column = column;
388
+ if (_column) {
389
+ return _column;
390
+ }
391
+ if (isCombolayer || isMulti) {
392
+ _column = dimensions.series[0];
393
+ if (!isMulti) {
394
+ dimensions.series.shift();
395
+ }
396
+ }
397
+ return _column;
398
+ }
399
+ function getComboLayers(category, dimensions, opts, prop) {
400
+ const comboLayers = _isEmpty(dimensions[prop]) ? [] : [...dimensions[prop]];
401
+ if (opts.type === "COMBINED_CHART" /* CHART_TYPE.COMBINED_CHART */)
402
+ comboLayers.shift();
403
+ return comboLayers.map((value, index) => {
404
+ return Object.assign(Object.assign({}, parseLayer(category, value, index + 1, opts)), { layer: { label: _get(value, "comboLayer.layer_type") }, label: _get(value, "comboLayer.y_axis.custom_label", value.text), combopt: { label: "COMBO" }, axis: { label: _get(value, "comboLayer.y_axis.position") } });
405
+ });
406
+ }
407
+ function getTrendLayer(trend) {
408
+ return {
409
+ visualization: {
410
+ thickness: trend.thickness,
411
+ style: trend.line_style,
412
+ color: trend.color,
413
+ },
414
+ trendtype: { label: trend.type },
415
+ combopt: { label: "TREND" },
416
+ };
417
+ }
418
+ function getReferenceLayers(references) {
419
+ return references.map((ref) => ({
420
+ index: Date.now(),
421
+ axis: Object.assign(Object.assign({}, ref.axis), { property: parsePropertyComplexData(ref.axis) }),
422
+ aggregate: { label: ref.aggregate },
423
+ labelType: { label: !ref.custom_label ? "VALUE" : "CUSTOM" },
424
+ combopt: { label: "REFERENCE" },
425
+ label: ref.custom_label,
426
+ value: ref.value,
427
+ valuetype: ref.type,
428
+ visualization: {
429
+ color: ref.color,
430
+ fill: ref.fill,
431
+ thickness: ref.thickness,
432
+ style: ref.line_style,
433
+ opacity: ref.opacity,
434
+ },
435
+ }));
436
+ }
437
+ function getSmallMultipleLayer(column) {
438
+ return {
439
+ visualization: {
440
+ displayBorder: column.smallMultiple.borders,
441
+ maxMultiplePanels: column.smallMultiple.limit.value,
442
+ displayMultiplePanels: column.smallMultiple.limit.active,
443
+ labels: {
444
+ axis: column.smallMultiple.labels,
445
+ },
446
+ },
447
+ combopt: { label: "SMALL_MULTIPLES" },
448
+ smallMultiplesColumn: Object.assign(Object.assign({}, column), { property: parsePropertyComplexData(column) }),
449
+ groupValue: Object.assign({}, column.dateGroup), // Group Value is needed in old chart editor and an-panel. Best practice is to use dateGroup from column object
450
+ };
451
+ }
452
+ export function getTrendsChartsConfig(trendInfo) {
453
+ trendInfo.trendByColumn.sorting = {
454
+ order: trendInfo.trendSort === "Asc" ? "asc" : "desc",
455
+ };
456
+ const opts = {
457
+ type: trendInfo.charType,
458
+ dimensions: {
459
+ categories: [trendInfo.trendByColumn],
460
+ pivots: [],
461
+ values: [trendInfo.column],
462
+ },
463
+ };
464
+ return getTableConfig(opts, true, true);
465
+ }
466
+ function getTableConfig(opts, inPreviewMode, isTrendChart = false) {
467
+ const fields = {};
468
+ const params = [
469
+ { objKey: "categories", fieldKey: "groupsList", type: "group" },
470
+ { objKey: "values", fieldKey: "columnsList", type: "column" },
471
+ ];
472
+ let count = 0;
473
+ params.forEach((param) => {
474
+ if (opts.dimensions[param.objKey].length) {
475
+ fields[param.fieldKey] = opts.dimensions[param.objKey].map((item) => {
476
+ const column = {
477
+ data: Object.assign(Object.assign({}, item), { property: parsePropertyComplexData(item) }),
478
+ index: new Date().getTime() + randomKey(),
479
+ type: param.type,
480
+ label: item.label || item.text,
481
+ visualization: item.visualization || "Values",
482
+ aggregate: setTotalAggregateInPreview(item.totalAggregate, inPreviewMode),
483
+ calculation: opts.dimensions.categories.length
484
+ ? parseCalculation(item, opts)
485
+ : null,
486
+ dataField: columnKey(item.id, item.type, item.property, count + 1),
487
+ qrveyid: item.qrveyid,
488
+ dateGroup: item.dateGroup,
489
+ sorting: parseSortOrder(opts.type, item),
490
+ sortIndex: item.sortIndex,
491
+ width: item.width,
492
+ };
493
+ if (item.aggregate)
494
+ column.groupAggregate = Object.assign({}, item.aggregate);
495
+ count += 1;
496
+ return column;
497
+ });
498
+ }
499
+ });
500
+ if (isTrendChart)
501
+ return { fields };
502
+ const isGrouped = fields.groupsList && !!fields.groupsList.length;
503
+ return {
504
+ fields,
505
+ isGrouped,
506
+ conditions: opts.conditions,
507
+ visualization: parseStyleSettingByType("TABLE_CHART" /* CHART_TYPE.TABLE_CHART */, Object.assign(Object.assign({}, opts), { isGrouped })),
508
+ totals: opts.dimensions.tableTotals,
509
+ isMultipleSorted: opts.isMultipleSorted,
510
+ trendsChart: opts.trendsCharts || [],
511
+ };
512
+ }
513
+ function getCrosstabConfig(opts) {
514
+ const fields = {};
515
+ const params = [
516
+ { objKey: "pivots", fieldKey: "columnsList", type: "column" },
517
+ { objKey: "categories", fieldKey: "rowsList", type: "row" },
518
+ { objKey: "values", fieldKey: "valuesList", type: "data" },
519
+ ];
520
+ params.forEach((param) => {
521
+ const dimension = param.objKey === "values" && !opts.dimensions[param.objKey].length
522
+ ? [opts.dimensions.categories[0] || opts.dimensions.pivots[0]]
523
+ : opts.dimensions[param.objKey];
524
+ fields[param.fieldKey] = dimension.map((item) => {
525
+ const column = {
526
+ data: Object.assign(Object.assign({}, item), { property: parsePropertyComplexData(item) }),
527
+ index: new Date().getTime() + randomKey(),
528
+ type: param.type,
529
+ qrveyid: item.qrveyid,
530
+ label: item.label || item.text,
531
+ sorting: parseSortOrder(opts.type, item),
532
+ };
533
+ if (item.dateGroup)
534
+ column.dateGroup = item.dateGroup;
535
+ if (item.aggregate && param.type === "data")
536
+ column.aggregate = Object.assign({}, item.aggregate);
537
+ return column;
538
+ });
539
+ });
540
+ const rowGrandTotals = [
541
+ "SHOW" /* CROSSTAB_TOTALS_OPTIONS.BOTH */,
542
+ "ROWSONLY" /* CROSSTAB_TOTALS_OPTIONS.ROWS */,
543
+ ].includes(opts.globalSettings.crosstab_totals.option);
544
+ const columnGrandTotals = [
545
+ "SHOW" /* CROSSTAB_TOTALS_OPTIONS.BOTH */,
546
+ "COLUMNSONLY" /* CROSSTAB_TOTALS_OPTIONS.COLUMNS */,
547
+ ].includes(opts.globalSettings.crosstab_totals.option);
548
+ return {
549
+ fields,
550
+ visualization: parseStyleSettingByType("CROSSTAB_CHART" /* CHART_TYPE.CROSSTAB_CHART */, opts),
551
+ config: {
552
+ showBorders: false,
553
+ width: 442,
554
+ height: 361,
555
+ fieldChooser: { enabled: false },
556
+ fieldPanel: {
557
+ visible: opts.globalSettings.crosstab_labels.value,
558
+ showFilterFields: false,
559
+ allowFieldDragging: false,
560
+ showColumnFields: true,
561
+ showRowFields: true,
562
+ showDataFields: false,
563
+ texts: { columnFieldArea: "", rowFieldArea: "" },
564
+ },
565
+ rowHeaderLayout: "tree",
566
+ showRowGrandTotals: opts.globalSettings.crosstab_totals.value && rowGrandTotals,
567
+ showColumnGrandTotals: opts.globalSettings.crosstab_totals.value && columnGrandTotals,
568
+ showRowTotals: opts.globalSettings.crosstab_subtotals,
569
+ showColumnTotals: opts.globalSettings.crosstab_subtotals,
570
+ allowSorting: opts.globalSettings.crosstab_labels.options.sorting,
571
+ allowSortingBySummary: false,
572
+ },
573
+ };
574
+ }
575
+ function getGeoMapConfig(opts) {
576
+ const fields = {};
577
+ const params = [
578
+ { objKey: "categories", fieldKey: "categories", type: "column" },
579
+ { objKey: "values", fieldKey: "values", type: "column" },
580
+ ];
581
+ params.forEach((param) => {
582
+ if (opts.dimensions[param.objKey].length) {
583
+ fields[param.fieldKey] = opts.dimensions[param.objKey].map((item) => {
584
+ const column = {
585
+ data: Object.assign(Object.assign({}, item), { property: parsePropertyComplexData(item) }),
586
+ index: new Date().getTime() + randomKey(),
587
+ type: param.type,
588
+ qrveyid: item.qrveyid,
589
+ };
590
+ if (item.aggregate && param.type === "data")
591
+ column.aggregate = Object.assign({}, item.aggregate);
592
+ return column;
593
+ });
594
+ }
595
+ });
596
+ return {
597
+ fields,
598
+ };
599
+ }
600
+ function isValidData(opts) {
601
+ let chartDimensions = [
602
+ "categories" /* CHART_DIMENSION.CATEGORIES */,
603
+ "values" /* CHART_DIMENSION.VALUES */,
604
+ ];
605
+ if (opts.isCombo) {
606
+ chartDimensions = [...chartDimensions, "series" /* CHART_DIMENSION.SERIES */];
607
+ }
608
+ if ([
609
+ "GEO_CHART_DOT" /* CHART_TYPE.GEO_CHART_DOT */,
610
+ "GEO_CHART_BUBBLE" /* CHART_TYPE.GEO_CHART_BUBBLE */,
611
+ "GEO_CHART_CHOROPLETH" /* CHART_TYPE.GEO_CHART_CHOROPLETH */,
612
+ ].includes(opts.type)) {
613
+ return !_isEmpty(opts.dimensions["categories" /* CHART_DIMENSION.CATEGORIES */]);
614
+ }
615
+ if (opts.type === "CROSSTAB_CHART" /* CHART_TYPE.CROSSTAB_CHART */)
616
+ chartDimensions = [...chartDimensions, "pivots" /* CHART_DIMENSION.PIVOT */];
617
+ return chartDimensions.some((dimension) => !_isEmpty(opts.dimensions[dimension]));
618
+ }
619
+ function getOldChartType(type, prevType, layerType) {
620
+ let chartType = type;
621
+ if (chartType === "COMBO_CHART" /* CHART_TYPE.COMBO_CHART */ ||
622
+ chartType === "COMBINED_CHART" /* CHART_TYPE.COMBINED_CHART */) {
623
+ chartType =
624
+ layerType || (isChartBasic(prevType) ? prevType : "BAR_CHART" /* CHART_TYPE.BAR_CHART */);
625
+ }
626
+ if (chartType === "BAR_CHART_MS" /* CHART_TYPE.BAR_CHART_MS */) {
627
+ chartType = "BAR_CHART" /* CHART_TYPE.BAR_CHART */;
628
+ }
629
+ if (chartType === "LINE_CHART_MS" /* CHART_TYPE.LINE_CHART_MS */) {
630
+ chartType = "LINE_CHART" /* CHART_TYPE.LINE_CHART */;
631
+ }
632
+ if (chartType === "SYMBOL_CHART_MS" /* CHART_TYPE.SYMBOL_CHART_MS */) {
633
+ chartType = "SYMBOL_CHART" /* CHART_TYPE.SYMBOL_CHART */;
634
+ }
635
+ if (isChartMap(type)) {
636
+ chartType = "GEO_CHART" /* CHART_TYPE.GEO_CHART */;
637
+ }
638
+ return chartType;
639
+ }
640
+ function getGlobalSettings(_chartType, opts) {
641
+ return parseGlobalSettingByType(_chartType, opts);
642
+ }
643
+ function setTotalAggregateInPreview(totalAggregate, _inPreviewMode) {
644
+ if (!totalAggregate)
645
+ return;
646
+ return totalAggregate;
647
+ }