VIPRTuple.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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', './VIPRItem'], function (_, VIPRDecoratable, VIPRItem) {
  11. // implements ITuple
  12. var VIPRTuple = function (_VIPRDecoratable) {
  13. _inherits(VIPRTuple, _VIPRDecoratable);
  14. function VIPRTuple(tuple, context, content, viprItemCache) {
  15. _classCallCheck(this, VIPRTuple);
  16. var _this = _possibleConstructorReturn(this, _VIPRDecoratable.apply(this, arguments));
  17. _this.tuple = tuple;
  18. _this.content = content;
  19. _this.context = context;
  20. _this.datapoints = [];
  21. _this.items = [];
  22. _this.dataset = context.dataset;
  23. _this.dataItemIndex = _this.context.index.dataitem;
  24. _this.dataItemFormats = _this.context.index.dataItemFormats;
  25. _this.itemClassSetIndex = _this.context.index.itemClassSet;
  26. _this._viprItemCache = viprItemCache;
  27. return _this;
  28. }
  29. VIPRTuple.prototype.getUniqueName = function getUniqueName() {
  30. return this.getItem(0).getUniqueName();
  31. };
  32. VIPRTuple.prototype.getCaption = function getCaption() {
  33. return this.getItem(0).getCaption();
  34. };
  35. VIPRTuple.prototype.getParent = function getParent() {
  36. return this.getItem(0).getParent();
  37. };
  38. VIPRTuple.prototype.getItemClassSetIndex = function getItemClassSetIndex() {
  39. //Since Enodr release, a tuple could have a itemClassSetIndex property
  40. //that indicates which itemClass the current tuple is using
  41. return this.itemClassSetIndex;
  42. };
  43. VIPRTuple.prototype._createVIPRItem = function _createVIPRItem(index, viprTuple, content) {
  44. var context = viprTuple.context;
  45. var viprItemInfo = viprTuple.tuple[index];
  46. var key = void 0;
  47. if (viprItemInfo.d) {
  48. key = viprItemInfo.d + '->' + viprItemInfo.u;
  49. } else {
  50. key = viprItemInfo.label + '->' + viprItemInfo.value;
  51. }
  52. if (!this._viprItemCache[key]) {
  53. this._viprItemCache[key] = new VIPRItem(this.tuple[index], context, content);
  54. }
  55. this._viprItemCache[key].addTuple(viprTuple);
  56. return this._viprItemCache[key];
  57. };
  58. VIPRTuple.prototype.getItem = function getItem(index) {
  59. if (index < this.getItemCount() && this.items[index] === undefined) {
  60. // keep track of the tuple item index as part of the context index
  61. this.context.index.tupleitem = index;
  62. this.context.index.dataitem = this.dataItemIndex;
  63. this.context.index.dataItemFormats = this.dataItemFormats;
  64. this.context.dataset = this.dataset;
  65. this.items[index] = this._createVIPRItem(index, this, this.content);
  66. }
  67. return this.items[index];
  68. };
  69. VIPRTuple.prototype.getItemCount = function getItemCount() {
  70. return this.tuple ? this.tuple.length : 0;
  71. };
  72. VIPRTuple.prototype.addDataPoint = function addDataPoint(datapoint) {
  73. if (this.datapoints.indexOf(datapoint) === -1) {
  74. this.datapoints.push(datapoint);
  75. }
  76. };
  77. VIPRTuple.prototype.decorate = function decorate(action, value) {
  78. var _VIPRDecoratable$prot;
  79. (_VIPRDecoratable$prot = _VIPRDecoratable.prototype.decorate).call.apply(_VIPRDecoratable$prot, [this].concat(Array.prototype.slice.call(arguments)));
  80. if (this.datapoints.length > 0) {
  81. // decorate the datapoints
  82. _.each(this.datapoints, function (dp) {
  83. dp.decorate(action, value);
  84. });
  85. }
  86. };
  87. return VIPRTuple;
  88. }(VIPRDecoratable);
  89. return VIPRTuple;
  90. });
  91. //# sourceMappingURL=VIPRTuple.js.map