fix(charts): phone layout of the Charts page (#130)

Below md: a one-row tab bar (the Vietnamese labels had wrapped out of the
fixed-height bar), 12px legends and 11px ticks, horizontal Languages and
Avg session bars, the reason under each recent deletion, the KPI total
across the row, a taller Genres card.

At every size: all 15 Genre labels on one line (Recharts had hidden 8,
the two largest included), pie legends in data order with muted text,
translated removal reasons (reasonKey in lib/deleted-reason), locale axis
numbers, treemap labels that fit their cells, no "(made_with[0])" in the
engine chart's description. CLAUDE.md: chart notes, gotcha 32 and the
unreleased-on-main note.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
poli0981andClaude Opus 5.5 authored and GitHub committed 2026-10-11 13:02:50 +07:00
1 parent 200cf2d17e
commit ec3ff9ab3a
28 files changed
+248 -77

No files matched your search

+4 -1
View File
@@ -57,7 +57,7 @@ Local admin without Access: put `DEV_ADMIN_EMAIL=you@example.com` in `webapp/.de
- Cache: react-query persisted to IndexedDB (`webapp.query-cache`, 7 days) by `lib/data/persister.ts` — byte 0 = format (1 deflate-raw, 0 plain), then the JSON; a legacy string is dropped; writes throttled 1 s and skipped when no data object changed. Persisted: `db`, `deleted`, `count-history` and only the `desc` files the current catalog names (`shouldPersistQuery`); stale `desc` queries are removed after a `db` success. `CACHE_BUSTER = ${APP.version}:data-v2`. **`gcTime` must stay >= persist `maxAge`.**
- Layout: `components/site/*` (sticky top nav + global search with the `/` shortcut + display menu + phone sheet menu; footer) — the window scrolls, not `<main>`. `/` is the Welcome page (`routes/welcome.tsx`).
- `/games`: search, filters, sort and page live in the URL — `lib/game-filters.ts` (`parseQuery` / `toParams` drop defaults; params `q genre platform status tag lang input engine ai access rating browser sort page`; `ai` treats "N/A" / a missing field as its own "Not disclosed" value and lists its options in a fixed order (`aiRank`); unit-tested) — rendered by `components/games/*` (filter chips with facet counts that ignore their own filter, a desktop ARIA table / phone list chosen by `useIsMobile`, 100 per page; the detail page's breadcrumb links back to the same list via router state). Counts show the whole catalog ("2,729 of 2,811") because 18+ games are hidden by default.
- `components/charts/` (19 charts, 4 lazy tabs, **no barrel `index.ts`**; every Recharts tooltip/cursor comes from `chart-theme.ts` + `chart-tooltip.tsx`), `components/game-thumb.tsx` (`lib/thumbnail.ts` → `/img/160|640/...` on the web, the original URL in Tauri), `components/legal-gate.tsx` (a non-dismissable Radix dialog **over** the page, so deep links land where they pointed; links flagged `inGate` in `lib/about.ts`; re-prompts when `LEGAL_VERSION` in `stores/prefs.ts` changes; no "Leave" button in Tauri).
- `components/charts/` (19 charts, 4 lazy tabs, **no barrel `index.ts`**; every Recharts tooltip/cursor comes from `chart-theme.ts` + `chart-tooltip.tsx`, every pie legend from `LEGEND_BASE` there; below `md` the charts get 12 px legends / 11 px ticks from a media block in `index.css`, the tab bar is one row of equal tabs, and Languages / Avg session switch to horizontal bars via `useIsMobile`), `components/game-thumb.tsx` (`lib/thumbnail.ts` → `/img/160|640/...` on the web, the original URL in Tauri), `components/legal-gate.tsx` (a non-dismissable Radix dialog **over** the page, so deep links land where they pointed; links flagged `inGate` in `lib/about.ts`; re-prompts when `LEGAL_VERSION` in `stores/prefs.ts` changes; no "Leave" button in Tauri).
- Styling: **Tailwind v4** via `@tailwindcss/vite` (no PostCSS, no `tailwind.config`); tokens are hex CSS variables in `src/index.css` (`:root` / `.dark`, `@theme inline`; `--brand-soft`, `--thumb`, `--success`, `--scrollbar-thumb(-hover/-active)` besides the shadcn set) and must match the approved mockup. Themed scrollbars (`@layer base`, only under `(hover: hover) and (pointer: fine)`): `::-webkit-scrollbar*` for Chromium/Safari, `scrollbar-color` / `scrollbar-width: thin` for Firefox only (gotcha 28); "Hide scrollbars" = unlayered `html[data-scrollbars='hidden']` rules (`hooks/useScrollbarsEffect.ts`). Self-hosted Geist / Geist Mono (`@fontsource-variable/*`, CSP `font-src 'self'`). Numbers and dates go through `lib/format.ts` (`useFormat`: en-GB / vi-VN). `webapp/scripts/gen_assets.py` redraws favicon, PWA icons and `og.png` from the same tokens and the Geist fonts in `node_modules`.
- `lib/gate.ts` (web only): when a tab comes back into view or a cover fails and the verification pass may have run out (`webapp.gate` hint), it asks `GET /api/verify` and reloads into the verification page; `lib/reload.ts` is the shared at-most-every-30-s reload guard.
- `hooks/useSeoHead.ts` sets canonical + robots per route (index.html has no static canonical/og:url on purpose).
@@ -137,6 +137,7 @@ Code **MIT** (`LICENSE`); catalog data **CC BY 4.0** for the maintainer's contri
29. **Pack names are content hashes: the build must stay deterministic** (column and dictionary order, zlib level 9 — a Node/zlib upgrade only re-downloads once), **and no hash may reach the JS bundle** (data-only deploys keep JS byte-identical; the manifest is fetched, never imported). `_headers` joins a header set by two matching rules with a comma — give each path one `Cache-Control`.
30. **itch.io shows the `Published` and `Updated` info rows only for a few weeks** after the event (every `Published` date in a 250-page sample of Oct 2026 was under four weeks old); an explicit `Release date` row stays. That is why `release_date` is N/A for most older games, and why a `--full` re-scrape keeps a known `release_date` / `thumbnail` instead of writing N/A (`KEEP_KNOWN_FIELDS` in `refresh.py`).
31. **Tauri crates and their npm packages must share major.minor** (`tauri` ↔ `@tauri-apps/api`, `tauri-plugin-x` ↔ `@tauri-apps/plugin-x`): `tauri build` refuses to build otherwise, and only the release workflows run it — every v4.3.0 release build first failed on `tauri-plugin-opener` 2.6.0 vs `@tauri-apps/plugin-opener` 2.7.0 after Dependabot bumped the npm side alone (#119). Webapp CI's `npm run check:tauri` (`webapp/scripts/check-tauri-versions.mjs`, lock files only) now fails such a PR; Dependabot's cargo updates run weekly on Mondays like npm so both groups arrive together. Fix a one-sided bump with `cargo update -p <crate>` in `webapp/src-tauri/`.
32. **Recharts hides category labels silently and styles legends its own way.** The default `interval="preserveEnd"` keeps a label only if its line box (font size × 1.5) plus `minTickGap` (5) fits its row, and the first one only if half of it fits above: the 15-row Genres chart showed 7 labels, without the two largest genres — category axes set `interval={0}`. A label wider than the axis wraps onto two lines, measured at the 16px body size unless `style` carries a size with a unit (`singleLineTick()` in `chart-theme.ts`). `<Legend>` sorts alphabetically (`itemSorter: 'value'`) and colours each label like its slice (amber/green text on white fails contrast) — pies spread `LEGEND_BASE`.
## Safe-edit rules
@@ -147,6 +148,8 @@ Code **MIT** (`LICENSE`); catalog data **CC BY 4.0** for the maintainer's contri
## Current state (Oct 2026)
**Unreleased on main** (web only, deployed on merge; the apps get it with the next release, whose notes must mention it): #130 (2026-10-11) fixes the Charts page on phones. Below `md`: the tab bar is one row (the Vietnamese labels had wrapped out of the fixed-height bar), 12 px legends and 11 px ticks, horizontal Languages / Avg session bars, the reason under each recent deletion, and the KPI total spans the row. At every size: all 15 Genre labels (Recharts had hidden 8, the two largest included), pie legends in data order with muted text, translated removal reasons and locale axis numbers.
**v4.3.0** (2026-10-10, PR #117; released the same day): itch.io's newer info rows in the catalog — `ai_disclosure` / `ai_content` (generative-AI disclosure) and `accessibility` — on the game page, as `/games` filters (`ai`, `access`) and as charts (Overview: "Generative AI"; Discovery: "Accessibility Features", "What AI Was Used For"); `description` = the creator's tagline. The whole catalog was re-scraped the same day with `force_update.yml` (6 × 600 + 10, ≈14.5 games/min; an itch.io outage ~05:20–06:50Z only cost retries): 3,236 of 3,251 games carry the new fields — No AI 53 %, AI Assisted 11 %, not disclosed 36 %; accessibility on 14 % (Subtitles 257, One button 119); the other 15 are 14 dead-page strikes awaiting confirmation and one password-protected page (`everium.itch.io/underthethorns`; it failed every check until #129 taught the refresh to strike such pages). Fixed on the way, same day: #118 (`force_update.yml` had never worked in v4 — it now dispatches `refresh.yml`, whose scan reads the latest main so queued batches rotate), #119 (`tauri-plugin-opener` 2.7: every first v4.3.0 release build had failed; the tag was moved before publishing), #120 (the 5 open Dependabot alerts; `check:tauri` CI guard; weekly cargo Dependabot), then Dependabot #122–#127.
**v4.2.0** (2026-10-03, PR #103): catalog packs + lazy descriptions (first visit ≈ 264 KB instead of ≈ 520 KB), compressed IndexedDB cache, `/data/*.json` only for apps 4.0–4.1.1 (410 + repository links for everyone else), `/img` cache fixes, themed scrollbars + "Hide scrollbars", policies (`LEGAL_VERSION` 2026-10-03: data reuse goes through the repository). Checked on the live site the same day: TLS 1.2/1.3 only, HSTS preload header (domain not on the preload list), Cloudflare compression already on (zstd/br), Smart Tiered Cache on but irrelevant here (`docs/operations.md` §1 step 12).
@@ -1,15 +1,17 @@
import { useMemo } from 'react'
import { Bar, BarChart, CartesianGrid, ResponsiveContainer, Tooltip, XAxis, YAxis } from 'recharts'
import { countByArray, topN } from '@/lib/analytics'
import { useFormat } from '@/lib/format'
import { useT } from '@/lib/i18n'
import type { Game } from '@/types/game'
import { ChartCard } from './chart-card'
import { BAR_CURSOR, TOOLTIP_BASE } from './chart-theme'
import { BAR_CURSOR, TOOLTIP_BASE, truncateLabel } from './chart-theme'
import { ChartTooltipContent } from './chart-tooltip'
import { PALETTE } from './palette'
export function AccessibilityChart({ games }: { games: Game[] }) {
const t = useT()
const fmt = useFormat()
const data = useMemo(() => topN(countByArray(games, 'accessibility'), 10), [games])
return (
<ChartCard title={t('charts.accessibility.title')} description={t('charts.accessibility.desc')}>
@@ -19,13 +21,14 @@ export function AccessibilityChart({ games }: { games: Game[] }) {
<ResponsiveContainer width="100%" height="100%">
<BarChart data={data} layout="vertical" margin={{ left: 20 }}>
<CartesianGrid horizontal={false} strokeDasharray="3 3" />
<XAxis type="number" allowDecimals={false} />
<XAxis type="number" allowDecimals={false} tickFormatter={fmt.number} />
<YAxis
dataKey="key"
type="category"
width={140}
interval={0}
tick={{ fontSize: 12 }}
tickFormatter={(v: string) => (v.length > 22 ? `${v.slice(0, 21)}…` : v)}
tickFormatter={truncateLabel(22)}
/>
<Tooltip {...TOOLTIP_BASE} cursor={BAR_CURSOR} content={<ChartTooltipContent />} />
<Bar dataKey="count" name={t('charts.series.games')} fill={PALETTE[7]} radius={[0, 4, 4, 0]} />
@@ -1,6 +1,7 @@
import { useMemo } from 'react'
import { Bar, BarChart, CartesianGrid, ResponsiveContainer, Tooltip, XAxis, YAxis } from 'recharts'
import { countByArray } from '@/lib/analytics'
import { useFormat } from '@/lib/format'
import { useT } from '@/lib/i18n'
import type { Game } from '@/types/game'
import { ChartCard } from './chart-card'
@@ -11,6 +12,7 @@ import { PALETTE } from './palette'
/** What AI-assisted games used AI for; the orange of "AI-assisted" in the disclosure chart. */
export function AiContentChart({ games }: { games: Game[] }) {
const t = useT()
const fmt = useFormat()
const data = useMemo(() => countByArray(games, 'ai_content'), [games])
return (
<ChartCard title={t('charts.aiContent.title')} description={t('charts.aiContent.desc')}>
@@ -20,8 +22,8 @@ export function AiContentChart({ games }: { games: Game[] }) {
<ResponsiveContainer width="100%" height="100%">
<BarChart data={data} layout="vertical" margin={{ left: 20 }}>
<CartesianGrid horizontal={false} strokeDasharray="3 3" />
<XAxis type="number" allowDecimals={false} />
<YAxis dataKey="key" type="category" width={100} tick={{ fontSize: 12 }} />
<XAxis type="number" allowDecimals={false} tickFormatter={fmt.number} />
<YAxis dataKey="key" type="category" width={100} interval={0} tick={{ fontSize: 12 }} />
<Tooltip {...TOOLTIP_BASE} cursor={BAR_CURSOR} content={<ChartTooltipContent />} />
<Bar dataKey="count" name={t('charts.series.games')} fill={PALETTE[6]} radius={[0, 4, 4, 0]} />
</BarChart>
@@ -6,7 +6,7 @@ import { AI_ASSISTED, AI_NONE, AI_UNDISCLOSED } from '@/lib/game-filters'
import { useT } from '@/lib/i18n'
import type { Game } from '@/types/game'
import { ChartCard } from './chart-card'
import { SLICE_STROKE, TOOLTIP_BASE } from './chart-theme'
import { LEGEND_BASE, SLICE_STROKE, TOOLTIP_BASE } from './chart-theme'
import { ChartTooltipContent } from './chart-tooltip'
import { NEUTRAL, PALETTE } from './palette'
@@ -42,8 +42,8 @@ export function AiDisclosureChart({ games }: { games: Game[] }) {
))}
</Pie>
<Tooltip {...TOOLTIP_BASE} content={<ChartTooltipContent total={total} />} />
{/* The data's order (no AI, AI-assisted, not disclosed), not Recharts' alphabetical default. */}
<Legend itemSorter={(item) => data.findIndex((d) => d.label === item.value)} />
{/* In the data's order: no AI, AI-assisted, not disclosed. */}
<Legend {...LEGEND_BASE} />
</PieChart>
</ResponsiveContainer>
</ChartCard>
@@ -1,25 +1,50 @@
import { useMemo } from 'react'
import { Bar, BarChart, CartesianGrid, ResponsiveContainer, Tooltip, XAxis, YAxis } from 'recharts'
import { countBy, topN } from '@/lib/analytics'
import { useFormat } from '@/lib/format'
import { useT } from '@/lib/i18n'
import { useIsMobile } from '@/lib/use-is-mobile'
import type { Game } from '@/types/game'
import { ChartCard } from './chart-card'
import { BAR_CURSOR, TOOLTIP_BASE } from './chart-theme'
import { BAR_CURSOR, singleLineTick, TOOLTIP_BASE, truncateLabel } from './chart-theme'
import { ChartTooltipContent } from './chart-tooltip'
import { PALETTE } from './palette'
export function AvgSessionChart({ games }: { games: Game[] }) {
const t = useT()
const fmt = useFormat()
// Phones get horizontal bars, like the languages chart: the slanted labels overlap there.
const isMobile = useIsMobile()
const data = useMemo(() => topN(countBy(games, 'average_session'), 8), [games])
return (
<ChartCard title={t('charts.avgSession.title')}>
<ResponsiveContainer width="100%" height="100%">
<BarChart data={data}>
<CartesianGrid strokeDasharray="3 3" />
<XAxis dataKey="key" tick={{ fontSize: 10 }} interval={0} angle={-20} textAnchor="end" height={60} />
<YAxis />
<BarChart data={data} layout={isMobile ? 'vertical' : 'horizontal'}>
<CartesianGrid horizontal={!isMobile} strokeDasharray="3 3" />
{isMobile ? (
<XAxis type="number" allowDecimals={false} tickFormatter={fmt.number} />
) : (
<XAxis dataKey="key" tick={{ fontSize: 10 }} interval={0} angle={-20} textAnchor="end" height={60} />
)}
{isMobile ? (
<YAxis
dataKey="key"
type="category"
width={110}
interval={0}
tick={singleLineTick(11)}
tickFormatter={truncateLabel(18)}
/>
) : (
<YAxis tickFormatter={fmt.number} />
)}
<Tooltip {...TOOLTIP_BASE} cursor={BAR_CURSOR} content={<ChartTooltipContent />} />
<Bar dataKey="count" name={t('charts.series.games')} fill={PALETTE[6]} radius={[4, 4, 0, 0]} />
<Bar
dataKey="count"
name={t('charts.series.games')}
fill={PALETTE[6]}
radius={isMobile ? [0, 4, 4, 0] : [4, 4, 0, 0]}
/>
</BarChart>
</ResponsiveContainer>
</ChartCard>
+5 -2
View File
@@ -1,12 +1,15 @@
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card'
import { cn } from '@/lib/utils'
interface ChartCardProps {
title: string
description?: string
/** Extra classes for the chart area, e.g. a taller one on phones (`max-md:h-96`). */
contentClassName?: string
children: React.ReactNode
}
export function ChartCard({ title, description, children }: ChartCardProps) {
export function ChartCard({ title, description, contentClassName, children }: ChartCardProps) {
return (
<Card>
<CardHeader>
@@ -21,7 +24,7 @@ export function ChartCard({ title, description, children }: ChartCardProps) {
moving focus. Only on the chart: the list cards (recently removed,
tag cloud) keep their scrollbar drag and text selection. */}
<CardContent
className="h-72"
className={cn('h-72', contentClassName)}
onMouseDown={(e) => {
if ((e.target as Element).closest('.recharts-wrapper')) e.preventDefault()
}}
@@ -16,3 +16,30 @@ export const LINE_CURSOR = { stroke: 'var(--muted-foreground)', strokeDasharray:
/** Seams between pie slices in the card colour (Recharts draws white seams by default). */
export const SLICE_STROKE = 'var(--card)'
/**
* Every pie <Legend>: the data's order (largest slice first) instead of Recharts'
* alphabetical default, and labels in the muted text colour instead of the slice
* colour, which fails contrast on the light theme; the swatch carries the colour.
* Phones get smaller legend text in index.css.
*/
export const LEGEND_BASE = {
itemSorter: null,
labelStyle: { color: 'var(--muted-foreground)' },
} as const
/**
* Tick text for a category axis whose labels must stay on one line. Recharts
* wraps a label wider than the axis, measured in a DOM span styled with `style`
* alone: without a size there, or with a unitless one, the span measures at the
* 16px body size, so a 12px "Interactive Fiction" broke in two and ran into its
* neighbours in the 15 thin rows of the Genres chart.
*/
export function singleLineTick(fontSize: number) {
return { fontSize, style: { fontSize: `${fontSize}px` } }
}
/** Shortens category labels longer than `max` characters (ticks, treemap cells); tooltips keep the whole name. */
export function truncateLabel(max: number): (value: string) => string {
return (value) => (value.length > max ? `${value.slice(0, max - 1)}…` : value)
}
@@ -4,7 +4,7 @@ import { deletionReasonCounts } from '@/lib/analytics'
import { useT } from '@/lib/i18n'
import type { DeletedGameEntry } from '@/types/game'
import { ChartCard } from './chart-card'
import { SLICE_STROKE, TOOLTIP_BASE } from './chart-theme'
import { LEGEND_BASE, SLICE_STROKE, TOOLTIP_BASE } from './chart-theme'
import { ChartTooltipContent } from './chart-tooltip'
import { PALETTE } from './palette'
@@ -30,7 +30,7 @@ export function DeletionReasonsChart({ deleted }: { deleted: DeletedGameEntry[]
))}
</Pie>
<Tooltip {...TOOLTIP_BASE} content={<ChartTooltipContent total={total} />} />
<Legend />
<Legend {...LEGEND_BASE} />
</PieChart>
</ResponsiveContainer>
</ChartCard>
@@ -1,6 +1,7 @@
import { useMemo } from 'react'
import { Bar, BarChart, CartesianGrid, ResponsiveContainer, Tooltip, XAxis, YAxis } from 'recharts'
import { deletionsByMonth } from '@/lib/analytics'
import { useFormat } from '@/lib/format'
import { useT } from '@/lib/i18n'
import type { DeletedGameEntry } from '@/types/game'
import { ChartCard } from './chart-card'
@@ -10,6 +11,7 @@ import { PALETTE } from './palette'
export function DeletionsOverTimeChart({ deleted }: { deleted: DeletedGameEntry[] }) {
const t = useT()
const fmt = useFormat()
const data = useMemo(() => deletionsByMonth(deleted), [deleted])
return (
<ChartCard title={t('charts.deletionsOverTime.title')} description={t('charts.deletionsOverTime.desc')}>
@@ -17,7 +19,7 @@ export function DeletionsOverTimeChart({ deleted }: { deleted: DeletedGameEntry[
<BarChart data={data}>
<CartesianGrid strokeDasharray="3 3" />
<XAxis dataKey="key" tick={{ fontSize: 10 }} interval={0} angle={-25} textAnchor="end" height={60} />
<YAxis allowDecimals={false} />
<YAxis allowDecimals={false} tickFormatter={fmt.number} />
<Tooltip {...TOOLTIP_BASE} cursor={BAR_CURSOR} content={<ChartTooltipContent />} />
<Bar dataKey="count" name={t('charts.series.removed')} fill={PALETTE[1]} radius={[4, 4, 0, 0]} />
</BarChart>
@@ -21,7 +21,13 @@ export function GameCountChart({ history }: { history: CountHistoryPoint[] }) {
<LineChart data={history} margin={{ left: 4, right: 8 }}>
<CartesianGrid strokeDasharray="3 3" />
<XAxis dataKey="date" tick={{ fontSize: 10 }} minTickGap={24} />
<YAxis tick={{ fontSize: 11 }} width={48} allowDecimals={false} domain={['auto', 'auto']} />
<YAxis
tick={{ fontSize: 11 }}
width={48}
allowDecimals={false}
domain={['auto', 'auto']}
tickFormatter={fmt.number}
/>
<Tooltip
{...TOOLTIP_BASE}
cursor={LINE_CURSOR}
+9 -4
View File
@@ -1,23 +1,28 @@
import { useMemo } from 'react'
import { Bar, BarChart, CartesianGrid, ResponsiveContainer, Tooltip, XAxis, YAxis } from 'recharts'
import { countBy, topN } from '@/lib/analytics'
import { useFormat } from '@/lib/format'
import { useT } from '@/lib/i18n'
import type { Game } from '@/types/game'
import { ChartCard } from './chart-card'
import { BAR_CURSOR, TOOLTIP_BASE } from './chart-theme'
import { BAR_CURSOR, singleLineTick, TOOLTIP_BASE } from './chart-theme'
import { ChartTooltipContent } from './chart-tooltip'
import { PALETTE } from './palette'
export function GenreChart({ games }: { games: Game[] }) {
const t = useT()
const fmt = useFormat()
const data = useMemo(() => topN(countBy(games, 'genre'), 15), [games])
return (
<ChartCard title={t('charts.genre.title')} description={t('charts.genre.desc')}>
// Taller on phones, where the cards stack: 15 rows get room to breathe.
<ChartCard title={t('charts.genre.title')} description={t('charts.genre.desc')} contentClassName="max-md:h-96">
<ResponsiveContainer width="100%" height="100%">
<BarChart data={data} layout="vertical" margin={{ left: 20 }}>
<CartesianGrid horizontal={false} strokeDasharray="3 3" />
<XAxis type="number" />
<YAxis dataKey="key" type="category" width={120} tick={{ fontSize: 12 }} />
<XAxis type="number" tickFormatter={fmt.number} />
{/* interval 0: every label. The default drops those whose line box doesn't
fit the row, which hid every other genre, the largest two included. */}
<YAxis dataKey="key" type="category" width={120} interval={0} tick={singleLineTick(12)} />
<Tooltip {...TOOLTIP_BASE} cursor={BAR_CURSOR} content={<ChartTooltipContent />} />
<Bar dataKey="count" name={t('charts.series.games')} fill={PALETTE[0]} radius={[0, 4, 4, 0]} />
</BarChart>
@@ -4,7 +4,7 @@ import { genreTreemapData } from '@/lib/analytics'
import { useT } from '@/lib/i18n'
import type { Game } from '@/types/game'
import { ChartCard } from './chart-card'
import { TOOLTIP_BASE } from './chart-theme'
import { TOOLTIP_BASE, truncateLabel } from './chart-theme'
import { ChartTooltipContent } from './chart-tooltip'
import { PALETTE } from './palette'
@@ -18,11 +18,17 @@ interface TreemapCellProps {
name?: string
}
// Custom cell renderer: hides the label on rectangles too small to fit it,
// so the treemap stays legible on narrow (mobile) viewports.
/** Width of a 12px semibold Geist character, rounded up. */
const LABEL_CHAR_PX = 7
// Custom cell renderer: shortens the label to the rectangle's width ("Simul…")
// and hides it where not even three letters fit, so the treemap stays legible
// on narrow (mobile) viewports.
function TreemapCell(props: TreemapCellProps) {
const { x = 0, y = 0, width = 0, height = 0, index = 0, depth = 1, name = '' } = props
if (depth !== 1 || width <= 0 || height <= 0) return null
const fits = Math.floor((width - 12) / LABEL_CHAR_PX)
const label = name.length <= fits || fits >= 4 ? truncateLabel(fits)(name) : null
return (
<g>
<rect
@@ -34,9 +40,9 @@ function TreemapCell(props: TreemapCellProps) {
stroke="var(--background)"
strokeWidth={2}
/>
{width > 56 && height > 24 && (
{label && height > 24 && (
<text x={x + 6} y={y + 18} fill="var(--background)" fontSize={12} fontWeight={600}>
{name}
{label}
</text>
)}
</g>
+3 -2
View File
@@ -25,8 +25,9 @@ export function KpiCards({ games, deleted, hiddenNsfw }: KpiCardsProps) {
]
return (
<div className="grid grid-cols-2 gap-4 md:grid-cols-5">
{items.map((item) => (
<Card key={item.label}>
{/* Phones: the total spans the row, so the other four fill two rows with no gap. */}
{items.map((item, i) => (
<Card key={item.label} className={i === 0 ? 'max-md:col-span-2' : undefined}>
<CardContent className="p-4">
<p className="text-xs text-muted-foreground">{item.label}</p>
<p className="mt-1 font-mono text-2xl font-semibold tracking-tight">{item.value}</p>
@@ -1,25 +1,50 @@
import { useMemo } from 'react'
import { Bar, BarChart, CartesianGrid, ResponsiveContainer, Tooltip, XAxis, YAxis } from 'recharts'
import { countByArray, topN } from '@/lib/analytics'
import { useFormat } from '@/lib/format'
import { useT } from '@/lib/i18n'
import { useIsMobile } from '@/lib/use-is-mobile'
import type { Game } from '@/types/game'
import { ChartCard } from './chart-card'
import { BAR_CURSOR, TOOLTIP_BASE } from './chart-theme'
import { BAR_CURSOR, singleLineTick, TOOLTIP_BASE, truncateLabel } from './chart-theme'
import { ChartTooltipContent } from './chart-tooltip'
import { PALETTE } from './palette'
export function LanguagesChart({ games }: { games: Game[] }) {
const t = useT()
const fmt = useFormat()
// Phones get horizontal bars: ten slanted names ("Spanish; Latin America") overlap in a narrow card.
const isMobile = useIsMobile()
const data = useMemo(() => topN(countByArray(games, 'languages'), 10), [games])
return (
<ChartCard title={t('charts.languages.title')}>
<ResponsiveContainer width="100%" height="100%">
<BarChart data={data}>
<CartesianGrid strokeDasharray="3 3" />
<XAxis dataKey="key" tick={{ fontSize: 11 }} interval={0} angle={-25} textAnchor="end" height={60} />
<YAxis />
<BarChart data={data} layout={isMobile ? 'vertical' : 'horizontal'}>
<CartesianGrid horizontal={!isMobile} strokeDasharray="3 3" />
{isMobile ? (
<XAxis type="number" allowDecimals={false} tickFormatter={fmt.number} />
) : (
<XAxis dataKey="key" tick={{ fontSize: 11 }} interval={0} angle={-25} textAnchor="end" height={60} />
)}
{isMobile ? (
<YAxis
dataKey="key"
type="category"
width={120}
interval={0}
tick={singleLineTick(11)}
tickFormatter={truncateLabel(18)}
/>
) : (
<YAxis tickFormatter={fmt.number} />
)}
<Tooltip {...TOOLTIP_BASE} cursor={BAR_CURSOR} content={<ChartTooltipContent />} />
<Bar dataKey="count" name={t('charts.series.games')} fill={PALETTE[4]} radius={[4, 4, 0, 0]} />
<Bar
dataKey="count"
name={t('charts.series.games')}
fill={PALETTE[4]}
radius={isMobile ? [0, 4, 4, 0] : [4, 4, 0, 0]}
/>
</BarChart>
</ResponsiveContainer>
</ChartCard>
@@ -4,7 +4,7 @@ import { topMadeWith } from '@/lib/analytics'
import { useT } from '@/lib/i18n'
import type { Game } from '@/types/game'
import { ChartCard } from './chart-card'
import { SLICE_STROKE, TOOLTIP_BASE } from './chart-theme'
import { LEGEND_BASE, SLICE_STROKE, TOOLTIP_BASE } from './chart-theme'
import { ChartTooltipContent } from './chart-tooltip'
import { PALETTE } from './palette'
@@ -29,7 +29,7 @@ export function MadeWithChart({ games }: { games: Game[] }) {
))}
</Pie>
<Tooltip {...TOOLTIP_BASE} content={<ChartTooltipContent />} />
<Legend />
<Legend {...LEGEND_BASE} />
</PieChart>
</ResponsiveContainer>
</ChartCard>
@@ -4,7 +4,7 @@ import { classifyOnline } from '@/lib/analytics'
import { useT } from '@/lib/i18n'
import type { Game } from '@/types/game'
import { ChartCard } from './chart-card'
import { SLICE_STROKE, TOOLTIP_BASE } from './chart-theme'
import { LEGEND_BASE, SLICE_STROKE, TOOLTIP_BASE } from './chart-theme'
import { ChartTooltipContent } from './chart-tooltip'
import { PALETTE } from './palette'
@@ -24,7 +24,7 @@ export function OnlineOfflineChart({ games }: { games: Game[] }) {
<Cell fill={PALETTE[3]} />
</Pie>
<Tooltip {...TOOLTIP_BASE} content={<ChartTooltipContent total={split.online + split.offline} />} />
<Legend />
<Legend {...LEGEND_BASE} />
</PieChart>
</ResponsiveContainer>
</ChartCard>
@@ -4,7 +4,7 @@ import { countByArray } from '@/lib/analytics'
import { useT } from '@/lib/i18n'
import type { Game } from '@/types/game'
import { ChartCard } from './chart-card'
import { SLICE_STROKE, TOOLTIP_BASE } from './chart-theme'
import { LEGEND_BASE, SLICE_STROKE, TOOLTIP_BASE } from './chart-theme'
import { ChartTooltipContent } from './chart-tooltip'
import { PALETTE } from './palette'
@@ -29,7 +29,7 @@ export function PlatformChart({ games }: { games: Game[] }) {
))}
</Pie>
<Tooltip {...TOOLTIP_BASE} content={<ChartTooltipContent />} />
<Legend />
<Legend {...LEGEND_BASE} />
</PieChart>
</ResponsiveContainer>
</ChartCard>
@@ -1,6 +1,7 @@
import { useMemo } from 'react'
import { Bar, BarChart, CartesianGrid, ResponsiveContainer, Tooltip, XAxis, YAxis } from 'recharts'
import { ratingHistogram } from '@/lib/analytics'
import { useFormat } from '@/lib/format'
import { useT } from '@/lib/i18n'
import type { Game } from '@/types/game'
import { ChartCard } from './chart-card'
@@ -10,6 +11,7 @@ import { PALETTE } from './palette'
export function RatingChart({ games }: { games: Game[] }) {
const t = useT()
const fmt = useFormat()
const data = useMemo(() => ratingHistogram(games, 10), [games])
return (
<ChartCard title={t('charts.rating.title')} description={t('charts.rating.desc')}>
@@ -17,7 +19,7 @@ export function RatingChart({ games }: { games: Game[] }) {
<BarChart data={data}>
<CartesianGrid strokeDasharray="3 3" />
<XAxis dataKey="key" tick={{ fontSize: 10 }} />
<YAxis />
<YAxis tickFormatter={fmt.number} />
<Tooltip {...TOOLTIP_BASE} cursor={BAR_CURSOR} content={<ChartTooltipContent />} />
<Bar dataKey="count" name={t('charts.series.games')} fill={PALETTE[5]} radius={[4, 4, 0, 0]} />
</BarChart>
@@ -1,5 +1,6 @@
import { useMemo } from 'react'
import { Badge } from '@/components/ui/badge'
import { reasonKey } from '@/lib/deleted-reason'
import { useFormat } from '@/lib/format'
import { useT } from '@/lib/i18n'
import type { DeletedGameEntry } from '@/types/game'
@@ -25,17 +26,25 @@ export function RecentDeletedChart({ deleted }: { deleted: DeletedGameEntry[] })
{recent.length === 0 ? (
<p className="text-muted-foreground">{t('charts.recentDeleted.empty')}</p>
) : (
recent.map((d) => (
<li
key={`${d.url}-${d.deleted_at}`}
className="flex items-center justify-between gap-2 border-b py-1 last:border-0"
>
<span className="truncate font-medium">{d.name}</span>
<Badge variant="outline" className="shrink-0 text-xs">
{d.reason}
</Badge>
</li>
))
recent.map((d) => {
const key = reasonKey(d.reason)
return (
// Phones: the reason goes under the name, which would otherwise shrink to a few letters.
<li
key={`${d.url}-${d.deleted_at}`}
className="flex items-center justify-between gap-2 border-b py-1 last:border-0 max-md:flex-col max-md:items-start max-md:gap-0.5"
>
<span className="truncate font-medium max-md:max-w-full">{d.name}</span>
<Badge
variant="outline"
className="shrink-0 text-xs max-md:block max-md:max-w-full max-md:truncate"
title={d.reason}
>
{key ? t(key) : d.reason}
</Badge>
</li>
)
})
)}
</ul>
</div>
@@ -4,7 +4,7 @@ import { countBy } from '@/lib/analytics'
import { useT } from '@/lib/i18n'
import type { Game } from '@/types/game'
import { ChartCard } from './chart-card'
import { SLICE_STROKE, TOOLTIP_BASE } from './chart-theme'
import { LEGEND_BASE, SLICE_STROKE, TOOLTIP_BASE } from './chart-theme'
import { ChartTooltipContent } from './chart-tooltip'
import { PALETTE } from './palette'
@@ -22,7 +22,7 @@ export function StatusChart({ games }: { games: Game[] }) {
))}
</Pie>
<Tooltip {...TOOLTIP_BASE} content={<ChartTooltipContent total={total} />} />
<Legend />
<Legend {...LEGEND_BASE} />
</PieChart>
</ResponsiveContainer>
</ChartCard>
@@ -1,28 +1,31 @@
import { useMemo } from 'react'
import { Bar, BarChart, CartesianGrid, ResponsiveContainer, Tooltip, XAxis, YAxis } from 'recharts'
import { topByRatingCount } from '@/lib/analytics'
import { useFormat } from '@/lib/format'
import { useT } from '@/lib/i18n'
import type { Game } from '@/types/game'
import { ChartCard } from './chart-card'
import { BAR_CURSOR, TOOLTIP_BASE } from './chart-theme'
import { BAR_CURSOR, TOOLTIP_BASE, truncateLabel } from './chart-theme'
import { ChartTooltipContent } from './chart-tooltip'
import { PALETTE } from './palette'
export function TopRatedCountChart({ games }: { games: Game[] }) {
const t = useT()
const fmt = useFormat()
const data = useMemo(() => topByRatingCount(games, 10), [games])
return (
<ChartCard title={t('charts.topRatedCount.title')} description={t('charts.topRatedCount.desc')}>
<ResponsiveContainer width="100%" height="100%">
<BarChart data={data} layout="vertical" margin={{ left: 20 }}>
<CartesianGrid horizontal={false} strokeDasharray="3 3" />
<XAxis type="number" allowDecimals={false} />
<XAxis type="number" allowDecimals={false} tickFormatter={fmt.number} />
<YAxis
dataKey="key"
type="category"
width={140}
interval={0}
tick={{ fontSize: 11 }}
tickFormatter={(v: string) => (v.length > 20 ? `${v.slice(0, 19)}…` : v)}
tickFormatter={truncateLabel(20)}
/>
<Tooltip {...TOOLTIP_BASE} cursor={BAR_CURSOR} content={<ChartTooltipContent />} />
<Bar dataKey="count" name={t('charts.series.ratings')} fill={PALETTE[3]} radius={[0, 4, 4, 0]} />
+18
View File
@@ -203,6 +203,24 @@
outline: none;
}
/* Phones: chart text at caption size. Legends otherwise take the 16px body size
(three rows under a pie) and axes their 10–16px props. Recharts reads both
sizes back from the DOM (legend box, getComputedStyle on a tick), so the
layout follows these rules. */
@media (width < 48rem) {
.recharts-legend-wrapper {
font-size: 12px;
line-height: 1.5;
}
.recharts-legend-item .recharts-surface {
width: 10px;
height: 10px;
}
.recharts-cartesian-axis-tick-value {
font-size: 11px;
}
}
/* index.html's static fallback shows only if the app hasn't started after a moment. */
[data-static-fallback] {
animation: static-fallback 0s 1.5s both;
+15
View File
@@ -0,0 +1,15 @@
import { describe, expect, it } from 'vitest'
import { reasonKey } from './deleted-reason'
describe('reasonKey', () => {
it('maps the pipeline reasons (scripts/refresh.py) to their labels', () => {
expect(reasonKey('Game page no longer exists (HTTP 404)')).toBe('deleted.reason.gone')
expect(reasonKey('Game page no longer exists (HTTP 410)')).toBe('deleted.reason.gone')
expect(reasonKey('Game became paid')).toBe('deleted.reason.paid')
expect(reasonKey('Game page is password-protected')).toBe('deleted.reason.private')
})
it('leaves any other reason to be shown as written', () => {
expect(reasonKey('Removed at the creator’s request')).toBeNull()
})
})
+9
View File
@@ -0,0 +1,9 @@
import type { MessageKey } from '@/lib/i18n'
/** The pipeline's standard removal reasons get a translated label; anything else is shown as written. */
export function reasonKey(reason: string): MessageKey | null {
if (/no longer exists|HTTP 4(?:04|10)/i.test(reason)) return 'deleted.reason.gone'
if (/became paid/i.test(reason)) return 'deleted.reason.paid'
if (/password-protected/i.test(reason)) return 'deleted.reason.private'
return null
}
+1 -1
View File
@@ -106,7 +106,7 @@ export const en = {
"charts.kpi.online": "Online (HTML5)",
"charts.kpi.totalGames": "Total games",
"charts.languages.title": "Top 10 Languages",
"charts.madeWith.desc": "Primary engine per game (made_with[0])",
"charts.madeWith.desc": "Primary engine per game",
"charts.madeWith.title": "Game Engines",
"charts.onlineOffline.desc": "HTML5 means playable in the browser",
"charts.onlineOffline.offline": "Offline only",
+1 -1
View File
@@ -108,7 +108,7 @@ export const vi: Record<MessageKey, string> = {
"charts.kpi.online": "Online (HTML5)",
"charts.kpi.totalGames": "Tổng số game",
"charts.languages.title": "Top 10 ngôn ngữ",
"charts.madeWith.desc": "Engine chính của mỗi game (made_with[0])",
"charts.madeWith.desc": "Engine chính của mỗi game",
"charts.madeWith.title": "Game engine",
"charts.onlineOffline.desc": "HTML5 nghĩa là chơi được ngay trên trình duyệt",
"charts.onlineOffline.offline": "Chỉ offline",
+19 -5
View File
@@ -37,6 +37,12 @@ function Heading({ children }: { children?: ReactNode }) {
const PAGE = 'mx-auto max-w-[1440px] px-4 pt-6 pb-12 sm:px-8 md:pt-7'
// Phones: one full-width row of equal tabs. A wrapping row overflowed the
// fixed-height bar with the Vietnamese labels; the labels never shrink below
// their text, and on the narrowest screens the bar scrolls instead.
const TABS_LIST = 'max-md:flex max-md:h-11 max-md:w-full max-md:overflow-x-auto max-md:scrollbar-hide'
const TAB = 'max-md:h-full max-md:flex-1 max-md:px-1 max-md:text-[13px]'
export default function Charts() {
const t = useT()
const fmt = useFormat()
@@ -78,11 +84,19 @@ export default function Charts() {
</Heading>
<Tabs defaultValue="overview">
<TabsList className="flex-wrap">
<TabsTrigger value="overview">{t('charts.tabs.overview')}</TabsTrigger>
<TabsTrigger value="reach">{t('charts.tabs.reach')}</TabsTrigger>
<TabsTrigger value="quality">{t('charts.tabs.quality')}</TabsTrigger>
<TabsTrigger value="discovery">{t('charts.tabs.discovery')}</TabsTrigger>
<TabsList className={TABS_LIST}>
<TabsTrigger value="overview" className={TAB}>
{t('charts.tabs.overview')}
</TabsTrigger>
<TabsTrigger value="reach" className={TAB}>
{t('charts.tabs.reach')}
</TabsTrigger>
<TabsTrigger value="quality" className={TAB}>
{t('charts.tabs.quality')}
</TabsTrigger>
<TabsTrigger value="discovery" className={TAB}>
{t('charts.tabs.discovery')}
</TabsTrigger>
</TabsList>
<TabsContent value="overview" className="space-y-4">
+2 -9
View File
@@ -5,17 +5,10 @@ import { RouteError } from '@/components/route-error'
import { Skeleton } from '@/components/ui/skeleton'
import { useDeletedGames } from '@/hooks/useGames'
import { useDocumentTitle } from '@/hooks/useDocumentTitle'
import { reasonKey } from '@/lib/deleted-reason'
import { useFormat } from '@/lib/format'
import { fold } from '@/lib/game-filters'
import { useT, type MessageKey } from '@/lib/i18n'
/** The pipeline's standard reasons get a translated label; anything else is shown as written. */
function reasonKey(reason: string): MessageKey | null {
if (/no longer exists|HTTP 4(?:04|10)/i.test(reason)) return 'deleted.reason.gone'
if (/became paid/i.test(reason)) return 'deleted.reason.paid'
if (/password-protected/i.test(reason)) return 'deleted.reason.private'
return null
}
import { useT } from '@/lib/i18n'
export default function Removed() {
const t = useT()