BinningActionsUtils.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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 Cognos Products: BI Cloud (C) Copyright IBM Corp. 2018, 2021
  6. * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  7. *
  8. */
  9. define(['underscore'], function (_) {
  10. var MAX_DECIMAL_PLACES = 2;
  11. var BinningActionsUtils = function () {
  12. function BinningActionsUtils() {
  13. _classCallCheck(this, BinningActionsUtils);
  14. }
  15. BinningActionsUtils.getBinningFilters = function getBinningFilters(localFilters, dataItem) {
  16. //@todo need clean up when completely hookup to using new API
  17. var binning = void 0;
  18. var binnedFilters = void 0;
  19. binning = dataItem.getBinning();
  20. if (binning) {
  21. binnedFilters = localFilters.getFilterEntries(localFilters.getCategoryFilterKey(dataItem.getColumnId(), dataItem.getId()));
  22. }
  23. return binnedFilters;
  24. };
  25. BinningActionsUtils.removeLocalBinnedFilterEntries = function removeLocalBinnedFilterEntries(localFilters, binnedFilters, options) {
  26. if (binnedFilters && binnedFilters.length && localFilters) {
  27. binnedFilters.forEach(function (binnedFilter) {
  28. localFilters.removeFilterEntry(binnedFilter);
  29. });
  30. localFilters.allFilterModificationComplete(options);
  31. }
  32. };
  33. /**
  34. * Clear compound filters for slot.
  35. *
  36. */
  37. BinningActionsUtils.removeCompoundFilters = function removeCompoundFilters(slot, localFilters, options) {
  38. if (localFilters && localFilters.models) {
  39. var columnIdsInSlot = void 0;
  40. var dataItemAPIs = slot.getDataItemList();
  41. columnIdsInSlot = dataItemAPIs ? _.map(dataItemAPIs, function (dataItem) {
  42. return dataItem.getColumnId();
  43. }) : [];
  44. localFilters.clearCompoundFilters(columnIdsInSlot);
  45. localFilters.allFilterModificationComplete(options);
  46. }
  47. };
  48. BinningActionsUtils.getBinningFilterForFormatedItem = function getBinningFilterForFormatedItem(formatSpec, localFilters, dataItem) {
  49. var format = dataItem.getFormat();
  50. // So that we can support the new dataItem API as well
  51. if (format.formatSpec) {
  52. format = format.formatSpec;
  53. }
  54. var maximumFractionDigits = format && (format.maximumFractionDigits || format.maximumFractionDigits === 0) ? format.maximumFractionDigits : MAX_DECIMAL_PLACES;
  55. var binningFilters;
  56. if ((formatSpec.maximumFractionDigits || formatSpec.maximumFractionDigits === 0) && formatSpec.maximumFractionDigits !== maximumFractionDigits) {
  57. binningFilters = BinningActionsUtils.getBinningFilters(localFilters, dataItem);
  58. }
  59. return binningFilters;
  60. };
  61. /**
  62. * Find the correct data item index
  63. * @param {Object} slot - slot api for slot we're checking against
  64. * @param {Integer} index - index of the data item we want to check, can be derived from slotState.mapIndex
  65. * @return {Integer || Null} Returns the index of the first data item in this slot that has the appropriate type for autobinning or null if none is found
  66. */
  67. BinningActionsUtils.findDataItemIndex = function findDataItemIndex(slot, index) {
  68. // when this path is triggered from rclick on axis title, we get the wrong mapindex for the data item
  69. // index is null but we have data items, maybe 1st dataitem isnt the right one which is the behaviour we saw by letting the incorrect index propagate forward
  70. // works fine if its from data slots view, mapindex comes in defined and correct
  71. if (typeof index !== 'number' && slot.getDataItemList().length > 0) {
  72. var dataItemAPIs = slot.getDataItemList();
  73. _.find(dataItemAPIs, function (dApi, idx) {
  74. if (dApi.getMetadataColumn().getType() === 'fact') {
  75. index = idx;
  76. return true;
  77. }
  78. });
  79. }
  80. return index;
  81. };
  82. /**
  83. * @param {Object} visAPI - API for current viz we want to check against
  84. * @param {Object} slot - slot api for slot we're checking against
  85. * @param {Object} dataItemAPI - dataItem API to check against
  86. * @return {Boolean} Returns true if autobinning is enabled on the viz (via vipr props),
  87. * and there's autobinning on the slot with context and (the slot has a context binning data item or the dataitemAPI contains the autobinning api(in case of other types of data))
  88. */
  89. BinningActionsUtils.isDataItemBinned = function isDataItemBinned(dataItemAPI) {
  90. return dataItemAPI.isBinned();
  91. };
  92. BinningActionsUtils.doesWidgetConfigSupportAutobinning = function doesWidgetConfigSupportAutobinning() {
  93. var config = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  94. return config.auto === true;
  95. };
  96. return BinningActionsUtils;
  97. }();
  98. return BinningActionsUtils;
  99. });
  100. //# sourceMappingURL=BinningActionsUtils.js.map