MCPcopy Index your code
hub / github.com/ChatLab/ChatLab / aggregateByLabel

Function aggregateByLabel

packages/core/src/chart/index.ts:189–214  ·  view source on GitHub ↗
(
  rows: Record<string, unknown>[],
  labelField: string,
  valueField: string
)

Source from the content-addressed store, hash-verified

187}
188
189function 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
216function buildLineData(rows: Record<string, unknown>[], spec: ChartSpec): LineChartRenderData {
217 const xField = spec.encoding.x!

Callers 2

buildLineDataFunction · 0.85
buildChartPayloadFunction · 0.85

Calls 4

toLabelFunction · 0.85
toNumberFunction · 0.85
setMethod · 0.80
getMethod · 0.65

Tested by

no test coverage detected