'use strict'; function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } /** * Licensed Materials - Property of IBM * IBM Cognos Products: BI Cloud (C) Copyright IBM Corp. 2016, 2020 * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp. */ define([], function () { 'use strict'; return function () { function EdgeIterator(edgeInfo) { var leafnode_index_no_summary = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0; _classCallCheck(this, EdgeIterator); this.edge = edgeInfo.edge; this.keys = edgeInfo.sortedKeys; this.currentKeyIndex = 0; this.subIterator = null; this.numberOfLeafNodes = 0; //this is the index of the leaf nodes over the entire edge not including the summary this.leafnode_index_no_summary = leafnode_index_no_summary; } EdgeIterator.prototype.next = function next(ancestors, maxLevel) { var next = null; if (this._previous && !this._previous.isSummary) { ++this.leafnode_index_no_summary; } if (this.currentKeyIndex < this.keys.length) { //an array of descendants including self var _self = []; var key = this.keys[this.currentKeyIndex]; var currentEdge = this.edge[key]; // Summary key doesn't have value. var edgeItem = currentEdge.value !== undefined ? currentEdge.value : key; _self.push(edgeItem); if (!this.subIterator && currentEdge.nestedEdges) { this._first = null; this.ancestor_or_self = !ancestors || ancestors.length === 0 ? [edgeItem] : ancestors.concat(edgeItem); this.numberOfLeafNodes = 0; this.subIterator = new this.EdgeIterator(currentEdge.nestedEdges, this.leafnode_index_no_summary); } if (this.subIterator) { var subCategory = this.subIterator.next(this.ancestor_or_self, maxLevel); if (subCategory) { if (subCategory.hasLeafNode || subCategory.isLeafNode) { //this is number of leaf nodes so far in the traversal this.numberOfLeafNodes++; } next = this.createNodeInfo(_self, edgeItem, currentEdge, subCategory, maxLevel); } else { // Move to the next index this.currentKeyIndex++; this.subIterator = null; this._first.noOfLeafNodes = this._previous.index + 1; this._first.first = true; next = this.next(ancestors, maxLevel); } } else { //leaf node info next = this.createLeafNodeInfo(_self, edgeItem, currentEdge, ancestors, maxLevel); this.currentKeyIndex++; } } if (!this._first) { this._first = next; } this._previous = next; return next; }; EdgeIterator.prototype.createLeafNodeInfo = function createLeafNodeInfo() /* descendant_or_self, value, currentEdge, ancestors, maxLevel */{ throw new Error('EdgeIterator.createLeafNodeInfo is not implemented'); }; EdgeIterator.prototype.createNodeInfo = function createNodeInfo() /* descendant_or_self, value, currentEdge, childNode, maxLevel */{ throw new Error('EdgeIterator.createNodeInfo is not implemented'); }; /** * This function rollup the 'Summary' of a descendants if a descendants are summaries and the current nodeInfo itself is also a summary * * @param {object} nodeInfo = the node to rollup summary of descendents * @param {string} value - the current nodeInfo summary value * @param {number} maxLevel - the maximum nesting level * @param {object} [childNode] - the immediate children of the nodeInfo * * @return {boolean} return true if rollup summaries else return false */ EdgeIterator.prototype.rollupSummariesOfDescendents = function rollupSummariesOfDescendents(nodeInfo, value, maxLevel, childNode) { var currentNestLevel = nodeInfo.nestLevel + (childNode ? childNode.descendant_or_self.length : 0); var rollup = nodeInfo.isSummary && !nodeInfo.isMeasure && Number.isInteger(maxLevel) && currentNestLevel < maxLevel; //there are gaps between currentNestLevel && maxLevel if (rollup) { var iterateMaxLevel = maxLevel - (childNode ? childNode.descendant_or_self.length : 0); for (var i = nodeInfo.nestLevel; i < iterateMaxLevel; i++) { nodeInfo.descendant_or_self.push(value); } } return rollup; }; return EdgeIterator; }(); }); //# sourceMappingURL=EdgeIterator.js.map