AbstractTupleLocator.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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. 2018, 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. define(['underscore'], function (_) {
  14. /**
  15. * Abstract class representing how to find data about tuple representations in
  16. * a visualization.
  17. */
  18. var AbstractTupleLocator = function () {
  19. function AbstractTupleLocator() {
  20. _classCallCheck(this, AbstractTupleLocator);
  21. }
  22. /**
  23. * @param {object} [filter] - a filter to limit results
  24. * @param {object} [filter.tuple] - a tuple filter - only results matching the provided tuple will be included
  25. * @param {boolean} [filter.isSelected] - set to `true` to only get selected items
  26. * @param {boolean} [filter.isHighlighted] - set to `true` to only get highlighted items
  27. * @param {object} [options]
  28. * @param {boolean} [options.includeInfo=false] - if `true`, each result will have an `info` section, containing members `key`, `type`, `tuple`, `tupleKeys`, `values`, `isSelected` and `isHighlighted`
  29. * @param {boolean} [options.includePoints=false] - if `true`, each result will have a `point` section, containing members `selectedNode`, `xOffset` and `yOffset`
  30. * @return {object[]} an array of objects, optionally containing `info` and `point` members per `options`
  31. */
  32. AbstractTupleLocator.prototype.findTupleVisualInfo = function findTupleVisualInfo() {
  33. throw new Error('Must be implemented by subclass');
  34. };
  35. /*
  36. * Determines whether an item satisfies a specified filter.
  37. * @param {object} options
  38. * @param {object} options.filter - in the same format as the one passed to findTupleVisualInfo
  39. * @param {object} options.item - the item provided by the VIPR API
  40. */
  41. AbstractTupleLocator.prototype._itemSatisfiesFilter = function _itemSatisfiesFilter(_ref) {
  42. var item = _ref.item,
  43. filter = _ref.filter;
  44. var valueInfo = this._getValueInfoFromItem(item);
  45. var itemHasFilterKey = function itemHasFilterKey(filterKey) {
  46. return !!valueInfo[filterKey];
  47. };
  48. var itemMatchesTuple = function itemMatchesTuple(filterTuple) {
  49. return filterTuple.length === valueInfo.tuple.length && _.difference(filterTuple, valueInfo.tuple).length === 0;
  50. };
  51. return Object.keys(filter || {}).every(function (filterKey) {
  52. return filterKey === 'tuple' ? itemMatchesTuple(_.isArray(filter.tuple) ? filter.tuple : [filter.tuple]) : itemHasFilterKey(filterKey);
  53. });
  54. };
  55. /*
  56. * Extracts useful information from the items provided by the VIPR API, in the format which should be returned by findTupleVisualInfo.
  57. * @param {object} item - item provided by the VIPR API
  58. */
  59. AbstractTupleLocator.prototype._getValueInfoFromItem = function _getValueInfoFromItem(item) {
  60. var valueInfo = { key: item.key, tuple: [], tupleKeys: [], values: [] };
  61. var addValueTuple = function addValueTuple(valueTuple) {
  62. if (valueTuple) {
  63. valueTuple.forEach(function (tuplePart) {
  64. valueInfo.tupleKeys.push(tuplePart.uniqueName || tuplePart.getUniqueName && tuplePart.getUniqueName());
  65. var rowCaption = tuplePart.source && tuplePart.source.getCaption ? tuplePart.source.getCaption() : '_notAvailable';
  66. valueInfo.tuple.push(rowCaption);
  67. });
  68. }
  69. };
  70. if (item.row) {
  71. valueInfo.type = 'datapoint';
  72. item.row.forEach(function (rowEntry) {
  73. if (rowEntry.value) {
  74. valueInfo.values.push(rowEntry.value);
  75. } else {
  76. addValueTuple(rowEntry.items);
  77. }
  78. });
  79. } else {
  80. valueInfo.type = 'axispoint';
  81. delete valueInfo.values; //axis entries don't have values.
  82. addValueTuple(item.items);
  83. }
  84. valueInfo.isSelected = !!(item.hasDecoration('selected') && item.getDecoration('selected'));
  85. valueInfo.isHighlighted = !!(item.hasDecoration('highlighted') && item.getDecoration('highlighted'));
  86. return valueInfo;
  87. };
  88. return AbstractTupleLocator;
  89. }();
  90. return AbstractTupleLocator;
  91. });
  92. //# sourceMappingURL=AbstractTupleLocator.js.map