123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154 |
- 'use strict';
- /*
- *+------------------------------------------------------------------------+
- *| Licensed Materials - Property of IBM
- *| IBM Cognos Products: BI Dashboard
- *| (C) Copyright IBM Corp. 2017
- *|
- *| US Government Users Restricted Rights - Use, duplication or disclosure
- *| restricted by GSA ADP Schedule Contract with IBM Corp.
- *+------------------------------------------------------------------------+
- */
- define(['./VisQueryPostProcessor'], function (BaseClass) {
- 'use strict';
- /**
- * This Class does Query result response post-processing such as processing the original query result
- * into a data structure that is required by GeoInfo, Data for small multiples visualization etc.
- **/
- var PostProcessorClass = BaseClass.extend({
- COL_MULTIPLIER_LIMIT: 30,
- ROW_MULTIPLIER_LIMIT: 30,
- _colMultiplier: null,
- _rowMultiplier: null,
- /*
- *@Constructor
- *@param {Object} options
- * for example: {'rowMultiplier': {'dataItemId': 'Sheet1.ProductLine','limit': 8}, 'rowMultiplier':{}}
- */
- init: function init(options) {
- PostProcessorClass.inherited('init', this, arguments);
- this._rowMultiplier = options.rowMultiplier;
- this._colMultiplier = options.colMultiplier;
- },
- getRowMultiplierLimit: function getRowMultiplierLimit() {
- if (this._rowMultiplier && this._rowMultiplier.limit !== null && this._rowMultiplier.limit !== undefined && this._rowMultiplier.limit > 0) {
- return this._rowMultiplier.limit;
- }
- return this.ROW_MULTIPLIER_LIMIT;
- },
- getRowMultiplierDataItem: function getRowMultiplierDataItem() {
- if (this._rowMultiplier) {
- return this._rowMultiplier.dataItemId;
- }
- return null;
- },
- /*Make COL multiplier limit getter a separated function*/
- getColMultiplierLimit: function getColMultiplierLimit() {
- if (this._colMultiplier && this._colMultiplier.limit !== null && this._colMultiplier.limit !== undefined && this._colMultiplier.limit > 0) {
- return this._colMultiplier.limit;
- }
- return this.COL_MULTIPLIER_LIMIT;
- },
- getColMultiplierDataItem: function getColMultiplierDataItem() {
- if (this._colMultiplier) {
- return this._colMultiplier.dataItemId;
- }
- return null;
- },
- /**
- *Process Query result based on the passed options to constructor.
- *For instance, limit the rows of datapoints so that in the response, for
- *specified dataitem, 'product', there will be only three tuples returned
- *
- *@return {QueryResultData}
- **/
- _processData: function _processData() {
- if (!this._queryResultData || !this._queryResultData.data) {
- return this._queryResultData;
- }
- var oInfo = this._getMultipliersInfo();
- var nRowMDataItemIndex = oInfo.nRowMDataItemIndex;
- var nColMDataItemIndex = oInfo.nColMDataItemIndex;
- var nRowMLimit = oInfo.nRowMLimit;
- var nColMLimit = oInfo.nColMLimit;
- //Clip DataItems
- if (nRowMLimit >= 0 && nRowMDataItemIndex >= 0 || nColMLimit >= 0 && nColMDataItemIndex) {
- this._clipDataItems(nRowMDataItemIndex, nRowMLimit);
- this._clipDataItems(nColMDataItemIndex, nColMLimit);
- //Clip DataPoints
- var nClipped = this._clipDatapoints(nRowMLimit, nRowMDataItemIndex, nColMLimit, nColMDataItemIndex);
- //Set ProcessInfo
- var oProcessInfo = {
- 'clipped': nClipped
- };
- if (nRowMLimit >= 0) {
- oProcessInfo.rowLimit = nRowMLimit;
- }
- if (nColMLimit >= 0) {
- oProcessInfo.colLimit = nColMLimit;
- }
- this._setProcessInfo(oProcessInfo);
- }
- //Process Done
- return this._queryResultData;
- },
- _getMultipliersInfo: function _getMultipliersInfo() {
- var nRowMLimit = this.getRowMultiplierLimit();
- var nColMLimit = this.getColMultiplierLimit();
- var nRowMDataItemIndex, nColMDataItemIndex; //The data item index that the data item maps to in the query result response
- var sRowMDataItemId = this.getRowMultiplierDataItem();
- if (sRowMDataItemId) {
- nRowMDataItemIndex = this._queryResultData.data.getDataItemIndex(sRowMDataItemId);
- }
- var sColMDataItemId = this.getColMultiplierDataItem();
- if (sColMDataItemId) {
- nColMDataItemIndex = this._queryResultData.data.getDataItemIndex(sColMDataItemId);
- }
- return {
- 'nRowMLimit': nRowMLimit,
- 'nRowMDataItemIndex': nRowMDataItemIndex,
- 'nColMLimit': nColMLimit,
- 'nColMDataItemIndex': nColMDataItemIndex
- };
- },
- _clipDatapoints: function _clipDatapoints(nRowMLimit, nRowMDataItemIndex, nColMLimit, nColMDataItemIndex) {
- var oData = this._queryResultData.data._resultData.data;
- var nOrigLength = oData.length;
- var nCounter = 0;
- while (nOrigLength > 0) {
- if (nRowMDataItemIndex >= 0 && oData[nOrigLength - 1].pt[nRowMDataItemIndex] > nRowMLimit - 1 || nColMDataItemIndex >= 0 && oData[nOrigLength - 1].pt[nColMDataItemIndex] > nColMLimit - 1) {
- oData.splice(nOrigLength - 1, 1); //Avoid create new Array
- nCounter++;
- }
- nOrigLength--;
- }
- return nCounter;
- },
- _clipDataItems: function _clipDataItems(dataItemIndex, limit) {
- if (this._queryResultData && limit >= 0 && dataItemIndex >= 0) {
- var aDataItems = this._queryResultData.data.getResultDataItems();
- if (aDataItems[dataItemIndex] && aDataItems[dataItemIndex].getTupleCount() > 0) {
- aDataItems[dataItemIndex].clipTuples(limit);
- }
- }
- }
- });
- return PostProcessorClass;
- });
- //# sourceMappingURL=PostProcessSmallMultiple.js.map
|