@gooddata/react-components
Version:
GoodData.UI - A powerful JavaScript library for building analytical applications
156 lines • 7.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) 2019-2020 GoodData Corporation
var get = require("lodash/get");
var has = require("lodash/has");
var set = require("lodash/set");
var keys = require("lodash/keys");
var isEmpty = require("lodash/isEmpty");
var cloneDeep = require("lodash/cloneDeep");
var BucketNames = require("../../constants/bucketNames");
var axis_1 = require("../constants/axis");
var bucketHelper_1 = require("./bucketHelper");
var bucket_1 = require("../constants/bucket");
var properties_1 = require("../constants/properties");
var uiConfig_1 = require("../constants/uiConfig");
var supportedProperties_1 = require("../constants/supportedProperties");
function getSupportedPropertiesControls(visualizationControlsProperties, supportedPropertiesList) {
var clonedControls = cloneDeep(visualizationControlsProperties);
if (supportedPropertiesList) {
return supportedPropertiesList.reduce(function (props, current) {
return has(clonedControls, current) ? set(props, current, get(clonedControls, current)) : props;
}, {});
}
return {};
}
exports.getSupportedPropertiesControls = getSupportedPropertiesControls;
function hasColorMapping(properties) {
return !!get(properties, ["controls", "colorMapping"]);
}
exports.hasColorMapping = hasColorMapping;
function setSecondaryMeasures(referencePoint, axisName) {
var _a;
if (!axisName) {
return referencePoint;
}
var newReferencePoint = cloneDeep(referencePoint);
var path = properties_1.PROPERTY_CONTROLS + "." + axisName;
var secondaryAxisProperties = get(newReferencePoint, path);
var buckets = get(newReferencePoint, bucket_1.BUCKETS, []);
var allMeasures = bucketHelper_1.getMeasureItems(buckets);
var secondaryMeasures = bucketHelper_1.getAllMeasuresShowOnSecondaryAxis(buckets);
if (!secondaryAxisProperties && !secondaryMeasures.length) {
return referencePoint;
}
var secondaryAxis = __assign({}, secondaryAxisProperties, { measures: bucketHelper_1.getItemsLocalIdentifiers(secondaryMeasures) });
var axis = (_a = {
0: axis_1.AXIS.PRIMARY
},
_a[allMeasures.length] = axis_1.AXIS.SECONDARY,
_a)[secondaryMeasures.length] || axis_1.AXIS.DUAL;
set(newReferencePoint, path, secondaryAxis);
set(newReferencePoint, uiConfig_1.UICONFIG_AXIS, axis);
return newReferencePoint;
}
exports.setSecondaryMeasures = setSecondaryMeasures;
function isEmptyObject(obj) {
return obj && keys(obj).length === 0;
}
exports.isEmptyObject = isEmptyObject;
function getSupportedProperties(visualizationProperties, supportedPropertiesList) {
var controls = get(visualizationProperties, "properties.controls", {});
var supportedControls = getSupportedPropertiesControls(controls, supportedPropertiesList);
return isEmpty(supportedControls)
? {}
: {
controls: supportedControls,
};
}
exports.getSupportedProperties = getSupportedProperties;
function getReferencePointWithSupportedProperties(referencePoint, supportedPropertiesList) {
var supportedControlsProperties = referencePoint.properties
? getSupportedPropertiesControls(referencePoint.properties.controls, supportedPropertiesList)
: {};
if (isEmpty(supportedControlsProperties)) {
var sortItems = referencePoint.properties && referencePoint.properties.sortItems;
var sortItemsExpand = sortItems && !isEmpty(sortItems) ? { sortItems: sortItems } : {};
return __assign({}, referencePoint, { properties: __assign({}, sortItemsExpand) });
}
var buckets = get(referencePoint, bucket_1.BUCKETS, []);
var stackCount = bucketHelper_1.getItemsCount(buckets, BucketNames.STACK);
var stackMeasuresToPercent = Boolean(supportedControlsProperties.stackMeasuresToPercent);
if (!stackCount && stackMeasuresToPercent) {
supportedControlsProperties.stackMeasures = true;
}
return __assign({}, referencePoint, { properties: __assign({}, referencePoint.properties, { controls: supportedControlsProperties }) });
}
exports.getReferencePointWithSupportedProperties = getReferencePointWithSupportedProperties;
function isStackingMeasure(properties) {
return get(properties, ["controls", "stackMeasures"], false);
}
exports.isStackingMeasure = isStackingMeasure;
function isStackingToPercent(properties) {
return get(properties, ["controls", "stackMeasuresToPercent"], false);
}
exports.isStackingToPercent = isStackingToPercent;
function isDualAxisOrSomeSecondaryAxisMeasure(extReferencePoint, secondaryMeasures) {
return (get(extReferencePoint, properties_1.PROPERTY_CONTROLS_DUAL_AXIS, true) ||
secondaryMeasures.some(function (item) { return get(item, bucket_1.SHOW_ON_SECONDARY_AXIS); }));
}
exports.isDualAxisOrSomeSecondaryAxisMeasure = isDualAxisOrSomeSecondaryAxisMeasure;
function removeImmutableOptionalStackingProperties(referencePoint, supportedPropertiesList) {
var buckets = get(referencePoint, bucket_1.BUCKETS, []);
var immutableProperties = [];
if (bucketHelper_1.getItemsCount(buckets, BucketNames.MEASURES) <= 1) {
immutableProperties = supportedProperties_1.OPTIONAL_STACKING_PROPERTIES;
}
if (bucketHelper_1.getItemsCount(buckets, BucketNames.STACK)) {
immutableProperties = supportedProperties_1.OPTIONAL_STACKING_PROPERTIES.slice(0, 1);
}
return supportedPropertiesList.filter(function (property) {
return !immutableProperties.some(function (immutableProperty) { return immutableProperty === property; });
});
}
exports.removeImmutableOptionalStackingProperties = removeImmutableOptionalStackingProperties;
// mapping between AD and SDK values
var AXIS_NAME_POSITION_MAPPING = {
auto: "middle",
bottom: "low",
middle: "middle",
top: "high",
left: "low",
center: "middle",
right: "high",
};
var AXIS_TYPES = ["xaxis", "yaxis", "secondary_xaxis", "secondary_yaxis"];
function getHighchartsAxisNameConfiguration(controlProperties, enableAxisNameConfiguration) {
if (enableAxisNameConfiguration === void 0) { enableAxisNameConfiguration = false; }
var axisProperties = AXIS_TYPES.reduce(function (result, axis) {
var axisNameConfig = get(controlProperties, axis + ".name");
if (isEmpty(axisNameConfig)) {
return result;
}
axisNameConfig.position =
AXIS_NAME_POSITION_MAPPING[enableAxisNameConfiguration ? axisNameConfig.position : AXIS_NAME_POSITION_MAPPING.auto];
result[axis] = __assign({}, controlProperties[axis], { name: axisNameConfig });
return result;
}, {});
return __assign({}, controlProperties, axisProperties);
}
exports.getHighchartsAxisNameConfiguration = getHighchartsAxisNameConfiguration;
function getColumnWidthsFromProperties(visualizationProperties) {
return get(visualizationProperties, "properties.controls.columnWidths");
}
exports.getColumnWidthsFromProperties = getColumnWidthsFromProperties;
//# sourceMappingURL=propertiesHelper.js.map