'use strict'; /** * Licensed Materials - Property of IBM * IBM Cognos Products: BI Cloud (C) Copyright IBM Corp. 2017 * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp. * */ define(['../../lib/@waca/core-client/js/core-client/ui/core/Class'], function (Class) { 'use strict'; /* * This class manages the slots mapping for Legacy Map (com.ibm.vis.rave2polygonmap) */ var LegacyMapMappingManager = Class.extend({ init: function init(visualization) { this.visualization = visualization; this.unmappedColumns = null; }, /** * Get column type, if categorySubType is 'location', use this * @param column * @return type or categorySubType */ _getColumnType: function _getColumnType(column) { var taxonomy = column.getTaxonomyList() ? column.getTaxonomyList()[0] : null; return taxonomy && taxonomy.getClass() === 'cGeoLocation' ? 'location' : column.getType(); }, _getSlotTypeForColumn: function _getSlotTypeForColumn(column) { var columnTypeToSlotTypeMap = { 'fact': 'ordinal', 'attribute': 'category', 'location': 'location' }; return columnTypeToSlotTypeMap[this._getColumnType(column)]; }, //Set the slots' mapping info in the given map _setExistingMappingInfo: function _setExistingMappingInfo(slotIdToColumnMap) { this.visualization.getSlots().getMappingInfoList().forEach(function (mapping) { slotIdToColumnMap[mapping.slot.getId()] = [mapping.dataItem.getColumnId()]; }); }, /** * Map the given unmappedColumns to slots. * Returns an array of columns, sorted in the order of corresponding mapped slots as defined in the visDefinition */ mapColumnsToSlots: function mapColumnsToSlots(visDefinition, unmappedColumns, bKeepExistingMapping) { var slotIdToColumnMap = {}; if (bKeepExistingMapping) { this._setExistingMappingInfo(slotIdToColumnMap); } var unmappedSlotDefs = visDefinition.getSlotList().filter(function (slotDef) { return !slotDef.getProperty('multiplier') && !slotIdToColumnMap[slotDef.getId()]; }); for (var i = 0; i < unmappedSlotDefs.length; i++) { var slotDef = unmappedSlotDefs[i]; var slotId = slotDef.getId(); if (!unmappedColumns.length) { break; } var column = this._findBestMatchingColumnForSlot(slotDef, unmappedColumns); slotIdToColumnMap[slotId] = [column.getId()]; unmappedColumns = unmappedColumns.filter(function (unmappedColumn) { return unmappedColumn.getId() !== column.getId(); }); } this.unmappedColumns = unmappedColumns; //return an array of unmappedColumns array in the same order as the slot definitions found in visDefinition return slotIdToColumnMap; }, getUnmappedColumns: function getUnmappedColumns() { if (this.unmappedColumns.length) { return this.unmappedColumns; } }, _findBestMatchingColumnForSlot: function _findBestMatchingColumnForSlot(slotDef, unmappedColumns) { var _this = this; var found; if (unmappedColumns.length === 0) { return; } //Assign location column first if (slotDef.getSubType() === 'location') { found = unmappedColumns.find(function (column) { return _this._getColumnType(column) === 'location'; }); if (found) { return found; } } //If no location, assign column of same type var type = slotDef.getType(); found = unmappedColumns.find(function (column) { return this._getSlotTypeForColumn(column) === type; }.bind(this)); if (found) { return found; } //Otherwise, use next unmapped column return unmappedColumns[0]; } }); return LegacyMapMappingManager; }); //# sourceMappingURL=LegacyMapMappingManager.js.map