123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583 |
- 'use strict';
- var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
- define([], function () {
- 'use strict';
-
- var FILTER_AGGREGATION_MAP = {
- sum: 'SUM'
- };
- var FILTER_PREPOST_MAP = {
- pre: 'PRE',
- post: 'POST',
- PRE: 'pre',
- POST: 'post'
- };
-
- var IRUtils = function () {
- function IRUtils() {
- _classCallCheck(this, IRUtils);
- }
-
- IRUtils.findDataItem = function findDataItem(spec, filter) {
- var targetDataViewIndex = -1;
- var targetDataViewItemIndex = -1;
- for (var dataViewIndex in spec.data.dataViews || []) {
- var viewItem = spec.data.dataViews[dataViewIndex];
- var dataItems = viewItem.dataItems || [];
- for (var dataViewItemIndex in dataItems) {
- if (filter(dataItems[dataViewItemIndex], dataViewItemIndex)) {
- targetDataViewIndex = dataViewIndex;
- targetDataViewItemIndex = dataViewItemIndex;
- }
- }
- }
- if (targetDataViewIndex === -1 || targetDataViewItemIndex === -1) {
-
- return;
- }
- return {
- viewIndex: targetDataViewIndex,
- viewItemIndex: targetDataViewItemIndex
- };
- };
- IRUtils.getColumnInfo = function getColumnInfo(currentColumnCombinations, visualization, itemId) {
- var columnEntry = currentColumnCombinations.find(function (combination) {
- return combination.itemId === itemId;
- });
- var isProjected = true;
- if (!columnEntry) {
- isProjected = false;
- var metadataColumn = visualization.getDataSource().getMetadataColumn(itemId);
- columnEntry = {
- id: metadataColumn.getId(),
- label: metadataColumn.getLabel()
- };
- }
- return _extends({}, columnEntry, {
- isProjected: isProjected
- });
- };
- IRUtils.IRAggregateType = function IRAggregateType(dashboardAggType) {
- return {
- sum: 'SUM',
- countdistinct: 'COUNT_DISTINCT',
- count: 'COUNT',
- avg: 'AVERAGE',
- min: 'MINIMUM',
- max: 'MAXIMUM'
- }[dashboardAggType];
- };
- IRUtils.fromIRAggregateType = function fromIRAggregateType(IRAggregateType) {
- return {
- SUM: 'sum',
- COUNT_DISTINCT: 'countdistinct',
- COUNT: 'count',
- AVERAGE: 'avg',
- MINIMUM: 'min',
- MAXIMUM: 'max'
- }[IRAggregateType];
- };
- IRUtils.IRTopBottomType = function IRTopBottomType(ty) {
- return ty === 'topcount' || ty === 'toppercent' ? 'TOP' : 'BOTTOM';
- };
- IRUtils.IRTopBottomMethod = function IRTopBottomMethod(ty) {
- return ty === 'bottompercent' || ty === 'toppercent' ? 'PERCENTAGE' : 'COUNT';
- };
- IRUtils.IRToTopBottomType = function IRToTopBottomType(ty, method) {
- var _ty = { BOTTOM: 'bottom', TOP: 'top' };
- var _suffix = { PERCENTAGE: 'percent', COUNT: 'count' };
- return _ty[ty] + _suffix[method];
- };
-
- IRUtils.localFilters2IRFilters = function localFilters2IRFilters(filters, filtersForRequest, visualization) {
- filters.forEach(function (filter) {
- var entry = {};
- entry.filterId = filter.id;
- entry.columnId = filter.columnId;
- entry.label = filter.binsLabel;
- if (!entry.label && visualization) {
- entry.label = visualization.getDataSource().getMetadataColumn(filter.columnId).getLabel();
- }
- if (filter.operator === 'in' || filter.operator === 'notin') {
- var inclusionValues = (filter.values || []).map(function (val) {
- return {
- uniqueValue: val.u,
- displayValue: val.d
- };
- });
- var exclusionValues = (filter.excludedValues || []).map(function (val) {
- return {
- uniqueValue: val.u,
- displayValue: val.d
- };
- });
- if (filter.conditions && (filter.conditions.or || filter.conditions.and)) {
-
-
- } else if (filter.conditions && filter.conditions.not) {
-
- } else if (!filter.conditions) {
- entry.type = 'INCLUSION_EXCLUSION';
- entry.inclusionValues = inclusionValues;
- entry.exclusionValues = exclusionValues;
- entry.invertFlag = filter.operator !== 'in';
- }
- } else if (filter.operator === 'between' || filter.operator === 'notbetween') {
- entry.lowValue = {
- value: filter.values[0].u,
- inclusive: false
- };
- entry.highValue = {
- value: filter.values[1].u,
- inclusive: false
- };
- entry.invertFlag = filter.operator === 'notbetween';
- entry.type = 'NUMERICRANGE';
- entry.filterAggregation = {
- aggregationType: FILTER_AGGREGATION_MAP[filter.aggregationType],
- preOrPostAggregation: FILTER_PREPOST_MAP[filter.preOrPost]
- };
- } else {
- entry.type = 'GENERIC';
- entry.expression = '';
- }
- if (entry.type) {
- filtersForRequest.push(entry);
- }
- });
- };
-
- IRUtils.topBottomToIRFilters = function topBottomToIRFilters(topBottom, filtersForRequest) {
- topBottom.forEach(function (tbEntry) {
- var entry = {};
- entry.filterId = tbEntry.id;
- entry.columnId = tbEntry.itemId;
- entry.topBottomType = IRUtils.IRTopBottomType(tbEntry.selection.topBottom.type);
- entry.method = IRUtils.IRTopBottomMethod(tbEntry.selection.topBottom.type);
- entry.domainSize = tbEntry.selection.topBottom.value;
- if (tbEntry.selection.context) {
- entry.byColumn = tbEntry.selection.context[0].itemId;
- }
- entry.type = 'TOP_BOTTOM';
- filtersForRequest.push(entry);
- });
- };
-
- IRUtils.IRFilters2TopBottom = function IRFilters2TopBottom(irFilter, widgetSpec, currentColumnCombinations, details, visualization) {
- if (details.reason === 'RECOMMEND_FILTER') {
- details.type = 'PART_TO_WHOLE';
- } else if (details.reason === 'INVERT_FILTER') {
- details.type = 'INVERT_FILTER_TOP_BOTTOM';
- }
- var dataItemRef = IRUtils.findDataItem(widgetSpec, function (dataItem) {
- return dataItem.id === irFilter.filterId;
- });
- var itemLabel = void 0;
- var selectionAggregate = void 0;
- if (dataItemRef) {
- var originalDataItem = widgetSpec.data.dataViews[dataItemRef.viewIndex].dataItems[dataItemRef.viewItemIndex];
- itemLabel = originalDataItem.itemLabel;
- var selection = originalDataItem.selection[0];
-
- if (selection && selection.context && selection.context[0] && selection.context[0].aggregate) {
- selectionAggregate = selection.context[0].aggregate;
- }
- } else {
- var columnIdParts = (irFilter.columnId || '').split('.');
- itemLabel = columnIdParts[columnIdParts.length - 1];
- }
- var dataItem = {};
- dataItem.id = irFilter.filterId;
- dataItem.itemId = irFilter.columnId;
- dataItem.itemLabel = itemLabel;
- var columnEntry = IRUtils.getColumnInfo(currentColumnCombinations, visualization, irFilter.columnId);
- details.column = columnEntry;
- var selectionItem = {
- operation: 'keep',
- topBottom: {
- type: IRUtils.IRToTopBottomType(irFilter.topBottomType, irFilter.method),
- value: irFilter.domainSize
- }
- };
- details.info = selectionItem.topBottom;
- if (irFilter.byColumn) {
- selectionItem.context = [{
- aggregate: selectionAggregate,
- itemId: irFilter.byColumn
- }];
- var byColumnEntry = IRUtils.getColumnInfo(currentColumnCombinations, visualization, irFilter.byColumn);
- details.byColumn = byColumnEntry;
- }
- dataItem.selection = [selectionItem];
- return dataItem;
- };
-
- IRUtils.IRFilters2LocalFilter = function IRFilters2LocalFilter(irFilter, widgetSpec) {
- var currentColumnCombinations = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
- var details = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
- var visualization = arguments[4];
- if (details.reason === 'INVERT_FILTER') {
- details.type = 'INVERT_FILTER_LOCAL';
- }
- var filter = {};
- filter.id = irFilter.filterId;
- filter.columnId = irFilter.columnId;
- var columnEntry = currentColumnCombinations.find(function (combination) {
- return combination.itemId === irFilter.columnId;
- });
- if (columnEntry) {
- details.column = {
- id: irFilter.columnId,
- label: columnEntry.label
- };
- } else if (visualization) {
- details.column = {
- id: irFilter.columnId,
- label: visualization.getDataSource().getMetadataColumn(irFilter.columnId).getLabel()
- };
- }
- if (irFilter.type === 'NUMERICRANGE') {
- if (irFilter.invertFlag) {
- filter.operator = 'notbetween';
- } else {
- filter.operator = 'between';
- }
- filter.values = [{
- d: irFilter.lowValue.value,
- u: irFilter.lowValue.value
- }, {
- d: irFilter.highValue.value,
- u: irFilter.highValue.value
- }];
-
- if (irFilter.filterAggregation) {
- filter.aggregationType = irFilter.filterAggregation.aggregationType;
- filter.preOrPost = FILTER_PREPOST_MAP[irFilter.filterAggregation.preOrPostAggregation];
- } else if (widgetSpec) {
- var localFilter = widgetSpec.localFilters.find(function (filter) {
- return filter.id === irFilter.filterId;
- });
- filter.aggregationType = localFilter.aggregationType;
- filter.preOrPost = localFilter.preOrPost;
- }
- } else if (irFilter.type === 'COMPOSITE') {
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- } else if (irFilter.type === 'INCLUSION_EXCLUSION' && !irFilter.filterCondition) {
- filter.columnId = irFilter.columnId;
- filter.id = irFilter.filterId;
- filter.operator = irFilter.invertFlag ? 'notin' : 'in';
- filter.values = (irFilter.inclusionValues || irFilter.values || []).map(function (value) {
- return {
- u: value.uniqueValue,
- d: value.displayValue
- };
- });
-
-
-
-
- filter.binsLabel = irFilter.label;
- } else if (irFilter.type === 'GENERIC') {
- filter.columnId = irFilter.columnId;
- filter.id = irFilter.filterId;
- }
- return filter;
- };
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- return IRUtils;
- }();
- return IRUtils;
- });
|