123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200 |
- '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: BI Dashboard
- *| (C) Copyright IBM Corp. 2019
- *|
- *| US Government Users Restricted Rights - Use, duplication or disclosure
- *| restricted by GSA ADP Schedule Contract with IBM Corp.
- *+------------------------------------------------------------------------+
- */
- define(['underscore'], function (_) {
- 'use strict';
- /**
- * This Class processes query response results and extracts the top-bottom rank to a separate result data
- * Used by JQGrid.js during rendering process
- */
- var RankProcessor = function () {
- /**
- * @Constructor
- * @param {Object} options
- */
- function RankProcessor(queryResult, findSlotDetailsByRealColumnIndex) {
- _classCallCheck(this, RankProcessor);
- this._queryResult = queryResult;
- this.dataRows = this._queryResult.getDataPointValueList();
- this.dataItems = this._queryResult.getResultItemList();
- this.findSlotDetailsByRealColumnIndex = findSlotDetailsByRealColumnIndex;
- // Array of item ids that are being referenced by rank columns
- this.rankRefIds = [];
- this.rankDataItems = [];
- this._prepareRankDataItems();
- }
- /**
- * Called during initialization. Looks at the original data
- * and detects the rank columns. For each rank column, generates a
- * mock rankDataItem which will later be used while rendering the JQGrid.
- */
- RankProcessor.prototype._prepareRankDataItems = function _prepareRankDataItems() {
- var _this = this;
- // Look at first row to determine if each column is a rank column
- this.dataRows[0] && this.dataRows[0].pt.forEach(function (colData, colIndex) {
- if (_this._getRankValue(colData, colIndex)) {
- _this.rankRefIds.push(_this.dataItems[colIndex].getId());
- var _findSlotDetailsByRea = _this.findSlotDetailsByRealColumnIndex(colIndex),
- slot = _findSlotDetailsByRea.slot,
- mapIndex = _findSlotDetailsByRea.mapIndex;
- var rankDataItemOpt = {
- refColumnIndex: colIndex,
- resultDataItem: _this.dataItems[colIndex],
- aggregationType: slot.getDataItemList()[mapIndex].getAggregation()
- };
- _this.rankDataItems.push(new RankDataItem(rankDataItemOpt));
- }
- });
- };
- /**
- * Process Query result based on the passed options to constructor.
- * @return {Array} rankDataItems
- */
- RankProcessor.prototype.processData = function processData() {
- if (this.dataRows.length) {
- this._processDataRows();
- this._processDataItems();
- }
- return this.rankDataItems;
- };
- RankProcessor.prototype._processDataRows = function _processDataRows() {
- _.each(this.dataRows, function (dataRow) {
- this._processDataPoint(dataRow.pt);
- }.bind(this));
- };
- RankProcessor.prototype._processDataPoint = function _processDataPoint(rowData) {
- var ranks = [];
- for (var col = 0; col < rowData.length; col++) {
- var colData = rowData[col];
- var rank = this._getRankValue(colData, col);
- if (rank > 0) {
- // obtain the reference unique id from the dataitems
- var ref = this.dataItems[col].getId();
- // order of the rank is determined by the order of the references mapped in the rank slot
- var rankIndex = this.rankRefIds.indexOf(ref);
- // collect the ranks from each decoration
- ranks[rankIndex] = {
- v: rank
- };
- }
- }
- // prepare the parameters for splice
- ranks.splice(0, 0, 0, 0);
- // prepend all collected ranks to the row
- Array.prototype.splice.apply(rowData, ranks);
- };
- RankProcessor.prototype._processDataItems = function _processDataItems() {
- for (var index = 0; index < this.rankRefIds.length; index++) {
- // append an empty place holder for the ranks append to the datapoints
- var rankedDataItem = _.find(this.dataItems, function (dataItem) {
- return dataItem.getId() === this.rankRefIds[index];
- }.bind(this));
- this.dataItems.splice(index, 0, rankedDataItem);
- }
- };
- /**
- * Tries to read the rank value from column data (i.e. each entry inside dataRow.pt)
- * If finds, returns the rank value, if not returns 0
- *
- * @param {*} colData
- * @param {*} colIndex
- * @return {Number} rank value from the data point
- */
- RankProcessor.prototype._getRankValue = function _getRankValue(colData, colIndex) {
- var rankValue = 0;
- if ((typeof colData === 'undefined' ? 'undefined' : _typeof(colData)) === 'object') {
- // continuous data with rank decoration
- if (colData.deco && colData.deco.rank) {
- rankValue = colData.deco.rank;
- }
- } else {
- // reference the categorical data items to obtain the rank decoration
- var tupleItem = this.dataItems[colIndex].getValue(colData)[0];
- if (tupleItem.deco && tupleItem.deco.rank) {
- rankValue = tupleItem.deco.rank;
- }
- }
- return rankValue;
- };
- return RankProcessor;
- }();
- var RankDataItem = function () {
- /**
- * @Constructor
- * @param {Object} options
- */
- function RankDataItem(options) {
- _classCallCheck(this, RankDataItem);
- this._refColumnIndex = options.refColumnIndex;
- this._resultDataItem = options.resultDataItem;
- this._aggregationType = options.aggregationType;
- }
- RankDataItem.prototype.isRank = function isRank() {
- return true;
- };
- RankDataItem.prototype.getType = function getType() {
- return 'fact';
- };
- RankDataItem.prototype.getLabel = function getLabel() {
- // There should be only one column
- return this._resultDataItem.getDataItemList()[0].getLabel();
- };
- RankDataItem.prototype.getId = function getId() {
- return this._resultDataItem.getId();
- };
- RankDataItem.prototype.getAggregation = function getAggregation() {
- return this._aggregationType;
- };
- RankDataItem.prototype.getRefColumnIndex = function getRefColumnIndex() {
- return this._refColumnIndex;
- };
- return RankDataItem;
- }();
- return RankProcessor;
- });
- //# sourceMappingURL=RankProcessor.js.map
|