'use strict'; function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } /** * Licensed Materials - Property of IBM * IBM Cognos Products: BI Cloud (C) Copyright IBM Corp. 2018, 2021 * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp. * */ define(['underscore'], function (_) { var MAX_DECIMAL_PLACES = 2; var BinningActionsUtils = function () { function BinningActionsUtils() { _classCallCheck(this, BinningActionsUtils); } BinningActionsUtils.getBinningFilters = function getBinningFilters(localFilters, dataItem) { //@todo need clean up when completely hookup to using new API var binning = void 0; var binnedFilters = void 0; binning = dataItem.getBinning(); if (binning) { binnedFilters = localFilters.getFilterEntries(localFilters.getCategoryFilterKey(dataItem.getColumnId(), dataItem.getId())); } return binnedFilters; }; BinningActionsUtils.removeLocalBinnedFilterEntries = function removeLocalBinnedFilterEntries(localFilters, binnedFilters, options) { if (binnedFilters && binnedFilters.length && localFilters) { binnedFilters.forEach(function (binnedFilter) { localFilters.removeFilterEntry(binnedFilter); }); localFilters.allFilterModificationComplete(options); } }; /** * Clear compound filters for slot. * */ BinningActionsUtils.removeCompoundFilters = function removeCompoundFilters(slot, localFilters, options) { if (localFilters && localFilters.models) { var columnIdsInSlot = void 0; var dataItemAPIs = slot.getDataItemList(); columnIdsInSlot = dataItemAPIs ? _.map(dataItemAPIs, function (dataItem) { return dataItem.getColumnId(); }) : []; localFilters.clearCompoundFilters(columnIdsInSlot); localFilters.allFilterModificationComplete(options); } }; BinningActionsUtils.getBinningFilterForFormatedItem = function getBinningFilterForFormatedItem(formatSpec, localFilters, dataItem) { var format = dataItem.getFormat(); // So that we can support the new dataItem API as well if (format.formatSpec) { format = format.formatSpec; } var maximumFractionDigits = format && (format.maximumFractionDigits || format.maximumFractionDigits === 0) ? format.maximumFractionDigits : MAX_DECIMAL_PLACES; var binningFilters; if ((formatSpec.maximumFractionDigits || formatSpec.maximumFractionDigits === 0) && formatSpec.maximumFractionDigits !== maximumFractionDigits) { binningFilters = BinningActionsUtils.getBinningFilters(localFilters, dataItem); } return binningFilters; }; /** * Find the correct data item index * @param {Object} slot - slot api for slot we're checking against * @param {Integer} index - index of the data item we want to check, can be derived from slotState.mapIndex * @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 */ BinningActionsUtils.findDataItemIndex = function findDataItemIndex(slot, index) { // when this path is triggered from rclick on axis title, we get the wrong mapindex for the data item // 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 // works fine if its from data slots view, mapindex comes in defined and correct if (typeof index !== 'number' && slot.getDataItemList().length > 0) { var dataItemAPIs = slot.getDataItemList(); _.find(dataItemAPIs, function (dApi, idx) { if (dApi.getMetadataColumn().getType() === 'fact') { index = idx; return true; } }); } return index; }; /** * @param {Object} visAPI - API for current viz we want to check against * @param {Object} slot - slot api for slot we're checking against * @param {Object} dataItemAPI - dataItem API to check against * @return {Boolean} Returns true if autobinning is enabled on the viz (via vipr props), * 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)) */ BinningActionsUtils.isDataItemBinned = function isDataItemBinned(dataItemAPI) { return dataItemAPI.isBinned(); }; BinningActionsUtils.doesWidgetConfigSupportAutobinning = function doesWidgetConfigSupportAutobinning() { var config = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; return config.auto === true; }; return BinningActionsUtils; }(); return BinningActionsUtils; }); //# sourceMappingURL=BinningActionsUtils.js.map