'use strict'; /** * Licensed Materials - Property of IBM * IBM Cognos Products: BI Cloud (C) Copyright IBM Corp. 2017, 2018 * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp. */ define(['underscore', '../../lib/@waca/core-client/js/core-client/ui/core/Class'], function (_, Class) { 'use strict'; var VisSelectionInfo = Class.extend({ init: function init() { this._aOrdinalSelections = []; this._aCategorySelections = []; this._slotToCategoryCount = {}; }, getCategorySelections: function getCategorySelections() { return this._aCategorySelections; }, getOrdinalSelections: function getOrdinalSelections() { return this._aAdditionalOrdinalSelections ? this._aOrdinalSelections.concat(this._aAdditionalOrdinalSelections) : this._aOrdinalSelections; }, _createSelectionObject: function _createSelectionObject(slot, slotDataItem, value, isEdgeSelection) { return { 'slot': slot, 'slotDataItem': slotDataItem, 'value': value, // TODO should use the same name tag 'isEdgeSelect' as event target classes 'isEdgeSelection': isEdgeSelection || this._isEdgeSelection(slot) }; }, addSelection: function addSelection(slot, slotDataItem, value, isEdgeSelection) { var slotType = slotDataItem.getType(); if (!this._ordinalSelectionAdded(slot, slotDataItem, slotType)) { this[slotType === 'fact' ? '_aOrdinalSelections' : '_aCategorySelections'].push(this._createSelectionObject(slot, slotDataItem, value, isEdgeSelection)); this._registerCategoryCount(slotType, slot, slotDataItem); } else if (slotType === 'fact') { //In the case of 'multiTuple' (lasso select), we want to capture all of the values of the ordinals not just one. this._aAdditionalOrdinalSelections = this._aAdditionalOrdinalSelections || []; this._aAdditionalOrdinalSelections.push(this._createSelectionObject(slot, slotDataItem, value, isEdgeSelection)); } }, _isEdgeSelection: function _isEdgeSelection(slot) { return slot.getDefinition() && slot.getDefinition().treatOrdinalAsCategory ? slot.getDefinition().treatOrdinalAsCategory : false; }, /** * Special handling for stacked dataItems on chart edges. * For nested dataPoints (stacked items) VIPR returns a list of selection entries pairing the same measure values * with each entry in the stacked item. We only want it in selection info if it hasn't already been added. * items: [ * {values: ['web', $5000], * {values: [{camping, $5000] * ] */ _ordinalSelectionAdded: function _ordinalSelectionAdded(slot, slotDataItem, slotType) { var ordinalSelectionFound = false; if (slotType === 'fact') { ordinalSelectionFound = _.find(this._aOrdinalSelections, function (ordinalSelection) { return ordinalSelection.slot.getId() === slot.getId() && ordinalSelection.slotDataItem.getId() === slotDataItem.getId(); }) ? true : false; } return ordinalSelectionFound; }, _registerCategoryCount: function _registerCategoryCount(slotType, slot, slotDataItem) { if (slotType !== 'fact') { var countEntry = this._slotToCategoryCount[slot.getId()] || { count: 0, dataItems: [] }; if (countEntry.dataItems.indexOf(slotDataItem.getId()) === -1) { countEntry.count += 1; countEntry.dataItems.push(slotDataItem.getId()); this._slotToCategoryCount[slot.getId()] = countEntry; } } }, getCategorySetSize: function getCategorySetSize() { var size = 0; var categoryCount = _.reduce(this._slotToCategoryCount, function (totalCat, slot) { return totalCat + slot.count; }, 0); if (this._aCategorySelections.length) { size = this._aCategorySelections.length / categoryCount; } return size; } }); return VisSelectionInfo; }); //# sourceMappingURL=VisSelectionInfo.js.map