'use strict'; var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; 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: Dashboard * (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(['../../../util/DashboardFormatter', '../../../widgets/livewidget/nls/StringResources', './CrosstabEdgeIterator', '../../../widgets/livewidget/query/QueryResultDataUtils'], function (Formatter, StringResources, CrosstabEdgeIterator, QueryResultDataUtils) { /** This class pivots the query data, [[column-level1, column-level2, row-level1, row-level2, measure1, measure2, .. measure-n ], [column-level1, column-level2, row-level1, row-level2, measure1, measure2, .. measure-n ], [ ... ]] into a table that can be easily rendered into a crosstab The transformed table looks something like : [ [ '' '' row-level1 row-level1 row-level1 row-level1 ... ] [ '' '' row-level2 row-level2 row-level2 row-level2 ... ] [ ... ] [ column-level1 column-level2 fact fact fact fact fact ... ] [ column-level1 column-level2 fact fact fact fact fact ... ] [ ... ] ] **/ 'use strict'; var SUMMARY_ID = StringResources.get('summaryCaption'); var ROW = 'row'; var COL = 'col'; var COLUMN = 'column'; var ORDINAL = 'ordinal'; var HEAT = 'heat'; var DATE = 'date'; var UNDEFINED = 'undefined'; var Pivot = function () { function Pivot(options) { var _this = this; _classCallCheck(this, Pivot); this.slots = options.slots; this.data = options.data; this.visModel = options.visModel; this.dashboard = options.dashboard; this.conditionalFormatting = options.conditionalFormatting; this.rowEdge = {}; this.columnEdge = {}; this.valuesMap = {}; this.colEdgeNestingLevel = 0; this.rowEdgeNestingLevel = 0; // Index tof the first value (measure) this._valuesStartIdx = 0; this._measuresInfo = []; this._rowInfo = []; this._columnInfo = []; this._conditionalMeasureInfoNew = []; this.indexInfo = { row: [], col: [] }; this.levelInfo = { row: {}, col: {} }; this.summaryValuePromises = []; var slotsAPIs = this.slots.getMappedSlotList(); if (options && options.data && options.data.getVersion && options.data.getVersion() === '2') { this._v2Summaries = true; } else { this.summaryAPI = this.visModel.ownerWidget.getFeature('summaryFeature'); } var resultDataItemList = QueryResultDataUtils.getResultDataItemList(this.data.getResultItemList()); var oSlot = void 0, aDataItems = void 0, dataItem = void 0; for (var slotIndex = 0; slotIndex < slotsAPIs.length; slotIndex++) { oSlot = slotsAPIs[slotIndex]; aDataItems = oSlot.getDataItemList(); if (oSlot.getId().indexOf(ROW) !== -1) { this._valuesStartIdx++; for (var dataItemIndex = 0; dataItemIndex < aDataItems.length; dataItemIndex++) { dataItem = aDataItems[dataItemIndex]; this.rowEdgeNestingLevel++; this._addEdgeDataItemInfo(slotIndex, dataItemIndex, ROW); this._rowInfo.push({ id: dataItem.getId(), dataType: oSlot.getDefinition().getType(), formatSpec: dataItem.getFormat() }); } } if (oSlot.getId().indexOf(COLUMN) !== -1) { this._valuesStartIdx++; for (var _dataItemIndex = 0; _dataItemIndex < aDataItems.length; _dataItemIndex++) { dataItem = aDataItems[_dataItemIndex]; this.colEdgeNestingLevel++; this._addEdgeDataItemInfo(slotIndex, _dataItemIndex, COL); this._columnInfo.push({ id: dataItem.getId(), dataType: oSlot.getDefinition().getType(), formatSpec: dataItem.getFormat() }); } } if (oSlot.getDefinition().getType() === ORDINAL) { for (var _dataItemIndex2 = 0; _dataItemIndex2 < aDataItems.length; _dataItemIndex2++) { dataItem = aDataItems[_dataItemIndex2]; var aggregationType = dataItem.getAggregation(); var info = { id: dataItem.getId(), label: dataItem.getLabel(), aggregationType: aggregationType, formatSpec: dataItem.getFormat(), columnId: dataItem.getColumnId() }; // exclude the conditional measure from other measures if (oSlot.getId() === HEAT) { this._conditionalMeasureInfo = info; if (this.conditionalFormatting) { this._conditionalMeasureInfoNew.push(info); } } else if (this._measureItemHasData(resultDataItemList, dataItem)) { this._measuresInfo.push(info); } } // set measure index for the conditionals if (this.conditionalFormatting) { (function () { var condFormats = _this.conditionalFormatting.getConditionalFormatting(); if (condFormats && condFormats.conditionalFormats) { _this._conditionalMeasureInfoNew.forEach(function (conditional) { var condFormat = condFormats.conditionalFormats.find(function (cf) { return cf.heatId === conditional.id; }); if (condFormat) { _this._measuresInfo.forEach(function (measureInfo, index) { if (measureInfo.columnId === condFormat.dataItemId) { conditional.measureIndex = index; } }); } }); } })(); } } } this._colRowInfo = this._columnInfo.concat(this._rowInfo); this._columnEdgeHasMeasure = this._measuresInfo.length > 1 || this.colEdgeNestingLevel === 0; if (this._columnEdgeHasMeasure) { this.colEdgeNestingLevelWithMeasure = this.colEdgeNestingLevel + 1; } else { this._crosstabMeasure = this._measuresInfo.length ? this._measuresInfo[0].label : null; } } //Add the dataItem index info to cache Pivot.prototype._addEdgeDataItemInfo = function _addEdgeDataItemInfo(slotIndex, nestedIndex, rowOrCol) { if (this.data) { if (rowOrCol === ROW) { this.indexInfo.row.push({ slotIndex: slotIndex, nestedIndex: nestedIndex }); } else { this.indexInfo.col.push({ slotIndex: slotIndex, nestedIndex: nestedIndex }); } } }; Pivot.prototype.create = function create() { this._hideSummaries = this.visModel.getPropertyValue('hideSummaries'); this._generateEdgesAndValueMap(); //Build the pivot table var pivotTable = []; this._addColumnEdgeCategories(pivotTable); this._addRowEdgeCategoriesAndFactCells(pivotTable); return pivotTable; }; Pivot.prototype.getNestingLevels = function getNestingLevels() { if (this._columnEdgeHasMeasure) { return { colNestingLevel: this.colEdgeNestingLevel + 1, rowNestingLevel: this.rowEdgeNestingLevel }; } else { return { colNestingLevel: this.colEdgeNestingLevel, rowNestingLevel: this.rowEdgeNestingLevel }; } }; Pivot.prototype.getLevelInfo = function getLevelInfo() { return this.levelInfo; }; /** * Extract either a cell value or the "tuple part" of an edge value at the specified nesting depth. * eg: for row n containing tuple(2004, Canada) on the rows (measure on columns) * getCellValue(n, 0, 0) would return '2004' * getCellValue(n, 0, 1) would return 'Canada' * getCellValue(n, 1) would return the measure value. * @param {number} i - the row * @param {number} c - the column base (it will be the same for all levels of nesting in a tuple) * @param {number} nestedIndex - the nesting level (which tuple part?) */ Pivot.prototype.getCellValue = function getCellValue(i, c, nestedIndex) { var originalResult = this.data.getValue(i, c); var result = originalResult; var isSummary = result && result.type === this.data.VALUE_TYPE.SUMMARY; if (Array.isArray(result) && nestedIndex !== undefined) { result = result[nestedIndex]; } if (isSummary) { //This code is specific for v2 summaries. //If this is an 'outersummary', the tuple length will be shorter than the nesting depth. //Backfill with the most detailed summary. result = result || originalResult && originalResult.length && originalResult[originalResult.length - 1]; if (result) { //Tuples (not tuple parts) are marked as summaries but we extract tupleParts in crosstab. //If we need to mark this tuplepart as a summary, mark a copy not the original! result = JSON.parse(JSON.stringify(result)); result.label = SUMMARY_ID; result.isSummary = true; } } return result; }; /** * This function calculate the levelInfo for rowEdge and colEdge * @param {string} row or col * @param {number} rowIndex or colIndex * @param {number} levelNumber */ Pivot.prototype._determineLevelInfo = function _determineLevelInfo(type, index, levelNumber) { if (this.levelInfo[type][index] !== undefined) { var _levelInfo$type$index = this.levelInfo[type][index], rootLevelnumber = _levelInfo$type$index.rootLevelnumber, maxLevelDepth = _levelInfo$type$index.maxLevelDepth; this.levelInfo[type][index] = { rootLevelnumber: Math.min(rootLevelnumber, levelNumber), maxLevelDepth: Math.max(maxLevelDepth, levelNumber - rootLevelnumber) }; } else { this.levelInfo[type][index] = { rootLevelnumber: levelNumber, maxLevelDepth: 0 }; } }; /** * this function process the incoming data and generates the colEdge, rowEdge and valuesMap which is then used to * to create the pivot table */ Pivot.prototype._generateEdgesAndValueMap = function _generateEdgesAndValueMap() { var _this2 = this; var rowEdge = {}; var columnEdge = {}; var numberOfRows = this.data.getRowCount(); var numberOfColumns = QueryResultDataUtils.getDataItemCount(this.data.getResultItemList()); // projected measure ending index var heatIndex = this._valuesStartIdx + this._measuresInfo.length; for (var i = 0; i < numberOfRows; i++) { // get the row edge dimension values var isSummaryCell = false; var rowDimensions = []; for (var cr = 0; cr < numberOfColumns; cr++) { // Make sure we have index info for this column if (this.indexInfo.row[cr] !== undefined) { var cellValue = this.getCellValue(i, this.indexInfo.row[cr].slotIndex, this.indexInfo.row[cr].nestedIndex); //Cellvalue can be null for some values in unbalanced hierarchies. Only contribute dimensions that are populated. if (cellValue) { isSummaryCell = isSummaryCell || cellValue.isSummary; //This will only be set for v2. rowDimensions.push(cellValue); // populate the levelInfo for row edge (fixed columns) var levelNumber = cellValue && cellValue.ln; if (levelNumber !== undefined) { this._determineLevelInfo(COL, cr, levelNumber); } } } } this._addDimensionToEdge(rowEdge, rowDimensions, this.rowEdgeNestingLevel, ROW); // get the column edge dimension values var columnDimensions = []; for (var cc = 0; cc < numberOfColumns; cc++) { // Make sure we have index info for this row if (this.indexInfo.col[cc] !== undefined) { var _cellValue = this.getCellValue(i, this.indexInfo.col[cc].slotIndex, this.indexInfo.col[cc].nestedIndex); //Cellvalue can be null for some values in unbalanced hierarchies. Only contribute dimensions that are populated. if (_cellValue) { isSummaryCell = isSummaryCell || _cellValue.isSummary; //This will only be set for v2. columnDimensions.push(_cellValue); // populate the levelInfo for column edge (fixed rows) var _levelNumber = _cellValue && _cellValue.ln; if (_levelNumber !== undefined) { this._determineLevelInfo(ROW, cc, _levelNumber); } } } } this._addDimensionToEdge(columnEdge, columnDimensions, this.colEdgeNestingLevel, COLUMN, this._columnEdgeHasMeasure ? this._measuresInfo : undefined); // separate the conditional measure from other measure values var measureValues = []; for (var cm = this._valuesStartIdx; cm < heatIndex; cm++) { measureValues.push(this.getCellValue(i, cm)); } if (this.conditionalFormatting) { // get the conditional values for (var _cm = 0; _cm < this._conditionalMeasureInfoNew.length; _cm++) { this._conditionalMeasureInfoNew[_cm].condValue = !isSummaryCell ? this.getCellValue(i, _cm + heatIndex).value : undefined; } } var conditionalValue = this._conditionalMeasureInfo && !isSummaryCell ? this.getCellValue(i, heatIndex).value : undefined; var dimensions = void 0; if (this._columnEdgeHasMeasure) { var _loop = function _loop(j) { dimensions = columnDimensions.concat(_this2._measuresInfo[j].label).concat(rowDimensions); if (_this2.conditionalFormatting) { var conditionalMeasureInfo = _this2._conditionalMeasureInfoNew.find(function (condMeasure) { return condMeasure.measureIndex === j; }); conditionalValue = conditionalMeasureInfo ? conditionalMeasureInfo.condValue : undefined; _this2._addValuesToMap(dimensions, measureValues[j] ? measureValues[j].value : measureValues[j], _this2._measuresInfo[j], conditionalValue, conditionalMeasureInfo); } else { _this2._addValuesToMap(dimensions, measureValues[j] ? measureValues[j].value : measureValues[j], _this2._measuresInfo[j], conditionalValue); } }; //for each measure, add its column label as part of the dimensions array to be process as normal for (var j = 0; j < this._measuresInfo.length; j++) { _loop(j); } } else { dimensions = columnDimensions.concat(rowDimensions); if (this.conditionalFormatting) { conditionalValue = this._conditionalMeasureInfoNew[0] ? this._conditionalMeasureInfoNew[0].condValue : undefined; this._addValuesToMap(dimensions, measureValues[0] ? measureValues[0].value : measureValues[0], this._measuresInfo[0], conditionalValue, this._conditionalMeasureInfoNew[0]); } else { this._addValuesToMap(dimensions, measureValues[0] ? measureValues[0].value : measureValues[0], this._measuresInfo[0], conditionalValue); } } } this.rowEdge = this._getEdgeWithSortedKeys(rowEdge, this.indexInfo.row, this.rowEdgeNestingLevel); this.columnEdge = this._getEdgeWithSortedKeys(columnEdge, this.indexInfo.col, this.colEdgeNestingLevelWithMeasure || this.colEdgeNestingLevel); }; /** * Returns a new object with edge and sortedKeys info. */ Pivot.prototype._getEdgeWithSortedKeys = function _getEdgeWithSortedKeys(edge, indicesMap, nestingLevel, level, nestedCategories) { level = level || 0; var sortedKeys = this._getSortedKeys(edge, indicesMap[level], nestedCategories); var newEdgeObject = { edge: edge, sortedKeys: sortedKeys }; if (level < nestingLevel - 1) { var categories = nestedCategories || []; for (var _category in edge) { if (edge.hasOwnProperty(_category)) { var nestedEdges = edge[_category].nestedEdges; if (nestedEdges) { var currLevel = _category === SUMMARY_ID ? nestingLevel : level + 1; categories[level] = _category; edge[_category].nestedEdges = this._getEdgeWithSortedKeys(nestedEdges, indicesMap, nestingLevel, currLevel, categories); // reset catergory nesting if (level === 0) { categories = []; // pop catergory nesting } else if (categories.length) { categories = categories.slice(categories.length); } } } } } return newEdgeObject; }; Pivot.prototype._getSortedKeys = function _getSortedKeys(srcObject, indices, nestedCategories) { var sortedKeys = []; if ((typeof indices === 'undefined' ? 'undefined' : _typeof(indices)) === UNDEFINED) { for (var key in srcObject) { if (key !== SUMMARY_ID && srcObject.hasOwnProperty(key)) { sortedKeys.push(key); } } } else { var resultItem = this.data.getResultItemList()[indices.slotIndex]; for (var i = 0, tupleCount = resultItem.getRowCount(); i < tupleCount; i++) { var tuple = resultItem.getValue(i); // need to compare the tuple nesting to nested categories in order to prevent // processing the wrong tuple. First, we need to get the values from the tuple, then // based on the nested index (level), only use up to that level for the comparison. var good = (typeof nestedCategories === 'undefined' ? 'undefined' : _typeof(nestedCategories)) === UNDEFINED; if (!good) { good = true; // PERFORMANCE - do the comparison without creating or copying arrays as was done below... // let selectVals = _.pluck(tuple, 'value'); // good = _.difference(nestedCategories, selectVals.slice(0, indices.nestedIndex)).length === 0; for (var k = 0; k < indices.nestedIndex; k++) { if (_typeof(tuple[k]) !== UNDEFINED && _typeof(nestedCategories[k]) !== UNDEFINED) { if (nestedCategories[k] !== tuple[k].value) { good = false; break; } } } } if (good) { for (var j = 0; j < tuple.length; j++) { var _key = tuple[j].value; //Only include key in the sortedKeys if it actualy exists in srcObject //(i.e. if a row/column doesn't include a given data item member, don't include it in the crosstab) if (_key && srcObject[_key] && sortedKeys.indexOf(_key) === -1) { sortedKeys.push(_key); break; } } } } } if (_typeof(srcObject[SUMMARY_ID]) !== UNDEFINED) { // add the summary back as the last key sortedKeys.push(SUMMARY_ID); } return sortedKeys; }; Pivot.prototype._addColumnEdgeCategories = function _addColumnEdgeCategories(pivotTable) { var colEdgeNestingLevel = this.colEdgeNestingLevelWithMeasure || this.colEdgeNestingLevel; var i = void 0, j = void 0; for (i = 0; i < colEdgeNestingLevel; i++) { var emptyCells = []; for (j = 0; j < this.rowEdgeNestingLevel; j++) { emptyCells.push({ type: 'corner', value: this._crosstabMeasure || '' }); } pivotTable.push(emptyCells); } var columnEdgeIterator = new CrosstabEdgeIterator(this.columnEdge); var nextColumnCategory = void 0, lastValue = void 0, rowIndex = void 0, category = void 0; while (nextColumnCategory = columnEdgeIterator.next()) { rowIndex = 0; category = nextColumnCategory; while (category) { lastValue = category; pivotTable[rowIndex].push(category); rowIndex++; rowIndex += this._handleUnbalancedCategory(category, pivotTable, rowIndex); category = category.subCategory; } // if an edge is missing a value for a nested row, we add the value of the parent for (j = rowIndex; j < colEdgeNestingLevel; j++) { pivotTable[j].push(lastValue); } } }; Pivot.prototype._addRowEdgeCategoriesAndFactCells = function _addRowEdgeCategoriesAndFactCells(pivotTable) { var rowEdgeIterator = new CrosstabEdgeIterator(this.rowEdge); var nextRowCategory = void 0, pivotTableRow = void 0, category = void 0, lastValue = void 0, index = void 0; while (nextRowCategory = rowEdgeIterator.next()) { pivotTableRow = []; pivotTable.push(pivotTableRow); category = nextRowCategory; index = 0; while (category) { lastValue = category; pivotTableRow.push(category); index += this._handleUnbalancedCategory(category, pivotTableRow); category = category.subCategory; index++; } // if an edge is missing a value for a nested row, we add the value of the parent for (var i = index; i < this.rowEdgeNestingLevel; i++) { if (lastValue) { pivotTableRow.push(lastValue); nextRowCategory.descendant_or_self.push(lastValue.value.value ? lastValue.value.value : lastValue.value); } } if (!this.conditionalFormatting) { this._addFactCellsToPivotTableRow(nextRowCategory, pivotTableRow); } else { this._addFactCellsToPivotTableRowNewCF(nextRowCategory, pivotTableRow); } } }; //If this category is an 'unbalanced parent', it will have a span similar to a row or columnspan. //Fill the edges of the pivotTable for each of missing descendant up to the span. //Note: for the rowEdge, rowIndex is undefined and pivotTable represents a single row. Pivot.prototype._handleUnbalancedCategory = function _handleUnbalancedCategory(category, pivotTable) { var rowIndex = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : undefined; if (!category.isSummary && category.value && category.value.span) { var unbalancedCellDepth = category.value.span - 1; for (var i = 0; i < unbalancedCellDepth; ++i) { //Clone the cell, clear the value and mark it as an unbalanced cell. var unbalancedCell = JSON.parse(JSON.stringify(category)); unbalancedCell.isUnbalanced = true; delete unbalancedCell.value; if (rowIndex !== undefined) { //For the column edge, we need to push data 1 cell to the right for span nested "rows" of the column edge pivotTable[rowIndex + i].push(unbalancedCell); } else { //For the row edge, we need to push cells in a single row, span cells to the right. pivotTable.push(unbalancedCell); } } return unbalancedCellDepth; } return 0; }; Pivot.prototype._addFactCellsToPivotTableRow = function _addFactCellsToPivotTableRow(rowEdge, pivotTableRow) { var _this3 = this; var columnEdgeIterator = new CrosstabEdgeIterator(this.columnEdge); var maxLevel = this.getNestingLevels().colNestingLevel - 1; var isOverallSummary = void 0, key = void 0, tuple = void 0, valueObj = void 0, rawValue = void 0, value = void 0, condValue = void 0, columnEdge = void 0, condProjected = void 0; if (this._conditionalMeasureInfo && this._measuresInfo) { condProjected = this._measuresInfo.find(function (info) { return info.label === _this3._conditionalMeasureInfo.label; }); } while (columnEdge = columnEdgeIterator.next(undefined, maxLevel)) { isOverallSummary = rowEdge.isOverallSummary || columnEdge.isOverallSummary; key = this.getKeyFromDataCells(columnEdge.descendant_or_self, rowEdge.descendant_or_self); tuple = this.getKeyFromDataCells(columnEdge.descendant_or_self_without_measures, rowEdge.descendant_or_self_without_measures); valueObj = this.valuesMap[key]; if (valueObj) { rawValue = valueObj.value; } // We need distinguish the null data point values from DSS for formatting purpose. // If missing by default: data should be undefined // If explicitly from DSS: data becomes null value = valueObj ? rawValue : null; condValue = null; if (rawValue !== undefined && rawValue !== null) { // populate with the conditional measure value if (this._conditionalMeasureInfo) { // conditional format only applies to the projected conditional measure // if the conditional measure is not projected, then format the entire crosstab if (valueObj && (this._conditionalMeasureInfo.label === valueObj.label || !condProjected)) { condValue = { value: valueObj.conditionalValue, formatted: Formatter.formatNull(valueObj.conditionalValue, this._conditionalMeasureInfo.formatSpec) }; } } } pivotTableRow.push({ rowEdge: rowEdge, columnEdge: columnEdge, value: value, rawValue: rawValue, key: key, tuple: tuple, condValue: condValue, isOverallSummary: isOverallSummary }); } }; Pivot.prototype._addFactCellsToPivotTableRowNewCF = function _addFactCellsToPivotTableRowNewCF(rowEdge, pivotTableRow) { var columnEdgeIterator = new CrosstabEdgeIterator(this.columnEdge); var maxLevel = this.getNestingLevels().colNestingLevel - 1; var isOverallSummary = void 0, key = void 0, tuple = void 0, valueObj = void 0, rawValue = void 0, value = void 0, condValue = void 0, columnEdge = void 0; while (columnEdge = columnEdgeIterator.next(undefined, maxLevel)) { isOverallSummary = rowEdge.isOverallSummary || columnEdge.isOverallSummary; key = this.getKeyFromDataCells(columnEdge.descendant_or_self, rowEdge.descendant_or_self); tuple = this.getKeyFromDataCells(columnEdge.descendant_or_self_without_measures, rowEdge.descendant_or_self_without_measures); valueObj = this.valuesMap[key]; if (valueObj) { rawValue = valueObj.value; } // We need distinguish the null data point values from DSS for formatting purpose. // If missing by default: data should be undefined // If explicitly from DSS: data becomes null value = valueObj ? rawValue : null; condValue = null; if (rawValue !== undefined && rawValue !== null) { // populate with the conditional measure value if (valueObj) { var conditionalMeasure = this._conditionalMeasureInfoNew.find(function (condMeasure) { return condMeasure.label === valueObj.conditionalLabel; }); if (conditionalMeasure) { condValue = { value: valueObj.conditionalValue, formatted: Formatter.formatNull(valueObj.conditionalValue, conditionalMeasure.formatSpec) }; } } } pivotTableRow.push({ rowEdge: rowEdge, columnEdge: columnEdge, value: value, rawValue: rawValue, key: key, tuple: tuple, condValue: condValue, isOverallSummary: isOverallSummary }); } }; Pivot.prototype.getKeyFromDataCells = function getKeyFromDataCells(aData, bData) { var aKeys = []; if (Array.isArray(aData)) { for (var i = 0; i < aData.length; i++) { aKeys.push(aData[i].value ? aData[i].value : aData[i]); } } if (Array.isArray(bData)) { for (var _i = 0; _i < bData.length; _i++) { aKeys.push(bData[_i].value ? bData[_i].value : bData[_i]); } } return aKeys.toString(); }; Pivot.prototype._addValuesToMap = function _addValuesToMap(dimensions, measureValue, measureInfo, conditionalValue, conditionalValueInfo) { if (measureValue === undefined) { // undefined return; } this.valuesMap[this.getKeyFromDataCells(dimensions)] = { label: measureInfo ? measureInfo.label : null, value: measureValue, conditionalLabel: conditionalValueInfo ? conditionalValueInfo.label : null, conditionalValue: conditionalValue, getFormatSpec: function getFormatSpec() { return measureInfo ? measureInfo.formatSpec : null; } }; }; Pivot.prototype._addDimensionToEdge = function _addDimensionToEdge(edge, dimensions, nestingLevel, type, measuresInfo, currentLevel) { currentLevel = currentLevel || 0; if (dimensions && dimensions.length > 0) { var memberKey = dimensions[0].value; if (!edge[memberKey]) { edge[memberKey] = { level: currentLevel, type: type, value: dimensions[0] }; if (dimensions[0].isSummary) { edge[memberKey].isSummary = dimensions[0].isSummary; } var formatSpec = null; if (type === ROW) { formatSpec = this._getFormatSpec(this._rowInfo[currentLevel]); } else if (type === COLUMN) { formatSpec = this._getFormatSpec(this._columnInfo[currentLevel]); } if (formatSpec && formatSpec.type === DATE) { edge[memberKey].formatSpec = formatSpec; } } var remaining = dimensions.slice(1, dimensions.length); if (remaining.length > 0) { if (!edge[memberKey].nestedEdges) { edge[memberKey].nestedEdges = {}; } this._addDimensionToEdge(edge[memberKey].nestedEdges, remaining, nestingLevel, type, measuresInfo, currentLevel + 1); } else if (this._columnEdgeHasMeasure && type === COLUMN) { //if we get here, this means we are at the innermost level of the nesting, so add the measures if there are any if (!edge[memberKey].nestedEdges) { edge[memberKey].nestedEdges = {}; edge[memberKey].hasMeasureChildren = true; } this._addMeasureToEdge(edge[memberKey].nestedEdges, measuresInfo, type, currentLevel + 1, false /*bIsSummary*/); } } else if (this._columnEdgeHasMeasure && type === COLUMN) { //if we get here, it means that there are no dimensions this._addMeasureToEdge(edge, measuresInfo, type, currentLevel, false /*bIsSummary*/); } }; Pivot.prototype._getFormatSpec = function _getFormatSpec(info) { return info.formatSpec && info.formatSpec.formatSpec; }; Pivot.prototype._addMeasureToEdge = function _addMeasureToEdge(edge, measuresInfo, type, currentLevel, bIsSummary, bIsOverallSummary) { if (measuresInfo) { var measure = void 0, measureLabel = void 0; for (var i = 0; i < measuresInfo.length; i++) { measure = measuresInfo[i]; measureLabel = measure.label; if (!edge[measureLabel]) { edge[measureLabel] = { level: currentLevel, type: type, isMeasure: true }; } if (bIsSummary) { edge[measureLabel].isSummary = true; // make sure the measures in the Summary are not sorted edge[measureLabel].noSort = true; if (bIsOverallSummary) { edge[measureLabel].isOverallSummary = true; } } } } }; /** * Not every data item mapped in slot have data return from query result, * in a situation such as suppression where all values of a measure were suppressed. * Verify and return a boolean indicating whether there are data returned for the mapped data item in slot * * @param {array} resultDataItemList list of data items returned from query result * @param {object} dataItemFromSlot mapped slot data item to verify * @return {boolean} true if the dataItem has data returned for turn false */ Pivot.prototype._measureItemHasData = function _measureItemHasData() { var resultDataItemList = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : []; var dataItemFromSlot = arguments[1]; if (!dataItemFromSlot) { throw new Error('Invalid dataItem provided'); } return !!resultDataItemList.find(function (item) { return item.getId() === dataItemFromSlot.getId(); }); }; return Pivot; }(); return Pivot; }); //# sourceMappingURL=Pivot.js.map