@sisense/sdk-pivot-query-client 2.17.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (189) hide show
  1. package/LICENSE.md +35 -0
  2. package/README.md +2 -0
  3. package/dist/__test-helpers__/testUtils.d.ts +30 -0
  4. package/dist/__test-helpers__/testUtils.js +89 -0
  5. package/dist/builders/index.d.ts +2 -0
  6. package/dist/builders/index.js +2 -0
  7. package/dist/builders/pivot-data-builder.d.ts +34 -0
  8. package/dist/builders/pivot-data-builder.js +182 -0
  9. package/dist/builders/socket-builder.d.ts +18 -0
  10. package/dist/builders/socket-builder.js +72 -0
  11. package/dist/cjs/__test-helpers__/testUtils.d.ts +30 -0
  12. package/dist/cjs/__test-helpers__/testUtils.js +104 -0
  13. package/dist/cjs/builders/index.d.ts +2 -0
  14. package/dist/cjs/builders/index.js +7 -0
  15. package/dist/cjs/builders/pivot-data-builder.d.ts +34 -0
  16. package/dist/cjs/builders/pivot-data-builder.js +186 -0
  17. package/dist/cjs/builders/socket-builder.d.ts +18 -0
  18. package/dist/cjs/builders/socket-builder.js +79 -0
  19. package/dist/cjs/data-handling/DataService.d.ts +672 -0
  20. package/dist/cjs/data-handling/DataService.js +1364 -0
  21. package/dist/cjs/data-handling/DivergenceComparator.d.ts +7 -0
  22. package/dist/cjs/data-handling/DivergenceComparator.js +20 -0
  23. package/dist/cjs/data-handling/constants.d.ts +44 -0
  24. package/dist/cjs/data-handling/constants.js +43 -0
  25. package/dist/cjs/data-handling/index.d.ts +3 -0
  26. package/dist/cjs/data-handling/index.js +23 -0
  27. package/dist/cjs/data-handling/types.d.ts +104 -0
  28. package/dist/cjs/data-handling/types.js +2 -0
  29. package/dist/cjs/data-handling/utils/createPivotTreeNode.d.ts +13 -0
  30. package/dist/cjs/data-handling/utils/createPivotTreeNode.js +21 -0
  31. package/dist/cjs/data-handling/utils/index.d.ts +4 -0
  32. package/dist/cjs/data-handling/utils/index.js +14 -0
  33. package/dist/cjs/data-handling/utils/jaqlProcessor.d.ts +122 -0
  34. package/dist/cjs/data-handling/utils/jaqlProcessor.js +661 -0
  35. package/dist/cjs/data-handling/utils/pivotTransforms.d.ts +74 -0
  36. package/dist/cjs/data-handling/utils/pivotTransforms.js +373 -0
  37. package/dist/cjs/data-handling/utils/plugins/PluginService.d.ts +135 -0
  38. package/dist/cjs/data-handling/utils/plugins/PluginService.js +383 -0
  39. package/dist/cjs/data-handling/utils/plugins/getters.d.ts +23 -0
  40. package/dist/cjs/data-handling/utils/plugins/getters.js +70 -0
  41. package/dist/cjs/data-handling/utils/plugins/types.d.ts +75 -0
  42. package/dist/cjs/data-handling/utils/plugins/types.js +2 -0
  43. package/dist/cjs/data-handling/utils/plugins/validator.d.ts +13 -0
  44. package/dist/cjs/data-handling/utils/plugins/validator.js +169 -0
  45. package/dist/cjs/data-load/AbstractDataLoadService.d.ts +256 -0
  46. package/dist/cjs/data-load/AbstractDataLoadService.js +473 -0
  47. package/dist/cjs/data-load/DataLoadService.d.ts +63 -0
  48. package/dist/cjs/data-load/DataLoadService.js +152 -0
  49. package/dist/cjs/data-load/SisenseDataLoadService.d.ts +44 -0
  50. package/dist/cjs/data-load/SisenseDataLoadService.js +87 -0
  51. package/dist/cjs/data-load/TestDataLoadService.d.ts +27 -0
  52. package/dist/cjs/data-load/TestDataLoadService.js +76 -0
  53. package/dist/cjs/data-load/constants.d.ts +13 -0
  54. package/dist/cjs/data-load/constants.js +28 -0
  55. package/dist/cjs/data-load/index.d.ts +6 -0
  56. package/dist/cjs/data-load/index.js +14 -0
  57. package/dist/cjs/data-load/sockets/SisenseSocket.d.ts +81 -0
  58. package/dist/cjs/data-load/sockets/SisenseSocket.js +162 -0
  59. package/dist/cjs/data-load/sockets/TestSocket.d.ts +61 -0
  60. package/dist/cjs/data-load/sockets/TestSocket.js +90 -0
  61. package/dist/cjs/data-load/sockets/helpers.d.ts +4 -0
  62. package/dist/cjs/data-load/sockets/helpers.js +27 -0
  63. package/dist/cjs/data-load/sockets/index.d.ts +2 -0
  64. package/dist/cjs/data-load/sockets/index.js +8 -0
  65. package/dist/cjs/data-load/types.d.ts +90 -0
  66. package/dist/cjs/data-load/types.js +2 -0
  67. package/dist/cjs/errors/LoadingCanceledError.d.ts +7 -0
  68. package/dist/cjs/errors/LoadingCanceledError.js +24 -0
  69. package/dist/cjs/errors/index.d.ts +1 -0
  70. package/dist/cjs/errors/index.js +6 -0
  71. package/dist/cjs/index.d.ts +17 -0
  72. package/dist/cjs/index.js +32 -0
  73. package/dist/cjs/package.json +12 -0
  74. package/dist/cjs/pivot-query-client.d.ts +13 -0
  75. package/dist/cjs/pivot-query-client.js +26 -0
  76. package/dist/cjs/tree-structure/AbstractTreeService.d.ts +308 -0
  77. package/dist/cjs/tree-structure/AbstractTreeService.js +716 -0
  78. package/dist/cjs/tree-structure/HeaderTreeService.d.ts +180 -0
  79. package/dist/cjs/tree-structure/HeaderTreeService.js +280 -0
  80. package/dist/cjs/tree-structure/TreeCellMap.d.ts +104 -0
  81. package/dist/cjs/tree-structure/TreeCellMap.js +145 -0
  82. package/dist/cjs/tree-structure/TreeService.d.ts +8 -0
  83. package/dist/cjs/tree-structure/TreeService.js +12 -0
  84. package/dist/cjs/tree-structure/constants.d.ts +6 -0
  85. package/dist/cjs/tree-structure/constants.js +10 -0
  86. package/dist/cjs/tree-structure/index.d.ts +5 -0
  87. package/dist/cjs/tree-structure/index.js +10 -0
  88. package/dist/cjs/tree-structure/types.d.ts +93 -0
  89. package/dist/cjs/tree-structure/types.js +2 -0
  90. package/dist/cjs/tree-structure/utils/index.d.ts +1 -0
  91. package/dist/cjs/tree-structure/utils/index.js +9 -0
  92. package/dist/cjs/tree-structure/utils/treeNode.d.ts +147 -0
  93. package/dist/cjs/tree-structure/utils/treeNode.js +534 -0
  94. package/dist/cjs/utils/array.d.ts +13 -0
  95. package/dist/cjs/utils/array.js +25 -0
  96. package/dist/cjs/utils/cloneObject.d.ts +30 -0
  97. package/dist/cjs/utils/cloneObject.js +225 -0
  98. package/dist/cjs/utils/index.d.ts +3 -0
  99. package/dist/cjs/utils/index.js +9 -0
  100. package/dist/cjs/utils/throttle.d.ts +12 -0
  101. package/dist/cjs/utils/throttle.js +39 -0
  102. package/dist/cjs/utils/types.d.ts +12 -0
  103. package/dist/cjs/utils/types.js +2 -0
  104. package/dist/data-handling/DataService.d.ts +672 -0
  105. package/dist/data-handling/DataService.js +1357 -0
  106. package/dist/data-handling/DivergenceComparator.d.ts +7 -0
  107. package/dist/data-handling/DivergenceComparator.js +16 -0
  108. package/dist/data-handling/constants.d.ts +44 -0
  109. package/dist/data-handling/constants.js +40 -0
  110. package/dist/data-handling/index.d.ts +3 -0
  111. package/dist/data-handling/index.js +4 -0
  112. package/dist/data-handling/types.d.ts +104 -0
  113. package/dist/data-handling/types.js +1 -0
  114. package/dist/data-handling/utils/createPivotTreeNode.d.ts +13 -0
  115. package/dist/data-handling/utils/createPivotTreeNode.js +17 -0
  116. package/dist/data-handling/utils/index.d.ts +4 -0
  117. package/dist/data-handling/utils/index.js +4 -0
  118. package/dist/data-handling/utils/jaqlProcessor.d.ts +122 -0
  119. package/dist/data-handling/utils/jaqlProcessor.js +621 -0
  120. package/dist/data-handling/utils/pivotTransforms.d.ts +74 -0
  121. package/dist/data-handling/utils/pivotTransforms.js +335 -0
  122. package/dist/data-handling/utils/plugins/PluginService.d.ts +135 -0
  123. package/dist/data-handling/utils/plugins/PluginService.js +379 -0
  124. package/dist/data-handling/utils/plugins/getters.d.ts +23 -0
  125. package/dist/data-handling/utils/plugins/getters.js +65 -0
  126. package/dist/data-handling/utils/plugins/types.d.ts +75 -0
  127. package/dist/data-handling/utils/plugins/types.js +1 -0
  128. package/dist/data-handling/utils/plugins/validator.d.ts +13 -0
  129. package/dist/data-handling/utils/plugins/validator.js +165 -0
  130. package/dist/data-load/AbstractDataLoadService.d.ts +256 -0
  131. package/dist/data-load/AbstractDataLoadService.js +466 -0
  132. package/dist/data-load/DataLoadService.d.ts +63 -0
  133. package/dist/data-load/DataLoadService.js +148 -0
  134. package/dist/data-load/SisenseDataLoadService.d.ts +44 -0
  135. package/dist/data-load/SisenseDataLoadService.js +83 -0
  136. package/dist/data-load/TestDataLoadService.d.ts +27 -0
  137. package/dist/data-load/TestDataLoadService.js +69 -0
  138. package/dist/data-load/constants.d.ts +13 -0
  139. package/dist/data-load/constants.js +25 -0
  140. package/dist/data-load/index.d.ts +6 -0
  141. package/dist/data-load/index.js +6 -0
  142. package/dist/data-load/sockets/SisenseSocket.d.ts +81 -0
  143. package/dist/data-load/sockets/SisenseSocket.js +155 -0
  144. package/dist/data-load/sockets/TestSocket.d.ts +61 -0
  145. package/dist/data-load/sockets/TestSocket.js +83 -0
  146. package/dist/data-load/sockets/helpers.d.ts +4 -0
  147. package/dist/data-load/sockets/helpers.js +23 -0
  148. package/dist/data-load/sockets/index.d.ts +2 -0
  149. package/dist/data-load/sockets/index.js +3 -0
  150. package/dist/data-load/types.d.ts +90 -0
  151. package/dist/data-load/types.js +1 -0
  152. package/dist/errors/LoadingCanceledError.d.ts +7 -0
  153. package/dist/errors/LoadingCanceledError.js +20 -0
  154. package/dist/errors/index.d.ts +1 -0
  155. package/dist/errors/index.js +2 -0
  156. package/dist/index.d.ts +17 -0
  157. package/dist/index.js +9 -0
  158. package/dist/pivot-query-client.d.ts +13 -0
  159. package/dist/pivot-query-client.js +22 -0
  160. package/dist/tree-structure/AbstractTreeService.d.ts +308 -0
  161. package/dist/tree-structure/AbstractTreeService.js +712 -0
  162. package/dist/tree-structure/HeaderTreeService.d.ts +180 -0
  163. package/dist/tree-structure/HeaderTreeService.js +276 -0
  164. package/dist/tree-structure/TreeCellMap.d.ts +104 -0
  165. package/dist/tree-structure/TreeCellMap.js +141 -0
  166. package/dist/tree-structure/TreeService.d.ts +8 -0
  167. package/dist/tree-structure/TreeService.js +8 -0
  168. package/dist/tree-structure/constants.d.ts +6 -0
  169. package/dist/tree-structure/constants.js +7 -0
  170. package/dist/tree-structure/index.d.ts +5 -0
  171. package/dist/tree-structure/index.js +4 -0
  172. package/dist/tree-structure/types.d.ts +93 -0
  173. package/dist/tree-structure/types.js +1 -0
  174. package/dist/tree-structure/utils/index.d.ts +1 -0
  175. package/dist/tree-structure/utils/index.js +1 -0
  176. package/dist/tree-structure/utils/treeNode.d.ts +147 -0
  177. package/dist/tree-structure/utils/treeNode.js +515 -0
  178. package/dist/tsconfig.prod.cjs.tsbuildinfo +1 -0
  179. package/dist/utils/array.d.ts +13 -0
  180. package/dist/utils/array.js +21 -0
  181. package/dist/utils/cloneObject.d.ts +30 -0
  182. package/dist/utils/cloneObject.js +221 -0
  183. package/dist/utils/index.d.ts +3 -0
  184. package/dist/utils/index.js +3 -0
  185. package/dist/utils/throttle.d.ts +12 -0
  186. package/dist/utils/throttle.js +35 -0
  187. package/dist/utils/types.d.ts +12 -0
  188. package/dist/utils/types.js +1 -0
  189. package/package.json +61 -0
