UNPKG

@syncfusion/ej2-pivotview

Version:

The pivot grid, or pivot table, is used to visualize large sets of relational data in a cross-tabular format, similar to an Excel pivot table.

872 lines (871 loc) 257 kB
import { extend, Internationalization, isNullOrUndefined, Ajax } from '@syncfusion/ej2-base'; import { PivotUtil } from '../util'; import { MDXQuery } from './mdx-query'; import * as cls from '../../common/base/css-constant'; /** * OlapEngine is used to manipulate the olap or Multi-Dimensional data as pivoting values. */ /** @hidden */ var OlapEngine = /** @class */ (function () { function OlapEngine() { /** @hidden */ this.fieldList = {}; /** @hidden */ this.columnCount = 0; /** @hidden */ this.rowCount = 0; /** @hidden */ this.colFirstLvl = 0; /** @hidden */ this.rowFirstLvl = 0; /** @hidden */ this.pageColStartPos = 0; /** @hidden */ this.enableSort = false; /** @hidden */ this.enableValueSorting = false; /** @hidden */ this.dataFields = {}; /** @hidden */ this.formatFields = {}; /** @hidden */ this.filterMembers = {}; /** @hidden */ this.drilledSets = {}; /** @hidden */ this.isExporting = false; this.aggregatedValueMatrix = []; this.mappingFields = {}; this.formatRegex = /^(?:[ncpae])(?:([0-9]|1[0-9]|20))?$/i; this.clonedValTuple = []; this.clonedColumnTuple = []; this.clonedRowTuple = []; /** @hidden */ this.pivotValues = []; /** @hidden */ this.valueContent = []; /** @hidden */ this.headerContent = []; /** @hidden */ this.rowStartPos = 0; /** @hidden */ this.pageRowStartPos = 0; /** @hidden */ this.tupColumnInfo = []; /** @hidden */ this.tupRowInfo = []; /** @hidden */ this.gridJSON = ''; /** @hidden */ this.namedSetsPosition = {}; /** @hidden */ this.colDepth = 0; this.totalCollection = []; this.parentObjCollection = {}; this.curDrillEndPos = -1; this.headerGrouping = {}; this.lastLevel = []; this.showRowSubTotals = true; this.showColumnSubTotals = true; this.hideRowTotalsObject = {}; this.hideColumnTotalsObject = {}; this.sortObject = {}; this.isColDrill = false; } /////////////////////////////////////////////////////////////////////////////////////////////////////////////// OlapEngine.prototype.renderEngine = function (dataSourceSettings, customProperties, onHeadersSort) { this.isEmptyData = false; this.getHeaderSortInfo = onHeadersSort; this.mdxQuery = ''; this.isMeasureAvail = false; this.allowMemberFilter = false; this.allowLabelFilter = false; this.allowValueFilter = false; this.isMondrian = false; this.aggregatedValueMatrix = []; this.measureReportItems = []; this.calcChildMembers = []; this.selectedItems = []; this.savedFieldList = undefined; this.savedFieldListData = undefined; this.formatFields = {}; this.filterMembers = {}; this.dataFields = {}; this.valueAxis = ''; this.columnCount = 0; this.rowCount = 0; this.colFirstLvl = 0; this.rowFirstLvl = 0; this.pageColStartPos = 0; this.sortObject = {}; this.globalize = new Internationalization(); this.locale = this.globalize.culture ? this.globalize.culture : 'en-US'; this.localeObj = customProperties ? customProperties.localeObj : undefined; this.enableValueSorting = customProperties ? customProperties.enableValueSorting : false; if (dataSourceSettings.url) { // this.isMondrian = (dataSourceSettings.providerType === 'mondrian'); this.dataSourceSettings = dataSourceSettings; this.measureIndex = !isNullOrUndefined(dataSourceSettings.valueIndex) ? dataSourceSettings.valueIndex : -1; this.valueAxis = dataSourceSettings.valueAxis === 'row' ? 'row' : 'column'; this.getAxisFields(); this.formats = dataSourceSettings.formatSettings ? dataSourceSettings.formatSettings : []; this.enableSort = dataSourceSettings.enableSorting === undefined ? true : dataSourceSettings.enableSorting; this.valueSortSettings = dataSourceSettings.valueSortSettings ? dataSourceSettings.valueSortSettings : undefined; this.filterSettings = dataSourceSettings.filterSettings ? dataSourceSettings.filterSettings : []; this.sortSettings = dataSourceSettings.sortSettings ? dataSourceSettings.sortSettings : []; this.allowMemberFilter = dataSourceSettings.allowMemberFilter ? true : false; this.allowLabelFilter = dataSourceSettings.allowLabelFilter ? true : false; this.allowValueFilter = dataSourceSettings.allowValueFilter ? true : false; this.drilledMembers = dataSourceSettings.drilledMembers ? this.updateDrilledItems(dataSourceSettings.drilledMembers) : []; this.calculatedFieldSettings = dataSourceSettings.calculatedFieldSettings ? dataSourceSettings.calculatedFieldSettings : []; this.emptyCellTextContent = dataSourceSettings.emptyCellsTextContent ? dataSourceSettings.emptyCellsTextContent : ''; this.pageSettings = customProperties ? (customProperties.pageSettings ? customProperties.pageSettings : this.pageSettings) : undefined; this.isPaging = this.pageSettings && (customProperties.enablePaging || customProperties.enableVirtualization) ? true : false; this.frameSortObject(); this.getFormattedFields(this.formats); this.savedFieldList = customProperties ? customProperties.savedFieldList : undefined; this.savedFieldListData = customProperties ? customProperties.savedFieldListData : undefined; this.fieldListData = []; this.fieldListObj = {}; this.setNamedSetsPosition(); if (!(this.savedFieldList && Object.keys(this.savedFieldList).length > 0 && this.savedFieldListData)) { this.getCubes(dataSourceSettings); this.getFieldList(dataSourceSettings); } else { this.updateFieldlist(true); } this.loadCalculatedMemberElements(this.calculatedFieldSettings); var measuresInfo = this.getMeasureInfo(); this.olapVirtualization = this.isPaging && dataSourceSettings.showSubTotals && (measuresInfo.measureIndex === (measuresInfo.measureAxis === 'column' ? dataSourceSettings.columns.length - 1 : dataSourceSettings.rows.length - 1)) && !isNullOrUndefined(this.pageSettings) && dataSourceSettings.showGrandTotals; this.isPaging = this.isPaging ? !this.olapVirtualization : this.isPaging; this.measureReportItems = []; // this.updateAllMembers(dataSourceSettings, this.filters); this.updateFilterItems(this.filterSettings); this.generateGridData(dataSourceSettings); } }; /////////////////////////////////////////////////////////////////////////////////////////////////////////////// OlapEngine.prototype.generateGridData = function (dataSourceSettings, action) { var refPaging = (action && action === 'navPaging' && this.isPaging && this.pageSettings !== undefined ? true : false); if (this.rows.length > 0 || this.columns.length > 0 || this.values.length > 0 || this.filters.length > 0) { MDXQuery.getCellSets(dataSourceSettings, this, refPaging); } else { MDXQuery.getCellSets(dataSourceSettings, this, true, undefined, true); this.generateEngine(undefined, undefined, { dataSourceSettings: dataSourceSettings, action: 'loadTableElements' }); } }; OlapEngine.prototype.generatePagingData = function (xmlDoc, request, customArgs) { var xmlaCellSet = [].slice.call(xmlDoc.querySelectorAll('Axes, CellData')); // this.rowCount = // (xmlaCellSet.length > 0 && [].slice.call(xmlaCellSet[0].querySelectorAll('Axis[name|="Axis1"] Tuple')).length > 0 ? // [].slice.call(xmlaCellSet[0].querySelectorAll('Axis[name|="Axis1"] Tuple')).length : 0); // this.columnCount = // (xmlaCellSet.length > 0 && [].slice.call(xmlaCellSet[0].querySelectorAll('Axis[name|="Axis0"] Tuple')).length > 0 ? // [].slice.call(xmlaCellSet[0].querySelectorAll('Axis[name|="Axis0"] Tuple')).length : 0); var countCells = xmlaCellSet[1] ? xmlaCellSet[1].querySelectorAll('FmtValue') : null; if (countCells && countCells.length > 0) { this.columnCount = Number(countCells[0].textContent); this.rowCount = Number(countCells[1].textContent); } var dataSourceSettings = customArgs.dataSourceSettings; MDXQuery.getCellSets(dataSourceSettings, this, true); }; OlapEngine.prototype.scrollPage = function () { if (this.olapVirtualization) { var virtualScrollingData = this.getVirtualScrollingData(this.clonedColumnTuple, this.clonedRowTuple); if (virtualScrollingData.isCalculated) { this.pivotValues = []; this.clearEngineProperties(); this.performEngine(virtualScrollingData.columnTuple, virtualScrollingData.rowTuple, virtualScrollingData.valueTuple); } this.pivotValues = this.pivotValues.slice(); } else { MDXQuery.getCellSets(this.dataSourceSettings, this, true); } }; OlapEngine.prototype.getVirtualScrollingData = function (colTuples, rowTuples) { var valTuples = this.clonedValTuple.slice(); var isCalculated = false; var calColPage = (this.pageSettings.currentColumnPage - 1) * this.pageSettings.columnPageSize; var calRowPage = (this.pageSettings.currentRowPage - 1) * this.pageSettings.rowPageSize; var calColSize = this.pageSettings.columnPageSize * 3; var calRowSize = this.pageSettings.rowPageSize * 3; calColPage = (this.columnCount < (calColPage + calColSize)) ? (this.columnCount > calColSize ? (this.columnCount - calColSize) : 0) : calColPage; calRowPage = (this.rowCount < (calRowPage + calRowSize)) ? (this.rowCount > calRowSize ? (this.rowCount - calRowSize) : 0) : calRowPage; if ((calColPage !== this.pageColStartPos || calRowPage !== this.pageRowStartPos) || !(colTuples.length <= calColSize && rowTuples.length <= calRowSize)) { isCalculated = true; var measureInfo = this.getMeasureInfo(); var isColGrandTolExists = !isNullOrUndefined(colTuples[0]) && (Number(colTuples[0].querySelectorAll('Member')[0].querySelector('LNum').textContent) === 0) && colTuples[0].querySelectorAll('Member')[0].querySelector('MEMBER_VALUE').textContent.startsWith('All'); var isRowGrandTolExists = !isNullOrUndefined(rowTuples[0]) && (Number(rowTuples[0].querySelectorAll('Member')[0].querySelector('LNum').textContent) === 0) && rowTuples[0].querySelectorAll('Member')[0].querySelector('MEMBER_VALUE').textContent.startsWith('All'); var isAddColGrandTotals = isColGrandTolExists ? (calColPage + calColSize >= colTuples.length - 1) : false; var isAddRowGrandTotals = isRowGrandTolExists ? (calRowPage + calRowSize >= rowTuples.length - 1) : false; var colDepth = isColGrandTolExists ? this.getAxisdepth(colTuples) : measureInfo.measureAxis === 'column' ? measureInfo.valueInfo.length : 1; var rowDepth = isRowGrandTolExists ? this.getAxisdepth(rowTuples) : measureInfo.measureAxis === 'row' ? measureInfo.valueInfo.length : 1; var colTuplesOffset = (isColGrandTolExists ? colDepth : 0) + calColPage; var rowTuplesOffset = (isRowGrandTolExists ? rowDepth : 0) + calRowPage; var virtualColTuples = colTuples.slice(colTuplesOffset, colTuplesOffset + calColSize); var virtualRowTuples = rowTuples.slice(rowTuplesOffset, rowTuplesOffset + calRowSize); var colLastLevel = virtualColTuples[0] ? Number(virtualColTuples[0].querySelectorAll('Member')[0].querySelector('LNum').textContent) : 0; var rowLastLevel = virtualRowTuples[0] ? Number(virtualRowTuples[0].querySelectorAll('Member')[0].querySelector('LNum').textContent) : 0; var colData = this.getVirtualTotals(colTuples.slice(0, colTuplesOffset), colLastLevel, isAddColGrandTotals, 'column', colDepth); var rowData = this.getVirtualTotals(rowTuples.slice(0, rowTuplesOffset), rowLastLevel, isAddRowGrandTotals, 'row', rowDepth); colTuplesOffset = virtualColTuples.length + colData.totalsCollection.length > calColSize ? Math.max(virtualColTuples.length + colData.totalsCollection.length - calColSize) : 0; rowTuplesOffset = virtualRowTuples.length + rowData.totalsCollection.length > calRowSize ? Math.max(virtualRowTuples.length + rowData.totalsCollection.length - calRowSize) : 0; virtualColTuples = colData.totalsCollection.concat(virtualColTuples.slice(colTuplesOffset, virtualColTuples.length)); virtualRowTuples = rowData.totalsCollection.concat(virtualRowTuples.slice(rowTuplesOffset, virtualRowTuples.length)); var virtualValuesTupples = this.getVirtualValues(valTuples, calColPage + colTuplesOffset, calRowPage + rowTuplesOffset, calColSize, calRowSize, colData.indexCollection, rowData.indexCollection, colTuples.length, rowTuples.length, colDepth, rowDepth, isRowGrandTolExists); colTuples = virtualColTuples.slice(); rowTuples = virtualRowTuples.slice(); valTuples = virtualValuesTupples.slice(); } this.pageColStartPos = calColPage; this.pageRowStartPos = calRowPage; return { columnTuple: colTuples, rowTuple: rowTuples, valueTuple: valTuples, isCalculated: isCalculated }; }; OlapEngine.prototype.getAxisdepth = function (tuplesCollection) { var depth = 0; for (var i = 0; i < tuplesCollection.length; i++) { var level = Number(tuplesCollection[i].querySelectorAll('Member')[0].querySelector('LNum').textContent); if (level === 0) { depth++; } else { break; } } return depth; }; OlapEngine.prototype.getVirtualTotals = function (tuplesCollection, lastLevel, isAddGrandTotals, axis, axisDepth) { var totalsCollection = []; var indexCollection = []; if (lastLevel !== 1) { for (var i = tuplesCollection.length - 1; i > 0; i--) { var currLevel = Number(tuplesCollection[i].querySelectorAll('Member')[0].querySelector('LNum').textContent); if (currLevel === 0) { break; } else if (lastLevel > currLevel) { lastLevel = currLevel; var nextLevel = Number(tuplesCollection[i - 1].querySelectorAll('Member')[0].querySelector('LNum').textContent); if (nextLevel === currLevel) { for (var offset = 0; offset < axisDepth; offset++) { totalsCollection[totalsCollection.length] = tuplesCollection[i - offset]; indexCollection[indexCollection.length] = i - offset; } i = axisDepth > 1 ? i - (axisDepth - 1) : i; } else { totalsCollection[totalsCollection.length] = tuplesCollection[i]; indexCollection[indexCollection.length] = i; } } else if (currLevel === 1) { break; } } } if (isAddGrandTotals) { for (var i = axisDepth; i > 0; i--) { totalsCollection = totalsCollection.concat([tuplesCollection[i - 1]]); indexCollection = indexCollection.concat([i - 1]); } } return { totalsCollection: totalsCollection.reverse(), indexCollection: indexCollection.reverse() }; }; OlapEngine.prototype.getVirtualValues = function (valueTuples, calColumnPage, calRowPage, calColunmnSize, calRowSize, colTotalsIndex, rowTotalsIndex, colTuplesLen, rowTuplesLen, columnDepth, rowDepth, isRowGrandTolExists) { var framedVirtValTuples = []; var virtValTuples = valueTuples; if (rowTuplesLen > calRowSize) { var rowValuesOffset = ((isRowGrandTolExists ? rowDepth : 0) + calRowPage) * colTuplesLen; virtValTuples = valueTuples.slice(rowValuesOffset, rowValuesOffset + (calRowSize * colTuplesLen)); var virtRowTotalValues = []; for (var i = 0; i < rowTotalsIndex.length; i++) { virtRowTotalValues = virtRowTotalValues.concat(valueTuples.slice(rowTotalsIndex[i] * colTuplesLen, (rowTotalsIndex[i] * colTuplesLen) + colTuplesLen)); } virtValTuples = virtRowTotalValues.concat(virtValTuples); } for (var i = 0, j = virtValTuples.length / colTuplesLen; i < j; i++) { var rows = virtValTuples.slice(i * colTuplesLen, (i * colTuplesLen) + colTuplesLen); var virtRows = rows.slice(calColumnPage + columnDepth, calColumnPage + columnDepth + calColunmnSize); var virtTotals = []; for (var x = 0; x < colTotalsIndex.length; x++) { virtTotals[virtTotals.length] = rows[colTotalsIndex[x]]; } framedVirtValTuples = framedVirtValTuples.concat(virtTotals.concat(virtRows)); } return framedVirtValTuples; }; OlapEngine.prototype.generateEngine = function (xmlDoc, request, customArgs) { if (customArgs.action !== 'down') { this.clearEngineProperties(); } this.xmlDoc = xmlDoc ? xmlDoc.cloneNode(true) : undefined; this.request = request; this.customArgs = customArgs; this.parentObjCollection = {}; this.curDrillEndPos = -1; this.onDemandDrillEngine = []; this.getSubTotalsVisibility(); this.xmlaCellSet = xmlDoc ? xmlDoc.querySelectorAll('Axes, CellData') : undefined; var columnTuples = this.xmlaCellSet && this.xmlaCellSet.length > 0 ? [].slice.call(this.xmlaCellSet[0].querySelectorAll('Axis[name|="Axis0"] Tuple')) : []; var rowTuples = this.xmlaCellSet && this.xmlaCellSet.length > 0 ? [].slice.call(this.xmlaCellSet[0].querySelectorAll('Axis[name|="Axis1"] Tuple')) : []; var valCollection = this.xmlaCellSet && this.xmlaCellSet.length > 1 ? [].slice.call(this.xmlaCellSet[1].querySelectorAll('Cell')) : []; if (this.olapVirtualization && !isNullOrUndefined(this.pageSettings)) { if (columnTuples.length * rowTuples.length !== valCollection.length) { var valueCollection = []; for (var colPos = 0; colPos < valCollection.length; colPos++) { if (!isNullOrUndefined(valCollection[colPos])) { valueCollection[Number(valCollection[colPos].getAttribute('CellOrdinal'))] = valCollection[colPos]; } } valCollection = valueCollection; } this.clonedValTuple = valCollection; var drillInfo = this.getDrillInfo('columns'); var columnData = this.getActualTuples(columnTuples, drillInfo); drillInfo = this.getDrillInfo('rows'); var rowData = this.getActualTuples(rowTuples, drillInfo, columnData.indexColls, columnTuples.length); this.clonedColumnTuple = columnData.tupColls; this.clonedRowTuple = rowData.tupColls; this.columnCount = this.clonedColumnTuple.length; this.rowCount = this.clonedRowTuple.length; columnData = rowData = undefined; var virtualScrollingData = this.getVirtualScrollingData(this.clonedColumnTuple, this.clonedRowTuple); this.performEngine(virtualScrollingData.columnTuple, virtualScrollingData.rowTuple, virtualScrollingData.valueTuple); } else { this.performEngine(columnTuples, rowTuples, valCollection); } }; OlapEngine.prototype.getDrillInfo = function (axis) { var drilledMembers = {}; var fieldColls = []; if (axis === 'columns') { fieldColls = this.dataSourceSettings.columns.map(function (field) { return field.name; }); } else if (axis === 'rows') { fieldColls = this.dataSourceSettings.rows.map(function (field) { return field.name; }); } if (fieldColls.length > 0) { for (var i = 0, j = this.drilledMembers.length; i < j; i++) { var drilledMember = this.drilledMembers[i]; var index = fieldColls.indexOf(drilledMember.name); if (index > -1) { if (!drilledMembers[index]) { drilledMembers[index] = []; } drilledMembers[index] = drilledMembers[index].concat(drilledMember.items); } } } return drilledMembers; }; OlapEngine.prototype.getActualTuples = function (tuplesColl, drillInfo, indexCollection, deapth) { var tupColls = []; var indexColls = []; var valueCollection = []; if (tuplesColl.length > 0) { var _loop_1 = function (i, j) { var tuples = tuplesColl[i]; var isAddElement = true; var isGrandSum = false; var isSum = false; var memTypeColl = tuples.getElementsByTagName('MEMBER_TYPE'); var uNameColl = tuples.getElementsByTagName('UName'); for (var k = 0, l = memTypeColl.length; k < l; k++) { var memType = Number(memTypeColl[k].textContent); var uName = uNameColl[k].textContent; if (isSum && memType < 2) { isAddElement = false; } else if (memType === 2) { isGrandSum = true; } else if (isGrandSum && memType < 2) { isAddElement = false; } if (drillInfo[k] && drillInfo[k].indexOf(uName) > -1) { isSum = true; } if (!isAddElement) { break; } } if (isAddElement) { tupColls[tupColls.length] = tuples; if (indexCollection) { var rowColls_1 = this_1.clonedValTuple.slice(i * deapth, (i * deapth) + deapth); valueCollection = valueCollection.concat(indexCollection.map(function (index) { return rowColls_1[index]; })); } else { indexColls[indexColls.length] = i; } } }; var this_1 = this; for (var i = 0, j = tuplesColl.length; i < j; i++) { _loop_1(i, j); } } else if (indexCollection) { var rowColls_2 = this.clonedValTuple.slice(0, deapth); valueCollection = valueCollection.concat(indexCollection.map(function (index) { return rowColls_2[index]; })); } if (valueCollection.length > 0) { this.clonedValTuple = valueCollection; } return { tupColls: tupColls, indexColls: indexColls }; }; OlapEngine.prototype.clearEngineProperties = function () { this.pivotValues = []; this.valueContent = []; this.headerContent = []; this.colDepth = 0; this.tupColumnInfo = []; this.tupRowInfo = []; this.colMeasures = {}; this.colMeasurePos = undefined; this.rowMeasurePos = undefined; this.rowStartPos = -1; }; OlapEngine.prototype.performEngine = function (columnTuples, rowTuples, valCollection) { this.totalCollection = []; var measureInfo = this.getMeasureInfo(); if (this.drilledMembers.length > 0) { // let st1: number = new Date().getTime(); var orderedInfo = void 0; var valCount = columnTuples.length && rowTuples.length ? columnTuples.length * rowTuples.length : columnTuples.length ? columnTuples.length : rowTuples.length; orderedInfo = this.frameMeasureOrder(measureInfo, 'column', columnTuples, valCollection, columnTuples.length, valCount); columnTuples = orderedInfo.orderedHeaderTuples; valCollection = orderedInfo.orderedValueTuples; orderedInfo = this.frameMeasureOrder(measureInfo, 'row', rowTuples, valCollection, columnTuples.length, valCount); rowTuples = orderedInfo.orderedHeaderTuples; valCollection = orderedInfo.orderedValueTuples; // let st2: number = (new Date().getTime() - st1) / 1000; // console.log('over-all:' + st2); } if (this.customArgs.action === 'down') { this.updateTupCollection(this.customArgs.drillInfo.axis === 'row' ? rowTuples.length : columnTuples.length); } var framedValCollection = {}; for (var colPos = 0; colPos < valCollection.length; colPos++) { if (!isNullOrUndefined(valCollection[colPos])) { framedValCollection[this.olapVirtualization ? colPos : Number(valCollection[colPos].getAttribute('CellOrdinal'))] = valCollection[colPos]; } } var valueSortData; this.valueSortSettings.columnIndex = undefined; if (this.enableValueSorting && this.valueSortSettings && !this.isPaging && !this.olapVirtualization) { valueSortData = this.getValueSortInfo(columnTuples, rowTuples, measureInfo); } if (this.customArgs.action === 'down' ? this.customArgs.drillInfo.axis === 'column' : true) { this.frameColumnHeader(columnTuples); if (!this.isPaging && !this.olapVirtualization) { this.performColumnSorting(framedValCollection, valueSortData); } } if (this.customArgs.action === 'down' ? this.customArgs.drillInfo.axis === 'row' : true) { this.frameRowHeader(rowTuples); if (!this.isPaging && !this.olapVirtualization) { this.performRowSorting(framedValCollection, valueSortData); } } this.frameValues(framedValCollection, columnTuples.length); this.performColumnSpanning(); if (!this.isPaging && !this.olapVirtualization && this.enableSort) { for (var i = 0; i < this.headerContent.length; i++) { this.headerContent[i] = this.pivotValues[i]; } } this.isEngineUpdated = true; this.isEmptyData = columnTuples.length === 0; //this.append(columnTuples.length); }; OlapEngine.prototype.getValueSortInfo = function (columnTuples, rowTuples, measureInfo) { var memberIndex; if (this.valueSortSettings.headerText) { var headersCollection = this.valueSortSettings.headerText.split(this.valueSortSettings.headerDelimiter); var granSumPos = headersCollection.indexOf('Grand Total'); if (granSumPos > -1) { var measure = headersCollection.join('').split(headersCollection[granSumPos]).join(''); headersCollection = []; headersCollection[measureInfo.measureIndex] = measure; } var measureAxis = ''; var measureIndex = measureInfo.measureIndex; for (var i = 0; i < this.dataSourceSettings.values.length; i++) { measureIndex = headersCollection.indexOf(this.dataSourceSettings.values[i].caption); if (this.dataSourceSettings.values[i].caption === headersCollection[measureIndex]) { headersCollection[measureIndex] = this.fieldList[this.dataSourceSettings.values[i].name].name; measureAxis = headersCollection[measureIndex]; break; } } if (measureIndex !== -1) { if (measureIndex < measureInfo.measureIndex) { headersCollection = this.reArrangeHeaders(headersCollection, measureInfo.measureIndex, measureAxis); } var membersColls = this.olapValueAxis === 'column' ? columnTuples : rowTuples; if (membersColls.length > 0) { var level = membersColls[0].getElementsByTagName('Member').length - (granSumPos > -1 ? measureIndex : 0); var member = this.getParentElement(membersColls, headersCollection, level, measureInfo.measureIndex, measureAxis, granSumPos > -1)[0]; memberIndex = membersColls.indexOf(member); } } } return { memberIndex: memberIndex, columnLength: columnTuples.length, rowLength: rowTuples.length, isValueSorting: memberIndex > -1 }; }; OlapEngine.prototype.getParentElement = function (membersColls, headersCollection, level, measureIndex, measureAxis, isGrandTotal) { var selectedMember = []; var parentLevel = 0; var isParentAvail = false; var isChildAvail = false; var index = membersColls[0].getElementsByTagName('Member').length - level; for (var i = 0; i < membersColls.length; i++) { if (isNullOrUndefined(membersColls[i].getElementsByTagName('Member')[index])) { selectedMember = []; break; } var memberUName = membersColls[i].getElementsByTagName('UName')[index].textContent; var memberCaption = membersColls[i].getElementsByTagName('Caption')[index].textContent; var memberLevel = Number(membersColls[i].getElementsByTagName('LNum')[index].textContent); var isParent = memberUName === headersCollection[index] || memberCaption === headersCollection[index] || (isNullOrUndefined(headersCollection[index]) && memberLevel === 0); if (isParent) { selectedMember[selectedMember.length] = membersColls[i]; isParentAvail = true; parentLevel = memberLevel; if (isGrandTotal) { break; } } else if (isParentAvail && parentLevel < memberLevel) { var childMember = []; for (var j = i; j < membersColls.length; j++) { var childUName = membersColls[j].getElementsByTagName('UName')[index].textContent; var childCaption = membersColls[j].getElementsByTagName('Caption')[index].textContent; var childLevel = Number(membersColls[j].getElementsByTagName('LNum')[index].textContent); var isChild = childUName === headersCollection[index + 1] || childCaption === headersCollection[index + 1] || (isNullOrUndefined(headersCollection[index + 1]) && childLevel === 0); if ((parentLevel + 1 === childLevel) && isChild) { childMember[childMember.length] = membersColls[j]; isChildAvail = true; } else if (parentLevel + 1 < childLevel) { if (isChildAvail) { childMember[childMember.length] = membersColls[j]; } else { break; } } else if (parentLevel + 1 > childLevel) { break; } } if (isChildAvail) { var childHeaderCollection = headersCollection.slice(0, index).concat(headersCollection.slice(index + 1, headersCollection.length)); var childMeasureIndex = childHeaderCollection.indexOf(measureAxis); if (childMeasureIndex < measureIndex) { childHeaderCollection = this.reArrangeHeaders(childHeaderCollection, measureIndex, measureAxis); } selectedMember = this.getParentElement(childMember, childHeaderCollection, childMember[0].getElementsByTagName('Member').length, measureIndex, measureAxis); } break; } else if (isParentAvail && !isParent) { break; } } if (isGrandTotal) { return selectedMember; } else if (index < (headersCollection.length - 1) && selectedMember.length > 0 && !isChildAvail) { selectedMember = this.getParentElement(selectedMember, headersCollection, level - 1, measureIndex, measureAxis); } return selectedMember; }; OlapEngine.prototype.reArrangeHeaders = function (headersCollection, measureIndex, measureAxis) { var actualIndex = headersCollection.indexOf(measureAxis); var headerColl1 = headersCollection.slice(0, actualIndex); var headerColl2 = headersCollection.slice(actualIndex + 1, headersCollection.length); headerColl1[measureIndex] = headersCollection[actualIndex]; return headerColl1.concat(headerColl2); }; OlapEngine.prototype.getSubTotalsVisibility = function () { this.showRowSubTotals = this.dataSourceSettings.showRowSubTotals && this.dataSourceSettings.showSubTotals; this.showColumnSubTotals = this.dataSourceSettings.showColumnSubTotals && this.dataSourceSettings.showSubTotals; this.showSubTotalsAtTop = this.showColumnSubTotals && this.dataSourceSettings.subTotalsPosition === 'Top'; this.showSubTotalsAtBottom = this.showRowSubTotals && this.dataSourceSettings.subTotalsPosition === 'Bottom'; this.hideRowTotalsObject = {}; this.hideColumnTotalsObject = {}; var axisCount = 1; do { if (axisCount === 1) { if (this.showColumnSubTotals) { for (var cCnt = 0; cCnt < this.dataSourceSettings.columns.length; cCnt++) { if (this.dataSourceSettings.columns[cCnt].showSubTotals === false) { this.hideColumnTotalsObject[this.dataSourceSettings.columns[cCnt].name] = cCnt; } } } } else { if (this.showRowSubTotals) { for (var rCnt = 0; rCnt < this.dataSourceSettings.rows.length; rCnt++) { if (this.dataSourceSettings.rows[rCnt].showSubTotals === false) { this.hideRowTotalsObject[this.dataSourceSettings.rows[rCnt].name] = rCnt; } } } } axisCount++; } while (axisCount < 3); }; OlapEngine.prototype.frameRowHeader = function (tuples) { var _this = this; this.headerGrouping = {}; this.lastLevel = []; var isGrandTotalAdd = true; var position = this.pivotValues.length; var pivotValues = []; var valueContent = []; if (this.customArgs.action !== 'down') { pivotValues = this.pivotValues; valueContent = this.valueContent; } else { position = this.customArgs.drillInfo.currentCell.rowIndex + 1; } this.rowStartPos = this.rowStartPos > 0 ? this.rowStartPos : position; var tupPos = 0; var lastAllStartPos; var lastAllCount; var prevUNArray = []; var allType = {}; var rowMembers = []; var availAllMember = false; var withoutAllStartPos = -1; var withoutAllEndPos = -1; var minLevel = []; var gTotals = [{ actualText: 'Grand Total', axis: 'row', colIndex: 0, formattedText: 'Grand Total', hasChild: false, level: -1, rowIndex: 0, index: [], type: 'grand sum', ordinal: 0, colSpan: 1, rowSpan: 1, memberType: 2, isDrilled: false, valueSort: { 'Grand Total': 1, levelName: 'Grand Total' } }]; var maxLevel = []; var measurePos; var newTupPosition = (this.customArgs.drillInfo && this.customArgs.drillInfo.axis === 'row') ? (this.customArgs.drillInfo.currentCell.ordinal + 1) : 0; while (tupPos < tuples.length) { var members = tuples[tupPos].querySelectorAll('Member'); maxLevel = this.frameTupCollection(members, maxLevel, (tupPos + newTupPosition), this.tupRowInfo, this.showRowSubTotals, this.hideRowTotalsObject, 'row'); tupPos++; } tupPos = 0; var prevTupInfo; var tuplesLength = tuples.length; if (this.customArgs.action === 'down') { var ordinal = this.customArgs.drillInfo.currentCell.ordinal + 1; tupPos = ordinal; tuplesLength += ordinal; lastAllCount = this.tupRowInfo[ordinal - 1].allCount; lastAllStartPos = this.tupRowInfo[ordinal - 1].allStartPos; prevTupInfo = this.tupRowInfo[ordinal - 1]; } var startTupPos = tupPos; var pagingAllowFlag = true; var lastMesPos = 0; var isGrandTotalTop = false; var subTotals = []; while (tupPos < tuplesLength && pagingAllowFlag) { var members = tuples[this.customArgs.action === 'down' ? (tupPos - (this.customArgs.drillInfo.currentCell.ordinal + 1)) : tupPos].querySelectorAll('Member'); var memPos = 0; var prevParent = void 0; var allCount = this.tupRowInfo[tupPos].allCount; var allStartPos = this.tupRowInfo[tupPos].allStartPos; var measure = this.tupRowInfo[tupPos].measure; var typeColl = this.tupRowInfo[tupPos].typeCollection; // let drillInfo: IDrillInfo[] = this.tupRowInfo[tupPos].drillInfo; var drillStartPos = this.tupRowInfo[tupPos].drillStartPos; var startDrillUniquename = this.tupRowInfo[tupPos].startDrillUniquename; // let drillEndPos: number = this.tupRowInfo[tupPos].drillEndPos; // let levelColl: number[] = this.tupRowInfo[tupPos].levelCollection; if (tupPos === 0 || tupPos === startTupPos) { var firstTupMembers = this.customArgs.action === 'down' ? this.tupRowInfo[0].members : members; while (memPos < firstTupMembers.length) { if (firstTupMembers[memPos].querySelector('MEMBER_TYPE').textContent === '1' && Number(firstTupMembers[memPos].querySelector('LNum').textContent) === 0) { minLevel[memPos] = 0; } else { minLevel[memPos] = Number(firstTupMembers[memPos].querySelector('LNum').textContent); } // if (firstTupMembers[memPos].querySelector('MEMBER_TYPE').textContent === '1' && // (this.isPaging || Number(firstTupMembers[memPos].querySelector('LNum').textContent) === 0)) { if (firstTupMembers[memPos].querySelector('MEMBER_TYPE').textContent === '1') { allType[memPos] = 0; withoutAllStartPos = withoutAllStartPos === -1 ? memPos : withoutAllStartPos; withoutAllEndPos = memPos; } else { allType[memPos] = 1; availAllMember = firstTupMembers[memPos].querySelector('MEMBER_TYPE').textContent === '3' ? availAllMember : true; } memPos++; } measurePos = typeColl.indexOf('3'); } memPos = 0; if (tupPos === 0 && (members.length > (allCount + (measure ? 1 : 0)) || (members.length === 1 && measure))) { gTotals.pop(); } if ((tupPos === 0 && this.isPaging) ? gTotals.length === 0 : (!availAllMember || allCount === lastAllCount || allStartPos !== lastAllStartPos || (members.length === 1 && measure))) { var attrDrill = this.checkAttributeDrill(this.tupRowInfo[tupPos].drillInfo, 'rows'); var drillAllow = drillStartPos > -1 ? (allCount > 0 ? (attrDrill || allStartPos > drillStartPos) : true) : true; drillAllow = (prevTupInfo && drillAllow && drillStartPos > -1) ? (prevTupInfo.startDrillUniquename !== startDrillUniquename ? true : ((withoutAllEndPos > prevTupInfo.measurePosition ? false : prevTupInfo.measureName !== this.tupRowInfo[tupPos].measureName) && (allStartPos === (drillStartPos + 1) || this.tupRowInfo[tupPos].measurePosition === (drillStartPos + 1)))) : drillAllow; var withoutAllAllow = (withoutAllStartPos > -1 && allCount > 0) ? (attrDrill || allStartPos > withoutAllEndPos) : true; isGrandTotalTop = this.dataSourceSettings.grandTotalsPosition === 'Top' && this.olapRowValueIndex === 0 && this.olapValueAxis === 'row' && this.dataSourceSettings.showGrandTotals && this.dataSourceSettings.showRowGrandTotals && (this.olapValueAxis === 'row' ? this.dataSourceSettings.rows.length > 1 : true); if (isGrandTotalTop && gTotals.length === 1) { gTotals = this.frameGrandTotalValues(tuples, gTotals, typeColl, measurePos); } if (members.length === allCount + (measure ? 1 : 0) && measure && !isGrandTotalTop) { var levelName = 'Grand Total' + this.valueSortSettings.headerDelimiter + this.dataFields[this.getUniqueName(members[measurePos].querySelector('UName').textContent)].caption ? this.dataFields[this.getUniqueName(members[measurePos].querySelector('UName').textContent)].caption : members[measurePos].querySelector('Caption').textContent; var formattedText = (typeColl[measurePos] === '3' && this.dataFields[this.getUniqueName(members[measurePos].querySelector('UName').textContent)] && this.dataFields[this.getUniqueName(members[measurePos].querySelector('UName').textContent)].caption) ? this.dataFields[this.getUniqueName(members[measurePos].querySelector('UName').textContent)].caption : members[measurePos].querySelector('Caption').textContent; gTotals = this.frameGrandTotalAxisSet(gTotals, this.getUniqueName(members[measurePos].querySelector('UName').textContent), formattedText, position, tupPos, Number(typeColl[measurePos]), members[measurePos].querySelector('PARENT_UNIQUE_NAME') ? members[measurePos].querySelector('PARENT_UNIQUE_NAME').textContent : undefined, members[measurePos].querySelector('LName').textContent, members[measurePos].getAttribute('Hierarchy'), { levelName: levelName, axis: members[measurePos].getAttribute('Hierarchy') }); gTotals[gTotals.length - 1].valueSort[levelName] = 1; } else if (!(allStartPos === 0 || (measurePos === 0 && allStartPos === 1)) && drillAllow && withoutAllAllow) { if (this.dataSourceSettings.grandTotalsPosition === 'Top' && isGrandTotalAdd && this.dataSourceSettings.showGrandTotals && (this.olapValueAxis === 'row' ? this.dataSourceSettings.rows.length > 1 : true)) { this.insertRowGrandTotal(gTotals, valueContent, pivotValues, tuples, position); position = this.pivotValues.length; isGrandTotalAdd = false; } prevTupInfo = this.tupRowInfo[tupPos]; var lastPos = position; var lastMemPos = memPos; prevParent = {}; var withoutAllDrilled = false; while (memPos < members.length && pagingAllowFlag) { var member = members[memPos]; if (member.querySelector('UName').textContent !== prevUNArray[memPos] && typeColl[memPos] !== '2' && ((Object.keys(prevParent).length > 0 ? (prevParent.isDrilled && !this.fieldList[prevParent.hierarchy].isHierarchy) : withoutAllDrilled) ? (typeColl[memPos] === '3' && (allType[memPos - 1] && allType[memPos + 1] !== 0)) : true)) { var lvl = Number(member.querySelector('LNum').textContent) - ((allType[memPos] && typeColl[memPos] !== '3') ? 1 : minLevel[memPos]); var isNamedSet = this.namedSetsPosition['row'][memPos] ? true : false; var uniqueName = this.getUniqueName(member.querySelector('UName').textContent); var depth = this.getDepth(this.tupRowInfo[tupPos], uniqueName, Number(typeColl[memPos])); var levelName = this.getCaptionCollectionWithMeasure(this.tupRowInfo[tupPos], memPos, true); if (this.showSubTotalsAtBottom && position > this.rowStartPos) { lastPos = position = this.insertRowSubTotal(pivotValues, valueContent, subTotals, position, lvl, levelName); } if (!(this.isPaging && pivotValues[lastMesPos][0] && this.fieldList[pivotValues[lastMesPos][0].hierarchy] && this.fieldList[pivotValues[lastMesPos][0].hierarchy].isHierarchy && pivotValues[lastMesPos][0].hasChild && !pivotValues[lastMesPos][0].isDrilled && !this.rows[memPos].isNamedSet && (this.rows[memPos].name.indexOf('[Measures]') === 0 || (this.fieldList[member.getAttribute('Hierarchy')] && (this.fieldList[member.getAttribute('Hierarchy')].isHierarchy || this.fieldList[member.getAttribute('Hierarchy')].hasAllMember))) && pivotValues[lastMesPos][0].depth < depth)) { pivotValues[position] = [{ axis: 'row', actualText: uniqueName, colIndex: 0, formattedText: (typeColl[memPos] === '3' && this.dataFields[uniqueName] && this.dataFields[uniqueName].caption) ? this.dataFields[uniqueName].caption : member.querySelector('Caption').textContent, hasChild: (this.fieldList[member.getAttribute('Hierarchy')] && this.fieldList[member.getAttribute('Hierarchy')].isHierarchy && memPos < this.rows.length - 1 && !this.rows[memPos + 1].isNamedSet && this.rows[memPos + 1].name.indexOf('[Measures]') < 0 && this.fieldList[this.rows[memPos + 1].name] && this.fieldList[this.rows[memPos + 1].name].hasAllMember) ? true : Number(member.querySelector('CHILDREN_CARDINALITY').textContent) > 0 ? true : false, level: lvl, depth: depth, rowIndex: position, index: [], ordinal: tupPos, type: 'header', colSpan: 1, rowSpan: 1, memberType: Number(typeColl[memPos]), isDrilled: (this.fieldList[member.getAttribute('Hierarchy')] && this.fieldList[member.getAttribute('Hierarchy')].isHierarchy &&