@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,74 @@
1
+ import { JaqlPanel, JaqlRequest } from '../../data-load/types.js';
2
+ import { TreeNode } from '../../tree-structure/types.js';
3
+ import { PivotDataNode, PivotTreeNode } from '../types.js';
4
+ export declare const insertSubTotals: (items: PivotTreeNode[], originalData: TreeNode | undefined, type: string, jaql: JaqlRequest | undefined, subtotalsForSingleRow: boolean | undefined) => Array<PivotTreeNode>;
5
+ export declare const postProcessSubTotal: (item: PivotTreeNode, jaql?: JaqlRequest) => void;
6
+ export declare const insertGrandTotals: (items: PivotTreeNode[], originalData: TreeNode | undefined, type: string, jaql?: JaqlRequest) => Array<PivotTreeNode>;
7
+ export declare const postProcessGrandTotal: (item: PivotTreeNode, jaql?: JaqlRequest) => void;
8
+ export declare const insertMeasureNodes: (items: PivotTreeNode[], originalData: TreeNode | undefined, type: string, jaql?: JaqlRequest) => Array<PivotTreeNode>;
9
+ export declare const postProcessMeasureNode: (item: PivotTreeNode, jaql?: JaqlRequest) => void;
10
+ export declare const applyColorFormatting: (item: PivotDataNode, rowItem: PivotTreeNode, columnItem: PivotTreeNode, measurePanel?: JaqlPanel) => void;
11
+ /**
12
+ * Pre-process initial tree structure
13
+ *
14
+ * @param {Array<TreeNode>} items - items to normalize
15
+ * @param {string} type - items types to normalize
16
+ * @param {JaqlRequest} jaql - jaql request
17
+ * @param {object} options - additional options
18
+ * @param {number} [options.level=0] - tree level, for internal use only
19
+ * @param {object} [options.measurePath={}] - items types to normalize
20
+ * @returns {Array<PivotTreeNode>} - normalized list of items
21
+ */
22
+ export declare const preProcessTree: (items: TreeNode | Array<TreeNode>, type: string, jaql: JaqlRequest, options?: {
23
+ level?: number | undefined;
24
+ measurePath?: {
25
+ [key: string]: string;
26
+ } | undefined;
27
+ } | undefined) => Array<PivotTreeNode>;
28
+ /**
29
+ * Post-process final tree structure with formatting event
30
+ *
31
+ * @param {PivotTreeNode} items - list of PivotTreeNode items
32
+ * @param {JaqlRequest} jaql - jaql request
33
+ * @param {object} [options] - additional options
34
+ * @param {boolean} [options.skipFormatEvent] - process tree but skip format event trigger
35
+ * @param {boolean} [options.onlyFormatEvents] - process tree with format event trigger only
36
+ * @param {Function} [options.iterateFn] - iterate function to call for each tree node
37
+ * @param {Function} [options.emitFn] - transform event emit function to call for each tree node
38
+ * @returns {void}
39
+ */
40
+ export declare const postProcessTree: (items: Array<PivotTreeNode>, jaql: JaqlRequest, options?: {
41
+ skipFormatEvent?: boolean | undefined;
42
+ onlyFormatEvents?: boolean | undefined;
43
+ iterateFn?: Function | undefined;
44
+ emitFn?: ((item: PivotTreeNode, panel: JaqlPanel | undefined, jaql: JaqlRequest) => void) | undefined;
45
+ } | undefined) => void;
46
+ declare const _default: {
47
+ insertSubTotals: (items: PivotTreeNode<any>[], originalData: TreeNode | undefined, type: string, jaql: JaqlRequest | undefined, subtotalsForSingleRow: boolean | undefined) => PivotTreeNode<any>[];
48
+ postProcessSubTotal: (item: PivotTreeNode<any>, jaql?: JaqlRequest | undefined) => void;
49
+ insertGrandTotals: (items: PivotTreeNode<any>[], originalData: TreeNode | undefined, type: string, jaql?: JaqlRequest | undefined) => PivotTreeNode<any>[];
50
+ postProcessGrandTotal: (item: PivotTreeNode<any>, jaql?: JaqlRequest | undefined) => void;
51
+ insertMeasureNodes: (items: PivotTreeNode<any>[], originalData: TreeNode | undefined, type: string, jaql?: JaqlRequest | undefined) => PivotTreeNode<any>[];
52
+ postProcessMeasureNode: (item: PivotTreeNode<any>, jaql?: JaqlRequest | undefined) => void;
53
+ applyColorFormatting: (item: PivotDataNode<any, import("../../index.js").InputStyles<{
54
+ [x: string]: string | number | null | undefined;
55
+ }>>, rowItem: PivotTreeNode<any>, columnItem: PivotTreeNode<any>, measurePanel?: JaqlPanel | undefined) => void;
56
+ preProcessTree: (items: TreeNode | TreeNode[], type: string, jaql: JaqlRequest, options?: {
57
+ level?: number | undefined;
58
+ measurePath?: {
59
+ [key: string]: string;
60
+ } | undefined;
61
+ } | undefined) => PivotTreeNode<any>[];
62
+ modifyTree: (items: PivotTreeNode<any>[], type: string, jaql: JaqlRequest, options?: {
63
+ originalData?: TreeNode | undefined;
64
+ applyIndexDivergence?: ((items: PivotTreeNode<any>[]) => void) | undefined;
65
+ subtotalsForSingleRow?: boolean | undefined;
66
+ } | undefined) => PivotTreeNode<any>[];
67
+ postProcessTree: (items: PivotTreeNode<any>[], jaql: JaqlRequest, options?: {
68
+ skipFormatEvent?: boolean | undefined;
69
+ onlyFormatEvents?: boolean | undefined;
70
+ iterateFn?: Function | undefined;
71
+ emitFn?: ((item: PivotTreeNode<any>, panel: JaqlPanel | undefined, jaql: JaqlRequest) => void) | undefined;
72
+ } | undefined) => void;
73
+ };
74
+ export default _default;
@@ -0,0 +1,373 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __importDefault = (this && this.__importDefault) || function (mod) {
26
+ return (mod && mod.__esModule) ? mod : { "default": mod };
27
+ };
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ exports.postProcessTree = exports.preProcessTree = exports.applyColorFormatting = exports.postProcessMeasureNode = exports.insertMeasureNodes = exports.postProcessGrandTotal = exports.insertGrandTotals = exports.postProcessSubTotal = exports.insertSubTotals = void 0;
30
+ const index_js_1 = require("../../tree-structure/utils/index.js");
31
+ const constants_js_1 = require("../constants.js");
32
+ const createPivotTreeNode_js_1 = __importDefault(require("./createPivotTreeNode.js"));
33
+ const jaqlProcessor = __importStar(require("./jaqlProcessor.js"));
34
+ /**
35
+ * Helper for checking if tree has only one branch on all it's depth levels
36
+ *
37
+ * @param {TreeNode} root - tree root node
38
+ * @param {string} type - tree node type, rows | columns
39
+ * @returns {boolean} - boolean response
40
+ */
41
+ function hasTreeMultipleBranches(root, type) {
42
+ if (!index_js_1.treeNode.hasChildren(root)) {
43
+ return false;
44
+ }
45
+ let forceTotals = false;
46
+ if (type === constants_js_1.PanelType.COLUMNS && root && root.isPart) {
47
+ forceTotals = true;
48
+ }
49
+ const children = index_js_1.treeNode.getChildren(root);
50
+ if (children.length > 1 || forceTotals) {
51
+ return true;
52
+ }
53
+ const [singleChild] = children;
54
+ return hasTreeMultipleBranches(singleChild);
55
+ }
56
+ /**
57
+ * Helper for checking if node value is empty
58
+ *
59
+ * @param {*} value - node value
60
+ * @returns {boolean} - is empty flag
61
+ */
62
+ function isEmptyValue(value) {
63
+ return value === null || value === undefined;
64
+ }
65
+ const insertSubTotals = (items, originalData, type, jaql, // eslint-disable-line no-unused-vars
66
+ subtotalsForSingleRow) => {
67
+ const result = [];
68
+ // eslint-disable-next-line sonarjs/cognitive-complexity
69
+ items.forEach((item) => {
70
+ // keep original item
71
+ result.push(item);
72
+ if (index_js_1.treeNode.hasChildren(item)) {
73
+ const newChildrenNodes = index_js_1.treeNode.getChildren(item);
74
+ const newChildren = (0, exports.insertSubTotals)(newChildrenNodes, originalData, type, jaql, subtotalsForSingleRow);
75
+ index_js_1.treeNode.setChildren(item, newChildren);
76
+ // check if item has subtotal
77
+ let hasSubTotals = false;
78
+ if (subtotalsForSingleRow || hasTreeMultipleBranches(item, type)) {
79
+ if (type === constants_js_1.PanelType.COLUMNS) {
80
+ if (typeof item.index !== 'undefined' && item.index > -1) {
81
+ hasSubTotals = true;
82
+ }
83
+ }
84
+ else if (type === constants_js_1.PanelType.ROWS) {
85
+ if (typeof item.data !== 'undefined') {
86
+ hasSubTotals = true;
87
+ }
88
+ }
89
+ }
90
+ if (hasSubTotals) {
91
+ const { value, index, data, jaqlIndex, measurePath } = item;
92
+ let roughSubTotalItem;
93
+ if (type === constants_js_1.PanelType.COLUMNS) {
94
+ roughSubTotalItem = index_js_1.treeNode.create(value, undefined, undefined, index);
95
+ }
96
+ else if (type === constants_js_1.PanelType.ROWS) {
97
+ roughSubTotalItem = index_js_1.treeNode.create(value, undefined, data);
98
+ }
99
+ if (roughSubTotalItem) {
100
+ const subTotalItem = (0, createPivotTreeNode_js_1.default)(roughSubTotalItem, type);
101
+ subTotalItem.userType = constants_js_1.UserType.SUB_TOTAL;
102
+ subTotalItem.jaqlIndex = jaqlIndex;
103
+ subTotalItem.measurePath = measurePath;
104
+ subTotalItem.master = item;
105
+ result.push(subTotalItem);
106
+ }
107
+ }
108
+ }
109
+ });
110
+ return result;
111
+ };
112
+ exports.insertSubTotals = insertSubTotals;
113
+ // eslint-disable-next-line no-unused-vars
114
+ const postProcessSubTotal = (item, jaql) => {
115
+ if (item.userType === constants_js_1.UserType.SUB_TOTAL) {
116
+ if (item.master) {
117
+ item.measurePath = item.master.measurePath;
118
+ }
119
+ }
120
+ };
121
+ exports.postProcessSubTotal = postProcessSubTotal;
122
+ const insertGrandTotals = (items, originalData, type, jaql) => {
123
+ const result = items;
124
+ if (type === constants_js_1.PanelType.COLUMNS && originalData) {
125
+ const rootItem = (0, createPivotTreeNode_js_1.default)(originalData);
126
+ const hasGrandTotals = typeof rootItem.index === 'number';
127
+ if (hasGrandTotals) {
128
+ const valuesTree = jaqlProcessor.getMetadataTree(jaql, constants_js_1.PanelType.MEASURES);
129
+ index_js_1.treeNode.getChildren(valuesTree).forEach((valueNode, i) => {
130
+ const roughGrandTotalItem = Object.assign(Object.assign({}, valueNode), { index: (rootItem.index || 0) + i });
131
+ const grandTotalItem = (0, createPivotTreeNode_js_1.default)(roughGrandTotalItem, type);
132
+ grandTotalItem.userType = constants_js_1.UserType.GRAND_TOTAL;
133
+ // set measure jaqlIndex
134
+ grandTotalItem.measureJaqlIndex = grandTotalItem.jaqlIndex;
135
+ result.push(grandTotalItem);
136
+ });
137
+ }
138
+ }
139
+ return result;
140
+ };
141
+ exports.insertGrandTotals = insertGrandTotals;
142
+ // eslint-disable-next-line no-unused-vars
143
+ const postProcessGrandTotal = (item, jaql) => {
144
+ if (item.userType === constants_js_1.UserType.GRAND_TOTAL) {
145
+ item.measurePath = undefined;
146
+ if (item.metadataType === constants_js_1.PanelType.ROWS) {
147
+ item.parent = undefined;
148
+ item.jaqlIndex = 0;
149
+ }
150
+ }
151
+ };
152
+ exports.postProcessGrandTotal = postProcessGrandTotal;
153
+ const insertMeasureNodes = (items, originalData, type, jaql) => {
154
+ let result = items;
155
+ if (type === constants_js_1.PanelType.COLUMNS) {
156
+ const valuesTree = jaqlProcessor.getMetadataTree(jaql, constants_js_1.PanelType.MEASURES);
157
+ const count = index_js_1.treeNode.getChildLength(valuesTree);
158
+ const columnsOptions = { maxLevel: 0 };
159
+ const columnsLastLevel = index_js_1.treeNode.getLastLevelNodes(result, [], 0, columnsOptions);
160
+ if (count > 1) {
161
+ // add values nodes at the last level
162
+ columnsLastLevel.forEach((lastNode) => {
163
+ if (lastNode.userType === constants_js_1.UserType.GRAND_TOTAL) {
164
+ return;
165
+ }
166
+ const lastChildren = index_js_1.treeNode.getChildren(valuesTree);
167
+ const lastFinalChildren = [];
168
+ for (let i = 0; i < lastChildren.length; i += 1) {
169
+ if (typeof lastNode.maxChilds === 'number' && i >= lastNode.maxChilds) {
170
+ // eslint-disable-next-line no-continue
171
+ continue;
172
+ }
173
+ const roughMeasureItem = Object.assign(Object.assign({}, lastChildren[i]), { index: (lastNode.index || 0) + i, measurePath: lastNode.measurePath });
174
+ const measureItem = (0, createPivotTreeNode_js_1.default)(roughMeasureItem, constants_js_1.PanelType.MEASURES);
175
+ measureItem.userType = constants_js_1.UserType.MEASURE_BOTTOM;
176
+ // set measure jaqlIndex
177
+ measureItem.measureJaqlIndex = measureItem.jaqlIndex;
178
+ lastFinalChildren.push(measureItem);
179
+ }
180
+ lastNode.minLevel = columnsOptions.maxLevel;
181
+ index_js_1.treeNode.setChildren(lastNode, lastFinalChildren);
182
+ });
183
+ }
184
+ else if (count === 1) {
185
+ // add value node at the first level
186
+ const valueNode = index_js_1.treeNode.getChildren(valuesTree)[0];
187
+ if (valueNode) {
188
+ const roughMeasureItem = Object.assign({}, valueNode);
189
+ const measureItem = (0, createPivotTreeNode_js_1.default)(roughMeasureItem, constants_js_1.PanelType.MEASURES);
190
+ measureItem.userType = constants_js_1.UserType.MEASURE_TOP;
191
+ index_js_1.treeNode.setChildren(measureItem, result);
192
+ result = [measureItem];
193
+ // set measure jaqlIndex
194
+ columnsLastLevel.forEach((lastNode) => {
195
+ lastNode.measureJaqlIndex = valueNode.jaqlIndex;
196
+ });
197
+ }
198
+ }
199
+ }
200
+ return result;
201
+ };
202
+ exports.insertMeasureNodes = insertMeasureNodes;
203
+ const postProcessMeasureNode = (item, jaql) => {
204
+ if (!index_js_1.treeNode.hasChildren(item) && typeof item.measureJaqlIndex !== 'undefined') {
205
+ jaqlProcessor.markSortedNode(jaql, item);
206
+ }
207
+ };
208
+ exports.postProcessMeasureNode = postProcessMeasureNode;
209
+ const applyColorFormatting = (item, rowItem, columnItem, measurePanel) => {
210
+ let style = {};
211
+ if (rowItem.userType === constants_js_1.UserType.SUB_TOTAL ||
212
+ rowItem.userType === constants_js_1.UserType.GRAND_TOTAL ||
213
+ columnItem.userType === constants_js_1.UserType.SUB_TOTAL ||
214
+ columnItem.userType === constants_js_1.UserType.GRAND_TOTAL ||
215
+ (columnItem.parent && columnItem.parent.userType === constants_js_1.UserType.SUB_TOTAL) ||
216
+ (columnItem.parent && columnItem.parent.userType === constants_js_1.UserType.GRAND_TOTAL)) {
217
+ // ignore SUB_TOTAL & GRAND_TOTAL
218
+ return;
219
+ }
220
+ const colorFormat = (measurePanel && measurePanel.format && measurePanel.format.color) || null;
221
+ if (!colorFormat) {
222
+ return;
223
+ }
224
+ const { value, cf = -1 } = item;
225
+ if (colorFormat.type === constants_js_1.ColorFormatType.COLOR) {
226
+ if (colorFormat.color && colorFormat.color !== 'transparent') {
227
+ style.backgroundColor = colorFormat.color;
228
+ }
229
+ }
230
+ if (colorFormat.type === constants_js_1.ColorFormatType.CONDITION) {
231
+ if (colorFormat.conditions && colorFormat.conditions.length) {
232
+ for (let i = 0, c = colorFormat.conditions.length; i < c; i += 1) {
233
+ // handle empty value case
234
+ if (isEmptyValue(value)) {
235
+ break;
236
+ }
237
+ // handle condition case
238
+ const conditions = colorFormat.conditions || [];
239
+ const { color } = conditions[i] || {};
240
+ if (color && cf === i) {
241
+ style.backgroundColor = color;
242
+ break;
243
+ }
244
+ }
245
+ }
246
+ }
247
+ if (Object.keys(style).length > 0) {
248
+ item.style = item.style || {};
249
+ Object.assign(item.style, style);
250
+ }
251
+ style = undefined;
252
+ };
253
+ exports.applyColorFormatting = applyColorFormatting;
254
+ /**
255
+ * Pre-process initial tree structure
256
+ *
257
+ * @param {Array<TreeNode>} items - items to normalize
258
+ * @param {string} type - items types to normalize
259
+ * @param {JaqlRequest} jaql - jaql request
260
+ * @param {object} options - additional options
261
+ * @param {number} [options.level=0] - tree level, for internal use only
262
+ * @param {object} [options.measurePath={}] - items types to normalize
263
+ * @returns {Array<PivotTreeNode>} - normalized list of items
264
+ */
265
+ const preProcessTree = (items, type, jaql, options) => {
266
+ const result = [];
267
+ const { level = 0, measurePath = {} } = options || {};
268
+ let finalItems;
269
+ if (Array.isArray(items)) {
270
+ finalItems = items;
271
+ }
272
+ else {
273
+ finalItems = index_js_1.treeNode.getChildren(items);
274
+ }
275
+ const panels = jaqlProcessor.getMetadataPanels(jaql, type);
276
+ const panel = panels[level];
277
+ const jaqlIndex = panel ? (panel.field || { index: Infinity }).index : undefined;
278
+ finalItems.forEach((item) => {
279
+ const pivotItem = (0, createPivotTreeNode_js_1.default)(item, type);
280
+ pivotItem.jaqlIndex = jaqlIndex;
281
+ if (typeof jaqlIndex !== 'undefined') {
282
+ pivotItem.measurePath = Object.assign(Object.assign({}, measurePath), { [jaqlIndex]: pivotItem.value });
283
+ }
284
+ // keep original item
285
+ result.push(pivotItem);
286
+ // check if item has children
287
+ if (index_js_1.treeNode.hasChildren(pivotItem)) {
288
+ const newChildrenNodes = index_js_1.treeNode.getChildren(pivotItem);
289
+ const childOptions = {
290
+ level: level + 1,
291
+ measurePath: pivotItem.measurePath,
292
+ };
293
+ const newChildren = (0, exports.preProcessTree)(newChildrenNodes, type, jaql, childOptions);
294
+ index_js_1.treeNode.setChildren(pivotItem, newChildren);
295
+ }
296
+ });
297
+ return result;
298
+ };
299
+ exports.preProcessTree = preProcessTree;
300
+ /**
301
+ * Post-process final tree structure with formatting event
302
+ *
303
+ * @param {PivotTreeNode} items - list of PivotTreeNode items
304
+ * @param {JaqlRequest} jaql - jaql request
305
+ * @param {object} [options] - additional options
306
+ * @param {boolean} [options.skipFormatEvent] - process tree but skip format event trigger
307
+ * @param {boolean} [options.onlyFormatEvents] - process tree with format event trigger only
308
+ * @param {Function} [options.iterateFn] - iterate function to call for each tree node
309
+ * @param {Function} [options.emitFn] - transform event emit function to call for each tree node
310
+ * @returns {void}
311
+ */
312
+ const postProcessTree = (items, jaql, options) => {
313
+ const { skipFormatEvent = false, onlyFormatEvents = false, iterateFn, emitFn } = options || {};
314
+ items.forEach((item) => {
315
+ if (iterateFn) {
316
+ iterateFn(item);
317
+ }
318
+ if (skipFormatEvent || !onlyFormatEvents) {
319
+ (0, exports.postProcessSubTotal)(item, jaql);
320
+ (0, exports.postProcessGrandTotal)(item, jaql);
321
+ (0, exports.postProcessMeasureNode)(item, jaql);
322
+ }
323
+ if (emitFn && (onlyFormatEvents || !skipFormatEvent)) {
324
+ const panel = jaqlProcessor.getMetadataPanelByIndex(jaql, item.jaqlIndex, item.metadataType || '');
325
+ emitFn(item, panel, jaql);
326
+ }
327
+ if (index_js_1.treeNode.hasChildren(item)) {
328
+ const itemChilds = index_js_1.treeNode.getChildren(item);
329
+ (0, exports.postProcessTree)(itemChilds, jaql, options);
330
+ }
331
+ });
332
+ };
333
+ exports.postProcessTree = postProcessTree;
334
+ /**
335
+ * Modify tree structure for subtotals and grand totals and some customization
336
+ *
337
+ * @param {Array<PivotTreeNode>} items - base items to modify
338
+ * @param {string} type - items types to normalize
339
+ * @param {JaqlRequest} jaql - initial data object
340
+ * @param {object} [options] - modify options
341
+ * @param {TreeNode} [options.originalData] - initial data object
342
+ * @param {Function} [options.applyIndexDivergence] - helper for applying index divergence
343
+ * @returns {PivotTreeNode | Array<PivotTreeNode>} - normalized list of items
344
+ */
345
+ const modifyTree = (items, type, jaql, options) => {
346
+ const { originalData, applyIndexDivergence, subtotalsForSingleRow } = options || {};
347
+ // items odd|even apply
348
+ if (applyIndexDivergence) {
349
+ applyIndexDivergence(items);
350
+ }
351
+ // insert subTotal
352
+ let modifiedItems = (0, exports.insertSubTotals)(items, originalData, type, jaql, subtotalsForSingleRow);
353
+ // insert grandTotal
354
+ modifiedItems = (0, exports.insertGrandTotals)(modifiedItems, originalData, type, jaql);
355
+ // measure nodes
356
+ modifiedItems = (0, exports.insertMeasureNodes)(modifiedItems, originalData, type, jaql);
357
+ index_js_1.treeNode.iterateThroughTree(modifiedItems, (item, parent) => {
358
+ item.parent = parent;
359
+ });
360
+ return modifiedItems;
361
+ };
362
+ exports.default = {
363
+ insertSubTotals: exports.insertSubTotals,
364
+ postProcessSubTotal: exports.postProcessSubTotal,
365
+ insertGrandTotals: exports.insertGrandTotals,
366
+ postProcessGrandTotal: exports.postProcessGrandTotal,
367
+ insertMeasureNodes: exports.insertMeasureNodes,
368
+ postProcessMeasureNode: exports.postProcessMeasureNode,
369
+ applyColorFormatting: exports.applyColorFormatting,
370
+ preProcessTree: exports.preProcessTree,
371
+ modifyTree,
372
+ postProcessTree: exports.postProcessTree,
373
+ };
@@ -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;