UNPKG

powerbi-visuals-utils-dataviewutils

Version:
46 lines 1.65 kB
// TODO: refactor & focus DataViewTransform into a service with well-defined dependencies. // TODO: refactor this, setGrouped, and groupValues to a test helper to stop using it in the product export function createValueColumns(values = [], valueIdentityFields, source) { const result = values; setGrouped(result); if (valueIdentityFields) { result.identityFields = valueIdentityFields; } if (source) { result.source = source; } return result; } export function setGrouped(values, groupedResult) { values.grouped = groupedResult ? () => groupedResult : () => groupValues(values); } /** Group together the values with a common identity. */ export function groupValues(values) { const groups = []; let currentGroup; for (let i = 0, len = values.length; i < len; i++) { const value = values[i]; if (!currentGroup || currentGroup.identity !== value.identity) { currentGroup = { values: [] }; if (value.identity) { currentGroup.identity = value.identity; const source = value.source; // allow null, which will be formatted as (Blank). if (source.groupName !== undefined) { currentGroup.name = source.groupName; } else if (source.displayName) { currentGroup.name = source.displayName; } } groups.push(currentGroup); } currentGroup.values.push(value); } return groups; } //# sourceMappingURL=dataViewTransform.js.map