RenderingInfo.js 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  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
  6. * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  7. */
  8. /**
  9. * @class RenderingInfo
  10. * @hideconstructor
  11. * @classdesc Widget Service Implementation class
  12. */
  13. define([], function () {
  14. var RenderingInfo = function () {
  15. function RenderingInfo(_ref) {
  16. var renderId = _ref.renderId;
  17. _classCallCheck(this, RenderingInfo);
  18. this._startTime = Date.now();
  19. this._withData = false;
  20. this._renderSequenceWithData = undefined;
  21. this._sequenceIds = [renderId];
  22. }
  23. /**
  24. * @public
  25. * @function getStartTime
  26. * @description get the start time of the render sequence
  27. * @returns {number} the start time in milliseconds
  28. */
  29. RenderingInfo.prototype.getStartTime = function getStartTime() {
  30. return this._startTime;
  31. };
  32. /**
  33. * @public
  34. * @function getEndTime
  35. * @description get the end time of the render sequence
  36. * @returns {number} the end time in milliseconds
  37. */
  38. RenderingInfo.prototype.getEndTime = function getEndTime() {
  39. return this._endTime;
  40. };
  41. /**
  42. * @public
  43. * @function setEndTime
  44. * @description set the end time of the render sequence
  45. * @param {number} endTime the end time of the render sequence
  46. */
  47. RenderingInfo.prototype.setEndTime = function setEndTime(endTime) {
  48. this._endTime = endTime;
  49. };
  50. /**
  51. * @public
  52. * @function setStartTime
  53. * @description set the start time of the render sequence
  54. * @param {number} startTime the start time of the render sequence
  55. */
  56. RenderingInfo.prototype.setStartTime = function setStartTime(startTime) {
  57. this._startTime = startTime;
  58. };
  59. /**
  60. * @public
  61. * @function getLastSequenceId
  62. * @description get the last sequence ID that was registered in RenderingInfo
  63. * @returns {number} the sequence ID of the last render recorded
  64. */
  65. RenderingInfo.prototype.getLastSequenceId = function getLastSequenceId() {
  66. return this._sequenceIds[this._sequenceIds.length - 1];
  67. };
  68. /**
  69. * @public
  70. * @function getDuration
  71. * @description returns the duration of the render sequence
  72. * @return {number} the duration in milliseconds
  73. */
  74. RenderingInfo.prototype.getDuration = function getDuration() {
  75. return this._endTime ? this._endTime - this._startTime : Date.now() - this._startTime;
  76. };
  77. /**
  78. * @public
  79. * @function setWithData
  80. * @description set whether or not the render is with data or not
  81. * @param {boolean} withData
  82. */
  83. RenderingInfo.prototype.setWithData = function setWithData(withData) {
  84. this._withData = withData;
  85. };
  86. /**
  87. * @public
  88. * @function isWithData
  89. * @description whether or not the render being recorded is with data
  90. * @return {boolean} whether or not the render is with data
  91. */
  92. RenderingInfo.prototype.isWithData = function isWithData() {
  93. return this._withData;
  94. };
  95. /**
  96. * @public
  97. * @function registerSequenceId
  98. * @description register the current sequence ID
  99. * @param {number} sequenceId
  100. */
  101. RenderingInfo.prototype.registerSequenceId = function registerSequenceId(sequenceId) {
  102. return this._sequenceIds.push(sequenceId);
  103. };
  104. /**
  105. * @public
  106. * @function getRenderSequenceWithData
  107. * @description get the information for the data query tracking
  108. * @return {RenderSequenceInfo} the object containing the data for the data query
  109. */
  110. RenderingInfo.prototype.getRenderSequenceWithData = function getRenderSequenceWithData() {
  111. return this._renderSequenceWithData;
  112. };
  113. /**
  114. * @public
  115. * @function setRenderSequenceWithData
  116. * @description set the object for the render data information
  117. * @param {RenderSequenceInfo} renderSequenceWithData the object containing the information about the data query
  118. */
  119. RenderingInfo.prototype.setRenderSequenceWithData = function setRenderSequenceWithData(renderSequenceWithData) {
  120. this._renderSequenceWithData = renderSequenceWithData;
  121. };
  122. /**
  123. * @public
  124. * @function getSequenceIds
  125. * @description get the list of sequence IDs
  126. * @return {number[]} the array for sequence IDs
  127. */
  128. RenderingInfo.prototype.getSequenceIds = function getSequenceIds() {
  129. return this._sequenceIds;
  130. };
  131. /**
  132. * @public
  133. * @function toJSON
  134. * @description get the render information in JSON form
  135. * @returns {Object} the JSON object with all the rendering time information
  136. */
  137. RenderingInfo.prototype.toJSON = function toJSON() {
  138. return {
  139. 'start time': this.getStartTime(),
  140. 'end time': this.getEndTime(),
  141. 'totalRenderingTime': this.getDuration(),
  142. 'sequenceIds': this.getSequenceIds(),
  143. 'sequenceWithData': this.getRenderSequenceWithData() ? this.getRenderSequenceWithData().toJSON() : {}
  144. };
  145. };
  146. return RenderingInfo;
  147. }();
  148. return RenderingInfo;
  149. });
  150. //# sourceMappingURL=RenderingInfo.js.map