123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134 |
- '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 Business Analytics (C) Copyright IBM Corp. 2018, 2020
- * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
- */
- define(['../../../../lib/@waca/dashboard-common/dist/core/APIFactory', '../../../../widgets/livewidget/nls/StringResources', '../api/SlotActionsProviderAPI', '../../../../apiHelpers/SlotAPIHelper'], function (APIFactory, stringResources, SlotActionsProviderAPI, SlotAPIHelper) {
- var BinAction = function () {
- function BinAction(_ref) {
- var content = _ref.content,
- dashboardAPI = _ref.dashboardAPI,
- features = _ref.features;
- _classCallCheck(this, BinAction);
- this.content = content;
- this.dashboard = dashboardAPI;
- this.icons = features && features['Dashboard.Icons'];
- this.content.getFeature('SlotActions').registerProvider('autoBinAction', this.getAPI());
- }
- BinAction.prototype.getAPI = function getAPI() {
- if (!this.api) {
- this.api = APIFactory.createAPI(this, [SlotActionsProviderAPI]);
- }
- return this.api;
- };
- BinAction.prototype._isOlap = function _isOlap(dataSource, dataItem) {
- return !!(dataSource.isOlapPackage() || dataItem && dataItem.getMetadataColumn().isOlapColumn());
- };
- BinAction.prototype._supportAction = function _supportAction(slot, itemIndex) {
- // Olap sources are unsupported, for now.
- var visualization = this.content.getFeature('Visualization');
- var dataSource = visualization.getDataSource();
- var dataItem = slot.getDataItemList()[itemIndex];
- var isOlap = this._isOlap(dataSource, dataItem);
- var unsupportedSource = !dataSource || isOlap;
- var definition = visualization.getDefinition();
- return itemIndex !== undefined && definition && definition.getProperty('canApplyBinning') && !unsupportedSource && !(SlotAPIHelper.isMultiMeasuresSeriesSlot(slot) || SlotAPIHelper.isMultiMeasuresValueSlot(slot)) && SlotAPIHelper.doesDataItemSupportBinning(slot, dataItem);
- };
- BinAction.prototype._getViewState = function _getViewState(slot, itemIndex) {
- var definition = this.content.getFeature('Visualization').getDefinition();
- if (slot) {
- // @todo get slot from visualizationAPI and use new SLOTAPI
- var dataItem = slot.getDataItemList()[itemIndex];
- if (dataItem) {
- var viewState = {
- height: 280,
- width: 400, // those are hints only; for the placement of the toolbar.,
- defaultNumberOfBins: definition.getProperty('binningConfig').defaultNumberOfBins,
- binningStateCb: dataItem.getBinning.bind(dataItem)
- };
- return viewState;
- }
- }
- return null;
- };
- /**
- * Find the correct data item index
- * @param {Object} slot - slot api for slot we're checking against
- * @return {Integer || undefined} Returns the index of the first data item in this slot that has the appropriate type for autobinning or undefined if none is found
- */
- BinAction.prototype._findDataItemIndex = function _findDataItemIndex(slot) {
- var index = void 0;
- // 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 (slot.getDataItemList().length > 0) {
- var dataItems = slot.getDataItemList();
- dataItems.find(function (dataItem, idx) {
- var metaDataColumn = dataItem.getMetadataColumn();
- if (metaDataColumn && metaDataColumn.getType() === 'fact') {
- index = idx;
- return true;
- }
- });
- }
- return index;
- };
- BinAction.prototype.getSlotActionList = function getSlotActionList(slotId, itemIndex) {
- var visualization = this.content.getFeature('Visualization');
- var slot = visualization.getSlots().getSlot(slotId);
- if (itemIndex === null || itemIndex === undefined) {
- itemIndex = this._findDataItemIndex(slot);
- }
- if (slot && this._supportAction(slot, itemIndex)) {
- var viewOptions = this._getViewState(slot, itemIndex);
- var autoBinIcon = this.icons.getIcon('dashboard-autobin');
- return [{
- name: 'autoBinAction',
- label: stringResources.get('autoBinActionText'),
- icon: autoBinIcon.id,
- type: 'NextView',
- view: {
- module: 'dashboard-analytics/dialogs/AutobinDialog',
- state: viewOptions
- },
- actions: {
- apply: this._applyBinning.bind(this, slot, itemIndex)
- }
- }];
- }
- return [];
- };
- BinAction.prototype._applyBinning = function _applyBinning(slot, itemIndex, binningState) {
- var dataItem = slot.getDataItemList()[itemIndex];
- if (binningState) {
- dataItem.setBinning({
- bins: binningState.numberOfBins
- });
- } else {
- dataItem.setBinning(null);
- }
- };
- return BinAction;
- }();
- return BinAction;
- });
- //# sourceMappingURL=BinAction.js.map
|