@gooddata/sdk-code-convertors 11.28.0-alpha.1
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.
- package/LICENSE +7 -0
- package/README.md +42 -0
- package/esm/configs/areaChart.d.ts +113 -0
- package/esm/configs/areaChart.d.ts.map +1 -0
- package/esm/configs/areaChart.js +232 -0
- package/esm/configs/areaChart.js.map +1 -0
- package/esm/configs/barChart.d.ts +101 -0
- package/esm/configs/barChart.d.ts.map +1 -0
- package/esm/configs/barChart.js +210 -0
- package/esm/configs/barChart.js.map +1 -0
- package/esm/configs/bubbleChart.d.ts +93 -0
- package/esm/configs/bubbleChart.d.ts.map +1 -0
- package/esm/configs/bubbleChart.js +186 -0
- package/esm/configs/bubbleChart.js.map +1 -0
- package/esm/configs/bulletChart.d.ts +87 -0
- package/esm/configs/bulletChart.d.ts.map +1 -0
- package/esm/configs/bulletChart.js +174 -0
- package/esm/configs/bulletChart.js.map +1 -0
- package/esm/configs/columnChart.d.ts +101 -0
- package/esm/configs/columnChart.d.ts.map +1 -0
- package/esm/configs/columnChart.js +210 -0
- package/esm/configs/columnChart.js.map +1 -0
- package/esm/configs/comboChart.d.ts +155 -0
- package/esm/configs/comboChart.d.ts.map +1 -0
- package/esm/configs/comboChart.js +355 -0
- package/esm/configs/comboChart.js.map +1 -0
- package/esm/configs/dependencyWheelChart.d.ts +37 -0
- package/esm/configs/dependencyWheelChart.d.ts.map +1 -0
- package/esm/configs/dependencyWheelChart.js +81 -0
- package/esm/configs/dependencyWheelChart.js.map +1 -0
- package/esm/configs/donutChart.d.ts +47 -0
- package/esm/configs/donutChart.d.ts.map +1 -0
- package/esm/configs/donutChart.js +96 -0
- package/esm/configs/donutChart.js.map +1 -0
- package/esm/configs/funnelChart.d.ts +47 -0
- package/esm/configs/funnelChart.d.ts.map +1 -0
- package/esm/configs/funnelChart.js +96 -0
- package/esm/configs/funnelChart.js.map +1 -0
- package/esm/configs/geoAreaChart.d.ts +62 -0
- package/esm/configs/geoAreaChart.d.ts.map +1 -0
- package/esm/configs/geoAreaChart.js +123 -0
- package/esm/configs/geoAreaChart.js.map +1 -0
- package/esm/configs/geoChart.d.ts +49 -0
- package/esm/configs/geoChart.d.ts.map +1 -0
- package/esm/configs/geoChart.js +157 -0
- package/esm/configs/geoChart.js.map +1 -0
- package/esm/configs/headlineChart.d.ts +89 -0
- package/esm/configs/headlineChart.d.ts.map +1 -0
- package/esm/configs/headlineChart.js +124 -0
- package/esm/configs/headlineChart.js.map +1 -0
- package/esm/configs/heatmapChart.d.ts +75 -0
- package/esm/configs/heatmapChart.d.ts.map +1 -0
- package/esm/configs/heatmapChart.js +158 -0
- package/esm/configs/heatmapChart.js.map +1 -0
- package/esm/configs/lineChart.d.ts +135 -0
- package/esm/configs/lineChart.d.ts.map +1 -0
- package/esm/configs/lineChart.js +294 -0
- package/esm/configs/lineChart.js.map +1 -0
- package/esm/configs/pieChart.d.ts +47 -0
- package/esm/configs/pieChart.d.ts.map +1 -0
- package/esm/configs/pieChart.js +96 -0
- package/esm/configs/pieChart.js.map +1 -0
- package/esm/configs/pyramidChart.d.ts +47 -0
- package/esm/configs/pyramidChart.d.ts.map +1 -0
- package/esm/configs/pyramidChart.js +96 -0
- package/esm/configs/pyramidChart.js.map +1 -0
- package/esm/configs/repeaterChart.d.ts +36 -0
- package/esm/configs/repeaterChart.d.ts.map +1 -0
- package/esm/configs/repeaterChart.js +104 -0
- package/esm/configs/repeaterChart.js.map +1 -0
- package/esm/configs/sankeyChart.d.ts +39 -0
- package/esm/configs/sankeyChart.d.ts.map +1 -0
- package/esm/configs/sankeyChart.js +84 -0
- package/esm/configs/sankeyChart.js.map +1 -0
- package/esm/configs/scatterChart.d.ts +95 -0
- package/esm/configs/scatterChart.d.ts.map +1 -0
- package/esm/configs/scatterChart.js +198 -0
- package/esm/configs/scatterChart.js.map +1 -0
- package/esm/configs/table.d.ts +61 -0
- package/esm/configs/table.d.ts.map +1 -0
- package/esm/configs/table.js +169 -0
- package/esm/configs/table.js.map +1 -0
- package/esm/configs/treemapChart.d.ts +47 -0
- package/esm/configs/treemapChart.d.ts.map +1 -0
- package/esm/configs/treemapChart.js +96 -0
- package/esm/configs/treemapChart.js.map +1 -0
- package/esm/configs/types.d.ts +93 -0
- package/esm/configs/types.d.ts.map +1 -0
- package/esm/configs/types.js +3 -0
- package/esm/configs/types.js.map +1 -0
- package/esm/configs/utils.d.ts +12 -0
- package/esm/configs/utils.d.ts.map +1 -0
- package/esm/configs/utils.js +76 -0
- package/esm/configs/utils.js.map +1 -0
- package/esm/configs/waterfallChart.d.ts +109 -0
- package/esm/configs/waterfallChart.d.ts.map +1 -0
- package/esm/configs/waterfallChart.js +214 -0
- package/esm/configs/waterfallChart.js.map +1 -0
- package/esm/conts.d.ts +9 -0
- package/esm/conts.d.ts.map +1 -0
- package/esm/conts.js +41 -0
- package/esm/conts.js.map +1 -0
- package/esm/execution/buildAfmExecution.d.ts +5 -0
- package/esm/execution/buildAfmExecution.d.ts.map +1 -0
- package/esm/execution/buildAfmExecution.js +374 -0
- package/esm/execution/buildAfmExecution.js.map +1 -0
- package/esm/from/declarativeAttributeHierarchyToYaml.d.ts +12 -0
- package/esm/from/declarativeAttributeHierarchyToYaml.d.ts.map +1 -0
- package/esm/from/declarativeAttributeHierarchyToYaml.js +26 -0
- package/esm/from/declarativeAttributeHierarchyToYaml.js.map +1 -0
- package/esm/from/declarativeDashboardToYaml.d.ts +59 -0
- package/esm/from/declarativeDashboardToYaml.d.ts.map +1 -0
- package/esm/from/declarativeDashboardToYaml.js +771 -0
- package/esm/from/declarativeDashboardToYaml.js.map +1 -0
- package/esm/from/declarativeDatasetToYaml.d.ts +9 -0
- package/esm/from/declarativeDatasetToYaml.d.ts.map +1 -0
- package/esm/from/declarativeDatasetToYaml.js +239 -0
- package/esm/from/declarativeDatasetToYaml.js.map +1 -0
- package/esm/from/declarativeDateInstanceToYaml.d.ts +8 -0
- package/esm/from/declarativeDateInstanceToYaml.d.ts.map +1 -0
- package/esm/from/declarativeDateInstanceToYaml.js +30 -0
- package/esm/from/declarativeDateInstanceToYaml.js.map +1 -0
- package/esm/from/declarativeMetricToYaml.d.ts +8 -0
- package/esm/from/declarativeMetricToYaml.d.ts.map +1 -0
- package/esm/from/declarativeMetricToYaml.js +34 -0
- package/esm/from/declarativeMetricToYaml.js.map +1 -0
- package/esm/from/declarativePluginToYaml.d.ts +10 -0
- package/esm/from/declarativePluginToYaml.d.ts.map +1 -0
- package/esm/from/declarativePluginToYaml.js +26 -0
- package/esm/from/declarativePluginToYaml.js.map +1 -0
- package/esm/from/declarativeVisualisationToYaml.d.ts +64 -0
- package/esm/from/declarativeVisualisationToYaml.d.ts.map +1 -0
- package/esm/from/declarativeVisualisationToYaml.js +1513 -0
- package/esm/from/declarativeVisualisationToYaml.js.map +1 -0
- package/esm/index.d.ts +18 -0
- package/esm/index.d.ts.map +1 -0
- package/esm/index.js +22 -0
- package/esm/index.js.map +1 -0
- package/esm/schemas/types.d.ts +32 -0
- package/esm/schemas/types.d.ts.map +1 -0
- package/esm/schemas/types.js +3 -0
- package/esm/schemas/types.js.map +1 -0
- package/esm/schemas/v1/metadata.d.ts +7277 -0
- package/esm/schemas/v1/metadata.d.ts.map +1 -0
- package/esm/schemas/v1/metadata.js +3 -0
- package/esm/schemas/v1/metadata.js.map +1 -0
- package/esm/sdk-code-convertors.d.ts +7861 -0
- package/esm/to/yamlAttributeHierarchyToDeclarative.d.ts +5 -0
- package/esm/to/yamlAttributeHierarchyToDeclarative.d.ts.map +1 -0
- package/esm/to/yamlAttributeHierarchyToDeclarative.js +16 -0
- package/esm/to/yamlAttributeHierarchyToDeclarative.js.map +1 -0
- package/esm/to/yamlDashboardToDeclarative.d.ts +29 -0
- package/esm/to/yamlDashboardToDeclarative.d.ts.map +1 -0
- package/esm/to/yamlDashboardToDeclarative.js +732 -0
- package/esm/to/yamlDashboardToDeclarative.js.map +1 -0
- package/esm/to/yamlDatasetToDeclarative.d.ts +41 -0
- package/esm/to/yamlDatasetToDeclarative.d.ts.map +1 -0
- package/esm/to/yamlDatasetToDeclarative.js +346 -0
- package/esm/to/yamlDatasetToDeclarative.js.map +1 -0
- package/esm/to/yamlDateDatasetToDeclarative.d.ts +5 -0
- package/esm/to/yamlDateDatasetToDeclarative.d.ts.map +1 -0
- package/esm/to/yamlDateDatasetToDeclarative.js +21 -0
- package/esm/to/yamlDateDatasetToDeclarative.js.map +1 -0
- package/esm/to/yamlMetricToDeclarative.d.ts +5 -0
- package/esm/to/yamlMetricToDeclarative.d.ts.map +1 -0
- package/esm/to/yamlMetricToDeclarative.js +24 -0
- package/esm/to/yamlMetricToDeclarative.js.map +1 -0
- package/esm/to/yamlPluginToDeclarative.d.ts +5 -0
- package/esm/to/yamlPluginToDeclarative.d.ts.map +1 -0
- package/esm/to/yamlPluginToDeclarative.js +17 -0
- package/esm/to/yamlPluginToDeclarative.js.map +1 -0
- package/esm/to/yamlVisualisationToDeclarative.d.ts +31 -0
- package/esm/to/yamlVisualisationToDeclarative.d.ts.map +1 -0
- package/esm/to/yamlVisualisationToDeclarative.js +1048 -0
- package/esm/to/yamlVisualisationToDeclarative.js.map +1 -0
- package/esm/tsdoc-metadata.json +11 -0
- package/esm/types.d.ts +66 -0
- package/esm/types.d.ts.map +1 -0
- package/esm/types.js +22 -0
- package/esm/types.js.map +1 -0
- package/esm/utils/configUtils.d.ts +20 -0
- package/esm/utils/configUtils.d.ts.map +1 -0
- package/esm/utils/configUtils.js +312 -0
- package/esm/utils/configUtils.js.map +1 -0
- package/esm/utils/convertBucketToTitle.d.ts +116 -0
- package/esm/utils/convertBucketToTitle.d.ts.map +1 -0
- package/esm/utils/convertBucketToTitle.js +370 -0
- package/esm/utils/convertBucketToTitle.js.map +1 -0
- package/esm/utils/customUrl.d.ts +4 -0
- package/esm/utils/customUrl.d.ts.map +1 -0
- package/esm/utils/customUrl.js +31 -0
- package/esm/utils/customUrl.js.map +1 -0
- package/esm/utils/dateUtils.d.ts +5 -0
- package/esm/utils/dateUtils.d.ts.map +1 -0
- package/esm/utils/dateUtils.js +43 -0
- package/esm/utils/dateUtils.js.map +1 -0
- package/esm/utils/errors.d.ts +35 -0
- package/esm/utils/errors.d.ts.map +1 -0
- package/esm/utils/errors.js +65 -0
- package/esm/utils/errors.js.map +1 -0
- package/esm/utils/filterUtils.d.ts +3 -0
- package/esm/utils/filterUtils.d.ts.map +1 -0
- package/esm/utils/filterUtils.js +26 -0
- package/esm/utils/filterUtils.js.map +1 -0
- package/esm/utils/granularityUtils.d.ts +17 -0
- package/esm/utils/granularityUtils.d.ts.map +1 -0
- package/esm/utils/granularityUtils.js +1434 -0
- package/esm/utils/granularityUtils.js.map +1 -0
- package/esm/utils/locationUtils.d.ts +11 -0
- package/esm/utils/locationUtils.d.ts.map +1 -0
- package/esm/utils/locationUtils.js +75 -0
- package/esm/utils/locationUtils.js.map +1 -0
- package/esm/utils/nameUtils.d.ts +7 -0
- package/esm/utils/nameUtils.d.ts.map +1 -0
- package/esm/utils/nameUtils.js +37 -0
- package/esm/utils/nameUtils.js.map +1 -0
- package/esm/utils/permissionUtils.d.ts +29 -0
- package/esm/utils/permissionUtils.d.ts.map +1 -0
- package/esm/utils/permissionUtils.js +82 -0
- package/esm/utils/permissionUtils.js.map +1 -0
- package/esm/utils/sharedUtils.d.ts +21 -0
- package/esm/utils/sharedUtils.d.ts.map +1 -0
- package/esm/utils/sharedUtils.js +63 -0
- package/esm/utils/sharedUtils.js.map +1 -0
- package/esm/utils/texts.d.ts +8 -0
- package/esm/utils/texts.d.ts.map +1 -0
- package/esm/utils/texts.js +47 -0
- package/esm/utils/texts.js.map +1 -0
- package/esm/utils/typeGuards.d.ts +51 -0
- package/esm/utils/typeGuards.d.ts.map +1 -0
- package/esm/utils/typeGuards.js +286 -0
- package/esm/utils/typeGuards.js.map +1 -0
- package/esm/utils/yamlUtils.d.ts +28 -0
- package/esm/utils/yamlUtils.d.ts.map +1 -0
- package/esm/utils/yamlUtils.js +163 -0
- package/esm/utils/yamlUtils.js.map +1 -0
- package/package.json +74 -0
|
@@ -0,0 +1,1048 @@
|
|
|
1
|
+
// (C) 2023-2026 GoodData Corporation
|
|
2
|
+
import { areaChart } from "../configs/areaChart.js";
|
|
3
|
+
import { barChart } from "../configs/barChart.js";
|
|
4
|
+
import { bubbleChart } from "../configs/bubbleChart.js";
|
|
5
|
+
import { bulletChart } from "../configs/bulletChart.js";
|
|
6
|
+
import { columnChart } from "../configs/columnChart.js";
|
|
7
|
+
import { comboChart } from "../configs/comboChart.js";
|
|
8
|
+
import { dependencyWheelChart } from "../configs/dependencyWheelChart.js";
|
|
9
|
+
import { donutChart } from "../configs/donutChart.js";
|
|
10
|
+
import { funnelChart } from "../configs/funnelChart.js";
|
|
11
|
+
import { geoAreaChart } from "../configs/geoAreaChart.js";
|
|
12
|
+
import { geoChart } from "../configs/geoChart.js";
|
|
13
|
+
import { headlineChart } from "../configs/headlineChart.js";
|
|
14
|
+
import { heatmapChart } from "../configs/heatmapChart.js";
|
|
15
|
+
import { lineChart } from "../configs/lineChart.js";
|
|
16
|
+
import { pieChart } from "../configs/pieChart.js";
|
|
17
|
+
import { pyramidChart } from "../configs/pyramidChart.js";
|
|
18
|
+
import { repeaterChart } from "../configs/repeaterChart.js";
|
|
19
|
+
import { sankeyChart } from "../configs/sankeyChart.js";
|
|
20
|
+
import { scatterChart } from "../configs/scatterChart.js";
|
|
21
|
+
import { table } from "../configs/table.js";
|
|
22
|
+
import { treemapChart } from "../configs/treemapChart.js";
|
|
23
|
+
import { waterfallChart } from "../configs/waterfallChart.js";
|
|
24
|
+
import { BucketsType } from "../types.js";
|
|
25
|
+
import { convertBucketToTitle } from "../utils/convertBucketToTitle.js";
|
|
26
|
+
import { mapDateAttribute, mapDateDataset } from "../utils/dateUtils.js";
|
|
27
|
+
import { CoreErrorCode, newError } from "../utils/errors.js";
|
|
28
|
+
import { parseDateValues } from "../utils/filterUtils.js";
|
|
29
|
+
import { convertGranularity, convertGranularityToId } from "../utils/granularityUtils.js";
|
|
30
|
+
import { mapLocationLabel } from "../utils/locationUtils.js";
|
|
31
|
+
import { assertUnreachable, convertIdToTitle, getFullBucket, getFullField } from "../utils/sharedUtils.js";
|
|
32
|
+
import { isAbsoluteDateFilter, isArithmeticMetricField, isAttributeField, isAttributeSort, isCalculatedMetricField, isInlineMetricField, isMetricAllValueFilter, isMetricComparisonValueFilter, isMetricField, isMetricRangeValueFilter, isMetricSort, isMetricValueFilterWithConditions, isNegativeAttributeFilter, isPoPMetricField, isPositiveAttributeFilter, isPreviousPeriodField, isRankingFilter, isRelativeDateFilter, parseReferenceObject, } from "../utils/typeGuards.js";
|
|
33
|
+
import { createIdentifier, createLocalIdentifier } from "../utils/yamlUtils.js";
|
|
34
|
+
/** @public */
|
|
35
|
+
export function yamlVisualisationToDeclarative(entities, input) {
|
|
36
|
+
const { buckets, sorts, filters, positions, attributeFilterConfigs } = yamlReportToDeclarative(entities, input);
|
|
37
|
+
const properties = yamlConfigToDeclarative(input, positions);
|
|
38
|
+
const layers = yamlLayersToDeclarative(entities, input, positions);
|
|
39
|
+
const content = {
|
|
40
|
+
version: "2",
|
|
41
|
+
visualizationUrl: yamlVisTypeToDeclarative(input),
|
|
42
|
+
buckets,
|
|
43
|
+
sorts,
|
|
44
|
+
filters,
|
|
45
|
+
properties,
|
|
46
|
+
...(attributeFilterConfigs ? { attributeFilterConfigs: attributeFilterConfigs } : {}),
|
|
47
|
+
...(layers.length ? { layers } : {}),
|
|
48
|
+
};
|
|
49
|
+
const output = {
|
|
50
|
+
id: input.id,
|
|
51
|
+
title: input.title ?? convertIdToTitle(input.id),
|
|
52
|
+
tags: input.tags ?? [],
|
|
53
|
+
description: input.description ?? "",
|
|
54
|
+
content,
|
|
55
|
+
};
|
|
56
|
+
if (input.is_hidden !== undefined) {
|
|
57
|
+
output.isHidden = input.is_hidden;
|
|
58
|
+
}
|
|
59
|
+
if (input.show_in_ai_results !== undefined) {
|
|
60
|
+
output.isHidden = input.show_in_ai_results === false;
|
|
61
|
+
}
|
|
62
|
+
return output;
|
|
63
|
+
}
|
|
64
|
+
function yamlVisTypeToDeclarative(def) {
|
|
65
|
+
switch (def.type) {
|
|
66
|
+
case "table":
|
|
67
|
+
return "local:table";
|
|
68
|
+
case "bar_chart":
|
|
69
|
+
return "local:bar";
|
|
70
|
+
case "column_chart":
|
|
71
|
+
return "local:column";
|
|
72
|
+
case "line_chart":
|
|
73
|
+
return "local:line";
|
|
74
|
+
case "area_chart":
|
|
75
|
+
return "local:area";
|
|
76
|
+
case "scatter_chart":
|
|
77
|
+
return "local:scatter";
|
|
78
|
+
case "bubble_chart":
|
|
79
|
+
return "local:bubble";
|
|
80
|
+
case "pie_chart":
|
|
81
|
+
return "local:pie";
|
|
82
|
+
case "donut_chart":
|
|
83
|
+
return "local:donut";
|
|
84
|
+
case "treemap_chart":
|
|
85
|
+
return "local:treemap";
|
|
86
|
+
case "pyramid_chart":
|
|
87
|
+
return "local:pyramid";
|
|
88
|
+
case "funnel_chart":
|
|
89
|
+
return "local:funnel";
|
|
90
|
+
case "heatmap_chart":
|
|
91
|
+
return "local:heatmap";
|
|
92
|
+
case "bullet_chart":
|
|
93
|
+
return "local:bullet";
|
|
94
|
+
case "waterfall_chart":
|
|
95
|
+
return "local:waterfall";
|
|
96
|
+
case "dependency_wheel_chart":
|
|
97
|
+
return "local:dependencywheel";
|
|
98
|
+
case "sankey_chart":
|
|
99
|
+
return "local:sankey";
|
|
100
|
+
case "headline_chart":
|
|
101
|
+
return "local:headline";
|
|
102
|
+
case "combo_chart":
|
|
103
|
+
return "local:combo2";
|
|
104
|
+
case "geo_chart":
|
|
105
|
+
return "local:pushpin";
|
|
106
|
+
case "geo_area_chart":
|
|
107
|
+
return "local:choropleth";
|
|
108
|
+
case "repeater_chart":
|
|
109
|
+
return "local:repeater";
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
function yamlConfigToDeclarative(def, positions) {
|
|
113
|
+
let controls;
|
|
114
|
+
let inlineVisualizations;
|
|
115
|
+
switch (def.type) {
|
|
116
|
+
case "table":
|
|
117
|
+
controls = table.save(def.query?.fields, def.config);
|
|
118
|
+
break;
|
|
119
|
+
case "bar_chart":
|
|
120
|
+
controls = barChart.save(def.query?.fields, def.config);
|
|
121
|
+
break;
|
|
122
|
+
case "column_chart":
|
|
123
|
+
controls = columnChart.save(def.query?.fields, def.config);
|
|
124
|
+
break;
|
|
125
|
+
case "line_chart":
|
|
126
|
+
controls = lineChart.save(def.query?.fields, def.config);
|
|
127
|
+
break;
|
|
128
|
+
case "area_chart":
|
|
129
|
+
controls = areaChart.save(def.query?.fields, def.config);
|
|
130
|
+
break;
|
|
131
|
+
case "scatter_chart":
|
|
132
|
+
controls = scatterChart.save(def.query?.fields, def.config);
|
|
133
|
+
break;
|
|
134
|
+
case "bubble_chart":
|
|
135
|
+
controls = bubbleChart.save(def.query?.fields, def.config);
|
|
136
|
+
break;
|
|
137
|
+
case "pie_chart":
|
|
138
|
+
controls = pieChart.save(def.query?.fields, def.config);
|
|
139
|
+
break;
|
|
140
|
+
case "donut_chart":
|
|
141
|
+
controls = donutChart.save(def.query?.fields, def.config);
|
|
142
|
+
break;
|
|
143
|
+
case "treemap_chart":
|
|
144
|
+
controls = treemapChart.save(def.query?.fields, def.config);
|
|
145
|
+
break;
|
|
146
|
+
case "pyramid_chart":
|
|
147
|
+
controls = pyramidChart.save(def.query?.fields, def.config);
|
|
148
|
+
break;
|
|
149
|
+
case "funnel_chart":
|
|
150
|
+
controls = funnelChart.save(def.query?.fields, def.config);
|
|
151
|
+
break;
|
|
152
|
+
case "heatmap_chart":
|
|
153
|
+
controls = heatmapChart.save(def.query?.fields, def.config);
|
|
154
|
+
break;
|
|
155
|
+
case "bullet_chart":
|
|
156
|
+
controls = bulletChart.save(def.query?.fields, def.config);
|
|
157
|
+
break;
|
|
158
|
+
case "waterfall_chart":
|
|
159
|
+
controls = waterfallChart.save(def.query?.fields, def.config);
|
|
160
|
+
break;
|
|
161
|
+
case "dependency_wheel_chart":
|
|
162
|
+
controls = dependencyWheelChart.save(def.query?.fields, def.config);
|
|
163
|
+
break;
|
|
164
|
+
case "sankey_chart":
|
|
165
|
+
controls = sankeyChart.save(def.query?.fields, def.config);
|
|
166
|
+
break;
|
|
167
|
+
case "headline_chart":
|
|
168
|
+
controls = headlineChart.save(def.query?.fields, def.config);
|
|
169
|
+
break;
|
|
170
|
+
case "combo_chart":
|
|
171
|
+
controls = comboChart.save(def.query?.fields, def.config, def.metrics);
|
|
172
|
+
break;
|
|
173
|
+
case "geo_chart":
|
|
174
|
+
controls = geoChart.save(def.query?.fields, def.config, positions);
|
|
175
|
+
break;
|
|
176
|
+
case "geo_area_chart":
|
|
177
|
+
controls = geoAreaChart.save(def.query?.fields, def.config, positions);
|
|
178
|
+
break;
|
|
179
|
+
case "repeater_chart":
|
|
180
|
+
controls = repeaterChart.save(def.query?.fields, def.config);
|
|
181
|
+
inlineVisualizations = repeaterChart.saveInlineVisualizations([
|
|
182
|
+
...(def.metrics ?? []),
|
|
183
|
+
...(def.columns ?? []),
|
|
184
|
+
]);
|
|
185
|
+
break;
|
|
186
|
+
}
|
|
187
|
+
return {
|
|
188
|
+
...(controls ? { controls } : {}),
|
|
189
|
+
...(inlineVisualizations ? { inlineVisualizations } : {}),
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
//REPORT
|
|
193
|
+
export function yamlReportToDeclarative(entities, input) {
|
|
194
|
+
const query = input.query;
|
|
195
|
+
const positions = [];
|
|
196
|
+
let attrFilterConfig = {};
|
|
197
|
+
const visBuckets = yamlBucketsToDeclarative(input);
|
|
198
|
+
const buckets = visBuckets
|
|
199
|
+
.map((bucket) => {
|
|
200
|
+
const { localIdentifier } = bucket;
|
|
201
|
+
const totals = [];
|
|
202
|
+
//do not include empty buckets
|
|
203
|
+
if (bucket.items.length === 0) {
|
|
204
|
+
return null;
|
|
205
|
+
}
|
|
206
|
+
const items = bucket.items
|
|
207
|
+
.map((item) => {
|
|
208
|
+
const { bucketItem, bucketTotals, longitude, latitude, filterConfig } = yamlBucketItemToDeclarative(entities, query, item, query.fields || {}, localIdentifier);
|
|
209
|
+
attrFilterConfig = {
|
|
210
|
+
...attrFilterConfig,
|
|
211
|
+
...filterConfig,
|
|
212
|
+
};
|
|
213
|
+
totals.push(...bucketTotals);
|
|
214
|
+
if (latitude && longitude) {
|
|
215
|
+
positions.push({ latitude, longitude });
|
|
216
|
+
}
|
|
217
|
+
return bucketItem;
|
|
218
|
+
})
|
|
219
|
+
.filter(Boolean);
|
|
220
|
+
return {
|
|
221
|
+
localIdentifier,
|
|
222
|
+
items,
|
|
223
|
+
...(totals.length ? { totals } : {}),
|
|
224
|
+
};
|
|
225
|
+
})
|
|
226
|
+
.filter(Boolean);
|
|
227
|
+
const sorts = yamlSortsToDeclarative(query.sort_by, query.fields || {});
|
|
228
|
+
const { filters, attributeFilterConfigs } = yamlFiltersToDeclarative(entities, query.filter_by, attrFilterConfig);
|
|
229
|
+
return {
|
|
230
|
+
buckets,
|
|
231
|
+
sorts,
|
|
232
|
+
filters,
|
|
233
|
+
positions,
|
|
234
|
+
attributeFilterConfigs,
|
|
235
|
+
};
|
|
236
|
+
}
|
|
237
|
+
function yamlBucketItemToDeclarative(entities, query, item, fields, bucketType) {
|
|
238
|
+
const location = bucketType === BucketsType.Location;
|
|
239
|
+
if (typeof item === "string") {
|
|
240
|
+
const { bucketItem, longitude, latitude, filterConfig } = yamlReportFieldToDeclarative(entities, query, item, fields[item], {
|
|
241
|
+
location,
|
|
242
|
+
});
|
|
243
|
+
return {
|
|
244
|
+
bucketTotals: [],
|
|
245
|
+
bucketItem,
|
|
246
|
+
longitude,
|
|
247
|
+
latitude,
|
|
248
|
+
filterConfig,
|
|
249
|
+
};
|
|
250
|
+
}
|
|
251
|
+
if (item.field) {
|
|
252
|
+
const { bucketItem, longitude, latitude, filterConfig } = yamlReportFieldToDeclarative(entities, query, item.field, fields[item.field], {
|
|
253
|
+
format: item.format,
|
|
254
|
+
location,
|
|
255
|
+
});
|
|
256
|
+
const bucketTotals = yamlReportTotalToDeclarative(item.totals, item.field);
|
|
257
|
+
return {
|
|
258
|
+
bucketTotals,
|
|
259
|
+
bucketItem,
|
|
260
|
+
longitude,
|
|
261
|
+
latitude,
|
|
262
|
+
filterConfig,
|
|
263
|
+
};
|
|
264
|
+
}
|
|
265
|
+
return {
|
|
266
|
+
bucketTotals: [],
|
|
267
|
+
};
|
|
268
|
+
}
|
|
269
|
+
function yamlReportFieldToDeclarative(entities, query, localName, f, opts) {
|
|
270
|
+
const field = resolveField(localName, f);
|
|
271
|
+
if (!field) {
|
|
272
|
+
return {};
|
|
273
|
+
}
|
|
274
|
+
if (isAttributeField(field) && opts.location) {
|
|
275
|
+
const { displayForm, latitude, longitude } = mapLocationLabel(entities, field);
|
|
276
|
+
if (displayForm) {
|
|
277
|
+
return {
|
|
278
|
+
bucketItem: {
|
|
279
|
+
attribute: {
|
|
280
|
+
showAllValues: field.show_all_values,
|
|
281
|
+
alias: field.title,
|
|
282
|
+
localIdentifier: localName,
|
|
283
|
+
displayForm: displayForm,
|
|
284
|
+
},
|
|
285
|
+
},
|
|
286
|
+
latitude,
|
|
287
|
+
longitude,
|
|
288
|
+
};
|
|
289
|
+
}
|
|
290
|
+
return {};
|
|
291
|
+
}
|
|
292
|
+
if (isAttributeField(field)) {
|
|
293
|
+
const displayForm = createIdentifier(field.using);
|
|
294
|
+
if (displayForm) {
|
|
295
|
+
return {
|
|
296
|
+
bucketItem: {
|
|
297
|
+
attribute: {
|
|
298
|
+
showAllValues: field.show_all_values,
|
|
299
|
+
alias: field.title,
|
|
300
|
+
localIdentifier: localName,
|
|
301
|
+
displayForm: displayForm,
|
|
302
|
+
},
|
|
303
|
+
},
|
|
304
|
+
};
|
|
305
|
+
}
|
|
306
|
+
return {};
|
|
307
|
+
}
|
|
308
|
+
if (isInlineMetricField(field)) {
|
|
309
|
+
return {
|
|
310
|
+
bucketItem: {
|
|
311
|
+
measure: {
|
|
312
|
+
alias: field.title,
|
|
313
|
+
title: convertBucketToTitle(entities, query, field),
|
|
314
|
+
localIdentifier: localName,
|
|
315
|
+
format: opts.format,
|
|
316
|
+
definition: {
|
|
317
|
+
inlineDefinition: {
|
|
318
|
+
maql: field.maql,
|
|
319
|
+
},
|
|
320
|
+
},
|
|
321
|
+
},
|
|
322
|
+
},
|
|
323
|
+
};
|
|
324
|
+
}
|
|
325
|
+
if (isCalculatedMetricField(field)) {
|
|
326
|
+
const item = createIdentifier(field.using, { forceMetric: true });
|
|
327
|
+
if (item) {
|
|
328
|
+
const aggregation = (field.aggregation ?? "SUM").toLowerCase();
|
|
329
|
+
const { filters, attributeFilterConfigs } = yamlFiltersToDeclarative(entities, field.filter_by);
|
|
330
|
+
return {
|
|
331
|
+
bucketItem: {
|
|
332
|
+
measure: {
|
|
333
|
+
alias: field.title,
|
|
334
|
+
title: convertBucketToTitle(entities, query, field),
|
|
335
|
+
localIdentifier: localName,
|
|
336
|
+
format: opts.format,
|
|
337
|
+
definition: {
|
|
338
|
+
measureDefinition: {
|
|
339
|
+
item,
|
|
340
|
+
aggregation,
|
|
341
|
+
filters,
|
|
342
|
+
computeRatio: field.compute_ratio,
|
|
343
|
+
},
|
|
344
|
+
},
|
|
345
|
+
},
|
|
346
|
+
},
|
|
347
|
+
filterConfig: attributeFilterConfigs,
|
|
348
|
+
};
|
|
349
|
+
}
|
|
350
|
+
return {};
|
|
351
|
+
}
|
|
352
|
+
if (isMetricField(field)) {
|
|
353
|
+
const item = createIdentifier(field.using, { forceMetric: true });
|
|
354
|
+
const { filters, attributeFilterConfigs } = yamlFiltersToDeclarative(entities, field.filter_by);
|
|
355
|
+
if (item) {
|
|
356
|
+
return {
|
|
357
|
+
bucketItem: {
|
|
358
|
+
measure: {
|
|
359
|
+
alias: field.title,
|
|
360
|
+
title: convertBucketToTitle(entities, query, field),
|
|
361
|
+
localIdentifier: localName,
|
|
362
|
+
format: opts.format,
|
|
363
|
+
definition: {
|
|
364
|
+
measureDefinition: {
|
|
365
|
+
item,
|
|
366
|
+
filters,
|
|
367
|
+
computeRatio: field.compute_ratio,
|
|
368
|
+
},
|
|
369
|
+
},
|
|
370
|
+
},
|
|
371
|
+
},
|
|
372
|
+
filterConfig: attributeFilterConfigs,
|
|
373
|
+
};
|
|
374
|
+
}
|
|
375
|
+
return {};
|
|
376
|
+
}
|
|
377
|
+
if (isArithmeticMetricField(field)) {
|
|
378
|
+
const measureIdentifiers = field.using;
|
|
379
|
+
if (measureIdentifiers.length >= 2) {
|
|
380
|
+
return {
|
|
381
|
+
bucketItem: {
|
|
382
|
+
measure: {
|
|
383
|
+
alias: field.title,
|
|
384
|
+
title: convertBucketToTitle(entities, query, field),
|
|
385
|
+
localIdentifier: localName,
|
|
386
|
+
format: opts.format,
|
|
387
|
+
definition: {
|
|
388
|
+
arithmeticMeasure: {
|
|
389
|
+
measureIdentifiers,
|
|
390
|
+
operator: (field.operator ?? "SUM").toLowerCase(),
|
|
391
|
+
},
|
|
392
|
+
},
|
|
393
|
+
},
|
|
394
|
+
},
|
|
395
|
+
};
|
|
396
|
+
}
|
|
397
|
+
return {};
|
|
398
|
+
}
|
|
399
|
+
if (isPoPMetricField(field)) {
|
|
400
|
+
const popAttribute = mapDateAttribute(query, field);
|
|
401
|
+
if (popAttribute) {
|
|
402
|
+
return {
|
|
403
|
+
bucketItem: {
|
|
404
|
+
measure: {
|
|
405
|
+
alias: field.title,
|
|
406
|
+
title: convertBucketToTitle(entities, query, field),
|
|
407
|
+
localIdentifier: localName,
|
|
408
|
+
format: opts.format,
|
|
409
|
+
definition: {
|
|
410
|
+
popMeasureDefinition: {
|
|
411
|
+
measureIdentifier: field.using,
|
|
412
|
+
popAttribute,
|
|
413
|
+
},
|
|
414
|
+
},
|
|
415
|
+
},
|
|
416
|
+
},
|
|
417
|
+
};
|
|
418
|
+
}
|
|
419
|
+
return {};
|
|
420
|
+
}
|
|
421
|
+
if (isPreviousPeriodField(field)) {
|
|
422
|
+
const dataset = mapDateDataset(query, field);
|
|
423
|
+
if (dataset) {
|
|
424
|
+
return {
|
|
425
|
+
bucketItem: {
|
|
426
|
+
measure: {
|
|
427
|
+
alias: field.title,
|
|
428
|
+
title: convertBucketToTitle(entities, query, field),
|
|
429
|
+
localIdentifier: localName,
|
|
430
|
+
format: opts.format,
|
|
431
|
+
definition: {
|
|
432
|
+
previousPeriodMeasure: {
|
|
433
|
+
measureIdentifier: field.using,
|
|
434
|
+
dateDataSets: [
|
|
435
|
+
{
|
|
436
|
+
dataSet: dataset,
|
|
437
|
+
periodsAgo: field.period ?? 1,
|
|
438
|
+
},
|
|
439
|
+
],
|
|
440
|
+
},
|
|
441
|
+
},
|
|
442
|
+
},
|
|
443
|
+
},
|
|
444
|
+
};
|
|
445
|
+
}
|
|
446
|
+
return {};
|
|
447
|
+
}
|
|
448
|
+
return {};
|
|
449
|
+
}
|
|
450
|
+
function resolveField(localName, field) {
|
|
451
|
+
if (field) {
|
|
452
|
+
return getFullField(field);
|
|
453
|
+
}
|
|
454
|
+
if (parseReferenceObject(localName)) {
|
|
455
|
+
return getFullField(localName);
|
|
456
|
+
}
|
|
457
|
+
return undefined;
|
|
458
|
+
}
|
|
459
|
+
//SORTS
|
|
460
|
+
export function yamlSortsToDeclarative(sort_by, fields) {
|
|
461
|
+
if (!sort_by) {
|
|
462
|
+
return [];
|
|
463
|
+
}
|
|
464
|
+
return sort_by
|
|
465
|
+
.map((sort) => {
|
|
466
|
+
if (isAttributeSort(sort)) {
|
|
467
|
+
return {
|
|
468
|
+
attributeSortItem: {
|
|
469
|
+
attributeIdentifier: sort.by,
|
|
470
|
+
aggregation: sort.aggregation?.toLowerCase(),
|
|
471
|
+
direction: sort.direction?.toLowerCase(),
|
|
472
|
+
},
|
|
473
|
+
};
|
|
474
|
+
}
|
|
475
|
+
if (isMetricSort(sort)) {
|
|
476
|
+
return {
|
|
477
|
+
measureSortItem: {
|
|
478
|
+
locators: sort.metrics
|
|
479
|
+
.map((loc) => yamlLocatorToDeclarative(loc, fields))
|
|
480
|
+
.filter(Boolean),
|
|
481
|
+
direction: sort.direction?.toLowerCase(),
|
|
482
|
+
},
|
|
483
|
+
};
|
|
484
|
+
}
|
|
485
|
+
return null;
|
|
486
|
+
})
|
|
487
|
+
.filter(Boolean);
|
|
488
|
+
}
|
|
489
|
+
function yamlLocatorToDeclarative(loc, fields) {
|
|
490
|
+
const locator = typeof loc === "string" ? { by: loc } : loc;
|
|
491
|
+
const field = getFullField(fields[locator.by]);
|
|
492
|
+
if (!field) {
|
|
493
|
+
return null;
|
|
494
|
+
}
|
|
495
|
+
if (isAttributeField(field) && !locator.function) {
|
|
496
|
+
return {
|
|
497
|
+
attributeLocatorItem: {
|
|
498
|
+
attributeIdentifier: locator.by,
|
|
499
|
+
element: locator.element ?? null,
|
|
500
|
+
},
|
|
501
|
+
};
|
|
502
|
+
}
|
|
503
|
+
if (isAttributeField(field) && locator.function) {
|
|
504
|
+
return {
|
|
505
|
+
totalLocatorItem: {
|
|
506
|
+
attributeIdentifier: locator.by,
|
|
507
|
+
totalFunction: locator.function.toLowerCase(),
|
|
508
|
+
},
|
|
509
|
+
};
|
|
510
|
+
}
|
|
511
|
+
return {
|
|
512
|
+
measureLocatorItem: {
|
|
513
|
+
measureIdentifier: locator.by,
|
|
514
|
+
},
|
|
515
|
+
};
|
|
516
|
+
}
|
|
517
|
+
function buildMeasureValueFilterDimensionality(filter) {
|
|
518
|
+
if (filter.dimensionality && Array.isArray(filter.dimensionality) && filter.dimensionality.length > 0) {
|
|
519
|
+
return filter.dimensionality.map((item) => createIdentifier(item) || createLocalIdentifier(item));
|
|
520
|
+
}
|
|
521
|
+
return undefined;
|
|
522
|
+
}
|
|
523
|
+
function createBaseMeasureValueFilter(filter) {
|
|
524
|
+
const measureValueFilter = {
|
|
525
|
+
// When MVF references a metric by ref (e.g. "metric/amount"), preserve "metric" type.
|
|
526
|
+
measure: createIdentifier(filter.using, { forceMetric: true }) || createLocalIdentifier(filter.using),
|
|
527
|
+
};
|
|
528
|
+
const dimensionality = buildMeasureValueFilterDimensionality(filter);
|
|
529
|
+
if (dimensionality) {
|
|
530
|
+
measureValueFilter.dimensionality = dimensionality;
|
|
531
|
+
}
|
|
532
|
+
return measureValueFilter;
|
|
533
|
+
}
|
|
534
|
+
function convertYamlConditionsToSdk(yamlConditions, nullValuesAsZero) {
|
|
535
|
+
const sdkConditions = [];
|
|
536
|
+
yamlConditions.forEach((c) => {
|
|
537
|
+
if ("condition" in c && c.condition) {
|
|
538
|
+
if (c.condition === "BETWEEN" || c.condition === "NOT_BETWEEN") {
|
|
539
|
+
const rangeCondition = c;
|
|
540
|
+
sdkConditions.push({
|
|
541
|
+
range: {
|
|
542
|
+
operator: rangeCondition.condition,
|
|
543
|
+
from: rangeCondition.from,
|
|
544
|
+
to: rangeCondition.to,
|
|
545
|
+
treatNullValuesAs: nullValuesAsZero ? 0 : undefined,
|
|
546
|
+
},
|
|
547
|
+
});
|
|
548
|
+
}
|
|
549
|
+
else {
|
|
550
|
+
const comparisonCondition = c;
|
|
551
|
+
sdkConditions.push({
|
|
552
|
+
comparison: {
|
|
553
|
+
operator: comparisonCondition.condition,
|
|
554
|
+
value: comparisonCondition.value,
|
|
555
|
+
treatNullValuesAs: nullValuesAsZero ? 0 : undefined,
|
|
556
|
+
},
|
|
557
|
+
});
|
|
558
|
+
}
|
|
559
|
+
}
|
|
560
|
+
});
|
|
561
|
+
return sdkConditions;
|
|
562
|
+
}
|
|
563
|
+
function yamlAbsoluteDateFilterToDeclarative(entities, filter) {
|
|
564
|
+
let result = {
|
|
565
|
+
filters: [
|
|
566
|
+
{
|
|
567
|
+
absoluteDateFilter: {
|
|
568
|
+
dataSet: createIdentifier(filter.using, { forceType: "dataset" }),
|
|
569
|
+
from: filter.from,
|
|
570
|
+
to: filter.to,
|
|
571
|
+
},
|
|
572
|
+
},
|
|
573
|
+
],
|
|
574
|
+
};
|
|
575
|
+
result = mergeDeclarativeResults(result, dateFilterEmptyValuesToDeclarative(filter));
|
|
576
|
+
result = mergeDeclarativeResults(result, dateFilterWithFieldToDeclarative(entities, filter));
|
|
577
|
+
return result;
|
|
578
|
+
}
|
|
579
|
+
function dateFilterEmptyValuesToDeclarative(filter) {
|
|
580
|
+
if (!filter.empty_values) {
|
|
581
|
+
return { filters: [] };
|
|
582
|
+
}
|
|
583
|
+
const identifier = createIdentifier(`${filter.using}.${convertGranularityToId(filter.granularity ?? "YEAR")}`, { forceType: "label" });
|
|
584
|
+
switch (filter.empty_values) {
|
|
585
|
+
case "exclude": {
|
|
586
|
+
return {
|
|
587
|
+
filters: [
|
|
588
|
+
{
|
|
589
|
+
negativeAttributeFilter: {
|
|
590
|
+
displayForm: identifier,
|
|
591
|
+
notIn: {
|
|
592
|
+
values: [""],
|
|
593
|
+
},
|
|
594
|
+
},
|
|
595
|
+
},
|
|
596
|
+
],
|
|
597
|
+
};
|
|
598
|
+
}
|
|
599
|
+
case "only": {
|
|
600
|
+
return {
|
|
601
|
+
filters: [
|
|
602
|
+
{
|
|
603
|
+
positiveAttributeFilter: {
|
|
604
|
+
displayForm: identifier,
|
|
605
|
+
in: {
|
|
606
|
+
values: [""],
|
|
607
|
+
},
|
|
608
|
+
},
|
|
609
|
+
},
|
|
610
|
+
],
|
|
611
|
+
};
|
|
612
|
+
}
|
|
613
|
+
}
|
|
614
|
+
return { filters: [] };
|
|
615
|
+
}
|
|
616
|
+
function dateFilterWithFieldToDeclarative(entities, filter) {
|
|
617
|
+
if (!filter.with) {
|
|
618
|
+
return { filters: [] };
|
|
619
|
+
}
|
|
620
|
+
return mergeDeclarativeResults(...Object.entries(filter.with).map(([key, withFilter]) => yamlFilterToDeclarative(entities, key, withFilter)));
|
|
621
|
+
}
|
|
622
|
+
function yamlRelativeDateFilterToDeclarative(entities, filter) {
|
|
623
|
+
const identifier = createIdentifier(filter.using, { forceType: "dataset" });
|
|
624
|
+
if (!identifier) {
|
|
625
|
+
throw new Error(`Could not find dataset ${filter.using} to use in relative date filter`);
|
|
626
|
+
}
|
|
627
|
+
let result = { filters: [], attributeFilterConfig: {} };
|
|
628
|
+
if (!!filter.granularity && typeof filter.from === "number" && typeof filter.to === "number") {
|
|
629
|
+
result = mergeDeclarativeResults(result, {
|
|
630
|
+
filters: [
|
|
631
|
+
{
|
|
632
|
+
relativeDateFilter: {
|
|
633
|
+
dataSet: identifier,
|
|
634
|
+
granularity: convertGranularity(filter.granularity),
|
|
635
|
+
from: filter.from,
|
|
636
|
+
to: filter.to,
|
|
637
|
+
},
|
|
638
|
+
},
|
|
639
|
+
],
|
|
640
|
+
});
|
|
641
|
+
}
|
|
642
|
+
else {
|
|
643
|
+
result = mergeDeclarativeResults(result, {
|
|
644
|
+
filters: [
|
|
645
|
+
{
|
|
646
|
+
relativeDateFilter: {
|
|
647
|
+
dataSet: identifier,
|
|
648
|
+
// This is not compliant with the types from gdc-model, but this is what AD emits for an all time filter.
|
|
649
|
+
// AD actually cannot understand an ALL_TIME_GRANULARITY granularity.
|
|
650
|
+
granularity: convertGranularity("YEAR"),
|
|
651
|
+
},
|
|
652
|
+
},
|
|
653
|
+
],
|
|
654
|
+
});
|
|
655
|
+
}
|
|
656
|
+
result = mergeDeclarativeResults(result, dateFilterEmptyValuesToDeclarative(filter));
|
|
657
|
+
result = mergeDeclarativeResults(result, dateFilterWithFieldToDeclarative(entities, filter));
|
|
658
|
+
return result;
|
|
659
|
+
}
|
|
660
|
+
function yamlPositiveAttributeFilterToDeclarative(entities, key, filter) {
|
|
661
|
+
return {
|
|
662
|
+
filters: [
|
|
663
|
+
{
|
|
664
|
+
positiveAttributeFilter: {
|
|
665
|
+
displayForm: createIdentifier(filter.using),
|
|
666
|
+
in: {
|
|
667
|
+
values: parseDateValues(entities, filter.using, filter.state?.include ?? []),
|
|
668
|
+
},
|
|
669
|
+
},
|
|
670
|
+
},
|
|
671
|
+
],
|
|
672
|
+
...(filter.display_as
|
|
673
|
+
? {
|
|
674
|
+
attributeFilterConfig: {
|
|
675
|
+
[key]: {
|
|
676
|
+
displayAsLabel: createIdentifier(filter.display_as, {
|
|
677
|
+
forceType: "label",
|
|
678
|
+
}),
|
|
679
|
+
},
|
|
680
|
+
},
|
|
681
|
+
}
|
|
682
|
+
: {}),
|
|
683
|
+
};
|
|
684
|
+
}
|
|
685
|
+
function yamlNegativeAttributeFilterToDeclarative(entities, key, filter) {
|
|
686
|
+
return {
|
|
687
|
+
filters: [
|
|
688
|
+
{
|
|
689
|
+
negativeAttributeFilter: {
|
|
690
|
+
displayForm: createIdentifier(filter.using),
|
|
691
|
+
notIn: {
|
|
692
|
+
values: parseDateValues(entities, filter.using, filter.state?.exclude ?? []),
|
|
693
|
+
},
|
|
694
|
+
},
|
|
695
|
+
},
|
|
696
|
+
],
|
|
697
|
+
...(filter.display_as
|
|
698
|
+
? {
|
|
699
|
+
attributeFilterConfig: {
|
|
700
|
+
[key]: {
|
|
701
|
+
displayAsLabel: createIdentifier(filter.display_as, {
|
|
702
|
+
forceType: "label",
|
|
703
|
+
}),
|
|
704
|
+
},
|
|
705
|
+
},
|
|
706
|
+
}
|
|
707
|
+
: {}),
|
|
708
|
+
};
|
|
709
|
+
}
|
|
710
|
+
function yamlMetricValueFilterWithConditionsToDeclarative(filter) {
|
|
711
|
+
// TypeScript narrows to MultipleConditions via type guard
|
|
712
|
+
const measureValueFilter = createBaseMeasureValueFilter(filter);
|
|
713
|
+
const sdkConditions = convertYamlConditionsToSdk(filter.conditions, filter.null_values_as_zero);
|
|
714
|
+
if (sdkConditions.length === 0) {
|
|
715
|
+
return { filters: [] };
|
|
716
|
+
}
|
|
717
|
+
if (sdkConditions.length === 1) {
|
|
718
|
+
measureValueFilter.condition = sdkConditions[0];
|
|
719
|
+
}
|
|
720
|
+
else if (sdkConditions.length > 1) {
|
|
721
|
+
measureValueFilter.conditions = sdkConditions;
|
|
722
|
+
}
|
|
723
|
+
return { filters: [{ measureValueFilter }] };
|
|
724
|
+
}
|
|
725
|
+
function yamlMetricRangeValueFilterToDeclarative(filter) {
|
|
726
|
+
const measureValueFilter = createBaseMeasureValueFilter(filter);
|
|
727
|
+
measureValueFilter.condition = {
|
|
728
|
+
range: {
|
|
729
|
+
operator: filter.condition,
|
|
730
|
+
from: filter.from,
|
|
731
|
+
to: filter.to,
|
|
732
|
+
treatNullValuesAs: filter.null_values_as_zero ? 0 : undefined,
|
|
733
|
+
},
|
|
734
|
+
};
|
|
735
|
+
return { filters: [{ measureValueFilter }] };
|
|
736
|
+
}
|
|
737
|
+
function yamlMetricComparisonValueFilterToDeclarative(filter) {
|
|
738
|
+
const measureValueFilter = createBaseMeasureValueFilter(filter);
|
|
739
|
+
measureValueFilter.condition = {
|
|
740
|
+
comparison: {
|
|
741
|
+
operator: filter.condition,
|
|
742
|
+
value: filter.value,
|
|
743
|
+
treatNullValuesAs: filter.null_values_as_zero ? 0 : undefined,
|
|
744
|
+
},
|
|
745
|
+
};
|
|
746
|
+
return { filters: [{ measureValueFilter }] };
|
|
747
|
+
}
|
|
748
|
+
function yamlMetricAllValueFilterToDeclarative(filter) {
|
|
749
|
+
const measureValueFilter = createBaseMeasureValueFilter(filter);
|
|
750
|
+
return { filters: [{ measureValueFilter }] };
|
|
751
|
+
}
|
|
752
|
+
function yamlRankingFilterToDeclarative(filter) {
|
|
753
|
+
return {
|
|
754
|
+
filters: [
|
|
755
|
+
{
|
|
756
|
+
rankingFilter: {
|
|
757
|
+
// Ranking filter can reference a metric by ref (e.g. "metric/amount"), preserve "metric" type.
|
|
758
|
+
measure: createIdentifier(filter.using, { forceMetric: true }) ||
|
|
759
|
+
createLocalIdentifier(filter.using),
|
|
760
|
+
...(filter.attribute
|
|
761
|
+
? {
|
|
762
|
+
attributes: [
|
|
763
|
+
createIdentifier(filter.attribute) ||
|
|
764
|
+
createLocalIdentifier(filter.attribute),
|
|
765
|
+
],
|
|
766
|
+
}
|
|
767
|
+
: {}),
|
|
768
|
+
operator: filter.top === undefined ? "BOTTOM" : "TOP",
|
|
769
|
+
value: filter.top === undefined ? filter.bottom : filter.top,
|
|
770
|
+
},
|
|
771
|
+
},
|
|
772
|
+
],
|
|
773
|
+
};
|
|
774
|
+
}
|
|
775
|
+
function yamlFilterToDeclarative(entities, key, filter) {
|
|
776
|
+
if (isAbsoluteDateFilter(filter)) {
|
|
777
|
+
return yamlAbsoluteDateFilterToDeclarative(entities, filter);
|
|
778
|
+
}
|
|
779
|
+
if (isRelativeDateFilter(filter)) {
|
|
780
|
+
return yamlRelativeDateFilterToDeclarative(entities, filter);
|
|
781
|
+
}
|
|
782
|
+
if (isPositiveAttributeFilter(filter)) {
|
|
783
|
+
return yamlPositiveAttributeFilterToDeclarative(entities, key, filter);
|
|
784
|
+
}
|
|
785
|
+
if (isNegativeAttributeFilter(filter)) {
|
|
786
|
+
return yamlNegativeAttributeFilterToDeclarative(entities, key, filter);
|
|
787
|
+
}
|
|
788
|
+
if (isMetricValueFilterWithConditions(filter)) {
|
|
789
|
+
return yamlMetricValueFilterWithConditionsToDeclarative(filter);
|
|
790
|
+
}
|
|
791
|
+
if (isMetricRangeValueFilter(filter)) {
|
|
792
|
+
return yamlMetricRangeValueFilterToDeclarative(filter);
|
|
793
|
+
}
|
|
794
|
+
if (isMetricComparisonValueFilter(filter)) {
|
|
795
|
+
return yamlMetricComparisonValueFilterToDeclarative(filter);
|
|
796
|
+
}
|
|
797
|
+
if (isMetricAllValueFilter(filter)) {
|
|
798
|
+
return yamlMetricAllValueFilterToDeclarative(filter);
|
|
799
|
+
}
|
|
800
|
+
if (isRankingFilter(filter)) {
|
|
801
|
+
return yamlRankingFilterToDeclarative(filter);
|
|
802
|
+
}
|
|
803
|
+
assertUnreachable(filter);
|
|
804
|
+
}
|
|
805
|
+
function mergeDeclarativeResults(...results) {
|
|
806
|
+
return {
|
|
807
|
+
filters: results.flatMap((result) => result.filters),
|
|
808
|
+
attributeFilterConfig: Object.assign({}, ...results.map((result) => result.attributeFilterConfig ?? {})),
|
|
809
|
+
};
|
|
810
|
+
}
|
|
811
|
+
export function yamlFiltersToDeclarative(entities, filters_by, attributeFilterConfigs = {}) {
|
|
812
|
+
const { filters, attributeFilterConfig } = mergeDeclarativeResults({ filters: [], attributeFilterConfig: attributeFilterConfigs }, ...(filters_by
|
|
813
|
+
? Object.entries(filters_by).map(([key, filter]) => yamlFilterToDeclarative(entities, key, filter))
|
|
814
|
+
: []));
|
|
815
|
+
return {
|
|
816
|
+
filters,
|
|
817
|
+
attributeFilterConfigs: Object.keys(attributeFilterConfig ?? {}).length > 0 ? attributeFilterConfig : undefined,
|
|
818
|
+
};
|
|
819
|
+
}
|
|
820
|
+
//TOTALS
|
|
821
|
+
export function yamlReportTotalToDeclarative(totals = [], attributeIdentifier) {
|
|
822
|
+
return totals.map((total) => {
|
|
823
|
+
return {
|
|
824
|
+
alias: total.title,
|
|
825
|
+
type: (total.type ?? "sum").toLowerCase(),
|
|
826
|
+
measureIdentifier: total.using,
|
|
827
|
+
attributeIdentifier,
|
|
828
|
+
};
|
|
829
|
+
});
|
|
830
|
+
}
|
|
831
|
+
//BUCKETS
|
|
832
|
+
export function yamlBucketsToDeclarative(input) {
|
|
833
|
+
const buckets = [];
|
|
834
|
+
switch (input.type) {
|
|
835
|
+
case "table": {
|
|
836
|
+
addBucket(buckets, BucketsType.Measures, input.metrics);
|
|
837
|
+
addBucket(buckets, BucketsType.Attribute, input.view_by, input.rows);
|
|
838
|
+
addBucket(buckets, BucketsType.Columns, input.segment_by, input.columns);
|
|
839
|
+
return buckets;
|
|
840
|
+
}
|
|
841
|
+
case "bar_chart":
|
|
842
|
+
case "column_chart":
|
|
843
|
+
case "area_chart": {
|
|
844
|
+
addBucket(buckets, BucketsType.Measures, input.metrics);
|
|
845
|
+
addBucket(buckets, BucketsType.View, input.view_by);
|
|
846
|
+
addBucket(buckets, BucketsType.Stack, input.segment_by, input.stack_by);
|
|
847
|
+
return buckets;
|
|
848
|
+
}
|
|
849
|
+
case "line_chart": {
|
|
850
|
+
addBucket(buckets, BucketsType.Measures, input.metrics);
|
|
851
|
+
addBucket(buckets, BucketsType.Trend, input.view_by, input.trend_by);
|
|
852
|
+
addBucket(buckets, BucketsType.Segment, input.segment_by);
|
|
853
|
+
return buckets;
|
|
854
|
+
}
|
|
855
|
+
case "scatter_chart": {
|
|
856
|
+
addBucket(buckets, BucketsType.Measures, input.metrics?.[0] ? [input.metrics[0]] : []);
|
|
857
|
+
addBucket(buckets, BucketsType.SecondaryMeasures, input.metrics?.[1] ? [input.metrics[1]] : []);
|
|
858
|
+
addBucket(buckets, BucketsType.Attribute, input.view_by, input.attributes);
|
|
859
|
+
addBucket(buckets, BucketsType.Segment, input.segment_by);
|
|
860
|
+
return buckets;
|
|
861
|
+
}
|
|
862
|
+
case "bubble_chart": {
|
|
863
|
+
addBucket(buckets, BucketsType.Measures, input.metrics?.[0] ? [input.metrics[0]] : []);
|
|
864
|
+
addBucket(buckets, BucketsType.SecondaryMeasures, input.metrics?.[1] ? [input.metrics[1]] : []);
|
|
865
|
+
addBucket(buckets, BucketsType.TertiaryMeasures, input.segment_by, input.size_by);
|
|
866
|
+
addBucket(buckets, BucketsType.View, input.view_by);
|
|
867
|
+
return buckets;
|
|
868
|
+
}
|
|
869
|
+
case "pie_chart":
|
|
870
|
+
case "donut_chart":
|
|
871
|
+
case "pyramid_chart":
|
|
872
|
+
case "funnel_chart":
|
|
873
|
+
case "waterfall_chart": {
|
|
874
|
+
addBucket(buckets, BucketsType.Measures, input.metrics);
|
|
875
|
+
addBucket(buckets, BucketsType.View, input.view_by);
|
|
876
|
+
return buckets;
|
|
877
|
+
}
|
|
878
|
+
case "treemap_chart": {
|
|
879
|
+
addBucket(buckets, BucketsType.Measures, input.metrics);
|
|
880
|
+
addBucket(buckets, BucketsType.View, input.view_by);
|
|
881
|
+
addBucket(buckets, BucketsType.Segment, input.segment_by);
|
|
882
|
+
return buckets;
|
|
883
|
+
}
|
|
884
|
+
case "heatmap_chart": {
|
|
885
|
+
addBucket(buckets, BucketsType.Measures, input.metrics);
|
|
886
|
+
addBucket(buckets, BucketsType.View, input.view_by, input.rows);
|
|
887
|
+
addBucket(buckets, BucketsType.Stack, input.segment_by, input.columns);
|
|
888
|
+
return buckets;
|
|
889
|
+
}
|
|
890
|
+
case "bullet_chart": {
|
|
891
|
+
addBucket(buckets, BucketsType.Measures, input.metrics?.[0] ? [input.metrics[0]] : []);
|
|
892
|
+
addBucket(buckets, BucketsType.SecondaryMeasures, input.metrics?.[1] ? [input.metrics[1]] : []);
|
|
893
|
+
addBucket(buckets, BucketsType.TertiaryMeasures, input.metrics?.[2] ? [input.metrics[2]] : []);
|
|
894
|
+
addBucket(buckets, BucketsType.View, input.view_by);
|
|
895
|
+
return buckets;
|
|
896
|
+
}
|
|
897
|
+
case "headline_chart": {
|
|
898
|
+
addBucket(buckets, BucketsType.Measures, input.metrics?.[0] ? [input.metrics[0]] : []);
|
|
899
|
+
addBucket(buckets, BucketsType.SecondaryMeasures, input.metrics?.slice(1) || []);
|
|
900
|
+
return buckets;
|
|
901
|
+
}
|
|
902
|
+
case "dependency_wheel_chart":
|
|
903
|
+
case "sankey_chart": {
|
|
904
|
+
addBucket(buckets, BucketsType.Measures, input.metrics);
|
|
905
|
+
addBucket(buckets, BucketsType.AttributeFrom, input.view_by?.[0] ? [input.view_by[0]] : [], input.from ? [input.from] : []);
|
|
906
|
+
addBucket(buckets, BucketsType.AttributeTo, input.view_by?.[1] ? [input.view_by[1]] : [], input.to ? [input.to] : []);
|
|
907
|
+
return buckets;
|
|
908
|
+
}
|
|
909
|
+
case "combo_chart": {
|
|
910
|
+
addBucket(buckets, BucketsType.Measures, input.metrics?.filter((b) => {
|
|
911
|
+
const bucket = getFullBucket(b);
|
|
912
|
+
return !bucket.axis || bucket.axis === "primary";
|
|
913
|
+
}));
|
|
914
|
+
addBucket(buckets, BucketsType.SecondaryMeasures, input.metrics?.filter((b) => {
|
|
915
|
+
const bucket = getFullBucket(b);
|
|
916
|
+
return bucket.axis === "secondary";
|
|
917
|
+
}));
|
|
918
|
+
addBucket(buckets, BucketsType.View, input.view_by);
|
|
919
|
+
return buckets;
|
|
920
|
+
}
|
|
921
|
+
case "geo_chart": {
|
|
922
|
+
return createPushpinBuckets({
|
|
923
|
+
viewBy: input.view_by,
|
|
924
|
+
metrics: input.metrics,
|
|
925
|
+
segmentBy: input.segment_by,
|
|
926
|
+
});
|
|
927
|
+
}
|
|
928
|
+
case "geo_area_chart": {
|
|
929
|
+
return createGeoAreaBuckets({
|
|
930
|
+
viewBy: input.view_by,
|
|
931
|
+
metrics: input.metrics,
|
|
932
|
+
segmentBy: input.segment_by,
|
|
933
|
+
});
|
|
934
|
+
}
|
|
935
|
+
case "repeater_chart": {
|
|
936
|
+
addBucket(buckets, BucketsType.Attribute, input.segment_by, input.rows);
|
|
937
|
+
addBucket(buckets, BucketsType.Columns, input.metrics, input.columns);
|
|
938
|
+
addBucket(buckets, BucketsType.View, input.view_by);
|
|
939
|
+
return buckets;
|
|
940
|
+
}
|
|
941
|
+
}
|
|
942
|
+
}
|
|
943
|
+
function addBucket(buckets, localIdentifier, ...itms) {
|
|
944
|
+
const items = itms.reduce((acc, itm) => [...acc, ...(itm || [])], []);
|
|
945
|
+
buckets.push({
|
|
946
|
+
localIdentifier,
|
|
947
|
+
items,
|
|
948
|
+
});
|
|
949
|
+
}
|
|
950
|
+
function createPushpinBuckets({ viewBy, metrics, segmentBy }) {
|
|
951
|
+
const buckets = [];
|
|
952
|
+
addBucket(buckets, BucketsType.Location, viewBy?.[0] ? [viewBy[0]] : []);
|
|
953
|
+
addBucket(buckets, BucketsType.Size, metrics?.[0] ? [metrics[0]] : []);
|
|
954
|
+
addBucket(buckets, BucketsType.Color, metrics?.[1] ? [metrics[1]] : []);
|
|
955
|
+
addBucket(buckets, BucketsType.Segment, segmentBy?.[0] ? [segmentBy[0]] : []);
|
|
956
|
+
return buckets;
|
|
957
|
+
}
|
|
958
|
+
function createGeoAreaBuckets({ viewBy, metrics, segmentBy }) {
|
|
959
|
+
const buckets = [];
|
|
960
|
+
addBucket(buckets, BucketsType.Area, viewBy?.[0] ? [viewBy[0]] : []);
|
|
961
|
+
addBucket(buckets, BucketsType.Color, metrics?.[0] ? [metrics[0]] : []);
|
|
962
|
+
addBucket(buckets, BucketsType.Segment, segmentBy?.[0] ? [segmentBy[0]] : []);
|
|
963
|
+
return buckets;
|
|
964
|
+
}
|
|
965
|
+
function yamlLayersToDeclarative(entities, input, _positions) {
|
|
966
|
+
if (!("layers" in input) || !Array.isArray(input.layers) || input.layers.length === 0) {
|
|
967
|
+
return [];
|
|
968
|
+
}
|
|
969
|
+
return input.layers.map((layer) => {
|
|
970
|
+
if (layer.type !== "pushpin" && layer.type !== "area") {
|
|
971
|
+
throw newError(CoreErrorCode.LayerTypeNotSupported, [layer.type ?? "<missing>"]);
|
|
972
|
+
}
|
|
973
|
+
const layerVisualizationType = layer.type === "pushpin" ? "geo_chart" : "geo_area_chart";
|
|
974
|
+
const baseQuery = layer.query;
|
|
975
|
+
const resolvedQuery = {
|
|
976
|
+
...input.query,
|
|
977
|
+
...baseQuery,
|
|
978
|
+
fields: {
|
|
979
|
+
...(input.query?.fields ?? {}),
|
|
980
|
+
...(baseQuery?.fields ?? {}),
|
|
981
|
+
},
|
|
982
|
+
};
|
|
983
|
+
const positions = [];
|
|
984
|
+
let attrFilterConfig = {};
|
|
985
|
+
const visBuckets = layer.type === "pushpin"
|
|
986
|
+
? createPushpinBuckets({
|
|
987
|
+
viewBy: layer.view_by,
|
|
988
|
+
metrics: layer.metrics,
|
|
989
|
+
segmentBy: layer.segment_by,
|
|
990
|
+
})
|
|
991
|
+
: createGeoAreaBuckets({
|
|
992
|
+
viewBy: layer.view_by,
|
|
993
|
+
metrics: layer.metrics,
|
|
994
|
+
segmentBy: layer.segment_by,
|
|
995
|
+
});
|
|
996
|
+
const buckets = visBuckets
|
|
997
|
+
.map((bucket) => {
|
|
998
|
+
const { localIdentifier } = bucket;
|
|
999
|
+
const totals = [];
|
|
1000
|
+
//do not include empty buckets
|
|
1001
|
+
if (bucket.items.length === 0) {
|
|
1002
|
+
return null;
|
|
1003
|
+
}
|
|
1004
|
+
const items = bucket.items
|
|
1005
|
+
.map((item) => {
|
|
1006
|
+
const { bucketItem, bucketTotals, longitude, latitude, filterConfig } = yamlBucketItemToDeclarative(entities, resolvedQuery, item, resolvedQuery.fields || {}, localIdentifier);
|
|
1007
|
+
if (longitude && latitude) {
|
|
1008
|
+
positions.push({ longitude, latitude });
|
|
1009
|
+
}
|
|
1010
|
+
if (filterConfig) {
|
|
1011
|
+
attrFilterConfig = { ...attrFilterConfig, ...filterConfig };
|
|
1012
|
+
}
|
|
1013
|
+
bucketTotals.forEach((total) => totals.push(total));
|
|
1014
|
+
return bucketItem;
|
|
1015
|
+
})
|
|
1016
|
+
.filter(Boolean);
|
|
1017
|
+
return {
|
|
1018
|
+
localIdentifier,
|
|
1019
|
+
items,
|
|
1020
|
+
totals,
|
|
1021
|
+
};
|
|
1022
|
+
})
|
|
1023
|
+
.filter(Boolean);
|
|
1024
|
+
const { filters: layerFilters, attributeFilterConfigs } = yamlFiltersToDeclarative(entities, baseQuery?.filter_by, attrFilterConfig);
|
|
1025
|
+
const layerProperties = layer.config || (layer.type === "pushpin" && positions.length > 0)
|
|
1026
|
+
? yamlConfigToDeclarative({
|
|
1027
|
+
...input,
|
|
1028
|
+
type: layerVisualizationType,
|
|
1029
|
+
query: resolvedQuery,
|
|
1030
|
+
metrics: layer.metrics,
|
|
1031
|
+
view_by: layer.view_by,
|
|
1032
|
+
segment_by: layer.segment_by,
|
|
1033
|
+
config: layer.config,
|
|
1034
|
+
}, positions)
|
|
1035
|
+
: undefined;
|
|
1036
|
+
return {
|
|
1037
|
+
id: layer.id,
|
|
1038
|
+
name: layer.title,
|
|
1039
|
+
type: layer.type,
|
|
1040
|
+
buckets,
|
|
1041
|
+
filters: layerFilters,
|
|
1042
|
+
...(attributeFilterConfigs ? { attributeFilterConfigs } : {}),
|
|
1043
|
+
sorts: yamlSortsToDeclarative(baseQuery?.sort_by, baseQuery?.fields ?? resolvedQuery.fields ?? {}),
|
|
1044
|
+
properties: layerProperties && Object.keys(layerProperties).length > 0 ? layerProperties : undefined,
|
|
1045
|
+
};
|
|
1046
|
+
});
|
|
1047
|
+
}
|
|
1048
|
+
//# sourceMappingURL=yamlVisualisationToDeclarative.js.map
|