pace: factor out `drawSplit()`

master
Rob Pilling 2024-10-10 18:08:53 +01:00
parent 25b16a1738
commit 4493b343bd
1 changed files with 13 additions and 10 deletions

View File

@ -104,13 +104,10 @@ const drawSplits = () => {
g.setFont("6x8", 2).setFontAlign(-1, -1);
let i = 0;
let totalTime = 0;
for(; ; i++) {
const split = splits[i + splitOffset];
if (split == null) break;
totalTime += split;
const y = Bangle.appRect.y + i * (barSize + barSpacing) + barSpacing / 2;
if (y > h) break;
@ -118,16 +115,22 @@ const drawSplits = () => {
g.setColor("#00f").fillRect(0, y, size, y + barSize);
const splitPace = calculatePace(split, 1); // Pace per km
g.setColor("#fff").drawString(`${i + 1 + splitOffset} @ ${splitPace.toFixed(2)}`, 0, y);
drawSplit(i, y, splitPace);
}
const pace = exs.stats.pacec.getString();
const splitTime = exs.state.duration - totalTime;
g.setColor("#fff").drawString(
`${i + 1 + splitOffset} @ ${pace} (${(splitTime / 1000).toFixed(2)})`,
const y = Bangle.appRect.y + i * (barSize + barSpacing) + barSpacing / 2;
drawSplit(i, y, pace);
};
const drawSplit = (i: number, y: number, pace: number | string) => {
g
.setColor("#fff")
.drawString(
`${i + 1 + splitOffset} ${typeof pace === "number" ? pace.toFixed(2) : pace}`,
0,
Bangle.appRect.y + i * (barSize + barSpacing) + barSpacing / 2,
y
);
};