From 7d4fdcd8aea4f5ed82c033e1fdf5cb6788c74ec2 Mon Sep 17 00:00:00 2001 From: Julian Tabel Date: Sat, 7 Feb 2026 22:00:11 +0100 Subject: [PATCH] Display bar chart labels inside bars with adaptive text color Move game/type labels from a fixed-width column into the bar itself so long names like "Pokemon Brilliant Diamond" aren't truncated. Compute luminance from the bar's hex color to pick dark or light text, with a subtle text shadow for readability at bar/track boundaries. Co-Authored-By: Claude Opus 4.6 --- frontend/src/pages/Stats.tsx | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/frontend/src/pages/Stats.tsx b/frontend/src/pages/Stats.tsx index 1178d93..e78c736 100644 --- a/frontend/src/pages/Stats.tsx +++ b/frontend/src/pages/Stats.tsx @@ -96,6 +96,13 @@ function PokemonList({ ) } +function hexLuminance(hex: string): number { + const r = parseInt(hex.slice(1, 3), 16) + const g = parseInt(hex.slice(3, 5), 16) + const b = parseInt(hex.slice(5, 7), 16) + return (0.299 * r + 0.587 * g + 0.114 * b) / 255 +} + function HorizontalBar({ label, value, @@ -110,12 +117,10 @@ function HorizontalBar({ colorHex?: string }) { const width = max > 0 ? (value / max) * 100 : 0 + const isLight = colorHex ? hexLuminance(colorHex) > 0.55 : false return (
- - {label} - -
+
+ + {label} +
{value}