@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.
Files changed (237) hide show
  1. package/LICENSE +7 -0
  2. package/README.md +42 -0
  3. package/esm/configs/areaChart.d.ts +113 -0
  4. package/esm/configs/areaChart.d.ts.map +1 -0
  5. package/esm/configs/areaChart.js +232 -0
  6. package/esm/configs/areaChart.js.map +1 -0
  7. package/esm/configs/barChart.d.ts +101 -0
  8. package/esm/configs/barChart.d.ts.map +1 -0
  9. package/esm/configs/barChart.js +210 -0
  10. package/esm/configs/barChart.js.map +1 -0
  11. package/esm/configs/bubbleChart.d.ts +93 -0
  12. package/esm/configs/bubbleChart.d.ts.map +1 -0
  13. package/esm/configs/bubbleChart.js +186 -0
  14. package/esm/configs/bubbleChart.js.map +1 -0
  15. package/esm/configs/bulletChart.d.ts +87 -0
  16. package/esm/configs/bulletChart.d.ts.map +1 -0
  17. package/esm/configs/bulletChart.js +174 -0
  18. package/esm/configs/bulletChart.js.map +1 -0
  19. package/esm/configs/columnChart.d.ts +101 -0
  20. package/esm/configs/columnChart.d.ts.map +1 -0
  21. package/esm/configs/columnChart.js +210 -0
  22. package/esm/configs/columnChart.js.map +1 -0
  23. package/esm/configs/comboChart.d.ts +155 -0
  24. package/esm/configs/comboChart.d.ts.map +1 -0
  25. package/esm/configs/comboChart.js +355 -0
  26. package/esm/configs/comboChart.js.map +1 -0
  27. package/esm/configs/dependencyWheelChart.d.ts +37 -0
  28. package/esm/configs/dependencyWheelChart.d.ts.map +1 -0
  29. package/esm/configs/dependencyWheelChart.js +81 -0
  30. package/esm/configs/dependencyWheelChart.js.map +1 -0
  31. package/esm/configs/donutChart.d.ts +47 -0
  32. package/esm/configs/donutChart.d.ts.map +1 -0
  33. package/esm/configs/donutChart.js +96 -0
  34. package/esm/configs/donutChart.js.map +1 -0
  35. package/esm/configs/funnelChart.d.ts +47 -0
  36. package/esm/configs/funnelChart.d.ts.map +1 -0
  37. package/esm/configs/funnelChart.js +96 -0
  38. package/esm/configs/funnelChart.js.map +1 -0
  39. package/esm/configs/geoAreaChart.d.ts +62 -0
  40. package/esm/configs/geoAreaChart.d.ts.map +1 -0
  41. package/esm/configs/geoAreaChart.js +123 -0
  42. package/esm/configs/geoAreaChart.js.map +1 -0
  43. package/esm/configs/geoChart.d.ts +49 -0
  44. package/esm/configs/geoChart.d.ts.map +1 -0
  45. package/esm/configs/geoChart.js +157 -0
  46. package/esm/configs/geoChart.js.map +1 -0
  47. package/esm/configs/headlineChart.d.ts +89 -0
  48. package/esm/configs/headlineChart.d.ts.map +1 -0
  49. package/esm/configs/headlineChart.js +124 -0
  50. package/esm/configs/headlineChart.js.map +1 -0
  51. package/esm/configs/heatmapChart.d.ts +75 -0
  52. package/esm/configs/heatmapChart.d.ts.map +1 -0
  53. package/esm/configs/heatmapChart.js +158 -0
  54. package/esm/configs/heatmapChart.js.map +1 -0
  55. package/esm/configs/lineChart.d.ts +135 -0
  56. package/esm/configs/lineChart.d.ts.map +1 -0
  57. package/esm/configs/lineChart.js +294 -0
  58. package/esm/configs/lineChart.js.map +1 -0
  59. package/esm/configs/pieChart.d.ts +47 -0
  60. package/esm/configs/pieChart.d.ts.map +1 -0
  61. package/esm/configs/pieChart.js +96 -0
  62. package/esm/configs/pieChart.js.map +1 -0
  63. package/esm/configs/pyramidChart.d.ts +47 -0
  64. package/esm/configs/pyramidChart.d.ts.map +1 -0
  65. package/esm/configs/pyramidChart.js +96 -0
  66. package/esm/configs/pyramidChart.js.map +1 -0
  67. package/esm/configs/repeaterChart.d.ts +36 -0
  68. package/esm/configs/repeaterChart.d.ts.map +1 -0
  69. package/esm/configs/repeaterChart.js +104 -0
  70. package/esm/configs/repeaterChart.js.map +1 -0
  71. package/esm/configs/sankeyChart.d.ts +39 -0
  72. package/esm/configs/sankeyChart.d.ts.map +1 -0
  73. package/esm/configs/sankeyChart.js +84 -0
  74. package/esm/configs/sankeyChart.js.map +1 -0
  75. package/esm/configs/scatterChart.d.ts +95 -0
  76. package/esm/configs/scatterChart.d.ts.map +1 -0
  77. package/esm/configs/scatterChart.js +198 -0
  78. package/esm/configs/scatterChart.js.map +1 -0
  79. package/esm/configs/table.d.ts +61 -0
  80. package/esm/configs/table.d.ts.map +1 -0
  81. package/esm/configs/table.js +169 -0
  82. package/esm/configs/table.js.map +1 -0
  83. package/esm/configs/treemapChart.d.ts +47 -0
  84. package/esm/configs/treemapChart.d.ts.map +1 -0
  85. package/esm/configs/treemapChart.js +96 -0
  86. package/esm/configs/treemapChart.js.map +1 -0
  87. package/esm/configs/types.d.ts +93 -0
  88. package/esm/configs/types.d.ts.map +1 -0
  89. package/esm/configs/types.js +3 -0
  90. package/esm/configs/types.js.map +1 -0
  91. package/esm/configs/utils.d.ts +12 -0
  92. package/esm/configs/utils.d.ts.map +1 -0
  93. package/esm/configs/utils.js +76 -0
  94. package/esm/configs/utils.js.map +1 -0
  95. package/esm/configs/waterfallChart.d.ts +109 -0
  96. package/esm/configs/waterfallChart.d.ts.map +1 -0
  97. package/esm/configs/waterfallChart.js +214 -0
  98. package/esm/configs/waterfallChart.js.map +1 -0
  99. package/esm/conts.d.ts +9 -0
  100. package/esm/conts.d.ts.map +1 -0
  101. package/esm/conts.js +41 -0
  102. package/esm/conts.js.map +1 -0
  103. package/esm/execution/buildAfmExecution.d.ts +5 -0
  104. package/esm/execution/buildAfmExecution.d.ts.map +1 -0
  105. package/esm/execution/buildAfmExecution.js +374 -0
  106. package/esm/execution/buildAfmExecution.js.map +1 -0
  107. package/esm/from/declarativeAttributeHierarchyToYaml.d.ts +12 -0
  108. package/esm/from/declarativeAttributeHierarchyToYaml.d.ts.map +1 -0
  109. package/esm/from/declarativeAttributeHierarchyToYaml.js +26 -0
  110. package/esm/from/declarativeAttributeHierarchyToYaml.js.map +1 -0
  111. package/esm/from/declarativeDashboardToYaml.d.ts +59 -0
  112. package/esm/from/declarativeDashboardToYaml.d.ts.map +1 -0
  113. package/esm/from/declarativeDashboardToYaml.js +771 -0
  114. package/esm/from/declarativeDashboardToYaml.js.map +1 -0
  115. package/esm/from/declarativeDatasetToYaml.d.ts +9 -0
  116. package/esm/from/declarativeDatasetToYaml.d.ts.map +1 -0
  117. package/esm/from/declarativeDatasetToYaml.js +239 -0
  118. package/esm/from/declarativeDatasetToYaml.js.map +1 -0
  119. package/esm/from/declarativeDateInstanceToYaml.d.ts +8 -0
  120. package/esm/from/declarativeDateInstanceToYaml.d.ts.map +1 -0
  121. package/esm/from/declarativeDateInstanceToYaml.js +30 -0
  122. package/esm/from/declarativeDateInstanceToYaml.js.map +1 -0
  123. package/esm/from/declarativeMetricToYaml.d.ts +8 -0
  124. package/esm/from/declarativeMetricToYaml.d.ts.map +1 -0
  125. package/esm/from/declarativeMetricToYaml.js +34 -0
  126. package/esm/from/declarativeMetricToYaml.js.map +1 -0
  127. package/esm/from/declarativePluginToYaml.d.ts +10 -0
  128. package/esm/from/declarativePluginToYaml.d.ts.map +1 -0
  129. package/esm/from/declarativePluginToYaml.js +26 -0
  130. package/esm/from/declarativePluginToYaml.js.map +1 -0
  131. package/esm/from/declarativeVisualisationToYaml.d.ts +64 -0
  132. package/esm/from/declarativeVisualisationToYaml.d.ts.map +1 -0
  133. package/esm/from/declarativeVisualisationToYaml.js +1513 -0
  134. package/esm/from/declarativeVisualisationToYaml.js.map +1 -0
  135. package/esm/index.d.ts +18 -0
  136. package/esm/index.d.ts.map +1 -0
  137. package/esm/index.js +22 -0
  138. package/esm/index.js.map +1 -0
  139. package/esm/schemas/types.d.ts +32 -0
  140. package/esm/schemas/types.d.ts.map +1 -0
  141. package/esm/schemas/types.js +3 -0
  142. package/esm/schemas/types.js.map +1 -0
  143. package/esm/schemas/v1/metadata.d.ts +7277 -0
  144. package/esm/schemas/v1/metadata.d.ts.map +1 -0
  145. package/esm/schemas/v1/metadata.js +3 -0
  146. package/esm/schemas/v1/metadata.js.map +1 -0
  147. package/esm/sdk-code-convertors.d.ts +7861 -0
  148. package/esm/to/yamlAttributeHierarchyToDeclarative.d.ts +5 -0
  149. package/esm/to/yamlAttributeHierarchyToDeclarative.d.ts.map +1 -0
  150. package/esm/to/yamlAttributeHierarchyToDeclarative.js +16 -0
  151. package/esm/to/yamlAttributeHierarchyToDeclarative.js.map +1 -0
  152. package/esm/to/yamlDashboardToDeclarative.d.ts +29 -0
  153. package/esm/to/yamlDashboardToDeclarative.d.ts.map +1 -0
  154. package/esm/to/yamlDashboardToDeclarative.js +732 -0
  155. package/esm/to/yamlDashboardToDeclarative.js.map +1 -0
  156. package/esm/to/yamlDatasetToDeclarative.d.ts +41 -0
  157. package/esm/to/yamlDatasetToDeclarative.d.ts.map +1 -0
  158. package/esm/to/yamlDatasetToDeclarative.js +346 -0
  159. package/esm/to/yamlDatasetToDeclarative.js.map +1 -0
  160. package/esm/to/yamlDateDatasetToDeclarative.d.ts +5 -0
  161. package/esm/to/yamlDateDatasetToDeclarative.d.ts.map +1 -0
  162. package/esm/to/yamlDateDatasetToDeclarative.js +21 -0
  163. package/esm/to/yamlDateDatasetToDeclarative.js.map +1 -0
  164. package/esm/to/yamlMetricToDeclarative.d.ts +5 -0
  165. package/esm/to/yamlMetricToDeclarative.d.ts.map +1 -0
  166. package/esm/to/yamlMetricToDeclarative.js +24 -0
  167. package/esm/to/yamlMetricToDeclarative.js.map +1 -0
  168. package/esm/to/yamlPluginToDeclarative.d.ts +5 -0
  169. package/esm/to/yamlPluginToDeclarative.d.ts.map +1 -0
  170. package/esm/to/yamlPluginToDeclarative.js +17 -0
  171. package/esm/to/yamlPluginToDeclarative.js.map +1 -0
  172. package/esm/to/yamlVisualisationToDeclarative.d.ts +31 -0
  173. package/esm/to/yamlVisualisationToDeclarative.d.ts.map +1 -0
  174. package/esm/to/yamlVisualisationToDeclarative.js +1048 -0
  175. package/esm/to/yamlVisualisationToDeclarative.js.map +1 -0
  176. package/esm/tsdoc-metadata.json +11 -0
  177. package/esm/types.d.ts +66 -0
  178. package/esm/types.d.ts.map +1 -0
  179. package/esm/types.js +22 -0
  180. package/esm/types.js.map +1 -0
  181. package/esm/utils/configUtils.d.ts +20 -0
  182. package/esm/utils/configUtils.d.ts.map +1 -0
  183. package/esm/utils/configUtils.js +312 -0
  184. package/esm/utils/configUtils.js.map +1 -0
  185. package/esm/utils/convertBucketToTitle.d.ts +116 -0
  186. package/esm/utils/convertBucketToTitle.d.ts.map +1 -0
  187. package/esm/utils/convertBucketToTitle.js +370 -0
  188. package/esm/utils/convertBucketToTitle.js.map +1 -0
  189. package/esm/utils/customUrl.d.ts +4 -0
  190. package/esm/utils/customUrl.d.ts.map +1 -0
  191. package/esm/utils/customUrl.js +31 -0
  192. package/esm/utils/customUrl.js.map +1 -0
  193. package/esm/utils/dateUtils.d.ts +5 -0
  194. package/esm/utils/dateUtils.d.ts.map +1 -0
  195. package/esm/utils/dateUtils.js +43 -0
  196. package/esm/utils/dateUtils.js.map +1 -0
  197. package/esm/utils/errors.d.ts +35 -0
  198. package/esm/utils/errors.d.ts.map +1 -0
  199. package/esm/utils/errors.js +65 -0
  200. package/esm/utils/errors.js.map +1 -0
  201. package/esm/utils/filterUtils.d.ts +3 -0
  202. package/esm/utils/filterUtils.d.ts.map +1 -0
  203. package/esm/utils/filterUtils.js +26 -0
  204. package/esm/utils/filterUtils.js.map +1 -0
  205. package/esm/utils/granularityUtils.d.ts +17 -0
  206. package/esm/utils/granularityUtils.d.ts.map +1 -0
  207. package/esm/utils/granularityUtils.js +1434 -0
  208. package/esm/utils/granularityUtils.js.map +1 -0
  209. package/esm/utils/locationUtils.d.ts +11 -0
  210. package/esm/utils/locationUtils.d.ts.map +1 -0
  211. package/esm/utils/locationUtils.js +75 -0
  212. package/esm/utils/locationUtils.js.map +1 -0
  213. package/esm/utils/nameUtils.d.ts +7 -0
  214. package/esm/utils/nameUtils.d.ts.map +1 -0
  215. package/esm/utils/nameUtils.js +37 -0
  216. package/esm/utils/nameUtils.js.map +1 -0
  217. package/esm/utils/permissionUtils.d.ts +29 -0
  218. package/esm/utils/permissionUtils.d.ts.map +1 -0
  219. package/esm/utils/permissionUtils.js +82 -0
  220. package/esm/utils/permissionUtils.js.map +1 -0
  221. package/esm/utils/sharedUtils.d.ts +21 -0
  222. package/esm/utils/sharedUtils.d.ts.map +1 -0
  223. package/esm/utils/sharedUtils.js +63 -0
  224. package/esm/utils/sharedUtils.js.map +1 -0
  225. package/esm/utils/texts.d.ts +8 -0
  226. package/esm/utils/texts.d.ts.map +1 -0
  227. package/esm/utils/texts.js +47 -0
  228. package/esm/utils/texts.js.map +1 -0
  229. package/esm/utils/typeGuards.d.ts +51 -0
  230. package/esm/utils/typeGuards.d.ts.map +1 -0
  231. package/esm/utils/typeGuards.js +286 -0
  232. package/esm/utils/typeGuards.js.map +1 -0
  233. package/esm/utils/yamlUtils.d.ts +28 -0
  234. package/esm/utils/yamlUtils.d.ts.map +1 -0
  235. package/esm/utils/yamlUtils.js +163 -0
  236. package/esm/utils/yamlUtils.js.map +1 -0
  237. package/package.json +74 -0
