Improvements to fitness page

- Data now comes from a calendar
- Hovering in charts shows day info
- Optical enhancements to chart rendering
- Allow setting/showing goal weight
- Allow toggeling between absolute and zoomed in weight axis
This commit is contained in:
2026-09-27 09:31:01 +02:00
parent 4116a0c332
commit 189635d103
7 changed files with 365 additions and 189 deletions
+15 -4
View File
@@ -646,6 +646,20 @@ func calendarDayLines(from, to time.Time) map[string]calDayLines {
}
}
for key, w := range calendarWeights(s, from, to) {
lines := out[key]
lines.Weight = strings.ReplaceAll(w, ".", ",") + " kg"
out[key] = lines
}
return out
}
// calendarWeights reads the weight role for [from, to): one entry per day,
// keyed by "YYYY-MM-DD", holding the kg value with a '.' decimal separator.
// Events whose title is not a weight are skipped; several entries on one day:
// the last edited one wins.
func calendarWeights(s calendarSettings, from, to time.Time) map[string]string {
out := map[string]string{}
stamps := map[string]time.Time{}
for _, ev := range calendarOccurrences(calendarsDir, s.Weight, from, to) {
m := weightTitle.FindStringSubmatch(ev.Summary)
@@ -653,14 +667,11 @@ func calendarDayLines(from, to time.Time) map[string]calDayLines {
continue
}
key := ev.Start.Format("2006-01-02")
// Several entries on one day: the last edited one wins.
if prev, ok := stamps[key]; ok && ev.Stamp.Before(prev) {
continue
}
stamps[key] = ev.Stamp
lines := out[key]
lines.Weight = strings.ReplaceAll(m[1], ".", ",") + " kg"
out[key] = lines
out[key] = strings.ReplaceAll(m[1], ",", ".")
}
return out
}