import { t } from '@/i18n'; import { formatValue } from '@/lib/format'; import type { FormatSpec as Spec } from '@/lib/types'; import { firstLast, type SeriesPoint } from './scales'; /** "Canada's GDP per capita rose from US$21.4k in 1990 to US$53.4k in 2024." */ export function summarizeSeries(subject: string, points: SeriesPoint[], spec: Spec): string { const fl = firstLast(points); if (!fl) return t('chart.noData'); const from = formatValue(fl.first.value, spec); const to = formatValue(fl.last.value, spec); const key = fl.last.value! > fl.first.value! ? 'chart.summary.rose' : fl.last.value! < fl.first.value! ? 'chart.summary.fell' : 'chart.summary.flat'; return t(key, { subject, from, y0: fl.first.year, to, y1: fl.last.year }); } export function summarizeMulti(names: string[], allPoints: SeriesPoint[][]): string { const years = allPoints.flat().map((p) => p.year); const y0 = Math.min(...years); const y1 = Math.max(...years); return t('chart.summary.multi', { n: names.length, y0, y1, names: names.join(', ') }); }