Utils.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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
  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(['../../../apiHelpers/SlotAPIHelper', '../../../visualizations/recommender/IRUtils'], function (SlotAPIHelper, IRUtils) {
  14. 'use strict';
  15. return function () {
  16. function Utils() {
  17. _classCallCheck(this, Utils);
  18. }
  19. // translation of top bottom spec into IR. TODO: use a common utility
  20. Utils.translateTopBottom2IR = function translateTopBottom2IR(tbEntry) {
  21. var entry = {};
  22. entry.filterId = tbEntry.id;
  23. entry.columnId = tbEntry.itemId;
  24. entry.topBottomType = IRUtils.IRTopBottomType(tbEntry.selection.topBottom.type);
  25. entry.method = IRUtils.IRTopBottomMethod(tbEntry.selection.topBottom.type);
  26. entry.domainSize = tbEntry.selection.topBottom.value;
  27. if (tbEntry.selection.topBottom.context) {
  28. entry.byColumn = tbEntry.selection.topBottom.context.itemId;
  29. }
  30. entry.type = 'TOP_BOTTOM';
  31. return entry;
  32. };
  33. Utils.getTopBottomItems = function getTopBottomItems(visualization) {
  34. var mappedSlots = visualization.getSlots().getMappedSlotList();
  35. if (!mappedSlots || !mappedSlots.length) {
  36. return;
  37. }
  38. var topBottomItems = [];
  39. // ignore hidden slots which are not considered as part of mappings
  40. // e.g. 'rank' slot of grid, 'size' slot of scatter
  41. mappedSlots.filter(function (slot) {
  42. return slot && !slot.getDefinition().isHidden();
  43. }).forEach(function (mappedSlot) {
  44. var dataItemAPIs = Utils.filterInvalidDataItems(mappedSlot.getDataItemList());
  45. dataItemAPIs.forEach(function (dataItemAPI) {
  46. var topBottomSpec = dataItemAPI.getTopBottom();
  47. // Ignore all the non contextual top bottom modifiers
  48. // smarts only understand top bottom with context
  49. if (topBottomSpec && topBottomSpec.context) {
  50. var translatedSpec = Utils.translateTopBottom2IR({
  51. id: dataItemAPI.getId(),
  52. itemId: dataItemAPI.getColumnId(),
  53. selection: {
  54. topBottom: topBottomSpec
  55. }
  56. });
  57. topBottomItems.push(translatedSpec);
  58. }
  59. });
  60. });
  61. return topBottomItems;
  62. };
  63. Utils.getUnboundColumnsIds = function getUnboundColumnsIds(visualization) {
  64. return Utils.filterInvalidDataItems(visualization.getSlots().getDataItemList()).map(function (dataItem) {
  65. return dataItem.getColumnId();
  66. });
  67. };
  68. Utils.filterInvalidDataItems = function filterInvalidDataItems(list) {
  69. return list.filter(function (dataItem) {
  70. return !SlotAPIHelper.isMultiMeasuresSeriesOrValueDataItem(dataItem) && !dataItem.isColumnUnavailable();
  71. });
  72. };
  73. Utils.getFilterItems = function getFilterItems(visualization) {
  74. var result = [];
  75. IRUtils.localFilters2IRFilters(visualization.getLocalFilters().getFilterList(), result);
  76. return result;
  77. };
  78. return Utils;
  79. }();
  80. });
  81. //# sourceMappingURL=Utils.js.map