EventUtils.js 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. 'use strict';
  2. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  3. /*
  4. *+------------------------------------------------------------------------+
  5. *| Licensed Materials - Property of IBM
  6. *| IBM Cognos Products: Dashboard
  7. *| (C) Copyright IBM Corp. 2019
  8. *|
  9. *| US Government Users Restricted Rights - Use, duplication or disclosure
  10. *| restricted by GSA ADP Schedule Contract with IBM Corp.
  11. *+------------------------------------------------------------------------+
  12. */
  13. /**
  14. * Event helper class
  15. **/
  16. define(['underscore'], function (_) {
  17. var _class, _temp;
  18. var EventUtils = (_temp = _class = function () {
  19. function EventUtils() {
  20. _classCallCheck(this, EventUtils);
  21. }
  22. // TODO QueryResultAPI: Remove after
  23. EventUtils.toDeprecatedPayload = function toDeprecatedPayload(value) {
  24. if (!value) {
  25. return value;
  26. }
  27. var useValue = value.value !== undefined ? value.value : value;
  28. var displayValue = value.label !== undefined ? value.label : useValue;
  29. var returnValue = {
  30. u: useValue,
  31. d: displayValue,
  32. value: useValue,
  33. label: displayValue
  34. };
  35. if (value.p !== undefined && value.p !== null) {
  36. returnValue.p = value.p;
  37. }
  38. return returnValue;
  39. };
  40. /**
  41. * Return keys for dataPoints.
  42. * @param datapoints Array of data points.
  43. */
  44. EventUtils.getDataPointKey = function getDataPointKey(dataPoint) {
  45. var key = '';
  46. var tempDataPoint = _.clone(dataPoint); //Make a copy to sort and keep dataPoint unchanged.
  47. var sortedDataPoint = tempDataPoint.sort(EventUtils.compareDataPointKey);
  48. _.each(sortedDataPoint, function (tuplePart) {
  49. var u = tuplePart.u || tuplePart;
  50. key += u + EventUtils.SEPARATOR;
  51. });
  52. return key.slice(0, -1);
  53. };
  54. EventUtils.compareDataPointKey = function compareDataPointKey(a, b) {
  55. if (a.u < b.u) {
  56. return -1;
  57. }
  58. if (a.u > b.u) {
  59. return 1;
  60. }
  61. return 0;
  62. };
  63. /**
  64. * Return keys for items (datapoint/edge).
  65. * @param tuples Array of data points or edge object
  66. */
  67. EventUtils.getItemKey = function getItemKey(tuple) {
  68. var key = void 0;
  69. if (Array.isArray(tuple)) {
  70. key = EventUtils.getDataPointKey(tuple);
  71. } else {
  72. key = tuple.u || tuple;
  73. }
  74. return key;
  75. };
  76. return EventUtils;
  77. }(), _class.SEPARATOR = '\xD7', _temp);
  78. return EventUtils;
  79. });
  80. //# sourceMappingURL=EventUtils.js.map