VIPRItem.js 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. 'use strict';
  2. var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
  3. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  4. 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; }
  5. 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; }
  6. /**
  7. * Licensed Materials - Property of IBM
  8. * IBM Business Analytics (C) Copyright IBM Corp. 2019, 2020
  9. * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  10. */
  11. define(['underscore', './VIPRDecoratable', './VIPRFormatter', '../../../widgets/livewidget/nls/StringResources'], function (_, VIPRDecoratable, VIPRFormatter, StringResources) {
  12. // implements IItem
  13. var VIPRItem = function (_VIPRDecoratable) {
  14. _inherits(VIPRItem, _VIPRDecoratable);
  15. function VIPRItem(item, context, content) {
  16. _classCallCheck(this, VIPRItem);
  17. var _this = _possibleConstructorReturn(this, _VIPRDecoratable.call(this, item, context));
  18. _this.item = item;
  19. _this.content = content;
  20. _this.context = context;
  21. _this._tuples = [];
  22. _this.dataset = context.dataset;
  23. _this._recalculateFormattedValue();
  24. _this.dataset = context.dataset;
  25. return _this;
  26. }
  27. /**
  28. * We are checking here if the aggregateTypeVisible toggler is on/off for multiMeasures
  29. * Regardless of the formatted string, this unformattedValue will remain constant which allows usage such as color consistency (fred is red)
  30. */
  31. VIPRItem.prototype._recalculateFormattedValue = function _recalculateFormattedValue() {
  32. var formatter = new VIPRFormatter(this.context.index.dataitem, this.context.index.tupleitem, this.context);
  33. if (this.item.value === undefined || this.item.label === null) {
  34. this.formattedValue = formatter.format(null);
  35. this.unformattedValue = this.formattedValue;
  36. } else if (this.item.aggregate) {
  37. var aggregateTypeVisible = !!this.content.getPropertyValue('widget.legend.aggregateTypeVisible');
  38. if (aggregateTypeVisible) {
  39. this.formattedValue = formatter.format(StringResources.get('multiMeasureLabel', { 'measureName': this.item.label.toString(), 'aggregate': StringResources.get(this.item.aggregate.toString()) }));
  40. this.unformattedValue = this.item.label + this.item.aggregate;
  41. } else {
  42. this.formattedValue = formatter.format(StringResources.get('measureLabel', { 'measureName': this.item.label.toString() }));
  43. this.unformattedValue = this.item.label + this.item.aggregate;
  44. }
  45. } else {
  46. this.formattedValue = formatter.format(this.item.label.toString());
  47. this.unformattedValue = this.item.label;
  48. }
  49. };
  50. VIPRItem.prototype.addTuple = function addTuple(tuple) {
  51. this._tuples.push(tuple);
  52. this._datapoints = null;
  53. };
  54. VIPRItem.prototype.getUniqueName = function getUniqueName() {
  55. return this.item.value === undefined || this.item.value === null ? this.item.value : this.item.value.toString();
  56. };
  57. VIPRItem.prototype.getCaption = function getCaption() {
  58. if (this.item.aggregate) {
  59. var currentAggregationPropertyValue = this.content.getPropertyValue('widget.legend.aggregateTypeVisible');
  60. if (currentAggregationPropertyValue != this.aggregationPropertyValue) {
  61. this._recalculateFormattedValue();
  62. this.aggregationPropertyValue = currentAggregationPropertyValue;
  63. }
  64. }
  65. if (!this.formattedValue) {
  66. this._recalculateFormattedValue();
  67. }
  68. return this.formattedValue;
  69. };
  70. VIPRItem.prototype.getParent = function getParent() {
  71. return this.item.p;
  72. };
  73. VIPRItem.prototype.decorate = function decorate(action, value) {
  74. var _VIPRDecoratable$prot;
  75. (_VIPRDecoratable$prot = _VIPRDecoratable.prototype.decorate).call.apply(_VIPRDecoratable$prot, [this].concat(Array.prototype.slice.call(arguments)));
  76. var datapoints = this.datapoints;
  77. if (datapoints.length > 0) {
  78. this.context.version++;
  79. // decorate the datapoints
  80. for (var i = 0; i < datapoints.length; i++) {
  81. datapoints[i].decorate(action, value);
  82. }
  83. }
  84. };
  85. _createClass(VIPRItem, [{
  86. key: 'datapoints',
  87. get: function get() {
  88. if (!this._datapoints) {
  89. this._datapoints = [];
  90. for (var i = 0; i < this._tuples.length; i++) {
  91. var tuple = this._tuples[i];
  92. for (var j = 0; j < tuple.datapoints.length; j++) {
  93. this._datapoints.push(tuple.datapoints[j]);
  94. }
  95. }
  96. }
  97. return this._datapoints;
  98. }
  99. }]);
  100. return VIPRItem;
  101. }(VIPRDecoratable);
  102. return VIPRItem;
  103. });
  104. //# sourceMappingURL=VIPRItem.js.map