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

Function buildChartPayload

packages/core/src/chart/index.ts:298–336  ·  view source on GitHub ↗
(
  rows: Record<string, unknown>[],
  rawSpec: unknown,
  options?: { truncated?: boolean }
)

Source from the content-addressed store, hash-verified

296}
297
298export function buildChartPayload(
299 rows: Record<string, unknown>[],
300 rawSpec: unknown,
301 options?: { truncated?: boolean }
302): ChartPayload {
303 const spec = normalizeChartSpec(rawSpec)
304 const dataset = inferChartDataset(rows, spec.fields)
305
306 const requiredFields = new Set<string>()
307 for (const field of Object.values(spec.encoding)) {
308 if (typeof field === 'string' && field) requiredFields.add(field)
309 }
310 for (const field of requiredFields) assertFieldExists(rows, field)
311
312 let data: ChartRenderData
313 switch (spec.type) {
314 case 'bar':
315 data = aggregateByLabel(rows, spec.encoding.x!, spec.encoding.y!)
316 break
317 case 'line':
318 data = buildLineData(rows, spec)
319 break
320 case 'pie':
321 data = aggregateByLabel(rows, spec.encoding.label!, spec.encoding.value!)
322 break
323 case 'heatmap':
324 data = buildHeatmapData(rows, spec)
325 break
326 }
327
328 return {
329 version: 1,
330 spec,
331 dataset,
332 data,
333 rowCount: rows.length,
334 truncated: options?.truncated,
335 }
336}

Callers 2

handlerFunction · 0.90
index.test.tsFile · 0.90

Calls 7

normalizeChartSpecFunction · 0.85
inferChartDatasetFunction · 0.85
assertFieldExistsFunction · 0.85
aggregateByLabelFunction · 0.85
buildLineDataFunction · 0.85
buildHeatmapDataFunction · 0.85
addMethod · 0.45

Tested by

no test coverage detected