KpiEventTarget.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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. *+------------------------------------------------------------------------+
  7. *| Licensed Materials - Property of IBM
  8. *| IBM Cognos Products: Dashboard
  9. *| (C) Copyright IBM Corp. 2019
  10. *|
  11. *| US Government Users Restricted Rights - Use, duplication or disclosure
  12. *| restricted by GSA ADP Schedule Contract with IBM Corp.
  13. *+------------------------------------------------------------------------+
  14. */
  15. define(['jquery', '../common/NonVIPREventTarget'], function ($, NonVIPREventTarget) {
  16. var BASE_SLOT_ID = 'actual';
  17. var TARGET_SLOT_ID = 'goal';
  18. var KpiEventTarget = function (_NonVIPREventTarget) {
  19. _inherits(KpiEventTarget, _NonVIPREventTarget);
  20. function KpiEventTarget() {
  21. var _ret;
  22. _classCallCheck(this, KpiEventTarget);
  23. for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
  24. args[_key] = arguments[_key];
  25. }
  26. var _this = _possibleConstructorReturn(this, _NonVIPREventTarget.call.apply(_NonVIPREventTarget, [this].concat(args)));
  27. var options = args[0] || {};
  28. _this.visControl = options.visControl;
  29. _this.view = options.view;
  30. _this.visualization = options.visualization;
  31. return _ret = _this.getAPI(), _possibleConstructorReturn(_this, _ret);
  32. }
  33. /**
  34. * Get the array of event targets based on the event.
  35. * Event target represents a data point object that corresponds to the event.
  36. *
  37. * @param event Event object
  38. */
  39. KpiEventTarget.prototype.getEventTargets = function getEventTargets(event) {
  40. var node = this._getTargetNode(event);
  41. if (!node || event.type === 'click') {
  42. return [];
  43. }
  44. var $node = $(node);
  45. //ignore the general widget
  46. if (!this.mouseWithinBoundCheck(event) || $node.hasClass('kpi-widget-content')) {
  47. return [];
  48. }
  49. return this._getTargets(event, $node);
  50. };
  51. KpiEventTarget.prototype.remove = function remove() {
  52. this.visControl = null;
  53. this.view = null;
  54. _NonVIPREventTarget.prototype.remove.call(this);
  55. };
  56. KpiEventTarget.prototype._getTargets = function _getTargets(event, $node) {
  57. var targets = [];
  58. var kpiNode$ = $($node.closest('.kpi-widget-value')[0]);
  59. // Possible the user clicked on the sparkline. If so ignore it.
  60. if (!kpiNode$.length) {
  61. return targets;
  62. }
  63. var selectionContext = this._getTargetSelectionContext(kpiNode$);
  64. if (selectionContext) {
  65. targets.push({
  66. key: $node.parent().attr('class'),
  67. type: 'datapoint',
  68. selectionContext: selectionContext,
  69. slotAPIs: selectionContext.slots,
  70. source: $node,
  71. isEdgeSelect: true,
  72. values: this._getTargetValues(kpiNode$),
  73. area: 'visualization'
  74. });
  75. }
  76. return targets;
  77. };
  78. KpiEventTarget.prototype._getTargetSelectionContext = function _getTargetSelectionContext($node) {
  79. var slot = void 0;
  80. var slots = this.visualization.getSlots();
  81. if ($node.hasClass('kpi-widget-base-value')) {
  82. slot = slots.getSlot(BASE_SLOT_ID);
  83. } else if ($node.hasClass('kpi-widget-target-value')) {
  84. slot = slots.getSlot(TARGET_SLOT_ID);
  85. //fix to disable event target for property set target value
  86. if (slot.getDataItemList().length === 0) {
  87. return null;
  88. }
  89. }
  90. return {
  91. mapIndex: 0,
  92. slots: [slot]
  93. };
  94. };
  95. KpiEventTarget.prototype._getTargetValues = function _getTargetValues($node) {
  96. var slots = [];
  97. var value = void 0;
  98. if ($node.hasClass('kpi-widget-base-value')) {
  99. value = this.view.getBaseValue();
  100. } else if ($node.hasClass('kpi-widget-target-value')) {
  101. value = this.view.getTargetValue();
  102. }
  103. if ($.isNumeric(value)) {
  104. slots.push([value]);
  105. }
  106. return slots;
  107. };
  108. return KpiEventTarget;
  109. }(NonVIPREventTarget);
  110. return KpiEventTarget;
  111. });
  112. //# sourceMappingURL=KpiEventTarget.js.map