@@ -0,0 +1,335 @@
1
+ import { treeNode } from '../../tree-structure/utils/index.js';
2
+ import { ColorFormatType, PanelType, UserType } from '../constants.js';
3
+ import createPivotTreeNode from './createPivotTreeNode.js';
4
+ import * as jaqlProcessor from './jaqlProcessor.js';
5
+ /**
6
+ * Helper for checking if tree has only one branch on all it's depth levels
7
+ *
8
+ * @param {TreeNode} root - tree root node
9
+ * @param {string} type - tree node type, rows | columns
10
+ * @returns {boolean} - boolean response
11
+ */
12
+ function hasTreeMultipleBranches(root, type) {
13
+ if (!treeNode.hasChildren(root)) {
14
+ return false;
15
+ }
16
+ let forceTotals = false;
17
+ if (type === PanelType.COLUMNS && root && root.isPart) {
18
+ forceTotals = true;
19
+ }
20
+ const children = treeNode.getChildren(root);
21
+ if (children.length > 1 || forceTotals) {
22
+ return true;
23
+ }
24
+ const [singleChild] = children;
25
+ return hasTreeMultipleBranches(singleChild);
26
+ }
27
+ /**
28
+ * Helper for checking if node value is empty
29
+ *
30
+ * @param {*} value - node value
31
+ * @returns {boolean} - is empty flag
32
+ */
33
+ function isEmptyValue(value) {
34
+ return value === null || value === undefined;
35
+ }
36
+ export const insertSubTotals = (items, originalData, type, jaql, // eslint-disable-line no-unused-vars
37
+ subtotalsForSingleRow) => {
38
+ const result = [];
39
+ // eslint-disable-next-line sonarjs/cognitive-complexity
40
+ items.forEach((item) => {
41
+ // keep original item
42
+ result.push(item);
43
+ if (treeNode.hasChildren(item)) {
44
+ const newChildrenNodes = treeNode.getChildren(item);
45
+ const newChildren = insertSubTotals(newChildrenNodes, originalData, type, jaql, subtotalsForSingleRow);
46
+ treeNode.setChildren(item, newChildren);
47
+ // check if item has subtotal
48
+ let hasSubTotals = false;
49
+ if (subtotalsForSingleRow || hasTreeMultipleBranches(item, type)) {
50
+ if (type === PanelType.COLUMNS) {
51
+ if (typeof item.index !== 'undefined' && item.index > -1) {
52
+ hasSubTotals = true;
53
+ }
54
+ }
55
+ else if (type === PanelType.ROWS) {
56
+ if (typeof item.data !== 'undefined') {
57
+ hasSubTotals = true;
58
+ }
59
+ }
60
+ }
61
+ if (hasSubTotals) {
62
+ const { value, index, data, jaqlIndex, measurePath } = item;
63
+ let roughSubTotalItem;
64
+ if (type === PanelType.COLUMNS) {
65
+ roughSubTotalItem = treeNode.create(value, undefined, undefined, index);
66
+ }
67
+ else if (type === PanelType.ROWS) {
68
+ roughSubTotalItem = treeNode.create(value, undefined, data);
69
+ }
70
+ if (roughSubTotalItem) {
71
+ const subTotalItem = createPivotTreeNode(roughSubTotalItem, type);
72
+ subTotalItem.userType = UserType.SUB_TOTAL;
73
+ subTotalItem.jaqlIndex = jaqlIndex;
74
+ subTotalItem.measurePath = measurePath;
75
+ subTotalItem.master = item;
76
+ result.push(subTotalItem);
77
+ }
78
+ }
79
+ }
80
+ });
81
+ return result;
82
+ };
83
+ // eslint-disable-next-line no-unused-vars
84
+ export const postProcessSubTotal = (item, jaql) => {
85
+ if (item.userType === UserType.SUB_TOTAL) {
86
+ if (item.master) {
87
+ item.measurePath = item.master.measurePath;
88
+ }
89
+ }
90
+ };
91
+ export const insertGrandTotals = (items, originalData, type, jaql) => {
92
+ const result = items;
93
+ if (type === PanelType.COLUMNS && originalData) {
94
+ const rootItem = createPivotTreeNode(originalData);
95
+ const hasGrandTotals = typeof rootItem.index === 'number';
96
+ if (hasGrandTotals) {
97
+ const valuesTree = jaqlProcessor.getMetadataTree(jaql, PanelType.MEASURES);
98
+ treeNode.getChildren(valuesTree).forEach((valueNode, i) => {
99
+ const roughGrandTotalItem = Object.assign(Object.assign({}, valueNode), { index: (rootItem.index || 0) + i });
100
+ const grandTotalItem = createPivotTreeNode(roughGrandTotalItem, type);
101
+ grandTotalItem.userType = UserType.GRAND_TOTAL;
102
+ // set measure jaqlIndex
103
+ grandTotalItem.measureJaqlIndex = grandTotalItem.jaqlIndex;
104
+ result.push(grandTotalItem);
105
+ });
106
+ }
107
+ }
108
+ return result;
109
+ };
110
+ // eslint-disable-next-line no-unused-vars
111
+ export const postProcessGrandTotal = (item, jaql) => {
112
+ if (item.userType === UserType.GRAND_TOTAL) {
113
+ item.measurePath = undefined;
114
+ if (item.metadataType === PanelType.ROWS) {
115
+ item.parent = undefined;
116
+ item.jaqlIndex = 0;
117
+ }
118
+ }
119
+ };
120
+ export const insertMeasureNodes = (items, originalData, type, jaql) => {
121
+ let result = items;
122
+ if (type === PanelType.COLUMNS) {
123
+ const valuesTree = jaqlProcessor.getMetadataTree(jaql, PanelType.MEASURES);
124
+ const count = treeNode.getChildLength(valuesTree);
125
+ const columnsOptions = { maxLevel: 0 };
126
+ const columnsLastLevel = treeNode.getLastLevelNodes(result, [], 0, columnsOptions);
127
+ if (count > 1) {
128
+ // add values nodes at the last level
129
+ columnsLastLevel.forEach((lastNode) => {
130
+ if (lastNode.userType === UserType.GRAND_TOTAL) {
131
+ return;
132
+ }
133
+ const lastChildren = treeNode.getChildren(valuesTree);
134
+ const lastFinalChildren = [];
135
+ for (let i = 0; i < lastChildren.length; i += 1) {
136
+ if (typeof lastNode.maxChilds === 'number' && i >= lastNode.maxChilds) {
137
+ // eslint-disable-next-line no-continue
138
+ continue;
139
+ }
140
+ const roughMeasureItem = Object.assign(Object.assign({}, lastChildren[i]), { index: (lastNode.index || 0) + i, measurePath: lastNode.measurePath });
141
+ const measureItem = createPivotTreeNode(roughMeasureItem, PanelType.MEASURES);
142
+ measureItem.userType = UserType.MEASURE_BOTTOM;
143
+ // set measure jaqlIndex
144
+ measureItem.measureJaqlIndex = measureItem.jaqlIndex;
145
+ lastFinalChildren.push(measureItem);
146
+ }
147
+ lastNode.minLevel = columnsOptions.maxLevel;
148
+ treeNode.setChildren(lastNode, lastFinalChildren);
149
+ });
150
+ }
151
+ else if (count === 1) {
152
+ // add value node at the first level
153
+ const valueNode = treeNode.getChildren(valuesTree)[0];
154
+ if (valueNode) {
155
+ const roughMeasureItem = Object.assign({}, valueNode);
156
+ const measureItem = createPivotTreeNode(roughMeasureItem, PanelType.MEASURES);
157
+ measureItem.userType = UserType.MEASURE_TOP;
158
+ treeNode.setChildren(measureItem, result);
159
+ result = [measureItem];
160
+ // set measure jaqlIndex
161
+ columnsLastLevel.forEach((lastNode) => {
162
+ lastNode.measureJaqlIndex = valueNode.jaqlIndex;
163
+ });
164
+ }
165
+ }
166
+ }
167
+ return result;
168
+ };
169
+ export const postProcessMeasureNode = (item, jaql) => {
170
+ if (!treeNode.hasChildren(item) && typeof item.measureJaqlIndex !== 'undefined') {
171
+ jaqlProcessor.markSortedNode(jaql, item);
172
+ }
173
+ };
174
+ export const applyColorFormatting = (item, rowItem, columnItem, measurePanel) => {
175
+ let style = {};
176
+ if (rowItem.userType === UserType.SUB_TOTAL ||
177
+ rowItem.userType === UserType.GRAND_TOTAL ||
178
+ columnItem.userType === UserType.SUB_TOTAL ||
179
+ columnItem.userType === UserType.GRAND_TOTAL ||
180
+ (columnItem.parent && columnItem.parent.userType === UserType.SUB_TOTAL) ||
181
+ (columnItem.parent && columnItem.parent.userType === UserType.GRAND_TOTAL)) {
182
+ // ignore SUB_TOTAL & GRAND_TOTAL
183
+ return;
184
+ }
185
+ const colorFormat = (measurePanel && measurePanel.format && measurePanel.format.color) || null;
186
+ if (!colorFormat) {
187
+ return;
188
+ }
189
+ const { value, cf = -1 } = item;
190
+ if (colorFormat.type === ColorFormatType.COLOR) {
191
+ if (colorFormat.color && colorFormat.color !== 'transparent') {
192
+ style.backgroundColor = colorFormat.color;
193
+ }
194
+ }
195
+ if (colorFormat.type === ColorFormatType.CONDITION) {
196
+ if (colorFormat.conditions && colorFormat.conditions.length) {
197
+ for (let i = 0, c = colorFormat.conditions.length; i < c; i += 1) {
198
+ // handle empty value case
199
+ if (isEmptyValue(value)) {
200
+ break;
201
+ }
202
+ // handle condition case
203
+ const conditions = colorFormat.conditions || [];
204
+ const { color } = conditions[i] || {};
205
+ if (color && cf === i) {
206
+ style.backgroundColor = color;
207
+ break;
208
+ }
209
+ }
210
+ }
211
+ }
212
+ if (Object.keys(style).length > 0) {
213
+ item.style = item.style || {};
214
+ Object.assign(item.style, style);
215
+ }
216
+ style = undefined;
217
+ };
218
+ /**
219
+ * Pre-process initial tree structure
220
+ *
221
+ * @param {Array<TreeNode>} items - items to normalize
222
+ * @param {string} type - items types to normalize
223
+ * @param {JaqlRequest} jaql - jaql request
224
+ * @param {object} options - additional options
225
+ * @param {number} [options.level=0] - tree level, for internal use only
226
+ * @param {object} [options.measurePath={}] - items types to normalize
227
+ * @returns {Array<PivotTreeNode>} - normalized list of items
228
+ */
229
+ export const preProcessTree = (items, type, jaql, options) => {
230
+ const result = [];
231
+ const { level = 0, measurePath = {} } = options || {};
232
+ let finalItems;
233
+ if (Array.isArray(items)) {
234
+ finalItems = items;
235
+ }
236
+ else {
237
+ finalItems = treeNode.getChildren(items);
238
+ }
239
+ const panels = jaqlProcessor.getMetadataPanels(jaql, type);
240
+ const panel = panels[level];
241
+ const jaqlIndex = panel ? (panel.field || { index: Infinity }).index : undefined;
242
+ finalItems.forEach((item) => {
243
+ const pivotItem = createPivotTreeNode(item, type);
244
+ pivotItem.jaqlIndex = jaqlIndex;
245
+ if (typeof jaqlIndex !== 'undefined') {
246
+ pivotItem.measurePath = Object.assign(Object.assign({}, measurePath), { [jaqlIndex]: pivotItem.value });
247
+ }
248
+ // keep original item
249
+ result.push(pivotItem);
250
+ // check if item has children
251
+ if (treeNode.hasChildren(pivotItem)) {
252
+ const newChildrenNodes = treeNode.getChildren(pivotItem);
253
+ const childOptions = {
254
+ level: level + 1,
255
+ measurePath: pivotItem.measurePath,
256
+ };
257
+ const newChildren = preProcessTree(newChildrenNodes, type, jaql, childOptions);
258
+ treeNode.setChildren(pivotItem, newChildren);
259
+ }
260
+ });
261
+ return result;
262
+ };
263
+ /**
264
+ * Post-process final tree structure with formatting event
265
+ *
266
+ * @param {PivotTreeNode} items - list of PivotTreeNode items
267
+ * @param {JaqlRequest} jaql - jaql request
268
+ * @param {object} [options] - additional options
269
+ * @param {boolean} [options.skipFormatEvent] - process tree but skip format event trigger
270
+ * @param {boolean} [options.onlyFormatEvents] - process tree with format event trigger only
271
+ * @param {Function} [options.iterateFn] - iterate function to call for each tree node
272
+ * @param {Function} [options.emitFn] - transform event emit function to call for each tree node
273
+ * @returns {void}
274
+ */
275
+ export const postProcessTree = (items, jaql, options) => {
276
+ const { skipFormatEvent = false, onlyFormatEvents = false, iterateFn, emitFn } = options || {};
277
+ items.forEach((item) => {
278
+ if (iterateFn) {
279
+ iterateFn(item);
280
+ }
281
+ if (skipFormatEvent || !onlyFormatEvents) {
282
+ postProcessSubTotal(item, jaql);
283
+ postProcessGrandTotal(item, jaql);
284
+ postProcessMeasureNode(item, jaql);
285
+ }
286
+ if (emitFn && (onlyFormatEvents || !skipFormatEvent)) {
287
+ const panel = jaqlProcessor.getMetadataPanelByIndex(jaql, item.jaqlIndex, item.metadataType || '');
288
+ emitFn(item, panel, jaql);
289
+ }
290
+ if (treeNode.hasChildren(item)) {
291
+ const itemChilds = treeNode.getChildren(item);
292
+ postProcessTree(itemChilds, jaql, options);
293
+ }
294
+ });
295
+ };
296
+ /**
297
+ * Modify tree structure for subtotals and grand totals and some customization
298
+ *
299
+ * @param {Array<PivotTreeNode>} items - base items to modify
300
+ * @param {string} type - items types to normalize
301
+ * @param {JaqlRequest} jaql - initial data object
302
+ * @param {object} [options] - modify options
303
+ * @param {TreeNode} [options.originalData] - initial data object
304
+ * @param {Function} [options.applyIndexDivergence] - helper for applying index divergence
305
+ * @returns {PivotTreeNode | Array<PivotTreeNode>} - normalized list of items
306
+ */
307
+ const modifyTree = (items, type, jaql, options) => {
308
+ const { originalData, applyIndexDivergence, subtotalsForSingleRow } = options || {};
309
+ // items odd|even apply
310
+ if (applyIndexDivergence) {
311
+ applyIndexDivergence(items);
312
+ }
313
+ // insert subTotal
314
+ let modifiedItems = insertSubTotals(items, originalData, type, jaql, subtotalsForSingleRow);
315
+ // insert grandTotal
316
+ modifiedItems = insertGrandTotals(modifiedItems, originalData, type, jaql);
317
+ // measure nodes
318
+ modifiedItems = insertMeasureNodes(modifiedItems, originalData, type, jaql);
319
+ treeNode.iterateThroughTree(modifiedItems, (item, parent) => {
320
+ item.parent = parent;
321
+ });
322
+ return modifiedItems;
323
+ };
324
+ export default {
325
+ insertSubTotals,
326
+ postProcessSubTotal,
327
+ insertGrandTotals,
328
+ postProcessGrandTotal,
329
+ insertMeasureNodes,
330
+ postProcessMeasureNode,
331
+ applyColorFormatting,
332
+ preProcessTree,
333
+ modifyTree,
334
+ postProcessTree,
335
+ };
@@ -0,0 +1,135 @@
1
+ import { JaqlRequest } from '../../../data-load/types.js';
2
+ import { ListOfPanelTypes } from '../../constants.js';
3
+ import { PivotTreeNode } from '../../types.js';
4
+ import { CellItem, DimensionMetadata, GlobalStyles, MeasureMetadata, Metadata, PluginConfig } from './types.js';
5
+ export declare class PluginService {
6
+ /**
7
+ * Handlers to apply for pivot cells
8
+ *
9
+ * @private
10
+ * */
11
+ plugins: Array<PluginConfig>;
12
+ /** @private global plugins config */
13
+ globalStyles?: GlobalStyles;
14
+ /** @private */
15
+ jaql: JaqlRequest;
16
+ /**
17
+ * Object to store indexes for data groups
18
+ */
19
+ private indexHelper;
20
+ /**
21
+ * Cache columns metadata after handling column tree node
22
+ *
23
+ * @private
24
+ * */
25
+ columnsMetadata: Array<{
26
+ metadata: Array<DimensionMetadata>;
27
+ type: Array<string>;
28
+ }>;
29
+ metadataCache: Map<string, Metadata>;
30
+ constructor(plugins: Array<any>, jaql: JaqlRequest, globalStyles?: GlobalStyles);
31
+ /**
32
+ * Get array of panels by type
33
+ *
34
+ * @param {ListOfPanelTypes} jaqlPanel - type of panels to return measures|columns|rows
35
+ * @returns {Array<any>} row level of measures in column tree
36
+ */
37
+ getJaqlPanels(jaqlPanel: ListOfPanelTypes): import("../../../data-load/types.js").JaqlPanel[];
38
+ /**
39
+ * Calculate level of measures in column tree
40
+ *
41
+ * @returns {number} row level of measures in column tree
42
+ */
43
+ getMeasuresLevel(): number;
44
+ /**
45
+ * Get count of row panels
46
+ *
47
+ * @returns {void}
48
+ */
49
+ getRowsColumnLength(): number;
50
+ /**
51
+ * Get count of row panels
52
+ *
53
+ * @param {Array<string>} types - array of types from current cell
54
+ * @returns {void}
55
+ */
56
+ getTotalTypes(types: Array<string>): Array<any>;
57
+ /**
58
+ * Calculate measure index and get panel metadata
59
+ *
60
+ * @param {number} index - measure index in row
61
+ * @returns {MeasureMetadata} measure metadata
62
+ */
63
+ getMeasureMetaByIndex(index: number): MeasureMetadata | undefined;
64
+ resetRowStartFrom(): void;
65
+ applyToColumns(columnTreeChildren: Array<PivotTreeNode>): void;
66
+ /**
67
+ * Apply plugins to columns values and cache metadata for measure handler
68
+ *
69
+ * @param {Array<any>} columnTreeChildren - measure index in row
70
+ * @param {object} indexes - measure index in row
71
+ * @returns {void}
72
+ */
73
+ private _applyToColumns;
74
+ /**
75
+ * Apply plugins to corner tree headers
76
+ *
77
+ * @param {any} cornerTree - measure index in row
78
+ * @returns {void}
79
+ */
80
+ applyToHeaders(cornerTree: PivotTreeNode): void;
81
+ applyToRows(rowTreeChildren: Array<PivotTreeNode>): void;
82
+ static getRowStartFromForPage(numberOfRows: number, numberOfMeasures: number, numberOfColumns: number): number;
83
+ /**
84
+ * Apply plugins to rows panels
85
+ *
86
+ * @param {Array<PivotTreeNode>} rowTreeChildren - measure index in row
87
+ * @returns {void}
88
+ */
89
+ private _applyToRows;
90
+ /**
91
+ * Apply plugins to value panels
92
+ *
93
+ * @param {Array<any>} values - measure index in row
94
+ * @param {object} rowData - row data
95
+ * @param {Array<string>} rowData.type - row types
96
+ * @param {Array<DimensionMetadata>} rowData.metadata - metadata of current row
97
+ * @param {object} indexes - parent indexes in tree
98
+ * @param {number} indexes.rowIndex - current row index
99
+ * @param {number} indexes.colIndex - colIndex of last row cell to calculate value cell index
100
+ * @returns {void}
101
+ */
102
+ applyToValues(values: Array<any>, rowData: {
103
+ type: Array<string>;
104
+ metadata: Array<DimensionMetadata>;
105
+ }, indexes: {
106
+ rowIndex: number;
107
+ colIndex: number;
108
+ }): void;
109
+ /**
110
+ * Add cell metadata to map for click/hover APIs
111
+ *
112
+ * @param {Metadata} metadata - cell metadata
113
+ * @param {CellItem} cellItem - cell content
114
+ * @param {number} rowIndex - cell row index
115
+ * @param {number} colIndex - cell column index
116
+ * @returns {void}
117
+ */
118
+ addToMetadata(metadata: Metadata, cellItem: CellItem, rowIndex: number, colIndex: number): void;
119
+ /**
120
+ * Apply global config to cells
121
+ *
122
+ * @param {CellItem} item - cell item to update by plugin
123
+ * @returns {void}
124
+ */
125
+ applyGlobal(item: CellItem): void;
126
+ /**
127
+ * Apply plugins to rows panels
128
+ *
129
+ * @param {Metadata} metadata - cell metadata
130
+ * @param {CellItem} item - cell item to update by plugin
131
+ * @returns {void}
132
+ */
133
+ apply(metadata: Metadata, item: CellItem): void;
134
+ }
135
+ export default PluginService;