UNPKG

@gooddata/react-components

Version:

GoodData.UI - A powerful JavaScript library for building analytical applications

60 lines 2.05 kB
"use strict"; 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 get = require("lodash/get"); /** * Transform * viewByParentAttribute: [P1, P1, P2, P2, P3], * viewByAttribute: [C1, C2, C1, C2, C2] * to * [{ * name: P1, * categories: [C1, C2] * }, { * name: P2, * categories: [C1, C2] * }, { * name: P3, * categories: [C2] * }] * @param viewByTwoAttributes */ function getCategoriesForTwoAttributes(viewByAttribute, viewByParentAttribute) { var keys = []; var children = viewByAttribute.items; var parent = viewByParentAttribute.items; var combinedResult = parent.reduce(function (result, parentAttr, index) { var _a; var uri = get(parentAttr, "attributeHeaderItem.uri", ""); var name = get(parentAttr, "attributeHeaderItem.name", ""); var value = get(children[index], "attributeHeaderItem.name", ""); var childCategories = get(result, uri + ".categories", []); if (!childCategories.length) { keys.push(uri); } return __assign({}, result, (_a = {}, _a[uri] = { name: name, categories: childCategories.concat([value]), }, _a)); }, {}); return keys.map(function (key) { var _a = combinedResult[key], name = _a.name, categories = _a.categories; return { name: name, categories: categories, }; }); } exports.getCategoriesForTwoAttributes = getCategoriesForTwoAttributes; //# sourceMappingURL=extendedStackingChartOptions.js.map