(sourceItems: T[], groupKey: string)
| 117 | } |
| 118 | |
| 119 | function buildExplicitColumns (sourceItems: T[], groupKey: string) { |
| 120 | const groupItems: C[] = [] |
| 121 | |
| 122 | const columnKeys = columnsProp |
| 123 | ? [...columnsProp] |
| 124 | : [...new Set(sourceItems.map(item => getPropertyFromItem(item, itemColumn)))] |
| 125 | |
| 126 | const columns: PivotColumn<C>[] = columnKeys.map(key => ({ |
| 127 | key: String(key), |
| 128 | cells: Array(rowKeys.length).fill(null), |
| 129 | items: [], |
| 130 | })) |
| 131 | const columnIndexByKey = new Map<any, number>(columnKeys.map((k, i) => [k, i])) |
| 132 | |
| 133 | for (const item of sourceItems) { |
| 134 | const rowKey = getPropertyFromItem(item, itemRow) |
| 135 | const columnKey = getPropertyFromItem(item, itemColumn) |
| 136 | const rowIndex = rowIndexByKey.get(rowKey) |
| 137 | const columnIndex = columnIndexByKey.get(columnKey) |
| 138 | |
| 139 | if (rowIndex === undefined || columnIndex === undefined) continue |
| 140 | |
| 141 | const cell = makeCell(item, rowKey, columnKey, groupKey) |
| 142 | columns[columnIndex].cells[rowIndex] = cell |
| 143 | columns[columnIndex].items.push(cell) |
| 144 | groupItems.push(cell) |
| 145 | } |
| 146 | |
| 147 | return { columns, groupItems } |
| 148 | } |
| 149 | |
| 150 | // Start a new column whenever the row key wraps |
| 151 | function buildInferredColumns (sourceItems: T[], groupKey: string) { |
no test coverage detected
searching dependent graphs…