Skip to content

Open-source gym & body-weight tracker, now in the App Store (iPhone + Apple Watch) and as an Android APK. Plan routines, log workouts, see which muscles are trained, import from Strong/Hevy/FitNotes. Self-host it or use it on the phone alone.

fix(charts): add the year from the 13th month tick, not by elapsed ms

lodepav89bc0aa1f267
diff --git a/frontend/src/components/LineChart.jsx b/frontend/src/components/LineChart.jsx
index 2e9096875..82e402960 100644
--- a/frontend/src/components/LineChart.jsx
+++ b/frontend/src/components/LineChart.jsx
@@ -95,9 +95,10 @@ export default function LineChart({ points, h = 150, unit = '', color = 'var(--a
ticks.push(tk)
}
if (ticks.length === 1) ticks[0] = { ...ticks[0], t: (t0 + t1) / 2, anchor: 'middle' }
- } else if (t1 - t0 > 366 * 864e5) {
- // Over more than a year a month name comes round again ("Apr | Jul | Oct | Jan | Apr"), so
- // each month says its year: "Apr '25".
+ } else if (ticks.length >= 13) {
+ // Twelve month names come round again from the thirteenth month on ("Apr | … | Mar | Apr"),
+ // so each month then says its year: "Apr '25". Counted in months, not milliseconds, so a span
+ // of exactly a year and a day, or one across a clock change, is caught as well.
for (const tk of ticks) tk.txt += " '" + String(new Date(tk.t).getFullYear()).slice(2)
}
const every = Math.max(1, Math.ceil(ticks.length / 7))
diff --git a/frontend/src/components/LineChart.test.jsx b/frontend/src/components/LineChart.test.jsx
index a3e82256a..3f0b28874 100644
--- a/frontend/src/components/LineChart.test.jsx
+++ b/frontend/src/components/LineChart.test.jsx
@@ -139,4 +139,11 @@ describe('LineChart x axis', () => {
expect(new Set(long).size).toBe(long.length)
expect(xLabels([at(2025, 10, 20, 12, 50), at(2026, 9, 30, 12, 60)]).every(l => !l.includes("'"))).toBe(true)
})
+
+ it('gives the months their year at exactly 366 days, where Apr comes round again', () => {
+ const edge = xLabels([at(2025, 3, 31, 0, 50), at(2026, 4, 1, 0, 60)])
+ expect(edge[0]).toBe("Apr '25")
+ expect(edge.at(-1)).toBe("Apr '26")
+ expect(new Set(edge).size).toBe(edge.length)
+ })
})