fix(charts): name a folded point of steps as a daily average

A week or month point of a cumulative metric is the average daily total,
which keeps the axis comparable with the 7, 30 and 90 day tabs. The
caption said "Weekly avg", which reads as an average week's total. Steps,
energy, distance, flights and daylight now say "Daily avg per week" or
"per month" on the caption and in the tooltip, in all seven languages;
level metrics keep the plain average.
This commit is contained in:
Marc-André Bombeck committed 2026-09-27 14:08:50 +02:00
1 parent b45a668cf4
commit 7b5ea8b353
10 files changed
+87 -10

No files matched your search

@@ -0,0 +1,25 @@
import { describe, expect, it } from "vitest";
import { bucketCaptionKey } from "../bucket-caption";
describe("bucketCaptionKey", () => {
it("names a cumulative metric's folded point as a daily average", () => {
expect(bucketCaptionKey("week", ["ACTIVITY_STEPS"])).toBe(
"charts.bucketWeeklyDaily",
);
expect(bucketCaptionKey("month", ["ACTIVE_ENERGY_BURNED"])).toBe(
"charts.bucketMonthlyDaily",
);
});
it("keeps the plain average for a level", () => {
expect(bucketCaptionKey("week", ["WEIGHT"])).toBe("charts.bucketWeekly");
expect(
bucketCaptionKey("month", ["BLOOD_PRESSURE_SYS", "BLOOD_PRESSURE_DIA"]),
).toBe("charts.bucketMonthly");
});
it("says nothing for days", () => {
expect(bucketCaptionKey("day", ["ACTIVITY_STEPS"])).toBeNull();
});
});
+29
View File
@@ -0,0 +1,29 @@
/**
* What a chart point means once the visible range folds days into weeks or
* months, as the caption and the tooltip name it.
*
* Every point of a week or month is the average day of that bucket, on every
* read path (the day points the chart folds itself, and the rollup tier rows
* the server serves for the "All" range). For a level (weight, pulse) that is
* simply the week's or month's average. For a cumulative metric (steps,
* energy, distance) it is the average DAILY total, which keeps the axis
* comparable with the 7, 30 and 90 day tabs; calling it a "weekly average"
* read as an average week's total, a figure seven times larger.
*/
import type { MeasurementType } from "@/generated/prisma/client";
import { CUMULATIVE_HK_TYPES } from "@/lib/measurements/apple-health-mapping";
import type { ChartBucketType } from "@/lib/charts/bucket-time-series";
export function bucketCaptionKey(
bucket: ChartBucketType,
types: readonly string[],
): string | null {
if (bucket === "day") return null;
const daily =
types.length > 0 &&
types.every((type) => CUMULATIVE_HK_TYPES.has(type as MeasurementType));
if (bucket === "week") {
return daily ? "charts.bucketWeeklyDaily" : "charts.bucketWeekly";
}
return daily ? "charts.bucketMonthlyDaily" : "charts.bucketMonthly";
}