SPB Git forge

spb/countryatlas

Public
20commits 1branches 0releases
268.3 MBsize
maindefault branch
12 days agolast push
TypeScript 57% Python 38.6% JavaScript 3.6% CSS 0.6%
1.0 KB · 23 lines typescript
Raw Blame History
1import { t } from '@/i18n';2import { formatValue } from '@/lib/format';3import type { FormatSpec as Spec } from '@/lib/types';4import { firstLast, type SeriesPoint } from './scales';56/** "Canada's GDP per capita rose from US$21.4k in 1990 to US$53.4k in 2024." */7export function summarizeSeries(subject: string, points: SeriesPoint[], spec: Spec): string {8  const fl = firstLast(points);9  if (!fl) return t('chart.noData');10  const from = formatValue(fl.first.value, spec);11  const to = formatValue(fl.last.value, spec);12  const key =13    fl.last.value! > fl.first.value! ? 'chart.summary.rose' : fl.last.value! < fl.first.value! ? 'chart.summary.fell' : 'chart.summary.flat';14  return t(key, { subject, from, y0: fl.first.year, to, y1: fl.last.year });15}1617export function summarizeMulti(names: string[], allPoints: SeriesPoint[][]): string {18  const years = allPoints.flat().map((p) => p.year);19  const y0 = Math.min(...years);20  const y1 = Math.max(...years);21  return t('chart.summary.multi', { n: names.length, y0, y1, names: names.join(', ') });22}23