@@ -0,0 +1,1513 @@
1
+ // (C) 2023-2026 GoodData Corporation
2
+ import { Document, Pair, YAMLMap, YAMLSeq } from "yaml";
3
+ import { filterAttributeElements, filterObjRef, getAttributeElementsItems, isAbsoluteDateFilter, isArithmeticMeasureDefinition, isAttribute, isAttributeElementsByValue, isAttributeLocator, isAttributeSort, isBucket, isComparisonCondition, isDateFilter, isFilter, isInlineMeasureDefinition, isInsight, isLocalIdRef, isMeasure, isMeasureDefinition, isMeasureLocator, isMeasureSort, isMeasureValueFilter, isNegativeAttributeFilter, isPoPMeasureDefinition, isPositiveAttributeFilter, isPreviousPeriodMeasureDefinition, isRangeCondition, isRankingFilter, isRelativeDateFilter, isTotalLocator, serializeObjRef, } from "@gooddata/sdk-model";
4
+ import { areaChart } from "../configs/areaChart.js";
5
+ import { barChart } from "../configs/barChart.js";
6
+ import { bubbleChart } from "../configs/bubbleChart.js";
7
+ import { bulletChart } from "../configs/bulletChart.js";
8
+ import { columnChart } from "../configs/columnChart.js";
9
+ import { comboChart } from "../configs/comboChart.js";
10
+ import { dependencyWheelChart } from "../configs/dependencyWheelChart.js";
11
+ import { donutChart } from "../configs/donutChart.js";
12
+ import { funnelChart } from "../configs/funnelChart.js";
13
+ import { geoAreaChart } from "../configs/geoAreaChart.js";
14
+ import { geoChart } from "../configs/geoChart.js";
15
+ import { headlineChart } from "../configs/headlineChart.js";
16
+ import { heatmapChart } from "../configs/heatmapChart.js";
17
+ import { lineChart } from "../configs/lineChart.js";
18
+ import { pieChart } from "../configs/pieChart.js";
19
+ import { pyramidChart } from "../configs/pyramidChart.js";
20
+ import { repeaterChart } from "../configs/repeaterChart.js";
21
+ import { sankeyChart } from "../configs/sankeyChart.js";
22
+ import { scatterChart } from "../configs/scatterChart.js";
23
+ import { table } from "../configs/table.js";
24
+ import { treemapChart } from "../configs/treemapChart.js";
25
+ import { waterfallChart } from "../configs/waterfallChart.js";
26
+ import { BucketsType } from "../types.js";
27
+ import { CoreErrorCode, newError } from "../utils/errors.js";
28
+ import { parseDateValues } from "../utils/filterUtils.js";
29
+ import { parseGranularity } from "../utils/granularityUtils.js";
30
+ import { remapLocationAttribute } from "../utils/locationUtils.js";
31
+ import { VISUALISATION_COMMENT } from "../utils/texts.js";
32
+ import { cleanUpItems, createFilterItemKeyName, entryWithSpace, fillOptionalMetaFields, getIdentifier, } from "../utils/yamlUtils.js";
33
+ /** @public */
34
+ export function declarativeVisualisationToYaml(entities, visualisation) {
35
+ // Build visualisation object
36
+ const insight = { insight: visualisation.content };
37
+ if (!isInsight(insight)) {
38
+ throw newError(CoreErrorCode.VisualizationNotSupported, [JSON.stringify(insight)]);
39
+ }
40
+ // Load type
41
+ const type = declarativeVisTypeToYaml(insight.insight);
42
+ if (!type) {
43
+ return {
44
+ content: "",
45
+ };
46
+ }
47
+ // Create new doc and add mandatory fields right away
48
+ const doc = new Document({
49
+ type,
50
+ id: visualisation.id,
51
+ });
52
+ // Add intro comment to the document
53
+ doc.commentBefore = VISUALISATION_COMMENT;
54
+ // Add optional meta fields
55
+ fillOptionalMetaFields(doc, visualisation);
56
+ // Add visibility flag only when hidden
57
+ if (visualisation.isHidden === true) {
58
+ doc.add(doc.createPair("show_in_ai_results", false));
59
+ }
60
+ const report = declarativeReportToYaml(entities, insight.insight);
61
+ doc.add(entryWithSpace("query", report.report));
62
+ declarativeVisToYaml(doc, insight.insight, report, entities);
63
+ return {
64
+ content: doc.toString({
65
+ lineWidth: 0,
66
+ }),
67
+ json: doc.toJSON(),
68
+ };
69
+ }
70
+ function declarativeReportToYaml(entities, def) {
71
+ const report = new YAMLMap();
72
+ const { fieldsMap, postProcessors, groups: derivedBuckets, } = declarativeBucketsToYaml(entities, def.buckets);
73
+ appendLayerFieldsToReport(fieldsMap, postProcessors, entities, def.layers);
74
+ if (fieldsMap.items.length > 0) {
75
+ report.add(new Pair("fields", fieldsMap));
76
+ }
77
+ const { filtersArray, filtersMap } = declarativeFiltersToYaml(entities, def.filters ?? []);
78
+ declarativeFiltersConfigToYaml(def, filtersMap);
79
+ if (filtersArray.items.length > 0) {
80
+ report.add(entryWithSpace("filter_by", filtersArray));
81
+ }
82
+ const { sortsArray } = declarativeSortsToYaml(def.sorts ?? []);
83
+ if (sortsArray.length > 0) {
84
+ report.add(entryWithSpace("sort_by", sortsArray));
85
+ }
86
+ postProcessors.filters?.forEach(({ filters, item }) => {
87
+ const { filtersArray, filtersMap } = declarativeFiltersToYaml(entities, filters);
88
+ declarativeFiltersConfigToYaml(def, filtersMap);
89
+ if (filtersArray.items.length > 0) {
90
+ item.add(new Pair("filter_by", filtersArray));
91
+ }
92
+ });
93
+ return {
94
+ report,
95
+ derivedBuckets,
96
+ };
97
+ }
98
+ function appendLayerFieldsToReport(fieldsMap, postProcessors, entities, layers) {
99
+ if (!layers || layers.length === 0) {
100
+ return;
101
+ }
102
+ const knownKeys = new Set(fieldsMap.items
103
+ .map((pair) => getPairKeyValue(pair))
104
+ .filter((key) => typeof key === "string" && key.length > 0));
105
+ layers.forEach((layer) => {
106
+ const { fieldsMap: layerFieldsMap, postProcessors: layerPostProcessors } = declarativeBucketsToYaml(entities, layer.buckets ?? []);
107
+ const valueMapping = new Map();
108
+ layerFieldsMap.items.forEach((pair) => {
109
+ const keyValue = getPairKeyValue(pair);
110
+ if (!keyValue) {
111
+ return;
112
+ }
113
+ let targetValue;
114
+ if (knownKeys.has(keyValue)) {
115
+ targetValue = fieldsMap.get(keyValue, true);
116
+ }
117
+ else {
118
+ knownKeys.add(keyValue);
119
+ const clonedPair = pair.clone(fieldsMap.schema);
120
+ fieldsMap.add(clonedPair);
121
+ targetValue = clonedPair.value;
122
+ }
123
+ if (pair.value instanceof YAMLMap && targetValue instanceof YAMLMap) {
124
+ valueMapping.set(pair.value, targetValue);
125
+ }
126
+ });
127
+ layerPostProcessors.filters.forEach((filterEntry) => {
128
+ const mappedItem = valueMapping.get(filterEntry.item);
129
+ if (mappedItem) {
130
+ postProcessors.filters.push({
131
+ item: mappedItem,
132
+ filters: filterEntry.filters,
133
+ });
134
+ }
135
+ });
136
+ });
137
+ }
138
+ function getPairKeyValue(pair) {
139
+ if (!pair) {
140
+ return undefined;
141
+ }
142
+ if (typeof pair.key === "string") {
143
+ return pair.key;
144
+ }
145
+ const key = pair.key;
146
+ if (key && typeof key.value === "string") {
147
+ return key.value;
148
+ }
149
+ return undefined;
150
+ }
151
+ export function declarativeFiltersConfigToYaml(insight, filtersMap) {
152
+ Object.keys(insight.attributeFilterConfigs ?? {}).forEach((key) => {
153
+ const filter = filtersMap[key];
154
+ if (filter) {
155
+ let localIdentifier = undefined;
156
+ if (isPositiveAttributeFilter(filter.filter) || isNegativeAttributeFilter(filter.filter)) {
157
+ localIdentifier = isPositiveAttributeFilter(filter.filter)
158
+ ? filter.filter.positiveAttributeFilter.localIdentifier
159
+ : filter.filter.negativeAttributeFilter.localIdentifier;
160
+ }
161
+ if (localIdentifier) {
162
+ if (insight.attributeFilterConfigs[localIdentifier].displayAsLabel) {
163
+ filter.yaml.add(new Pair("display_as", getIdentifier(insight.attributeFilterConfigs[localIdentifier].displayAsLabel)));
164
+ }
165
+ }
166
+ }
167
+ });
168
+ }
169
+ export function declarativeVisTypeToYaml(def) {
170
+ switch (def.visualizationUrl) {
171
+ case "local:table":
172
+ return "table";
173
+ case "local:bar":
174
+ return "bar_chart";
175
+ case "local:column":
176
+ return "column_chart";
177
+ case "local:line":
178
+ return "line_chart";
179
+ case "local:area":
180
+ return "area_chart";
181
+ case "local:scatter":
182
+ return "scatter_chart";
183
+ case "local:bubble":
184
+ return "bubble_chart";
185
+ case "local:pie":
186
+ return "pie_chart";
187
+ case "local:donut":
188
+ return "donut_chart";
189
+ case "local:treemap":
190
+ return "treemap_chart";
191
+ case "local:pyramid":
192
+ return "pyramid_chart";
193
+ case "local:funnel":
194
+ return "funnel_chart";
195
+ case "local:heatmap":
196
+ return "heatmap_chart";
197
+ case "local:bullet":
198
+ return "bullet_chart";
199
+ case "local:waterfall":
200
+ return "waterfall_chart";
201
+ case "local:dependencywheel":
202
+ return "dependency_wheel_chart";
203
+ case "local:sankey":
204
+ return "sankey_chart";
205
+ case "local:headline":
206
+ return "headline_chart";
207
+ case "local:combo2":
208
+ return "combo_chart";
209
+ case "local:pushpin":
210
+ return "geo_chart";
211
+ case "local:choropleth":
212
+ return "geo_area_chart";
213
+ case "local:repeater":
214
+ return "repeater_chart";
215
+ default:
216
+ return null;
217
+ }
218
+ }
219
+ function declarativeVisToYaml(doc, def, report, entities) {
220
+ switch (def.visualizationUrl) {
221
+ case "local:table":
222
+ declarativeVisTableToYaml(doc, def, report);
223
+ break;
224
+ case "local:bar":
225
+ declarativeVisBarToYaml(doc, def, report);
226
+ break;
227
+ case "local:column":
228
+ declarativeVisColumnToYaml(doc, def, report);
229
+ break;
230
+ case "local:line":
231
+ declarativeVisLineToYaml(doc, def, report);
232
+ break;
233
+ case "local:area":
234
+ declarativeVisAreaToYaml(doc, def, report);
235
+ break;
236
+ case "local:scatter":
237
+ declarativeVisScatterToYaml(doc, def, report);
238
+ break;
239
+ case "local:bubble":
240
+ declarativeVisBubbleToYaml(doc, def, report);
241
+ break;
242
+ case "local:pie":
243
+ declarativeVisPieToYaml(doc, def, report);
244
+ break;
245
+ case "local:donut":
246
+ declarativeVisDonutToYaml(doc, def, report);
247
+ break;
248
+ case "local:treemap":
249
+ declarativeVisTreemapToYaml(doc, def, report);
250
+ break;
251
+ case "local:pyramid":
252
+ declarativeVisPyramidToYaml(doc, def, report);
253
+ break;
254
+ case "local:funnel":
255
+ declarativeVisFunnelToYaml(doc, def, report);
256
+ break;
257
+ case "local:heatmap":
258
+ declarativeVisHeatmapToYaml(doc, def, report);
259
+ break;
260
+ case "local:bullet":
261
+ declarativeVisBulletToYaml(doc, def, report);
262
+ break;
263
+ case "local:waterfall":
264
+ declarativeVisWaterfallToYaml(doc, def, report);
265
+ break;
266
+ case "local:dependencywheel":
267
+ declarativeVisDependencyWheelToYaml(doc, def, report);
268
+ break;
269
+ case "local:sankey":
270
+ declarativeVisSankeyToYaml(doc, def, report);
271
+ break;
272
+ case "local:headline":
273
+ declarativeVisHeadlineToYaml(doc, def, report);
274
+ break;
275
+ case "local:combo2":
276
+ declarativeVisComboToYaml(doc, def, report);
277
+ break;
278
+ case "local:pushpin":
279
+ declarativeVisGeoToYaml(doc, def, report, entities);
280
+ break;
281
+ case "local:choropleth":
282
+ declarativeVisGeoAreaToYaml(doc, def, report, entities);
283
+ break;
284
+ case "local:repeater":
285
+ declarativeVisRepeaterToYaml(doc, def, report);
286
+ break;
287
+ default:
288
+ break;
289
+ }
290
+ }
291
+ export function declarativeBucketsToYaml(entities, buckets) {
292
+ const fullFieldsMap = new YAMLMap();
293
+ const groups = [];
294
+ const postProcessors = {
295
+ filters: [],
296
+ };
297
+ const addField = (local, def, group, { format, axis } = {}) => {
298
+ fullFieldsMap.add(new Pair(local, def));
299
+ group.items.push(createBucketGroupItem(local, format, axis));
300
+ };
301
+ //create buckets
302
+ buckets.forEach((bucket) => {
303
+ if (isBucket(bucket)) {
304
+ const group = { items: [], type: bucket.localIdentifier };
305
+ const attributesMap = {};
306
+ const isLocation = bucket.localIdentifier === BucketsType.Location;
307
+ //items
308
+ bucket.items.forEach((item) => {
309
+ if (isAttribute(item) && isLocation) {
310
+ const remapped = remapLocationAttribute(entities, item);
311
+ const def = declarativeAttributeToYaml(remapped.attribute);
312
+ addField(item.attribute.localIdentifier, def, group);
313
+ attributesMap[item.attribute.localIdentifier] = def;
314
+ return;
315
+ }
316
+ if (isAttribute(item)) {
317
+ const def = declarativeAttributeToYaml(item.attribute);
318
+ addField(item.attribute.localIdentifier, def, group);
319
+ attributesMap[item.attribute.localIdentifier] = def;
320
+ return;
321
+ }
322
+ if (isMeasure(item) && isInlineMeasureDefinition(item.measure.definition)) {
323
+ const def = declarativeInlineMetricToYaml(item.measure, item.measure.definition);
324
+ addField(item.measure.localIdentifier, def, group, { format: item.measure.format });
325
+ attributesMap[item.measure.localIdentifier] = def;
326
+ return;
327
+ }
328
+ if (isMeasure(item) && isMeasureDefinition(item.measure.definition)) {
329
+ const def = declarativeNormalMetricToYaml(item.measure, item.measure.definition, postProcessors);
330
+ addField(item.measure.localIdentifier, def, group, { format: item.measure.format });
331
+ attributesMap[item.measure.localIdentifier] = def;
332
+ return;
333
+ }
334
+ if (isMeasure(item) && isArithmeticMeasureDefinition(item.measure.definition)) {
335
+ const def = declarativeArithmeticMetricToYaml(item.measure, item.measure.definition);
336
+ addField(item.measure.localIdentifier, def, group, { format: item.measure.format });
337
+ attributesMap[item.measure.localIdentifier] = def;
338
+ return;
339
+ }
340
+ if (isMeasure(item) && isPoPMeasureDefinition(item.measure.definition)) {
341
+ const def = declarativePoPMetricToYaml(item.measure, item.measure.definition);
342
+ addField(item.measure.localIdentifier, def, group, { format: item.measure.format });
343
+ attributesMap[item.measure.localIdentifier] = def;
344
+ return;
345
+ }
346
+ if (isMeasure(item) && isPreviousPeriodMeasureDefinition(item.measure.definition)) {
347
+ const def = declarativePreviousPeriodMetricToYaml(item.measure, item.measure.definition);
348
+ addField(item.measure.localIdentifier, def, group, { format: item.measure.format });
349
+ attributesMap[item.measure.localIdentifier] = def;
350
+ return;
351
+ }
352
+ throw newError(CoreErrorCode.BucketItemTypeNotSupported, [JSON.stringify(item)]);
353
+ });
354
+ //totals
355
+ bucket.totals?.forEach((total) => {
356
+ const { totalMap, attribute } = declarativeTotalToYaml(total);
357
+ const item = group.items.find((item) => item?.field === attribute);
358
+ if (item) {
359
+ item.totals = [...(item.totals ?? []), totalMap];
360
+ }
361
+ });
362
+ groups.push(group);
363
+ }
364
+ });
365
+ //try shortened fields
366
+ const fieldsMap = new YAMLMap();
367
+ fullFieldsMap.items.forEach((item) => {
368
+ const shortened = getShortenedBucket(item.value);
369
+ const hasFilters = postProcessors.filters.find((fi) => fi.item === item.value);
370
+ //NOTE: If shortened form is available and item has no filters to post process
371
+ // use shortened version of the item
372
+ if (shortened && !hasFilters) {
373
+ fieldsMap.add(new Pair(item.key, shortened));
374
+ }
375
+ else {
376
+ fieldsMap.add(item);
377
+ }
378
+ });
379
+ return {
380
+ fieldsMap,
381
+ groups,
382
+ postProcessors,
383
+ };
384
+ }
385
+ export function declarativeAttributeToYaml(def) {
386
+ const map = new YAMLMap();
387
+ if (def.alias) {
388
+ map.add(new Pair("title", def.alias));
389
+ }
390
+ const id = getIdentifier(def.displayForm);
391
+ map.add(new Pair("using", id));
392
+ if (def.showAllValues) {
393
+ map.add(new Pair("show_all_values", true));
394
+ }
395
+ return map;
396
+ }
397
+ export function declarativeInlineMetricToYaml(def, inlineDef) {
398
+ const map = new YAMLMap();
399
+ fillDefaultMetricProperties(map, def);
400
+ const id = inlineDef.inlineDefinition;
401
+ map.add(new Pair("maql", id.maql));
402
+ return map;
403
+ }
404
+ export function declarativeNormalMetricToYaml(def, metricDefinition, postProcessors) {
405
+ const map = new YAMLMap();
406
+ fillDefaultMetricProperties(map, def);
407
+ const md = metricDefinition.measureDefinition;
408
+ if (md.aggregation) {
409
+ map.add(new Pair("aggregation", md.aggregation.toUpperCase()));
410
+ }
411
+ if (md.computeRatio) {
412
+ map.add(new Pair("compute_ratio", md.computeRatio));
413
+ }
414
+ if (md.filters && md.filters.length > 0) {
415
+ postProcessors.filters.push({ item: map, filters: md.filters });
416
+ }
417
+ const id = getIdentifier(md.item);
418
+ map.add(new Pair("using", id));
419
+ return map;
420
+ }
421
+ export function declarativeArithmeticMetricToYaml(def, arithmeticDefinition) {
422
+ const map = new YAMLMap();
423
+ fillDefaultMetricProperties(map, def);
424
+ const ad = arithmeticDefinition.arithmeticMeasure;
425
+ map.add(new Pair("operator", ad.operator.toUpperCase()));
426
+ map.add(new Pair("using", ad.measureIdentifiers));
427
+ return map;
428
+ }
429
+ export function declarativePoPMetricToYaml(def, popDefinition) {
430
+ const map = new YAMLMap();
431
+ fillDefaultMetricProperties(map, def);
432
+ const pop = popDefinition.popMeasureDefinition;
433
+ const id = getIdentifier(pop.popAttribute, true);
434
+ const [date] = id.split(".");
435
+ map.add(new Pair("type", "PREVIOUS_YEAR"));
436
+ map.add(new Pair("date_filter", date));
437
+ map.add(new Pair("using", pop.measureIdentifier));
438
+ return map;
439
+ }
440
+ export function declarativePreviousPeriodMetricToYaml(def, previousDefinition) {
441
+ const map = new YAMLMap();
442
+ fillDefaultMetricProperties(map, def);
443
+ const previous = previousDefinition.previousPeriodMeasure;
444
+ if (previous.dateDataSets.length > 1) {
445
+ throw newError(CoreErrorCode.MultipleDateDataSets, [JSON.stringify(previous)]);
446
+ }
447
+ const prev = previous.dateDataSets[0];
448
+ const id = getIdentifier(prev.dataSet, true);
449
+ const [date] = id.split(".");
450
+ map.add(new Pair("type", "PREVIOUS_PERIOD"));
451
+ if (prev.periodsAgo > 1) {
452
+ map.add(new Pair("period", prev.periodsAgo));
453
+ }
454
+ map.add(new Pair("date_filter", date));
455
+ map.add(new Pair("using", previous.measureIdentifier));
456
+ return map;
457
+ }
458
+ function fillDefaultMetricProperties(map, def) {
459
+ if (def.alias) {
460
+ map.add(new Pair("title", def.alias));
461
+ }
462
+ //NOTE: Title is skipped because is generated by client automatically, do not use it in code
463
+ }
464
+ function createBucketGroupItem(field, format, axis) {
465
+ return {
466
+ field,
467
+ ...(format ? { format } : {}),
468
+ ...(axis ? { axis } : {}),
469
+ };
470
+ }
471
+ function getShortenedBucket(def) {
472
+ if (def.items.length === 1) {
473
+ const item = def.items[0];
474
+ if (["using"].includes(item.key)) {
475
+ return item.value;
476
+ }
477
+ }
478
+ return false;
479
+ }
480
+ function detectEmptyValuesFilterType(filter) {
481
+ const attributeElements = filterAttributeElements(filter);
482
+ const items = attributeElements ? getAttributeElementsItems(attributeElements) : [];
483
+ if (items.length !== 1 || items[0] !== "") {
484
+ return undefined;
485
+ }
486
+ return isPositiveAttributeFilter(filter) ? "only" : "exclude";
487
+ }
488
+ function getObjRefGroupingKey(objRef) {
489
+ if (!objRef || typeof objRef !== "object") {
490
+ return undefined;
491
+ }
492
+ if ("identifier" in objRef) {
493
+ const identifier = objRef.identifier;
494
+ if (typeof identifier === "string") {
495
+ return identifier;
496
+ }
497
+ if (identifier && typeof identifier === "object" && "id" in identifier) {
498
+ const id = identifier.id;
499
+ if (typeof id === "string") {
500
+ return id;
501
+ }
502
+ }
503
+ }
504
+ if ("uri" in objRef) {
505
+ const uri = objRef.uri;
506
+ if (typeof uri === "string") {
507
+ return uri;
508
+ }
509
+ }
510
+ if ("localIdentifier" in objRef) {
511
+ const localIdentifier = objRef.localIdentifier;
512
+ if (typeof localIdentifier === "string") {
513
+ return localIdentifier;
514
+ }
515
+ }
516
+ return serializeObjRef(objRef);
517
+ }
518
+ /**
519
+ * Groups date filters with their associated attribute filters. Leaves the rest alone.
520
+ * @param filters
521
+ */
522
+ function groupFiltersByDateFilter(filters) {
523
+ const dateFilters = [...filters].filter(isDateFilter);
524
+ const nonDateFilters = [...filters].filter((f) => !isDateFilter(f));
525
+ const result = { grouped: {}, rest: [] };
526
+ const getFilterRefDetails = (filter) => {
527
+ const objRef = filterObjRef(filter);
528
+ if (!objRef) {
529
+ return {
530
+ objRef: undefined,
531
+ filterRef: undefined,
532
+ };
533
+ }
534
+ return {
535
+ objRef,
536
+ filterRef: getObjRefGroupingKey(objRef),
537
+ };
538
+ };
539
+ dateFilters.forEach((dateFilter) => {
540
+ const { filterRef: datasetId } = getFilterRefDetails(dateFilter);
541
+ if (datasetId === undefined) {
542
+ result.rest.push(dateFilter);
543
+ return;
544
+ }
545
+ if (result.grouped[datasetId]) {
546
+ result.rest.push(dateFilter);
547
+ }
548
+ else {
549
+ result.grouped[datasetId] = { dateFilter, attributeFilters: [] };
550
+ }
551
+ });
552
+ nonDateFilters.forEach((filter) => {
553
+ const { filterRef: filterId } = getFilterRefDetails(filter);
554
+ if (filterId === undefined) {
555
+ result.rest.push(filter);
556
+ return;
557
+ }
558
+ const datasetId = filterId.split(".")[0];
559
+ const group = result.grouped[datasetId];
560
+ if (group) {
561
+ group.attributeFilters.push(filter);
562
+ }
563
+ else {
564
+ result.rest.push(filter);
565
+ }
566
+ });
567
+ return result;
568
+ }
569
+ export function declarativeFiltersToYaml(entities, filters) {
570
+ const filtersArray = [];
571
+ const filtersMap = new YAMLMap();
572
+ const usedKeys = new Set();
573
+ const getUniqueKey = (baseKey) => {
574
+ let key = baseKey;
575
+ let suffix = 2;
576
+ while (usedKeys.has(key)) {
577
+ key = `${baseKey}_${suffix}`;
578
+ suffix += 1;
579
+ }
580
+ usedKeys.add(key);
581
+ return key;
582
+ };
583
+ const filtersGroupedByDateFilter = groupFiltersByDateFilter(filters);
584
+ filtersGroupedByDateFilter.rest.forEach((filter) => {
585
+ const result = declarativeFilterToYaml(entities, filter, getUniqueKey);
586
+ if (!result) {
587
+ return;
588
+ }
589
+ const { key, yaml, filter: originalFilter } = result;
590
+ filtersArray.push(new Pair(key, yaml));
591
+ filtersMap[key] = {
592
+ yaml,
593
+ filter: originalFilter,
594
+ };
595
+ });
596
+ Object.values(filtersGroupedByDateFilter.grouped).forEach(({ dateFilter, attributeFilters }) => {
597
+ const result = declarativeFilterToYaml(entities, dateFilter, getUniqueKey, attributeFilters);
598
+ if (!result) {
599
+ return;
600
+ }
601
+ const { key, yaml, filter: originalFilter } = result;
602
+ filtersArray.push(new Pair(key, yaml));
603
+ filtersMap[key] = {
604
+ yaml,
605
+ filter: originalFilter,
606
+ };
607
+ });
608
+ return {
609
+ filtersMap,
610
+ filtersArray: filtersArray.reduce((map, filter) => {
611
+ map.add(filter);
612
+ return map;
613
+ }, new YAMLMap()),
614
+ };
615
+ }
616
+ function declarativeFilterToYaml(entities, filter, getUniqueKey, connectedAttributeFilters) {
617
+ if (!isFilter(filter)) {
618
+ return null;
619
+ }
620
+ const key = getUniqueKey(createFilterItemKeyName(filter));
621
+ if (isAbsoluteDateFilter(filter)) {
622
+ return {
623
+ key,
624
+ yaml: declarativeAbsoluteDateFilterToYaml(filter.absoluteDateFilter, connectedAttributeFilters, entities, getUniqueKey),
625
+ filter,
626
+ };
627
+ }
628
+ if (isRelativeDateFilter(filter)) {
629
+ return {
630
+ key,
631
+ yaml: declarativeRelativeDateFilterToYaml(filter.relativeDateFilter, connectedAttributeFilters, entities, getUniqueKey),
632
+ filter,
633
+ };
634
+ }
635
+ if (isPositiveAttributeFilter(filter)) {
636
+ return {
637
+ key,
638
+ yaml: declarativePositiveAttributeFilterToYaml(entities, filter.positiveAttributeFilter),
639
+ filter,
640
+ };
641
+ }
642
+ if (isNegativeAttributeFilter(filter)) {
643
+ return {
644
+ key,
645
+ yaml: declarativeNegativeAttributeFilterToYaml(entities, filter.negativeAttributeFilter),
646
+ filter,
647
+ };
648
+ }
649
+ if (isMeasureValueFilter(filter)) {
650
+ return {
651
+ key,
652
+ yaml: declarativeMeasureValueFilterToYaml(filter.measureValueFilter),
653
+ filter,
654
+ };
655
+ }
656
+ if (isRankingFilter(filter)) {
657
+ return {
658
+ key,
659
+ yaml: declarativeRankingFilterToYaml(filter.rankingFilter),
660
+ filter,
661
+ };
662
+ }
663
+ throw newError(CoreErrorCode.FilterItemTypeNotSupported, [JSON.stringify(filter)]);
664
+ }
665
+ /**
666
+ * Modifies `map`, adding `empty_filters` and `with` keys, populated from connectedAttributeFilters.
667
+ */
668
+ function processConnectedAttributeFilters(map, connectedAttributeFilters, entities, getUniqueKey) {
669
+ // empty values filter
670
+ const emptyValuesFilter = connectedAttributeFilters.find((filter) => detectEmptyValuesFilterType(filter));
671
+ if (emptyValuesFilter) {
672
+ map.add(new Pair("empty_values", detectEmptyValuesFilterType(emptyValuesFilter)));
673
+ }
674
+ // additional attribute filters
675
+ const additionalAttributeFilters = connectedAttributeFilters.filter((filter) => filter !== emptyValuesFilter);
676
+ if (additionalAttributeFilters.length === 0) {
677
+ return;
678
+ }
679
+ const withMap = new YAMLMap();
680
+ map.add(new Pair("with", withMap));
681
+ additionalAttributeFilters?.forEach((filter) => {
682
+ const converted = declarativeFilterToYaml(entities, filter, getUniqueKey);
683
+ if (!converted) {
684
+ return;
685
+ }
686
+ withMap.add(new Pair(converted.key, converted.yaml));
687
+ });
688
+ }
689
+ export function declarativeAbsoluteDateFilterToYaml(absoluteDateFilter, connectedAttributeFilters = [], entities, getUniqueKey) {
690
+ const map = new YAMLMap();
691
+ // base date filter attributes
692
+ map.add(new Pair("type", "date_filter"));
693
+ map.add(new Pair("from", absoluteDateFilter.from));
694
+ map.add(new Pair("to", absoluteDateFilter.to));
695
+ const id = getIdentifier(absoluteDateFilter.dataSet, true);
696
+ map.add(new Pair("using", id));
697
+ // connected attribute filters
698
+ processConnectedAttributeFilters(map, connectedAttributeFilters, entities, getUniqueKey);
699
+ return map;
700
+ }
701
+ function isRelativeDateFilterAllTime(relativeDateFilter) {
702
+ const { granularity, from, to } = relativeDateFilter;
703
+ // This should be enough to tell the type is IRelativeDateFilterAllTimeBody
704
+ if (granularity === "ALL_TIME_GRANULARITY") {
705
+ return true;
706
+ }
707
+ // But unfortunately AD emits granularity as GDC.time.year for an all time date filter, so we need this check as well
708
+ return granularity === "GDC.time.year" && from === undefined && to === undefined;
709
+ }
710
+ export function declarativeRelativeDateFilterToYaml(relativeDateFilter, connectedAttributeFilters = [], entities, getUniqueKey) {
711
+ const map = new YAMLMap();
712
+ map.add(new Pair("type", "date_filter"));
713
+ if (isRelativeDateFilterAllTime(relativeDateFilter)) {
714
+ // Do not add anything
715
+ }
716
+ else {
717
+ // Add granularity
718
+ if (relativeDateFilter.granularity) {
719
+ map.add(new Pair("granularity", parseGranularity(relativeDateFilter.granularity)));
720
+ }
721
+ // Add from/to only if both are defined
722
+ if (relativeDateFilter.from !== undefined && relativeDateFilter.to !== undefined) {
723
+ map.add(new Pair("from", relativeDateFilter.from));
724
+ map.add(new Pair("to", relativeDateFilter.to));
725
+ }
726
+ }
727
+ const id = getIdentifier(relativeDateFilter.dataSet, true);
728
+ map.add(new Pair("using", id));
729
+ processConnectedAttributeFilters(map, connectedAttributeFilters, entities, getUniqueKey);
730
+ return map;
731
+ }
732
+ export function declarativePositiveAttributeFilterToYaml(entities, attributeFilter) {
733
+ const map = new YAMLMap();
734
+ map.add(new Pair("type", "attribute_filter"));
735
+ const id = getIdentifier(attributeFilter.displayForm);
736
+ map.add(new Pair("using", id));
737
+ if (isAttributeElementsByValue(attributeFilter.in)) {
738
+ const ind = attributeFilter.in;
739
+ // Filter out null/undefined but preserve empty strings which are valid attribute values
740
+ const values = ind.values.filter((v) => v !== null && v !== undefined);
741
+ map.add(new Pair("state", new Pair("include", parseDateValues(entities, id, values))));
742
+ }
743
+ return map;
744
+ }
745
+ export function declarativeNegativeAttributeFilterToYaml(entities, attributeFilter) {
746
+ const map = new YAMLMap();
747
+ map.add(new Pair("type", "attribute_filter"));
748
+ const id = getIdentifier(attributeFilter.displayForm);
749
+ map.add(new Pair("using", id));
750
+ if (isAttributeElementsByValue(attributeFilter.notIn)) {
751
+ const ind = attributeFilter.notIn;
752
+ // Filter out null/undefined but preserve empty strings which are valid attribute values
753
+ const values = ind.values.filter((v) => v !== null && v !== undefined);
754
+ if (values.length > 0) {
755
+ map.add(new Pair("state", new Pair("exclude", parseDateValues(entities, id, values))));
756
+ }
757
+ }
758
+ return map;
759
+ }
760
+ function addSingleConditionToYaml(map, condition) {
761
+ if (isComparisonCondition(condition)) {
762
+ const comp = condition.comparison;
763
+ map.add(new Pair("condition", comp.operator.toUpperCase()));
764
+ map.add(new Pair("value", comp.value));
765
+ map.add(new Pair("null_values_as_zero", comp.treatNullValuesAs !== undefined));
766
+ }
767
+ else if (isRangeCondition(condition)) {
768
+ const range = condition.range;
769
+ map.add(new Pair("condition", range.operator.toUpperCase()));
770
+ map.add(new Pair("from", range.from));
771
+ map.add(new Pair("to", range.to));
772
+ map.add(new Pair("null_values_as_zero", range.treatNullValuesAs !== undefined));
773
+ }
774
+ }
775
+ function addConditionToYamlMap(conditionMap, condition) {
776
+ let hasTreatNullValues = false;
777
+ if (isComparisonCondition(condition)) {
778
+ const comp = condition.comparison;
779
+ conditionMap.add(new Pair("condition", comp.operator.toUpperCase()));
780
+ conditionMap.add(new Pair("value", comp.value));
781
+ if (comp.treatNullValuesAs !== undefined) {
782
+ hasTreatNullValues = true;
783
+ }
784
+ }
785
+ else if (isRangeCondition(condition)) {
786
+ const range = condition.range;
787
+ conditionMap.add(new Pair("condition", range.operator.toUpperCase()));
788
+ conditionMap.add(new Pair("from", range.from));
789
+ conditionMap.add(new Pair("to", range.to));
790
+ if (range.treatNullValuesAs !== undefined) {
791
+ hasTreatNullValues = true;
792
+ }
793
+ }
794
+ return hasTreatNullValues;
795
+ }
796
+ export function declarativeMeasureValueFilterToYaml(measureValueFilter) {
797
+ const map = new YAMLMap();
798
+ map.add(new Pair("type", "metric_value_filter"));
799
+ if (isLocalIdRef(measureValueFilter.measure)) {
800
+ map.add(new Pair("using", measureValueFilter.measure.localIdentifier));
801
+ }
802
+ else {
803
+ map.add(new Pair("using", getIdentifier(measureValueFilter.measure)));
804
+ }
805
+ // Handle multiple conditions (new SDK model feature)
806
+ if (measureValueFilter.conditions && measureValueFilter.conditions.length > 1) {
807
+ // Multiple conditions: use conditions array
808
+ const conditionsSeq = new YAMLSeq();
809
+ let treatNullValuesAsZero = false;
810
+ measureValueFilter.conditions.forEach((cond) => {
811
+ const conditionMap = new YAMLMap();
812
+ if (addConditionToYamlMap(conditionMap, cond)) {
813
+ treatNullValuesAsZero = true;
814
+ }
815
+ conditionsSeq.add(conditionMap);
816
+ });
817
+ map.add(new Pair("conditions", conditionsSeq));
818
+ if (treatNullValuesAsZero) {
819
+ map.add(new Pair("null_values_as_zero", true));
820
+ }
821
+ }
822
+ else if (measureValueFilter.conditions?.length === 1) {
823
+ // Single condition in array: use old format for cleaner output
824
+ addSingleConditionToYaml(map, measureValueFilter.conditions[0]);
825
+ }
826
+ else if (measureValueFilter.condition) {
827
+ // Fallback to single condition field for backward compatibility
828
+ addSingleConditionToYaml(map, measureValueFilter.condition);
829
+ }
830
+ // Handle dimensionality field
831
+ if (measureValueFilter.dimensionality && Array.isArray(measureValueFilter.dimensionality)) {
832
+ const dimensionalitySeq = new YAMLSeq();
833
+ measureValueFilter.dimensionality.forEach((item) => {
834
+ if (isLocalIdRef(item)) {
835
+ dimensionalitySeq.add(item.localIdentifier);
836
+ }
837
+ else {
838
+ dimensionalitySeq.add(getIdentifier(item));
839
+ }
840
+ });
841
+ map.add(new Pair("dimensionality", dimensionalitySeq));
842
+ }
843
+ return map;
844
+ }
845
+ export function declarativeRankingFilterToYaml(rankingFilter) {
846
+ const map = new YAMLMap();
847
+ map.add(new Pair("type", "ranking_filter"));
848
+ if (isLocalIdRef(rankingFilter.measure)) {
849
+ map.add(new Pair("using", rankingFilter.measure.localIdentifier));
850
+ }
851
+ else {
852
+ map.add(new Pair("using", getIdentifier(rankingFilter.measure)));
853
+ }
854
+ if (rankingFilter.operator === "TOP") {
855
+ map.add(new Pair("top", rankingFilter.value));
856
+ }
857
+ if (rankingFilter.operator === "BOTTOM") {
858
+ map.add(new Pair("bottom", rankingFilter.value));
859
+ }
860
+ //NOTE: There can be array, but UI allows only 1 attr now
861
+ if (rankingFilter.attributes?.[0]) {
862
+ const first = rankingFilter.attributes[0];
863
+ if (isLocalIdRef(first)) {
864
+ map.add(new Pair("attribute", first.localIdentifier));
865
+ }
866
+ else {
867
+ map.add(new Pair("attribute", getIdentifier(first)));
868
+ }
869
+ }
870
+ return map;
871
+ }
872
+ export function declarativeSortsToYaml(sorts) {
873
+ const sortsArray = [];
874
+ sorts.forEach((sort) => {
875
+ if (isAttributeSort(sort)) {
876
+ sortsArray.push(declarativeAttributeSortToYaml(sort));
877
+ }
878
+ if (isMeasureSort(sort)) {
879
+ sortsArray.push(declarativeMeasureSortToYaml(sort));
880
+ }
881
+ });
882
+ return {
883
+ sortsArray,
884
+ };
885
+ }
886
+ export function declarativeAttributeSortToYaml(sort) {
887
+ const { attributeIdentifier, aggregation, direction } = sort.attributeSortItem;
888
+ const map = new YAMLMap();
889
+ map.add(new Pair("type", "attribute_sort"));
890
+ map.add(new Pair("by", attributeIdentifier));
891
+ map.add(new Pair("direction", direction.toUpperCase()));
892
+ if (aggregation) {
893
+ map.add(new Pair("aggregation", aggregation.toUpperCase()));
894
+ }
895
+ return map;
896
+ }
897
+ export function declarativeMeasureSortToYaml(sort) {
898
+ const { locators, direction } = sort.measureSortItem;
899
+ const map = new YAMLMap();
900
+ map.add(new Pair("type", "metric_sort"));
901
+ map.add(new Pair("direction", direction.toUpperCase()));
902
+ const items = locators.map((locator) => {
903
+ const item = new YAMLMap();
904
+ if (isAttributeLocator(locator)) {
905
+ item.add(new Pair("by", locator.attributeLocatorItem.attributeIdentifier));
906
+ if (locator.attributeLocatorItem.element) {
907
+ item.add(new Pair("element", locator.attributeLocatorItem.element));
908
+ }
909
+ if (item.items.length === 1) {
910
+ return item.items[0].value;
911
+ }
912
+ return item;
913
+ }
914
+ if (isMeasureLocator(locator)) {
915
+ return locator.measureLocatorItem.measureIdentifier;
916
+ }
917
+ if (isTotalLocator(locator)) {
918
+ item.add(new Pair("by", locator.totalLocatorItem.attributeIdentifier));
919
+ item.add(new Pair("function", locator.totalLocatorItem.totalFunction.toUpperCase()));
920
+ return item;
921
+ }
922
+ return undefined;
923
+ });
924
+ map.add(new Pair("metrics", items.filter(Boolean)));
925
+ return map;
926
+ }
927
+ //visualisations
928
+ function declarativeVisTableToYaml(doc, def, report) {
929
+ //buckets
930
+ const metrics = report.derivedBuckets.find((item) => item.type === BucketsType.Measures);
931
+ if (metrics && metrics.items.length > 0) {
932
+ doc.add(entryWithSpace("metrics", groupToYaml(metrics)));
933
+ }
934
+ const attribute = report.derivedBuckets.find((item) => item.type === BucketsType.Attribute);
935
+ if (attribute && attribute.items.length > 0) {
936
+ doc.add(entryWithSpace("view_by", groupToYaml(attribute)));
937
+ }
938
+ const columns = report.derivedBuckets.find((item) => item.type === BucketsType.Columns);
939
+ if (columns && columns.items.length > 0) {
940
+ doc.add(entryWithSpace("segment_by", groupToYaml(columns)));
941
+ }
942
+ const config = table.load(def.properties);
943
+ if (config) {
944
+ doc.add(config);
945
+ }
946
+ }
947
+ function declarativeVisBarToYaml(doc, def, report) {
948
+ //buckets
949
+ const metrics = report.derivedBuckets.find((item) => item.type === BucketsType.Measures);
950
+ if (metrics && metrics.items.length > 0) {
951
+ doc.add(entryWithSpace("metrics", groupToYaml(metrics)));
952
+ }
953
+ const view = report.derivedBuckets.find((item) => item.type === BucketsType.View);
954
+ if (view && view.items.length > 0) {
955
+ doc.add(entryWithSpace("view_by", groupToYaml(view)));
956
+ }
957
+ const stack = report.derivedBuckets.find((item) => item.type === BucketsType.Stack);
958
+ if (stack && stack.items.length > 0) {
959
+ doc.add(entryWithSpace("segment_by", groupToYaml(stack)));
960
+ }
961
+ const config = barChart.load(def.properties);
962
+ if (config) {
963
+ doc.add(config);
964
+ }
965
+ }
966
+ function declarativeVisColumnToYaml(doc, def, report) {
967
+ //buckets
968
+ const metrics = report.derivedBuckets.find((item) => item.type === BucketsType.Measures);
969
+ if (metrics && metrics.items.length > 0) {
970
+ doc.add(entryWithSpace("metrics", groupToYaml(metrics)));
971
+ }
972
+ const view = report.derivedBuckets.find((item) => item.type === BucketsType.View);
973
+ if (view && view.items.length > 0) {
974
+ doc.add(entryWithSpace("view_by", groupToYaml(view)));
975
+ }
976
+ const stack = report.derivedBuckets.find((item) => item.type === BucketsType.Stack);
977
+ if (stack && stack.items.length > 0) {
978
+ doc.add(entryWithSpace("segment_by", groupToYaml(stack)));
979
+ }
980
+ const config = columnChart.load(def.properties);
981
+ if (config) {
982
+ doc.add(config);
983
+ }
984
+ }
985
+ function declarativeVisLineToYaml(doc, def, report) {
986
+ //buckets
987
+ const metrics = report.derivedBuckets.find((item) => item.type === BucketsType.Measures);
988
+ if (metrics && metrics.items.length > 0) {
989
+ doc.add(entryWithSpace("metrics", groupToYaml(metrics)));
990
+ }
991
+ const trend = report.derivedBuckets.find((item) => item.type === BucketsType.Trend);
992
+ if (trend && trend.items.length > 0) {
993
+ doc.add(entryWithSpace("view_by", groupToYaml(trend)));
994
+ }
995
+ const segment = report.derivedBuckets.find((item) => item.type === BucketsType.Segment);
996
+ if (segment && segment.items.length > 0) {
997
+ doc.add(entryWithSpace("segment_by", groupToYaml(segment)));
998
+ }
999
+ const config = lineChart.load(def.properties);
1000
+ if (config) {
1001
+ doc.add(config);
1002
+ }
1003
+ }
1004
+ function declarativeVisAreaToYaml(doc, def, report) {
1005
+ //buckets
1006
+ const metrics = report.derivedBuckets.find((item) => item.type === BucketsType.Measures);
1007
+ if (metrics && metrics.items.length > 0) {
1008
+ doc.add(entryWithSpace("metrics", groupToYaml(metrics)));
1009
+ }
1010
+ const view = report.derivedBuckets.find((item) => item.type === BucketsType.View);
1011
+ if (view && view.items.length > 0) {
1012
+ doc.add(entryWithSpace("view_by", groupToYaml(view)));
1013
+ }
1014
+ const stack = report.derivedBuckets.find((item) => item.type === BucketsType.Stack);
1015
+ if (stack && stack.items.length > 0) {
1016
+ doc.add(entryWithSpace("segment_by", groupToYaml(stack)));
1017
+ }
1018
+ const config = areaChart.load(def.properties);
1019
+ if (config) {
1020
+ doc.add(config);
1021
+ }
1022
+ }
1023
+ function declarativeVisScatterToYaml(doc, def, report) {
1024
+ //buckets
1025
+ const metrics1 = report.derivedBuckets.find((item) => item.type === BucketsType.Measures);
1026
+ const metrics2 = report.derivedBuckets.find((item) => item.type === BucketsType.SecondaryMeasures);
1027
+ const metrics = {
1028
+ items: cleanUpItems([
1029
+ ...(metrics1?.items.length ? metrics1.items : [null]),
1030
+ ...(metrics2?.items.length ? metrics2.items : [null]),
1031
+ ]),
1032
+ type: BucketsType.Measures,
1033
+ };
1034
+ if (metrics.items.length > 0) {
1035
+ doc.add(entryWithSpace("metrics", groupToYaml(metrics)));
1036
+ }
1037
+ const attributes = report.derivedBuckets.find((item) => item.type === BucketsType.Attribute);
1038
+ if (attributes && attributes.items.length > 0) {
1039
+ doc.add(entryWithSpace("view_by", groupToYaml(attributes)));
1040
+ }
1041
+ const segments = report.derivedBuckets.find((item) => item.type === BucketsType.Segment);
1042
+ if (segments && segments.items.length > 0) {
1043
+ doc.add(entryWithSpace("segment_by", groupToYaml(segments)));
1044
+ }
1045
+ const config = scatterChart.load(def.properties);
1046
+ if (config) {
1047
+ doc.add(config);
1048
+ }
1049
+ }
1050
+ function declarativeVisBubbleToYaml(doc, def, report) {
1051
+ //buckets
1052
+ const metrics1 = report.derivedBuckets.find((item) => item.type === BucketsType.Measures);
1053
+ const metrics2 = report.derivedBuckets.find((item) => item.type === BucketsType.SecondaryMeasures);
1054
+ const metrics = {
1055
+ items: cleanUpItems([
1056
+ ...(metrics1?.items.length ? metrics1.items : [null]),
1057
+ ...(metrics2?.items.length ? metrics2.items : [null]),
1058
+ ]),
1059
+ type: BucketsType.Measures,
1060
+ };
1061
+ if (metrics.items.length > 0) {
1062
+ doc.add(entryWithSpace("metrics", groupToYaml(metrics)));
1063
+ }
1064
+ const view = report.derivedBuckets.find((item) => item.type === BucketsType.View);
1065
+ if (view && view.items.length > 0) {
1066
+ doc.add(entryWithSpace("view_by", groupToYaml(view)));
1067
+ }
1068
+ const tertiaryMetrics = report.derivedBuckets.find((item) => item.type === BucketsType.TertiaryMeasures);
1069
+ if (tertiaryMetrics && tertiaryMetrics.items.length > 0) {
1070
+ doc.add(entryWithSpace("segment_by", groupToYaml(tertiaryMetrics)));
1071
+ }
1072
+ const config = bubbleChart.load(def.properties);
1073
+ if (config) {
1074
+ doc.add(config);
1075
+ }
1076
+ }
1077
+ function declarativeVisPieToYaml(doc, def, report) {
1078
+ //buckets
1079
+ const metrics = report.derivedBuckets.find((item) => item.type === BucketsType.Measures);
1080
+ if (metrics && metrics.items.length > 0) {
1081
+ doc.add(entryWithSpace("metrics", groupToYaml(metrics)));
1082
+ }
1083
+ const view = report.derivedBuckets.find((item) => item.type === BucketsType.View);
1084
+ if (view && view.items.length > 0) {
1085
+ doc.add(entryWithSpace("view_by", groupToYaml(view)));
1086
+ }
1087
+ const config = pieChart.load(def.properties);
1088
+ if (config) {
1089
+ doc.add(config);
1090
+ }
1091
+ }
1092
+ function declarativeVisDonutToYaml(doc, def, report) {
1093
+ //buckets
1094
+ const metrics = report.derivedBuckets.find((item) => item.type === BucketsType.Measures);
1095
+ if (metrics && metrics.items.length > 0) {
1096
+ doc.add(entryWithSpace("metrics", groupToYaml(metrics)));
1097
+ }
1098
+ const view = report.derivedBuckets.find((item) => item.type === BucketsType.View);
1099
+ if (view && view.items.length > 0) {
1100
+ doc.add(entryWithSpace("view_by", groupToYaml(view)));
1101
+ }
1102
+ const config = donutChart.load(def.properties);
1103
+ if (config) {
1104
+ doc.add(config);
1105
+ }
1106
+ }
1107
+ function declarativeVisTreemapToYaml(doc, def, report) {
1108
+ //buckets
1109
+ const metrics = report.derivedBuckets.find((item) => item.type === BucketsType.Measures);
1110
+ if (metrics && metrics.items.length > 0) {
1111
+ doc.add(entryWithSpace("metrics", groupToYaml(metrics)));
1112
+ }
1113
+ const view = report.derivedBuckets.find((item) => item.type === BucketsType.View);
1114
+ if (view && view.items.length > 0) {
1115
+ doc.add(entryWithSpace("view_by", groupToYaml(view)));
1116
+ }
1117
+ const segment = report.derivedBuckets.find((item) => item.type === BucketsType.Segment);
1118
+ if (segment && segment.items.length > 0) {
1119
+ doc.add(entryWithSpace("segment_by", groupToYaml(segment)));
1120
+ }
1121
+ const config = treemapChart.load(def.properties);
1122
+ if (config) {
1123
+ doc.add(config);
1124
+ }
1125
+ }
1126
+ function declarativeVisPyramidToYaml(doc, def, report) {
1127
+ //buckets
1128
+ const metrics = report.derivedBuckets.find((item) => item.type === BucketsType.Measures);
1129
+ if (metrics && metrics.items.length > 0) {
1130
+ doc.add(entryWithSpace("metrics", groupToYaml(metrics)));
1131
+ }
1132
+ const view = report.derivedBuckets.find((item) => item.type === BucketsType.View);
1133
+ if (view && view.items.length > 0) {
1134
+ doc.add(entryWithSpace("view_by", groupToYaml(view)));
1135
+ }
1136
+ const config = pyramidChart.load(def.properties);
1137
+ if (config) {
1138
+ doc.add(config);
1139
+ }
1140
+ }
1141
+ function declarativeVisFunnelToYaml(doc, def, report) {
1142
+ //buckets
1143
+ const metrics = report.derivedBuckets.find((item) => item.type === BucketsType.Measures);
1144
+ if (metrics && metrics.items.length > 0) {
1145
+ doc.add(entryWithSpace("metrics", groupToYaml(metrics)));
1146
+ }
1147
+ const view = report.derivedBuckets.find((item) => item.type === BucketsType.View);
1148
+ if (view && view.items.length > 0) {
1149
+ doc.add(entryWithSpace("view_by", groupToYaml(view)));
1150
+ }
1151
+ const config = funnelChart.load(def.properties);
1152
+ if (config) {
1153
+ doc.add(config);
1154
+ }
1155
+ }
1156
+ function declarativeVisHeatmapToYaml(doc, def, report) {
1157
+ //buckets
1158
+ const metrics = report.derivedBuckets.find((item) => item.type === BucketsType.Measures);
1159
+ if (metrics && metrics.items.length > 0) {
1160
+ doc.add(entryWithSpace("metrics", groupToYaml(metrics)));
1161
+ }
1162
+ const view = report.derivedBuckets.find((item) => item.type === BucketsType.View);
1163
+ if (view && view.items.length > 0) {
1164
+ doc.add(entryWithSpace("view_by", groupToYaml(view)));
1165
+ }
1166
+ const stack = report.derivedBuckets.find((item) => item.type === BucketsType.Stack);
1167
+ if (stack && stack.items.length > 0) {
1168
+ doc.add(entryWithSpace("segment_by", groupToYaml(stack)));
1169
+ }
1170
+ const config = heatmapChart.load(def.properties);
1171
+ if (config) {
1172
+ doc.add(config);
1173
+ }
1174
+ }
1175
+ function declarativeVisBulletToYaml(doc, def, report) {
1176
+ //buckets
1177
+ const metrics1 = report.derivedBuckets.find((item) => item.type === BucketsType.Measures);
1178
+ const metrics2 = report.derivedBuckets.find((item) => item.type === BucketsType.SecondaryMeasures);
1179
+ const metrics3 = report.derivedBuckets.find((item) => item.type === BucketsType.TertiaryMeasures);
1180
+ const metrics = {
1181
+ items: cleanUpItems([
1182
+ ...(metrics1?.items.length ? metrics1.items : [null]),
1183
+ ...(metrics2?.items.length ? metrics2.items : [null]),
1184
+ ...(metrics3?.items.length ? metrics3.items : [null]),
1185
+ ]),
1186
+ type: BucketsType.Measures,
1187
+ };
1188
+ if (metrics.items.length > 0) {
1189
+ doc.add(entryWithSpace("metrics", groupToYaml(metrics)));
1190
+ }
1191
+ const view = report.derivedBuckets.find((item) => item.type === BucketsType.View);
1192
+ if (view && view.items.length > 0) {
1193
+ doc.add(entryWithSpace("view_by", groupToYaml(view)));
1194
+ }
1195
+ const config = bulletChart.load(def.properties);
1196
+ if (config) {
1197
+ doc.add(config);
1198
+ }
1199
+ }
1200
+ function declarativeVisWaterfallToYaml(doc, def, report) {
1201
+ //buckets
1202
+ const metrics = report.derivedBuckets.find((item) => item.type === BucketsType.Measures);
1203
+ if (metrics && metrics.items.length > 0) {
1204
+ doc.add(entryWithSpace("metrics", groupToYaml(metrics)));
1205
+ }
1206
+ const view = report.derivedBuckets.find((item) => item.type === BucketsType.View);
1207
+ if (view && view.items.length > 0) {
1208
+ doc.add(entryWithSpace("view_by", groupToYaml(view)));
1209
+ }
1210
+ const config = waterfallChart.load(def.properties);
1211
+ if (config) {
1212
+ doc.add(config);
1213
+ }
1214
+ }
1215
+ function declarativeVisDependencyWheelToYaml(doc, def, report) {
1216
+ //buckets
1217
+ const metrics = report.derivedBuckets.find((item) => item.type === BucketsType.Measures);
1218
+ if (metrics && metrics.items.length > 0) {
1219
+ doc.add(entryWithSpace("metrics", groupToYaml(metrics)));
1220
+ }
1221
+ const from = report.derivedBuckets.find((item) => item.type === BucketsType.AttributeFrom);
1222
+ const to = report.derivedBuckets.find((item) => item.type === BucketsType.AttributeTo);
1223
+ const view = {
1224
+ items: cleanUpItems([
1225
+ ...(from?.items.length ? from.items : [null]),
1226
+ ...(to?.items.length ? to.items : [null]),
1227
+ ]),
1228
+ type: BucketsType.View,
1229
+ };
1230
+ if (view && view.items.length > 0) {
1231
+ doc.add(entryWithSpace("view_by", groupToYaml(view)));
1232
+ }
1233
+ const config = dependencyWheelChart.load(def.properties);
1234
+ if (config) {
1235
+ doc.add(config);
1236
+ }
1237
+ }
1238
+ function declarativeVisSankeyToYaml(doc, def, report) {
1239
+ //buckets
1240
+ const metrics = report.derivedBuckets.find((item) => item.type === BucketsType.Measures);
1241
+ if (metrics && metrics.items.length > 0) {
1242
+ doc.add(entryWithSpace("metrics", groupToYaml(metrics)));
1243
+ }
1244
+ const from = report.derivedBuckets.find((item) => item.type === BucketsType.AttributeFrom);
1245
+ const to = report.derivedBuckets.find((item) => item.type === BucketsType.AttributeTo);
1246
+ const view = {
1247
+ items: cleanUpItems([
1248
+ ...(from?.items.length ? from.items : [null]),
1249
+ ...(to?.items.length ? to.items : [null]),
1250
+ ]),
1251
+ type: BucketsType.View,
1252
+ };
1253
+ if (view && view.items.length > 0) {
1254
+ doc.add(entryWithSpace("view_by", groupToYaml(view)));
1255
+ }
1256
+ const config = sankeyChart.load(def.properties);
1257
+ if (config) {
1258
+ doc.add(config);
1259
+ }
1260
+ }
1261
+ function declarativeVisHeadlineToYaml(doc, def, report) {
1262
+ //buckets
1263
+ const metrics1 = report.derivedBuckets.find((item) => item.type === BucketsType.Measures);
1264
+ const metrics2 = report.derivedBuckets.find((item) => item.type === BucketsType.SecondaryMeasures);
1265
+ const metrics = {
1266
+ items: [...(metrics1?.items ?? [null]), ...(metrics2?.items ?? [])],
1267
+ type: BucketsType.Measures,
1268
+ };
1269
+ if (metrics && metrics.items.length > 0) {
1270
+ doc.add(entryWithSpace("metrics", groupToYaml(metrics)));
1271
+ }
1272
+ const config = headlineChart.load(def.properties);
1273
+ if (config) {
1274
+ doc.add(config);
1275
+ }
1276
+ }
1277
+ function declarativeVisComboToYaml(doc, def, report) {
1278
+ //buckets
1279
+ const metrics1 = addAxisTypeToGroup(report.derivedBuckets.find((item) => item.type === BucketsType.Measures), "primary");
1280
+ const metrics2 = addAxisTypeToGroup(report.derivedBuckets.find((item) => item.type === BucketsType.SecondaryMeasures), "secondary");
1281
+ const metrics = {
1282
+ items: [...(metrics1?.items ?? []), ...(metrics2?.items ?? [])],
1283
+ type: BucketsType.Measures,
1284
+ };
1285
+ if (metrics && metrics.items.length > 0) {
1286
+ doc.add(entryWithSpace("metrics", groupToYaml(metrics)));
1287
+ }
1288
+ const view = report.derivedBuckets.find((item) => item.type === BucketsType.View);
1289
+ if (view && view.items.length > 0) {
1290
+ doc.add(entryWithSpace("view_by", groupToYaml(view)));
1291
+ }
1292
+ const config = comboChart.load(def.properties);
1293
+ if (config) {
1294
+ doc.add(config);
1295
+ }
1296
+ }
1297
+ function addPushpinBucketsToYaml(target, groups) {
1298
+ const sizeBucket = groups.find((item) => item.type === BucketsType.Size);
1299
+ const colorBucket = groups.find((item) => item.type === BucketsType.Color);
1300
+ const metrics = {
1301
+ items: cleanUpItems([
1302
+ ...(sizeBucket?.items.length ? sizeBucket.items : [null]),
1303
+ ...(colorBucket?.items ? colorBucket.items : [null]),
1304
+ ]),
1305
+ type: BucketsType.Measures,
1306
+ };
1307
+ if (metrics.items.length > 0) {
1308
+ target.add(entryWithSpace("metrics", groupToYaml(metrics)));
1309
+ }
1310
+ const location = groups.find((item) => item.type === BucketsType.Location);
1311
+ if (location && location.items.length > 0) {
1312
+ target.add(entryWithSpace("view_by", groupToYaml(location)));
1313
+ }
1314
+ const segment = groups.find((item) => item.type === BucketsType.Segment);
1315
+ if (segment && segment.items.length > 0) {
1316
+ target.add(entryWithSpace("segment_by", groupToYaml(segment)));
1317
+ }
1318
+ }
1319
+ function addGeoAreaBucketsToYaml(target, groups) {
1320
+ const colorBucket = groups.find((item) => item.type === BucketsType.Color);
1321
+ const metrics = {
1322
+ items: cleanUpItems([...(colorBucket?.items.length ? colorBucket.items : [null])]),
1323
+ type: BucketsType.Measures,
1324
+ };
1325
+ if (metrics.items.length > 0) {
1326
+ target.add(entryWithSpace("metrics", groupToYaml(metrics)));
1327
+ }
1328
+ const area = groups.find((item) => item.type === BucketsType.Area);
1329
+ if (area && area.items.length > 0) {
1330
+ target.add(entryWithSpace("view_by", groupToYaml(area)));
1331
+ }
1332
+ const segment = groups.find((item) => item.type === BucketsType.Segment);
1333
+ if (segment && segment.items.length > 0) {
1334
+ target.add(entryWithSpace("segment_by", groupToYaml(segment)));
1335
+ }
1336
+ }
1337
+ function declarativeVisGeoToYaml(doc, def, report, entities) {
1338
+ //buckets
1339
+ addPushpinBucketsToYaml(doc, report.derivedBuckets);
1340
+ const config = geoChart.load(def.properties);
1341
+ if (config) {
1342
+ doc.add(config);
1343
+ }
1344
+ appendLayers(doc, def, entities);
1345
+ }
1346
+ function declarativeVisGeoAreaToYaml(doc, def, report, entities) {
1347
+ //buckets
1348
+ addGeoAreaBucketsToYaml(doc, report.derivedBuckets);
1349
+ const config = geoAreaChart.load(def.properties);
1350
+ if (config) {
1351
+ doc.add(config);
1352
+ }
1353
+ appendLayers(doc, def, entities);
1354
+ }
1355
+ function appendLayers(doc, def, entities) {
1356
+ const layersDefinition = def.layers ?? [];
1357
+ if (layersDefinition.length === 0) {
1358
+ return;
1359
+ }
1360
+ const layers = declarativeLayersToYaml(entities, layersDefinition);
1361
+ if (layers.items.length > 0) {
1362
+ doc.add(entryWithSpace("layers", layers));
1363
+ }
1364
+ }
1365
+ function declarativeVisRepeaterToYaml(doc, def, report) {
1366
+ const columns = report.derivedBuckets.find((item) => item.type === BucketsType.Columns);
1367
+ const columnsMapped = addChartTypeToGroup(columns, def.properties);
1368
+ if (columnsMapped && columnsMapped.items.length > 0) {
1369
+ doc.add(entryWithSpace("metrics", groupToYaml(columnsMapped)));
1370
+ }
1371
+ const view = report.derivedBuckets.find((item) => item.type === BucketsType.View);
1372
+ if (view && view.items.length > 0) {
1373
+ doc.add(entryWithSpace("view_by", groupToYaml(view)));
1374
+ }
1375
+ const attribute = report.derivedBuckets.find((item) => item.type === BucketsType.Attribute);
1376
+ if (attribute && attribute.items.length > 0) {
1377
+ doc.add(entryWithSpace("segment_by", groupToYaml(attribute)));
1378
+ }
1379
+ const config = repeaterChart.load(def.properties);
1380
+ if (config) {
1381
+ doc.add(config);
1382
+ }
1383
+ }
1384
+ //TOTALS
1385
+ export function declarativeTotalToYaml(total) {
1386
+ const map = new YAMLMap();
1387
+ if (total.alias) {
1388
+ map.add(new Pair("title", total.alias));
1389
+ }
1390
+ map.add(new Pair("type", total.type.toUpperCase()));
1391
+ map.add(new Pair("using", total.measureIdentifier));
1392
+ return {
1393
+ totalMap: map,
1394
+ attribute: total.attributeIdentifier,
1395
+ };
1396
+ }
1397
+ function groupToYaml(group) {
1398
+ return group.items.map((item) => {
1399
+ if (!item) {
1400
+ return null;
1401
+ }
1402
+ const keys = Object.keys(item);
1403
+ if (keys.length === 1) {
1404
+ return item.field;
1405
+ }
1406
+ const map = new YAMLMap();
1407
+ map.add(new Pair("field", item.field));
1408
+ if (item.format) {
1409
+ map.add(new Pair("format", item.format));
1410
+ }
1411
+ if (item.totals && item.totals.length > 0) {
1412
+ map.add(new Pair("totals", item.totals));
1413
+ }
1414
+ if (item.axis) {
1415
+ map.add(new Pair("axis", item.axis));
1416
+ }
1417
+ if (item.display_as) {
1418
+ map.add(new Pair("display_as", item.display_as));
1419
+ }
1420
+ return map;
1421
+ });
1422
+ }
1423
+ function addAxisTypeToGroup(group, axis) {
1424
+ if (!group) {
1425
+ return undefined;
1426
+ }
1427
+ return {
1428
+ ...group,
1429
+ items: group.items.map((item) => {
1430
+ if (item) {
1431
+ return {
1432
+ ...item,
1433
+ axis,
1434
+ };
1435
+ }
1436
+ return item;
1437
+ }),
1438
+ };
1439
+ }
1440
+ function addChartTypeToGroup(group, config) {
1441
+ if (!group || !config) {
1442
+ return group;
1443
+ }
1444
+ if (!config["inlineVisualizations"]) {
1445
+ return group;
1446
+ }
1447
+ const props = config["inlineVisualizations"];
1448
+ return {
1449
+ ...group,
1450
+ items: group.items.map((item) => {
1451
+ if (item && props[item.field]) {
1452
+ return {
1453
+ ...item,
1454
+ display_as: props[item.field].type,
1455
+ };
1456
+ }
1457
+ return item;
1458
+ }),
1459
+ };
1460
+ }
1461
+ function declarativeLayersToYaml(entities, layersDefinition) {
1462
+ const layers = new YAMLSeq();
1463
+ layersDefinition.forEach((layer) => {
1464
+ const { groups } = declarativeBucketsToYaml(entities, layer.buckets ?? []);
1465
+ const layerKind = resolveLayerExportKind(layer.type);
1466
+ const layerMap = new YAMLMap();
1467
+ layerMap.add(new Pair("id", layer.id));
1468
+ if (layer.name) {
1469
+ layerMap.add(new Pair("title", layer.name));
1470
+ }
1471
+ if (layer.type) {
1472
+ layerMap.add(new Pair("type", layer.type));
1473
+ }
1474
+ appendLayerBucketsForKind(layerMap, groups, layerKind);
1475
+ addLayerConfig(layerMap, layerKind, layer.properties);
1476
+ layers.add(layerMap);
1477
+ });
1478
+ return layers;
1479
+ }
1480
+ function resolveLayerExportKind(rawLayerType) {
1481
+ if (rawLayerType === "pushpin") {
1482
+ return "pushpin";
1483
+ }
1484
+ if (rawLayerType === "area") {
1485
+ return "area";
1486
+ }
1487
+ throw newError(CoreErrorCode.LayerTypeNotSupported, [rawLayerType ?? "<missing>"]);
1488
+ }
1489
+ function appendLayerBucketsForKind(layerMap, groups, kind) {
1490
+ if (kind === "pushpin") {
1491
+ addPushpinBucketsToYaml(layerMap, groups);
1492
+ return;
1493
+ }
1494
+ if (kind === "area") {
1495
+ addGeoAreaBucketsToYaml(layerMap, groups);
1496
+ return;
1497
+ }
1498
+ throw newError(CoreErrorCode.LayerTypeNotSupported, [kind]);
1499
+ }
1500
+ function addLayerConfig(layerMap, layerKind, properties) {
1501
+ if (!properties) {
1502
+ return;
1503
+ }
1504
+ const config = layerKind === "pushpin"
1505
+ ? geoChart.load(properties)
1506
+ : layerKind === "area"
1507
+ ? geoAreaChart.load(properties)
1508
+ : null;
1509
+ if (config) {
1510
+ layerMap.add(config);
1511
+ }
1512
+ }
1513
+ //# sourceMappingURL=declarativeVisualisationToYaml.js.map