VIPRDataPointIterator.js 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. 'use strict';
  2. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  3. /**
  4. * Licensed Materials - Property of IBM
  5. * IBM Business Analytics (C) Copyright IBM Corp. 2019, 2020
  6. * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  7. */
  8. define(['underscore', './VIPRDataPoint'], function (_, VIPRDataPoint) {
  9. // implements IDataPointIterator
  10. var VIPRDataPointIterator = function () {
  11. function VIPRDataPointIterator(dataset, context) {
  12. _classCallCheck(this, VIPRDataPointIterator);
  13. this.dataPointIndex = -1;
  14. this.queryResult = dataset.queryResult;
  15. this.dataset = dataset;
  16. this.dataItemInfo = this._getDataItemInfo();
  17. //viprDataPoints is a map that matches the lifecycle of the VIPRDataset.
  18. //It stores backing datapoint objects that the vipr IDataPoint objects use for their API.
  19. //This is needed to support decorating the IDataPoints.
  20. this.viprDataPoints = this.dataset.viprDataPoints;
  21. this.context = context;
  22. }
  23. VIPRDataPointIterator.prototype.nextValue = function nextValue() {
  24. if (++this.dataPointIndex < this.queryResult.getRowCount()) {
  25. var thisdatapoint = this.viprDataPoints[this.dataPointIndex];
  26. //No IDatapoint exists for this key yet....create an object and create the API with asIDataPoint.
  27. if (!thisdatapoint) {
  28. thisdatapoint = new VIPRDataPoint(this.dataPointIndex, this.dataset, this.dataItemInfo, this.context);
  29. this.viprDataPoints[this.dataPointIndex] = thisdatapoint;
  30. }
  31. return thisdatapoint;
  32. }
  33. return null;
  34. };
  35. VIPRDataPointIterator.prototype.getTupleItems = function getTupleItems() {
  36. return this.viprDataPoints[this.dataPointIndex].getTupleItems();
  37. };
  38. //Cache information about the dataItems to avoid
  39. VIPRDataPointIterator.prototype._getDataItemInfo = function _getDataItemInfo() {
  40. var _this = this;
  41. var dataItemInfo = {
  42. isLatLong: {},
  43. formatter: {}
  44. };
  45. this.dataset.dataItems.forEach(function (dataItem, resultItemIndex) {
  46. var slotDef = _this.dataset.slots[resultItemIndex] && _this.dataset.slots[resultItemIndex].getDefinition();
  47. var subType = slotDef && slotDef.getSubType();
  48. if (subType === 'longitude' || subType === 'latitude') {
  49. dataItemInfo.isLatLong[resultItemIndex] = true;
  50. }
  51. if (dataItem.getFormatter) {
  52. dataItemInfo.formatter[resultItemIndex] = dataItem.getFormatter && dataItem.getFormatter();
  53. }
  54. });
  55. return dataItemInfo;
  56. };
  57. return VIPRDataPointIterator;
  58. }();
  59. return VIPRDataPointIterator;
  60. });
  61. //# sourceMappingURL=VIPRDataPointIterator.js.map