diff --git a/src/pages/workouts/components/LineWithLineChart.ts b/src/pages/workouts/components/LineWithLineChart.ts index e620d79..376e89d 100644 --- a/src/pages/workouts/components/LineWithLineChart.ts +++ b/src/pages/workouts/components/LineWithLineChart.ts @@ -35,17 +35,21 @@ class LineWithLineController extends LineController { const ctx = this.chart.ctx; const topY = this.chart.scales.linearAxis.top; const bottomY = this.chart.scales.linearAxis.bottom; - const zoom = - (this.chart.chartArea.right - this.chart.chartArea.left) / - this.chart.config.data!.labels!.length; const xVertical = this.getMapX(); + // The X axis is a time scale with irregular intervals (pauses), so the + // pixel position must come from Chart.js itself, not from index * zoom. + const meta = this.chart.getDatasetMeta(0); for (const i in xVertical) { - // console.log("xVertical", xVertical) - // console.log("ctx", this.chart) + const idx = Number(i); + const point = meta.data[idx] as { x?: number } | undefined; + const x = point?.x ?? NaN; + if (!Number.isFinite(x)) { + continue; + } ctx.save(); ctx.beginPath(); - ctx.moveTo(xVertical[i] * zoom, topY); - ctx.lineTo(xVertical[i] * zoom, bottomY); + ctx.moveTo(x, topY); + ctx.lineTo(x, bottomY); ctx.lineWidth = 3; ctx.strokeStyle = "#666"; ctx.stroke();