From 8756c70d2d909c92ff0401e71d8fa49e508e1a4c Mon Sep 17 00:00:00 2001 From: Selina Date: Wed, 26 Nov 2025 18:23:28 +0800 Subject: [PATCH 1/3] Add actual date in tooltip for reviews graph --- CONTRIBUTORS | 1 + ts/routes/graphs/reviews.ts | 22 +++++++++++++++++++--- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/CONTRIBUTORS b/CONTRIBUTORS index 2ec25da2d..729ff83ff 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -255,6 +255,7 @@ Ranjit Odedra Eltaurus jariji Francisco Esteva +Selina ******************** diff --git a/ts/routes/graphs/reviews.ts b/ts/routes/graphs/reviews.ts index ed0e07f8c..1f382c24b 100644 --- a/ts/routes/graphs/reviews.ts +++ b/ts/routes/graphs/reviews.ts @@ -7,9 +7,10 @@ import type { GraphsResponse } from "@generated/anki/stats_pb"; import * as tr from "@generated/ftl"; -import { localizedNumber } from "@tslib/i18n"; +import { localizedDate, localizedNumber } from "@tslib/i18n"; import { dayLabel, timeSpan, TimespanUnit } from "@tslib/time"; import type { Bin, ScaleSequential } from "d3"; +import { timeDay, timeHour } from "d3"; import { area, axisBottom, @@ -47,12 +48,17 @@ export interface GraphData { // indexed by day, where day is relative to today reviewCount: Map; reviewTime: Map; + rolloverHour: number; } type BinType = Bin, number>; export function gatherData(data: GraphsResponse): GraphData { - return { reviewCount: numericMap(data.reviews!.count), reviewTime: numericMap(data.reviews!.time) }; + return { + reviewCount: numericMap(data.reviews!.count), + reviewTime: numericMap(data.reviews!.time), + rolloverHour: data.rolloverHour, + }; } enum BinIndex { @@ -212,10 +218,20 @@ export function renderReviews( } function tooltipText(d: BinType, cumulative: number): string { + const now = new Date(); + let date = timeDay.offset(now, Math.floor(d.x0!)); + date = timeHour.offset(date, -sourceData.rolloverHour); + const dateStr = localizedDate(date, { + weekday: "long", + year: "numeric", + month: "long", + day: "numeric", + }); const day = dayLabel(d.x0!, d.x1!); const totals = totalsForBin(d); const dayTotal = valueLabel(sum(totals)); - let buf = ``; + let buf = + `
${day}${dayTotal}
`; const lines: [BinIndex | null, string][] = [ [BinIndex.Filtered, tr.statisticsCountsFilteredCards()], [BinIndex.Learn, tr.statisticsCountsLearningCards()], From 4134c3708bc5e3e309c43f71c21c543401ac8c47 Mon Sep 17 00:00:00 2001 From: Selina Date: Wed, 26 Nov 2025 19:19:46 +0800 Subject: [PATCH 2/3] Fix range date display for year graph --- ts/routes/graphs/reviews.ts | 39 +++++++++++++++++++++++++++++-------- 1 file changed, 31 insertions(+), 8 deletions(-) diff --git a/ts/routes/graphs/reviews.ts b/ts/routes/graphs/reviews.ts index 1f382c24b..4c83920a4 100644 --- a/ts/routes/graphs/reviews.ts +++ b/ts/routes/graphs/reviews.ts @@ -218,15 +218,38 @@ export function renderReviews( } function tooltipText(d: BinType, cumulative: number): string { + let dateStr: string; const now = new Date(); - let date = timeDay.offset(now, Math.floor(d.x0!)); - date = timeHour.offset(date, -sourceData.rolloverHour); - const dateStr = localizedDate(date, { - weekday: "long", - year: "numeric", - month: "long", - day: "numeric", - }); + const larger = Math.max(Math.abs(d.x0!), Math.abs(d.x1!)); + const smaller = Math.min(Math.abs(d.x0!), Math.abs(d.x1!)); + if (larger - smaller > 1) { + // range (year) + let startDate = timeDay.offset(now, Math.floor(d.x0!)); + startDate = timeHour.offset(startDate, -sourceData.rolloverHour); + let endDate = timeDay.offset(now, Math.floor(d.x1!) - 1); + endDate = timeHour.offset(endDate, -sourceData.rolloverHour); + const startDateStr = localizedDate(startDate, { + year: "numeric", + month: "short", + day: "numeric", + }); + const endDateStr = localizedDate(endDate, { + year: "numeric", + month: "short", + day: "numeric", + }); + dateStr = startDateStr + " - " + endDateStr; + } else { + // 1 month, 3 months + let date = timeDay.offset(now, Math.floor(d.x0!)); + date = timeHour.offset(date, -sourceData.rolloverHour); + dateStr = localizedDate(date, { + weekday: "long", + year: "numeric", + month: "long", + day: "numeric", + }); + } const day = dayLabel(d.x0!, d.x1!); const totals = totalsForBin(d); const dayTotal = valueLabel(sum(totals)); From c5b0c850f90c6e1db0c93deb962aebd48b2dbe33 Mon Sep 17 00:00:00 2001 From: Selina Date: Tue, 2 Dec 2025 18:27:52 +0800 Subject: [PATCH 3/3] Simplify date bin size check --- ts/routes/graphs/reviews.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/ts/routes/graphs/reviews.ts b/ts/routes/graphs/reviews.ts index 4c83920a4..87d449257 100644 --- a/ts/routes/graphs/reviews.ts +++ b/ts/routes/graphs/reviews.ts @@ -220,9 +220,7 @@ export function renderReviews( function tooltipText(d: BinType, cumulative: number): string { let dateStr: string; const now = new Date(); - const larger = Math.max(Math.abs(d.x0!), Math.abs(d.x1!)); - const smaller = Math.min(Math.abs(d.x0!), Math.abs(d.x1!)); - if (larger - smaller > 1) { + if (d.x1! - d.x0! > 1) { // range (year) let startDate = timeDay.offset(now, Math.floor(d.x0!)); startDate = timeHour.offset(startDate, -sourceData.rolloverHour);
${dateStr}
${day}${dayTotal}