'use client'; import Link from 'next/link'; import { t } from '@/i18n'; import { formatValue, grouped, ordinal } from '@/lib/format'; import { routes } from '@/lib/site'; import type { FormatSpec } from '@/lib/types'; import type { DistributionResponse } from '@/lib/types-analytics'; import { Histogram, type HistogramMarker } from '@/components/charts/histogram'; /** * Distribution of an indicator across countries: histogram with markers (world median, the highlighted * country, its region median) and a table of medians by region and income group. */ export function DistributionPanel({ data, spec }: { data: DistributionResponse; spec: FormatSpec }) { const markers: HistogramMarker[] = []; if (data.stats.median != null) markers.push({ id: 'world', label: t('indicator.dist.worldMedian'), value: data.stats.median, tone: 'ink' }); const h = data.highlight; if (h && h.value != null) markers.push({ id: 'hl', label: h.country.name ?? h.country.id, value: h.value, tone: 'accent' }); if (h && h.region_median != null && h.region) markers.push({ id: 'region', label: t('indicator.dist.regionMedian', { region: h.region.name ?? '' }), value: h.region_median, tone: 'muted' }); return (
{h.country.flag} {h.country.name} {' '} {t('indicator.dist.highlight', { value: formatValue(h.value, spec), pct: h.percentile != null ? ordinal(Math.round(h.percentile)) : t('common.na'), rank: h.rank ?? '', n: h.n ?? '' })}
) : null}| {t('indicator.dist.group')} | {t('indicator.trend.median')} | {t('indicator.dist.n')} |
|---|---|---|
| {t('common.world')} | {formatValue(data.stats.median, spec)} | {grouped(data.n)} |
| {r.group.name} | {formatValue(r.median, spec)} | {grouped(r.n)} |
| {r.group.name} | {formatValue(r.median, spec)} | {grouped(r.n)} |