Files
free-games-itchio-list/webapp/src/components/charts/online-offline-chart.tsx
T
poli0981andClaude Opus 5.5 047d918d43 feat: accessibility statement, keyboard/screen-reader/chart/contrast fixes; 4.6.0 (#183) [skip-discuss]
Accessibility pass for the website and the apps (WCAG 2.2 AA target) and the accessibility statement: root ACCESSIBILITY.md + docs/i18n/vi/ACCESSIBILITY.md, the accessibility issue form, a default PR template; focus management, the '/' shortcut switch, chart names and data tables, contrast tokens with a CI check, Windows contrast themes; a docs sync of verified mismatches; version 4.6.0 with the two deps sweeps since 4.5.0 (#176, #182).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-09 14:16:50 +07:00

54 lines
1.9 KiB
TypeScript

import { useMemo } from 'react'
import { Cell, Legend, Pie, PieChart, ResponsiveContainer, Tooltip } from 'recharts'
import { classifyOnline } from '@/lib/analytics'
import { tableRows } from '@/lib/chart-table'
import { useT } from '@/lib/i18n'
import type { Game } from '@/types/game'
import { ChartCard } from './chart-card'
import { chartAria, LEGEND_BASE, SERIES_ANIMATION, SLICE_STROKE, TOOLTIP_BASE } from './chart-theme'
import { ChartTooltipContent } from './chart-tooltip'
import { PALETTE } from './palette'
export function OnlineOfflineChart({ games }: { games: Game[] }) {
const t = useT()
const split = useMemo(() => classifyOnline(games), [games])
const data = [
{ key: t('charts.onlineOffline.online'), count: split.online },
{ key: t('charts.onlineOffline.offline'), count: split.offline },
]
return (
<ChartCard
id="online-offline"
title={t('charts.onlineOffline.title')}
description={t('charts.onlineOffline.desc')}
table={{
label: t('charts.table.kind'),
value: t('charts.series.games'),
rows: tableRows(data, split.online + split.offline),
}}
>
<ResponsiveContainer width="100%" height="100%">
<PieChart {...chartAria('online-offline')}>
{/* Blue and orange: apart in lightness and for colour-blind readers (green and amber were not). */}
<Pie
{...SERIES_ANIMATION}
rootTabIndex={-1}
data={data}
dataKey="count"
nameKey="key"
innerRadius="50%"
outerRadius="80%"
paddingAngle={2}
stroke={SLICE_STROKE}
>
<Cell fill={PALETTE[4]} />
<Cell fill={PALETTE[6]} />
</Pie>
<Tooltip {...TOOLTIP_BASE} content={<ChartTooltipContent total={split.online + split.offline} />} />
<Legend {...LEGEND_BASE} />
</PieChart>
</ResponsiveContainer>
</ChartCard>
)
}