( rows: Record<string, unknown>[], labelField: string, valueField: string )
| 187 | } |
| 188 | |
| 189 | function aggregateByLabel( |
| 190 | rows: Record<string, unknown>[], |
| 191 | labelField: string, |
| 192 | valueField: string |
| 193 | ): { |
| 194 | labels: string[] |
| 195 | values: number[] |
| 196 | } { |
| 197 | const labels: string[] = [] |
| 198 | const indexByLabel = new Map<string, number>() |
| 199 | const values: number[] = [] |
| 200 | |
| 201 | for (const row of rows) { |
| 202 | const label = toLabel(row[labelField]) |
| 203 | let index = indexByLabel.get(label) |
| 204 | if (index === undefined) { |
| 205 | index = labels.length |
| 206 | indexByLabel.set(label, index) |
| 207 | labels.push(label) |
| 208 | values.push(0) |
| 209 | } |
| 210 | values[index] += toNumber(row[valueField], valueField) |
| 211 | } |
| 212 | |
| 213 | return { labels, values } |
| 214 | } |
| 215 | |
| 216 | function buildLineData(rows: Record<string, unknown>[], spec: ChartSpec): LineChartRenderData { |
| 217 | const xField = spec.encoding.x! |
no test coverage detected