@gooddata/react-components
Version:
GoodData.UI - A powerful JavaScript library for building analytical applications
80 lines • 3.48 kB
JavaScript
;
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
Object.defineProperty(exports, "__esModule", { value: true });
// (C) 2007-2020 GoodData Corporation
var isArray = require("lodash/isArray");
var get = require("lodash/get");
var constants_1 = require("../../components/visualizations/chart/constants");
var utils_1 = require("../utils");
function getViewByTwoAttributes(viewBy) {
if (!viewBy) {
return [];
}
if (viewBy && isArray(viewBy)) {
// only get first two attributes
return viewBy.slice(0, constants_1.VIEW_BY_ATTRIBUTES_LIMIT);
}
return [viewBy];
}
exports.getViewByTwoAttributes = getViewByTwoAttributes;
/**
* multiple measures => ignore computeRatio
*/
function sanitizeComputeRatioOnMeasures(measures, forceDisableComputeRatio) {
if (measures === void 0) { measures = []; }
if (forceDisableComputeRatio === void 0) { forceDisableComputeRatio = false; }
var nonEmptyMeasures = measures || [];
if (nonEmptyMeasures.length > 1 || forceDisableComputeRatio) {
return nonEmptyMeasures.map(utils_1.disableBucketItemComputeRatio);
}
return nonEmptyMeasures;
}
exports.sanitizeComputeRatioOnMeasures = sanitizeComputeRatioOnMeasures;
/**
* Show a measure as a percentage
* one measure
* => computeRatio = false or not set => evaluate stackMeasuresToPercent
* stackMeasures is applied only when there are [2 measures and more]
* stackMeasuresToPercent is applied only when there are [1 measure + 1 stackBy] or [2 measures and more]
*/
function sanitizeConfig(measures, config) {
if (measures === void 0) { measures = []; }
if (config === void 0) { config = {}; }
if (measures.length === 1) {
var isComputeRatio = utils_1.getComputeRatio(measures[0]);
var stackMeasures = config.stackMeasures, stackMeasuresToPercent = config.stackMeasuresToPercent;
return __assign({}, config, { stackMeasures: stackMeasures && !isComputeRatio, stackMeasuresToPercent: stackMeasuresToPercent && !isComputeRatio });
}
return config;
}
exports.sanitizeConfig = sanitizeConfig;
/**
* Show a measure as a percentage
* one measure
* => computeRatio = false or not set => evaluate stackMeasuresToPercent
* multiple measures
* => ignore computeRatio and use stackMeasuresToPercent
*
* stackMeasures is applied only when there are [2 measures and more]
* stackMeasuresToPercent is applied only when there are [1 measure + 1 stackBy] or [2 measures and up]
*/
function getSanitizedStackingConfigFromAfm(afm, chartConfig) {
if (get(afm, ["measures", "length"]) === 1) {
var stackMeasures = chartConfig.stackMeasures, stackMeasuresToPercent = chartConfig.stackMeasuresToPercent;
var isComputeRatio = get(afm, ["measures", "0", "definition", "measure", "computeRatio"], false);
return __assign({}, chartConfig, { stackMeasures: stackMeasures && !isComputeRatio, stackMeasuresToPercent: stackMeasuresToPercent && !isComputeRatio });
}
return chartConfig;
}
exports.getSanitizedStackingConfigFromAfm = getSanitizedStackingConfigFromAfm;
//# sourceMappingURL=common.js.map