diff --git a/web/src/features/dailyTotals/DailyTotalsChart.tsx b/web/src/features/dailyTotals/DailyTotalsChart.tsx index 12dad56..ddc43bd 100644 --- a/web/src/features/dailyTotals/DailyTotalsChart.tsx +++ b/web/src/features/dailyTotals/DailyTotalsChart.tsx @@ -2,9 +2,9 @@ // A chart of the site's daily totals over a month, a year or all time: players with a recorded time on the // Players page, runs and world records per day on the Activity page. Hovering, tapping or arrow keys read a // point. Every range arrives with the page, so switching is instant. -import { useState } from "react"; +import { type ReactNode, useState } from "react"; import type { Schemas } from "@/api/client"; -import { Card, Label } from "@/ui/Card"; +import { Card } from "@/ui/Card"; import { LineChart } from "@/ui/LineChart"; import { Segmented } from "@/ui/Segmented"; @@ -78,13 +78,38 @@ export function DailyTotalsChart({ const rangeLabel = ranges.find((r) => r.value === range)?.label ?? ""; return ( - -
- + +
+ {shown && ( +

+ {data.kind === "players" ? ( + + {shown.y === 1 ? "player" : "players"} with a recorded time + + ) : ( + <> + {/* Each number in its line's color, so the line reads as the legend. */} + + {shown.y === 1 ? "run" : "runs"} + + + + {shown.y2 === 1 ? "world record" : "world records"} + + + )} + + + {when(shown.day, bucketDays)} + +

+ )} { @@ -94,32 +119,8 @@ export function DailyTotalsChart({ />
- {shown && ( -

- {data.kind === "players" ? ( - - ) : ( - <> - - - - )} - - {active === null ? "Latest: " : ""} - {when(shown.day, bucketDays)} - -

- )} - {points.length < 2 ? ( -

+

{current ? "Not enough days yet to draw a chart." : "This range couldn't be loaded."} @@ -127,6 +128,7 @@ export function DailyTotalsChart({ ) : (

axis.format(Math.round(value))} /> {/* Indented by the value labels' width, so the dates sit under the plot's ends. */} -
+
{date.format(new Date(points[0]?.day ?? 0))} {date.format(new Date(points.at(-1)?.day ?? 0))}
@@ -152,30 +154,27 @@ export function DailyTotalsChart({ ); } -function Amount({ +function Stat({ value, - unit, - swatch, + tone = "text-text", + children, }: { value: number; - unit: string; - /** The line's color, beside its number, when the chart has two. */ - swatch?: string; + tone?: string; + children: ReactNode; }) { return ( - - {swatch && ( - - )} - - {count.format(value)} - - - {value === 1 ? unit : `${unit}s`} - + + {count.format(value)}{" "} + {children} + + ); +} + +function Dot({ className }: { className?: string }) { + return ( + + ยท ); }