VIPRDataPoint.js 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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. 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', './VIPRValue'], function (_, VIPRDecoratable, VIPRValue) {
  11. // implements IDataPoint
  12. var VIPRDataPoint = function (_VIPRDecoratable) {
  13. _inherits(VIPRDataPoint, _VIPRDecoratable);
  14. /**
  15. * @param {Number} index - the index of this datapoint
  16. * @param {Object} dataset - the ViprDataSet object
  17. * @param {Object} dataIteminfo - an object that describes whether dataItems are latlong or have format callbacks.
  18. * @param {Boolean[]} dataItemInfo.isLatLong - true if this item denotes a lattitude or longitude value
  19. * @param {Function[]} dataItemInfo.formatter - set if the VIPRDataItem has a formatter
  20. * @param {Object} context - the context.
  21. */
  22. function VIPRDataPoint(index, dataset, dataItemInfo, context) {
  23. _classCallCheck(this, VIPRDataPoint);
  24. var _this = _possibleConstructorReturn(this, _VIPRDecoratable.call(this, null, context));
  25. _this.index = index;
  26. _this.dataset = dataset;
  27. _this.dataItemInfo = dataItemInfo;
  28. _this.context = context;
  29. _this.queryResult = dataset.queryResult;
  30. _this.viprValues = {}; //Keep any viprValue (IValue) objects.
  31. return _this;
  32. }
  33. /**
  34. * @param {Number} resultItemIndex - the index of this categorical resultItem in the QueryResult AND the VIPRDataSet
  35. * @returns {Number} the index of the tuple for this item that this datapoint represents.
  36. */
  37. VIPRDataPoint.prototype.getTupleIndex = function getTupleIndex(resultItemIndex) {
  38. var tupleIndex = this.queryResult.getValueIndex(this.index, resultItemIndex);
  39. // Keep a reverse-reference from tuple to the datapoint
  40. var viprDataItem = this.dataset.getDataItem && this.dataset.getDataItem(resultItemIndex);
  41. viprDataItem && viprDataItem.getTuple(tupleIndex).addDataPoint(this);
  42. return tupleIndex;
  43. };
  44. /**
  45. * @param {Number} resultItemIndex - the index of this continuous resultItem in the QueryResult AND the VIPRDataSet
  46. * @returns {Object} A VIPRValue API which includes a getValue() getCaption() to get the actual values.
  47. */
  48. VIPRDataPoint.prototype.getValue = function getValue(resultItemIndex) {
  49. if (this.viprValues[resultItemIndex] === undefined) {
  50. var valueObj = this.queryResult.getValue(this.index, resultItemIndex);
  51. if (this.dataItemInfo.isLatLong[resultItemIndex]) {
  52. //For values which are lat/long, the datapoint contains the index in the resultItem values
  53. //where the lat/long is stored.
  54. //(using getValue hides this detail except that the value is returned as a tuple array of length 1)
  55. valueObj = valueObj[0].value;
  56. }
  57. this.viprValues[resultItemIndex] = new VIPRValue(valueObj, this.dataItemInfo.formatter[resultItemIndex], resultItemIndex);
  58. }
  59. return this.viprValues[resultItemIndex];
  60. };
  61. /**
  62. * @description - Decorate this datapoint with the named decoration
  63. * @param {string} name - The name of the decoration for this datapoint (eg. selected, highlighted)
  64. * @returns {Boolean} value - the value of the decoration (usu true, false or undefined)
  65. */
  66. VIPRDataPoint.prototype.decorate = function decorate(name, value) {
  67. value = typeof value === 'undefined' ? true : value;
  68. _VIPRDecoratable.prototype.decorate.call(this, name, value);
  69. };
  70. /**
  71. * @returns The full, evaluated tuple for the categorical items in this datapoint.
  72. */
  73. VIPRDataPoint.prototype.getTupleItems = function getTupleItems() {
  74. var _this2 = this;
  75. var items = [];
  76. this.dataset.dataItems.forEach(function (dataItem, i) {
  77. if (dataItem.getType() === 'cat' || _this2.dataItemInfo.isLatLong[i]) {
  78. var value = _this2.queryResult.getValue(_this2.index, i);
  79. if (Array.isArray(value)) {
  80. items.push.apply(items, value);
  81. }
  82. }
  83. });
  84. return items;
  85. };
  86. /**
  87. * @description This additional api returns a key for the datapoint based on the valueIndexes of each categorical tuple
  88. * @example used to match query result tuples against points in smartAnnotation responses for decorating - see VIPRView)
  89. * @returns {String} - a "key" of form 'n,m,...' where n and m are the tupleIndexes of each categorical item.
  90. */
  91. VIPRDataPoint.prototype.getDataPointKey = function getDataPointKey() {
  92. var _this3 = this;
  93. var tupleIndexes = [];
  94. this.dataset.dataItems.forEach(function (dataItem, i) {
  95. if (dataItem.getType() === 'cat' || _this3.dataItemInfo.isLatLong[i]) {
  96. tupleIndexes.push(_this3.queryResult.getValueIndex(_this3.index, i));
  97. }
  98. });
  99. return tupleIndexes.toString();
  100. };
  101. return VIPRDataPoint;
  102. }(VIPRDecoratable);
  103. return VIPRDataPoint;
  104. });
  105. //# sourceMappingURL=VIPRDataPoint.js.map