UNPKG

@1771technologies/lytenyte-pro

Version:

Blazingly fast headless React data grid with 100s of features.

32 lines (31 loc) 1.28 kB
import { computeField } from "@1771technologies/lytenyte-core/internal"; import { pivotPathsWithTotals } from "./pivot-paths-with-totals.js"; export function pivotPaths(filtered, leafs, columns, measures, labelFilter) { const pathSet = new Set(); for (let i = 0; i < filtered.length; i++) { const row = leafs[filtered[i]]; const current = []; for (let j = 0; j < columns.length; j++) { const c = columns[j]; const filterFn = labelFilter?.[j]; const field = c.field ?? c.id; const value = field ? computeField(field, row) : null; if (filterFn && !filterFn(value === null ? value : String(value))) continue; const pivotKey = value == null ? "ln__blank__" : String(value); current.push(pivotKey); } if (measures?.length) { for (const measure of measures) { pathSet.add([...current, measure.dim.id].join("-->")); } } else { current.push("ln__noop"); pathSet.add(current.join("-->")); } } const paths = [...pathSet]; const pathsWithTotals = pivotPathsWithTotals(paths, measures?.map((x) => x.dim.id) ?? []); return pathsWithTotals; }