'use strict'; function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } /** * Licensed Materials - Property of IBM * IBM Business Analytics (C) Copyright IBM Corp. 2019, 2020 * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp. */ define(['underscore', './VIPRDecoratable', './VIPRItemClass', './VIPRFormatter'], function (_, VIPRDecoratable, VIPRItemClass, VIPRFormatter) { // implements IContDataItem var VIPRContDataItem = function (_VIPRDecoratable) { _inherits(VIPRContDataItem, _VIPRDecoratable); function VIPRContDataItem(resultItem, context, content) { _classCallCheck(this, VIPRContDataItem); var _this = _possibleConstructorReturn(this, _VIPRDecoratable.apply(this, arguments)); _this.context = context; _this.queryResult = context && context.queryResult; _this.content = content; // Ordinal slots normally does not take multiple dataitems (ie. stacked) // even for multi-measures case (ie. bar, column) the multiple ordinal dataitems are merged in to a single ordinal measure // and each measures are separated as series. // So at the end, from the VIPRData perspective a numeric dataitem (aka slot), has only one measure. _this.formatter = new VIPRFormatter(_this.context.index.dataitem, 0, _this.context); //getTupleHeaders() return the array of itemClass, each Item Class contains an array of Tuple headers _this.itemClass = new VIPRItemClass(resultItem.getDataItemList()[0], _this.context); _this.domain = _this._createDomain(); // Min Max Data Item domain return _this; } /* * Format data from min/max query */ VIPRContDataItem.prototype._getMinMaxData = function _getMinMaxData(minmaxResult) { var resultItems = minmaxResult.getResultItemList(); var data = []; for (var index = 0; index + 1 < resultItems.length; index += 2) { var resultDataItem = resultItems[index]; var dataItem = resultDataItem.getDataItemList()[0]; var min = minmaxResult.getValue(0, index).value; var max = minmaxResult.getValue(0, index + 1).value; data.push({ min: min, max: max, columnId: dataItem.getColumnId(), aggregation: dataItem.getAggregation(), explicit: this._explicitMinMax(min, max) }); } return data; }; VIPRContDataItem.prototype._explicitMinMax = function _explicitMinMax(min, max) { //TODO: Revisit the domain.explicit setting post R7 //refer: EXPLORE-2277 EXPLORE-2692 var visualization = this.content && this.content.getFeature('Visualization'); return visualization && visualization.getType() === 'Tiledmap' && min !== undefined && min !== null && max !== undefined && max !== null; }; /* * Create a domain incorporating min/max from all measures */ VIPRContDataItem.prototype._createMultiMeasureDomain = function _createMultiMeasureDomain(minmaxResult) { var overAllMin = void 0; var overAllMax = void 0; var overAllExplicit = void 0; var minmaxData = this._getMinMaxData(minmaxResult); minmaxData.forEach(function (_ref) { var min = _ref.min, max = _ref.max, explicit = _ref.explicit; overAllMin = overAllMin !== undefined ? Math.min(overAllMin, min) : min; overAllMax = overAllMax !== undefined ? Math.max(overAllMax, max) : max; overAllExplicit = explicit; }); return { min: overAllMin, max: overAllMax, explicit: overAllExplicit }; }; /* * Create a domain only incorporating min/max for own data item */ VIPRContDataItem.prototype._createNonMultiMeasureDomain = function _createNonMultiMeasureDomain(minmaxResult) { var minmaxData = this._getMinMaxData(minmaxResult); var columnId = this.itemClass.dataItem.getColumnId(); var aggregation = this.itemClass.dataItem.getAggregation(); var minmax = minmaxData.find(function (minmax) { return minmax.columnId === columnId && minmax.aggregation === aggregation; }); if (minmax) { return { min: minmax.min, max: minmax.max, explicit: minmax.explicit }; } else { return null; } }; /** * @returns the domain (min/max) for the data item */ VIPRContDataItem.prototype._createDomain = function _createDomain() { var domain = null; var minmaxResult = this.context.minmaxResult; if (minmaxResult) { if (this.itemClass.getUniqueName() === '_multiMeasuresValue') { domain = this._createMultiMeasureDomain(minmaxResult); } else { domain = this._createNonMultiMeasureDomain(minmaxResult); } } return domain; }; VIPRContDataItem.prototype.getUniqueName = function getUniqueName() { return this.itemClass.getUniqueName(); }; VIPRContDataItem.prototype.getCaption = function getCaption() { return this.itemClass.getCaption(); }; VIPRContDataItem.prototype.getType = function getType() { return 'cont'; }; VIPRContDataItem.prototype.getDomain = function getDomain() /*aggregation TODO for stacked charts*/{ return this.domain; }; VIPRContDataItem.prototype.getFormatter = function getFormatter() { return this.formatter; }; VIPRContDataItem.prototype.getItemClass = function getItemClass() { return this.itemClass; }; return VIPRContDataItem; }(VIPRDecoratable); return VIPRContDataItem; }); //# sourceMappingURL=VIPRContDataItem.js.map