From e054e13a5918cc9db523d649a3ccb98533de3ec6 Mon Sep 17 00:00:00 2001 From: lobo Date: Sun, 4 Oct 2026 10:43:02 +0200 Subject: [PATCH] feat(stats): add chart form selection and pie, donut, line charts Tag rows with 0 games are no longer clickable. --- public/i18n/de.json | 10 ++ public/i18n/en.json | 10 ++ src/components/stats/ChartPicker.jsx | 25 +++ src/components/stats/FinishedStats.jsx | 31 ++-- src/components/stats/PileTrend.jsx | 22 ++- src/components/stats/PlatformStats.jsx | 18 ++- src/components/stats/SliceChart.jsx | 76 +++++++++ src/components/stats/StatsSection.jsx | 16 +- src/components/stats/TasteStats.jsx | 46 ++++-- src/components/stats/TrendStats.jsx | 12 +- src/components/stats/YearLine.jsx | 48 ++++++ src/components/stats/statGroupTile.jsx | 12 +- src/pages/Dashboard.jsx | 2 +- src/pages/Dashboard.test.jsx | 15 ++ src/pages/PublicProfilePage.jsx | 2 +- src/pages/PublicProfilePage.test.jsx | 67 ++++++++ src/pages/StatsPage.jsx | 34 +++- src/pages/StatsPage.test.jsx | 215 ++++++++++++++++++++++++- src/utils/statCharts.js | 114 +++++++++++++ src/utils/statCharts.test.js | 94 +++++++++++ src/utils/stats.js | 2 +- 21 files changed, 815 insertions(+), 56 deletions(-) create mode 100644 src/components/stats/ChartPicker.jsx create mode 100644 src/components/stats/SliceChart.jsx create mode 100644 src/components/stats/YearLine.jsx create mode 100644 src/utils/statCharts.js create mode 100644 src/utils/statCharts.test.js diff --git a/public/i18n/de.json b/public/i18n/de.json index 899be1b..e69a44e 100644 --- a/public/i18n/de.json +++ b/public/i18n/de.json @@ -560,6 +560,16 @@ "TURN_BASED_STRATEGY_TBS": "Rundenstrategie", "VISUAL_NOVEL": "Visual Novel" }, + "CHART": { + "LABEL": "Diagramm", + "BARS": "Balken", + "PIE": "Torte", + "DONUT": "Ring", + "LINE": "Linie", + "LIST": "Liste", + "OTHER": "Andere", + "OVERLAP": "Anteil der Spiele, ein Spiel kann mehrfach zählen" + }, "DRILL": { "SHOW_ALL": "Alle anzeigen", "LOAD_MORE": "Mehr laden", diff --git a/public/i18n/en.json b/public/i18n/en.json index 634686a..0b4ce0a 100644 --- a/public/i18n/en.json +++ b/public/i18n/en.json @@ -560,6 +560,16 @@ "TURN_BASED_STRATEGY_TBS": "Turn-based strategy", "VISUAL_NOVEL": "Visual novel" }, + "CHART": { + "LABEL": "Chart", + "BARS": "Bars", + "PIE": "Pie", + "DONUT": "Donut", + "LINE": "Line", + "LIST": "List", + "OTHER": "Other", + "OVERLAP": "Share of games, a game can count more than once" + }, "DRILL": { "SHOW_ALL": "Show all", "LOAD_MORE": "Load more", diff --git a/src/components/stats/ChartPicker.jsx b/src/components/stats/ChartPicker.jsx new file mode 100644 index 0000000..ed55bc4 --- /dev/null +++ b/src/components/stats/ChartPicker.jsx @@ -0,0 +1,25 @@ +import {useTranslation} from 'react-i18next'; + +import {Button} from '@/components/ui/button'; +import {STAT_CHARTS} from '../../utils/statCharts.js'; + +/** + * The chart forms of a stat group as buttons. + * + * @param value the shown form + * @param onChange `(form)` + */ +export default function ChartPicker({group, value, onChange}) { + const {t} = useTranslation(); + return ( +
+ {STAT_CHARTS[group].map((form) => ( + + ))} +
+ ); +} diff --git a/src/components/stats/FinishedStats.jsx b/src/components/stats/FinishedStats.jsx index f75e11b..9969f8f 100644 --- a/src/components/stats/FinishedStats.jsx +++ b/src/components/stats/FinishedStats.jsx @@ -2,12 +2,15 @@ import {useTranslation} from 'react-i18next'; import {Flag} from 'lucide-react'; import StatsSection from './StatsSection.jsx'; +import ChartPicker from './ChartPicker.jsx'; +import YearLine from './YearLine.jsx'; import {DrillRow, StatCount, useStatDrill} from './StatDrill.jsx'; /** * @param onSelect `(year)`: the rows are buttons + * @param bars false: a plain list, without the bars */ -export function YearBars({perYear, onSelect}) { +export function YearBars({perYear, onSelect, bars = true}) { const max = Math.max(1, ...perYear.map((y) => y.games)); return (