123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- 'use strict';
- /**
- * Licensed Materials - Property of IBM
- * IBM Cognos Products: BI Cloud (C) Copyright IBM Corp. 2018
- * 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', 'underscore'], function (Class, _) {
- 'use strict';
- var VisRecommenderBindingFallback = Class.extend({
- init: function init(visualization) {
- VisRecommenderBindingFallback.inherited('init', this, arguments);
- this.visualization = visualization;
- },
- destroy: function destroy() {
- VisRecommenderBindingFallback.inherited('destroy', this, arguments);
- },
- /*
- Assign each unassigned column to a slot based on the following priority. The highest ranking slot will be chosen:
- 1) empty required slot with the same type
- 2) empty slot with the same type
- 3) empty required slot with another types
- 4) empty slot
- If the above conditions are still not satisfied, repeat the steps but with a slot that is not empty but has capacity for another item(rank 5-8)
- If a slot does not meet this criteria, it means that there is no slot that has capacity and is ranked 9 and will remain unmapped.
- */
- assignUnboundColumns: function assignUnboundColumns(recommendation, slotDefinitions) {
- var _this = this;
- var unboundColumnIds = recommendation.unbound.slice(0);
- _.each(unboundColumnIds, function (column) {
- column = _this.visualization.getDataSource().getMetadataColumn(column);
- var rankSlots = _.map(slotDefinitions, function (slotDef) {
- return _this._rankSlot(slotDef, recommendation.slots, column);
- });
- var bestRank = Math.min.apply(Math, rankSlots);
- if (bestRank > 0 && bestRank < 9) {
- var index = _.indexOf(rankSlots, bestRank);
- var recommendedSlotId = slotDefinitions[index].getId();
- var columnId = column.getId();
- if (recommendation.slots[recommendedSlotId]) {
- recommendation.slots[recommendedSlotId].push(columnId);
- } else {
- recommendation.slots[recommendedSlotId] = [columnId];
- }
- recommendation.unbound.splice(_.indexOf(recommendation.unbound, columnId), 1);
- }
- });
- return recommendation;
- },
- /*
- Used in assignUnboundColumns method to rank a columns affinity to be placed into a slot based
- on the priorities defined above. Rank 1 is a perfect match. Rank 9 means it cant be matched.
- */
- _rankSlot: function _rankSlot(slot, recommendedSlots, column) {
- if (!recommendedSlots[slot.getId()]) {
- if (this._slotMatchesColumn(slot, column)) {
- return !slot.isOptional() ? 1 : 2;
- } else if (!slot.isOptional()) {
- return 3;
- }
- return 4;
- } else if (this._slotHasCapacity(slot, recommendedSlots)) {
- if (this._slotMatchesColumn(slot, column)) {
- return !slot.isOptional() ? 5 : 6;
- } else if (!slot.isOptional()) {
- return 7;
- }
- return 8;
- }
- return 9;
- },
- /*
- Depending on whether the slot can be stacked or not, there will be 2 measures for capacity: maxStackedItems and
- maxItems, respectively. If slot.maxStackItems is -1, it means there is no limit. If slot.maxItems does not exist
- then it means no limit.
- */
- _slotHasCapacity: function _slotHasCapacity(slot, recommendedSlots) {
- var id = slot.getId();
- var maxItems = slot.getMaxItems();
- if (maxItems && maxItems > -1) {
- return (recommendedSlots[id] ? recommendedSlots[id].length : 0) < maxItems;
- }
- return true;
- },
- _slotMatchesColumn: function _slotMatchesColumn(slot, column) {
- var slotType = slot.getType();
- var columnType = column.getType();
- if (slotType === 'any') {
- return true;
- } else if (slotType === 'ordinal' && columnType === 'fact' || slotType === 'category' && columnType === 'attribute') {
- return true;
- }
- return false;
- }
- });
- return VisRecommenderBindingFallback;
- });
- //# sourceMappingURL=VisRecommenderBindingFallback.js.map
|