SelectorTupleLocator.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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. 2018, 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(['underscore', './AbstractTupleLocator'], function (_, AbstractTupleLocator) {
  16. var SelectorTupleLocator = function (_AbstractTupleLocator) {
  17. _inherits(SelectorTupleLocator, _AbstractTupleLocator);
  18. /**
  19. * A tuple locator which tries points based on elements found by a CSS
  20. * selector. This is not the most robust approach, use it only as needed.
  21. */
  22. function SelectorTupleLocator(_ref) {
  23. var $el = _ref.$el,
  24. selector = _ref.selector,
  25. viprWidget = _ref.viprWidget;
  26. _classCallCheck(this, SelectorTupleLocator);
  27. var _this = _possibleConstructorReturn(this, _AbstractTupleLocator.call(this));
  28. _this.$el = $el;
  29. _this.selector = selector;
  30. _this.viprWidget = viprWidget;
  31. return _this;
  32. }
  33. SelectorTupleLocator.prototype.findTupleVisualInfo = function findTupleVisualInfo(filter, _ref2) {
  34. var _this2 = this;
  35. var includeInfo = _ref2.includeInfo,
  36. includePoints = _ref2.includePoints;
  37. //Query selector to get elements, and thus candidate points
  38. var matches = this.$el.find(this.selector).toArray().map(function (e) {
  39. return _this2._getPoint(e);
  40. }).map(function (point) {
  41. return _this2._getItemsAtCenterOfElement(point).map(function (item) {
  42. //Get info from item
  43. var info = _this2._getValueInfoFromItem(item);
  44. //Filter items according to specified filter
  45. if (_this2._itemSatisfiesFilter({ item: item, filter: filter })) {
  46. var result = {};
  47. if (includeInfo) {
  48. result.info = info;
  49. }
  50. if (includePoints) {
  51. result.point = point;
  52. }
  53. return result;
  54. }
  55. }).filter(function (result) {
  56. return !!result;
  57. });
  58. });
  59. return _.flatten(matches);
  60. };
  61. SelectorTupleLocator.prototype._getPoint = function _getPoint(e) {
  62. var _e$getBoundingClientR = e.getBoundingClientRect(),
  63. left = _e$getBoundingClientR.left,
  64. top = _e$getBoundingClientR.top,
  65. width = _e$getBoundingClientR.width,
  66. height = _e$getBoundingClientR.height;
  67. return {
  68. selectedNode: e,
  69. left: left,
  70. top: top,
  71. xOffset: width / 2,
  72. yOffset: height / 2
  73. };
  74. };
  75. SelectorTupleLocator.prototype._getItemsAtCenterOfElement = function _getItemsAtCenterOfElement(_ref3) {
  76. var left = _ref3.left,
  77. top = _ref3.top,
  78. xOffset = _ref3.xOffset,
  79. yOffset = _ref3.yOffset;
  80. var coord = this.viprWidget.getVisCoordinate(left + xOffset, top + yOffset);
  81. return this.viprWidget.getItemsAtPoint(coord);
  82. };
  83. return SelectorTupleLocator;
  84. }(AbstractTupleLocator);
  85. return SelectorTupleLocator;
  86. });
  87. //# sourceMappingURL=SelectorTupleLocator.js.map