VIPRDataSet.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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(['./VIPRDecoratable', './VIPRDataPointIterator', './VIPRCatDataItem', './VIPRContDataItem', './VIPRCatContDataItem', '../../../apiHelpers/SlotAPIHelper'], function (VIPRDecoratable, VIPRDataPointIterator, VIPRCatDataItem, VIPRContDataItem, VIPRCatContDataItem, SlotAPIHelper) {
  11. // We should ignore any dataItem that is not part of the vipr slots
  12. // Adding a tooltip slot caused an error in the constructor
  13. var VIPRDataSet = function (_VIPRDecoratable) {
  14. _inherits(VIPRDataSet, _VIPRDecoratable);
  15. function VIPRDataSet(datasetId, queryResult, slots, context, content) {
  16. _classCallCheck(this, VIPRDataSet);
  17. var _this = _possibleConstructorReturn(this, _VIPRDecoratable.call(this));
  18. _this.id = datasetId;
  19. _this.queryResult = queryResult;
  20. _this.slots = slots;
  21. _this.context = context;
  22. _this.context.queryResult = queryResult;
  23. _this.context.dataset = _this;
  24. _this.viprDataPoints = {};
  25. // Need to preload dataItems to handle empty result.
  26. _this.dataItems = [];
  27. var resultDataItems = queryResult.getResultItemList();
  28. var numberOfDataItems = resultDataItems ? resultDataItems.length : 0;
  29. for (var index = 0; index < numberOfDataItems; index++) {
  30. var resultDataItem = resultDataItems[index];
  31. // properly resolve the slot by looking for the dataitem in the slots.
  32. // CADBLOC-1504: SparkLine View for KPI is a line chart we built on fly, the temp dataItem id for it couldn't be used to find a slot, in this scenario, we find slot based on index
  33. var slot = _this._getSlot(resultDataItem) || _this.slots[index];
  34. var slotDef = slot && slot.getDefinition();
  35. var slotDataItems = slot && slot.getDataItemList();
  36. if (slotDataItems && slotDataItems.length) {
  37. // @todo check for multi measure case?
  38. var type = slotDataItems[0].getType(); // sample the type with the first dataitem
  39. var VIPRDataItem = type === 'attribute' ? VIPRCatDataItem : VIPRContDataItem;
  40. var latLongSubTypes = ['latitude', 'longitude'];
  41. if (latLongSubTypes.indexOf(slotDef.getSubType()) > -1) {
  42. VIPRDataItem = VIPRCatContDataItem;
  43. }
  44. _this.context.index = {
  45. dataitem: _this.slots.indexOf(slot)
  46. };
  47. _this.dataItems[index] = new VIPRDataItem(resultDataItem, _this.context, content);
  48. }
  49. }
  50. return _this;
  51. }
  52. VIPRDataSet.prototype._getSlot = function _getSlot(resultDataItem) {
  53. var slot = this.slots.find(function (slot) {
  54. if (SlotAPIHelper.isMultiMeasuresValueSlot(slot) && resultDataItem.getDataItemList()[0].getId() === SlotAPIHelper.MULTI_MEASURES_VALUE) {
  55. return true;
  56. }
  57. var foundDataItem = slot.getDataItemList().find(function (dataItem) {
  58. return dataItem.getId() === resultDataItem.getDataItemList()[0].getId();
  59. });
  60. return foundDataItem;
  61. });
  62. return slot;
  63. };
  64. VIPRDataSet.prototype.getId = function getId() {
  65. return this.id;
  66. };
  67. // implement IDataSet
  68. VIPRDataSet.prototype.getDataItem = function getDataItem(index) {
  69. return index < this.dataItems.length ? this.dataItems[index] : null;
  70. };
  71. VIPRDataSet.prototype.getDataItemCount = function getDataItemCount() {
  72. return this.dataItems.length;
  73. };
  74. VIPRDataSet.prototype.getDataPointIterator = function getDataPointIterator() {
  75. return new VIPRDataPointIterator(this, this.context);
  76. };
  77. return VIPRDataSet;
  78. }(VIPRDecoratable);
  79. return VIPRDataSet;
  80. });
  81. //# sourceMappingURL=VIPRDataSet.js.map