VIPRContDataItem.js 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. 'use strict';
  2. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  3. function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
  4. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  5. /**
  6. * Licensed Materials - Property of IBM
  7. * IBM Business Analytics (C) Copyright IBM Corp. 2019, 2020
  8. * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  9. */
  10. define(['underscore', './VIPRDecoratable', './VIPRItemClass', './VIPRFormatter'], function (_, VIPRDecoratable, VIPRItemClass, VIPRFormatter) {
  11. // implements IContDataItem
  12. var VIPRContDataItem = function (_VIPRDecoratable) {
  13. _inherits(VIPRContDataItem, _VIPRDecoratable);
  14. function VIPRContDataItem(resultItem, context, content) {
  15. _classCallCheck(this, VIPRContDataItem);
  16. var _this = _possibleConstructorReturn(this, _VIPRDecoratable.apply(this, arguments));
  17. _this.context = context;
  18. _this.queryResult = context && context.queryResult;
  19. _this.content = content;
  20. // Ordinal slots normally does not take multiple dataitems (ie. stacked)
  21. // even for multi-measures case (ie. bar, column) the multiple ordinal dataitems are merged in to a single ordinal measure
  22. // and each measures are separated as series.
  23. // So at the end, from the VIPRData perspective a numeric dataitem (aka slot), has only one measure.
  24. _this.formatter = new VIPRFormatter(_this.context.index.dataitem, 0, _this.context);
  25. //getTupleHeaders() return the array of itemClass, each Item Class contains an array of Tuple headers
  26. _this.itemClass = new VIPRItemClass(resultItem.getDataItemList()[0], _this.context);
  27. _this.domain = _this._createDomain(); // Min Max Data Item domain
  28. return _this;
  29. }
  30. /*
  31. * Format data from min/max query
  32. */
  33. VIPRContDataItem.prototype._getMinMaxData = function _getMinMaxData(minmaxResult) {
  34. var resultItems = minmaxResult.getResultItemList();
  35. var data = [];
  36. for (var index = 0; index + 1 < resultItems.length; index += 2) {
  37. var resultDataItem = resultItems[index];
  38. var dataItem = resultDataItem.getDataItemList()[0];
  39. var min = minmaxResult.getValue(0, index).value;
  40. var max = minmaxResult.getValue(0, index + 1).value;
  41. data.push({
  42. min: min,
  43. max: max,
  44. columnId: dataItem.getColumnId(),
  45. aggregation: dataItem.getAggregation(),
  46. explicit: this._explicitMinMax(min, max)
  47. });
  48. }
  49. return data;
  50. };
  51. VIPRContDataItem.prototype._explicitMinMax = function _explicitMinMax(min, max) {
  52. //TODO: Revisit the domain.explicit setting post R7
  53. //refer: EXPLORE-2277 EXPLORE-2692
  54. var visualization = this.content && this.content.getFeature('Visualization');
  55. return visualization && visualization.getType() === 'Tiledmap' && min !== undefined && min !== null && max !== undefined && max !== null;
  56. };
  57. /*
  58. * Create a domain incorporating min/max from all measures
  59. */
  60. VIPRContDataItem.prototype._createMultiMeasureDomain = function _createMultiMeasureDomain(minmaxResult) {
  61. var overAllMin = void 0;
  62. var overAllMax = void 0;
  63. var overAllExplicit = void 0;
  64. var minmaxData = this._getMinMaxData(minmaxResult);
  65. minmaxData.forEach(function (_ref) {
  66. var min = _ref.min,
  67. max = _ref.max,
  68. explicit = _ref.explicit;
  69. overAllMin = overAllMin !== undefined ? Math.min(overAllMin, min) : min;
  70. overAllMax = overAllMax !== undefined ? Math.max(overAllMax, max) : max;
  71. overAllExplicit = explicit;
  72. });
  73. return {
  74. min: overAllMin,
  75. max: overAllMax,
  76. explicit: overAllExplicit
  77. };
  78. };
  79. /*
  80. * Create a domain only incorporating min/max for own data item
  81. */
  82. VIPRContDataItem.prototype._createNonMultiMeasureDomain = function _createNonMultiMeasureDomain(minmaxResult) {
  83. var minmaxData = this._getMinMaxData(minmaxResult);
  84. var columnId = this.itemClass.dataItem.getColumnId();
  85. var aggregation = this.itemClass.dataItem.getAggregation();
  86. var minmax = minmaxData.find(function (minmax) {
  87. return minmax.columnId === columnId && minmax.aggregation === aggregation;
  88. });
  89. if (minmax) {
  90. return {
  91. min: minmax.min,
  92. max: minmax.max,
  93. explicit: minmax.explicit
  94. };
  95. } else {
  96. return null;
  97. }
  98. };
  99. /**
  100. * @returns the domain (min/max) for the data item
  101. */
  102. VIPRContDataItem.prototype._createDomain = function _createDomain() {
  103. var domain = null;
  104. var minmaxResult = this.context.minmaxResult;
  105. if (minmaxResult) {
  106. if (this.itemClass.getUniqueName() === '_multiMeasuresValue') {
  107. domain = this._createMultiMeasureDomain(minmaxResult);
  108. } else {
  109. domain = this._createNonMultiMeasureDomain(minmaxResult);
  110. }
  111. }
  112. return domain;
  113. };
  114. VIPRContDataItem.prototype.getUniqueName = function getUniqueName() {
  115. return this.itemClass.getUniqueName();
  116. };
  117. VIPRContDataItem.prototype.getCaption = function getCaption() {
  118. return this.itemClass.getCaption();
  119. };
  120. VIPRContDataItem.prototype.getType = function getType() {
  121. return 'cont';
  122. };
  123. VIPRContDataItem.prototype.getDomain = function getDomain() /*aggregation TODO for stacked charts*/{
  124. return this.domain;
  125. };
  126. VIPRContDataItem.prototype.getFormatter = function getFormatter() {
  127. return this.formatter;
  128. };
  129. VIPRContDataItem.prototype.getItemClass = function getItemClass() {
  130. return this.itemClass;
  131. };
  132. return VIPRContDataItem;
  133. }(VIPRDecoratable);
  134. return VIPRContDataItem;
  135. });
  136. //# sourceMappingURL=VIPRContDataItem.js.map