Summary.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. 'use strict';
  2. 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; };
  3. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  4. /**
  5. * Licensed Materials - Property of IBM
  6. * IBM Cognos Products: BI Cloud (C) Copyright IBM Corp. 2016, 2018
  7. * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  8. */
  9. define(['../../../widgets/livewidget/nls/StringResources'], function (StringResources) {
  10. 'use strict';
  11. var PROCESSING = StringResources.get('processing');
  12. var NOT_AVAILABLE = StringResources.get('value_is_not_available');
  13. var Summary = function () {
  14. function Summary(mappingInfo, isLocalSummary) {
  15. _classCallCheck(this, Summary);
  16. this._numberOfValues = 0;
  17. this._formatSpec = mappingInfo.formatSpec;
  18. this._aggregationType = mappingInfo.aggregationType;
  19. this._isLocalSummary = isLocalSummary;
  20. this._uniqueId = mappingInfo.id;
  21. }
  22. /**
  23. * Add call back functions and required parameters when summary is local supported type
  24. * @param {object} cbContext -
  25. * categoryUIds: used as query Key to find the corresponding summary query result
  26. * tupleUIds: used as tuple key to find the value from the right summary query result
  27. * cbGetSummary: callback to invoke getSummary in SummaryFeature
  28. * cbOnCellDataChange: callback when summary value is ready
  29. */
  30. Summary.prototype.addCallBackContext = function addCallBackContext(cbContext) {
  31. this.categoryUIds = cbContext.categoryUIds;
  32. this.tupleUIds = cbContext.tupleUIds;
  33. this.getSummary = cbContext.cbGetSummary;
  34. this.onCellDataChange = cbContext.cbOnCellDataChange;
  35. this.addSummaryValuePromise = cbContext.cbAddSummaryValuePromise;
  36. };
  37. Summary.prototype.addValue = function addValue(value) {
  38. if (!this._isLocalSummary) {
  39. // Just return if local summary does not support the aggregation type
  40. return;
  41. }
  42. var newValue = value;
  43. if (value && (typeof value === 'undefined' ? 'undefined' : _typeof(value)) === 'object') {
  44. newValue = value.getSummarizedValue();
  45. }
  46. if (typeof newValue !== 'number') {
  47. return;
  48. }
  49. if (typeof this.value !== 'number') {
  50. this.value = newValue;
  51. return;
  52. }
  53. switch (this._aggregationType) {
  54. case 'min':
  55. this.value = Math.min(this.value, newValue);
  56. break;
  57. case 'max':
  58. this.value = Math.max(this.value, newValue);
  59. break;
  60. default:
  61. this.value += newValue;
  62. }
  63. };
  64. Summary.prototype.getSummarizedValue = function getSummarizedValue(rowIdx, colIdx) {
  65. var _this = this;
  66. if (!this._isLocalSummary) {
  67. if (this.getSummary) {
  68. this.valuePromise = this.getSummary(this.categoryUIds, this._uniqueId, this.tupleUIds).then(function (value) {
  69. _this.onCellDataChange(rowIdx, colIdx, value, _this._formatSpec);
  70. });
  71. if (this.addSummaryValuePromise) {
  72. this.addSummaryValuePromise(this.valuePromise);
  73. }
  74. return PROCESSING;
  75. } else {
  76. return NOT_AVAILABLE;
  77. }
  78. }
  79. return this.getValue();
  80. };
  81. Summary.prototype.getValue = function getValue() {
  82. return typeof this.value === 'number' ? this.value : null;
  83. };
  84. Summary.prototype.getFormatSpec = function getFormatSpec() {
  85. return this._formatSpec;
  86. };
  87. return Summary;
  88. }();
  89. return Summary;
  90. });
  91. //# sourceMappingURL=Summary.js.map