PostProcessSmallMultiple.js 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. 'use strict';
  2. /*
  3. *+------------------------------------------------------------------------+
  4. *| Licensed Materials - Property of IBM
  5. *| IBM Cognos Products: BI Dashboard
  6. *| (C) Copyright IBM Corp. 2017
  7. *|
  8. *| US Government Users Restricted Rights - Use, duplication or disclosure
  9. *| restricted by GSA ADP Schedule Contract with IBM Corp.
  10. *+------------------------------------------------------------------------+
  11. */
  12. define(['./VisQueryPostProcessor'], function (BaseClass) {
  13. 'use strict';
  14. /**
  15. * This Class does Query result response post-processing such as processing the original query result
  16. * into a data structure that is required by GeoInfo, Data for small multiples visualization etc.
  17. **/
  18. var PostProcessorClass = BaseClass.extend({
  19. COL_MULTIPLIER_LIMIT: 30,
  20. ROW_MULTIPLIER_LIMIT: 30,
  21. _colMultiplier: null,
  22. _rowMultiplier: null,
  23. /*
  24. *@Constructor
  25. *@param {Object} options
  26. * for example: {'rowMultiplier': {'dataItemId': 'Sheet1.ProductLine','limit': 8}, 'rowMultiplier':{}}
  27. */
  28. init: function init(options) {
  29. PostProcessorClass.inherited('init', this, arguments);
  30. this._rowMultiplier = options.rowMultiplier;
  31. this._colMultiplier = options.colMultiplier;
  32. },
  33. getRowMultiplierLimit: function getRowMultiplierLimit() {
  34. if (this._rowMultiplier && this._rowMultiplier.limit !== null && this._rowMultiplier.limit !== undefined && this._rowMultiplier.limit > 0) {
  35. return this._rowMultiplier.limit;
  36. }
  37. return this.ROW_MULTIPLIER_LIMIT;
  38. },
  39. getRowMultiplierDataItem: function getRowMultiplierDataItem() {
  40. if (this._rowMultiplier) {
  41. return this._rowMultiplier.dataItemId;
  42. }
  43. return null;
  44. },
  45. /*Make COL multiplier limit getter a separated function*/
  46. getColMultiplierLimit: function getColMultiplierLimit() {
  47. if (this._colMultiplier && this._colMultiplier.limit !== null && this._colMultiplier.limit !== undefined && this._colMultiplier.limit > 0) {
  48. return this._colMultiplier.limit;
  49. }
  50. return this.COL_MULTIPLIER_LIMIT;
  51. },
  52. getColMultiplierDataItem: function getColMultiplierDataItem() {
  53. if (this._colMultiplier) {
  54. return this._colMultiplier.dataItemId;
  55. }
  56. return null;
  57. },
  58. /**
  59. *Process Query result based on the passed options to constructor.
  60. *For instance, limit the rows of datapoints so that in the response, for
  61. *specified dataitem, 'product', there will be only three tuples returned
  62. *
  63. *@return {QueryResultData}
  64. **/
  65. _processData: function _processData() {
  66. if (!this._queryResultData || !this._queryResultData.data) {
  67. return this._queryResultData;
  68. }
  69. var oInfo = this._getMultipliersInfo();
  70. var nRowMDataItemIndex = oInfo.nRowMDataItemIndex;
  71. var nColMDataItemIndex = oInfo.nColMDataItemIndex;
  72. var nRowMLimit = oInfo.nRowMLimit;
  73. var nColMLimit = oInfo.nColMLimit;
  74. //Clip DataItems
  75. if (nRowMLimit >= 0 && nRowMDataItemIndex >= 0 || nColMLimit >= 0 && nColMDataItemIndex) {
  76. this._clipDataItems(nRowMDataItemIndex, nRowMLimit);
  77. this._clipDataItems(nColMDataItemIndex, nColMLimit);
  78. //Clip DataPoints
  79. var nClipped = this._clipDatapoints(nRowMLimit, nRowMDataItemIndex, nColMLimit, nColMDataItemIndex);
  80. //Set ProcessInfo
  81. var oProcessInfo = {
  82. 'clipped': nClipped
  83. };
  84. if (nRowMLimit >= 0) {
  85. oProcessInfo.rowLimit = nRowMLimit;
  86. }
  87. if (nColMLimit >= 0) {
  88. oProcessInfo.colLimit = nColMLimit;
  89. }
  90. this._setProcessInfo(oProcessInfo);
  91. }
  92. //Process Done
  93. return this._queryResultData;
  94. },
  95. _getMultipliersInfo: function _getMultipliersInfo() {
  96. var nRowMLimit = this.getRowMultiplierLimit();
  97. var nColMLimit = this.getColMultiplierLimit();
  98. var nRowMDataItemIndex, nColMDataItemIndex; //The data item index that the data item maps to in the query result response
  99. var sRowMDataItemId = this.getRowMultiplierDataItem();
  100. if (sRowMDataItemId) {
  101. nRowMDataItemIndex = this._queryResultData.data.getDataItemIndex(sRowMDataItemId);
  102. }
  103. var sColMDataItemId = this.getColMultiplierDataItem();
  104. if (sColMDataItemId) {
  105. nColMDataItemIndex = this._queryResultData.data.getDataItemIndex(sColMDataItemId);
  106. }
  107. return {
  108. 'nRowMLimit': nRowMLimit,
  109. 'nRowMDataItemIndex': nRowMDataItemIndex,
  110. 'nColMLimit': nColMLimit,
  111. 'nColMDataItemIndex': nColMDataItemIndex
  112. };
  113. },
  114. _clipDatapoints: function _clipDatapoints(nRowMLimit, nRowMDataItemIndex, nColMLimit, nColMDataItemIndex) {
  115. var oData = this._queryResultData.data._resultData.data;
  116. var nOrigLength = oData.length;
  117. var nCounter = 0;
  118. while (nOrigLength > 0) {
  119. if (nRowMDataItemIndex >= 0 && oData[nOrigLength - 1].pt[nRowMDataItemIndex] > nRowMLimit - 1 || nColMDataItemIndex >= 0 && oData[nOrigLength - 1].pt[nColMDataItemIndex] > nColMLimit - 1) {
  120. oData.splice(nOrigLength - 1, 1); //Avoid create new Array
  121. nCounter++;
  122. }
  123. nOrigLength--;
  124. }
  125. return nCounter;
  126. },
  127. _clipDataItems: function _clipDataItems(dataItemIndex, limit) {
  128. if (this._queryResultData && limit >= 0 && dataItemIndex >= 0) {
  129. var aDataItems = this._queryResultData.data.getResultDataItems();
  130. if (aDataItems[dataItemIndex] && aDataItems[dataItemIndex].getTupleCount() > 0) {
  131. aDataItems[dataItemIndex].clipTuples(limit);
  132. }
  133. }
  134. }
  135. });
  136. return PostProcessorClass;
  137. });
  138. //# sourceMappingURL=PostProcessSmallMultiple.js.map