fix(workout): вертикальные линии на графике теперь по реальному времени
Gitea Actions Demo / build_and_push (push) Successful in 48s
Details
Gitea Actions Demo / build_and_push (push) Successful in 48s
Details
X серых линий брался как index * zoom (категорийная шкала), а ось X — time-шкала с нерегулярными интервалами (паузы/стоянки), поэтому линия смещалась от момента на карте. Теперь позиция берётся из chart.getDatasetMeta(0).data[idx].x (реальный пиксель time-шкалы Chart.js).
This commit is contained in:
parent
f008d4b595
commit
21054afa43
|
|
@ -35,17 +35,21 @@ class LineWithLineController extends LineController {
|
||||||
const ctx = this.chart.ctx;
|
const ctx = this.chart.ctx;
|
||||||
const topY = this.chart.scales.linearAxis.top;
|
const topY = this.chart.scales.linearAxis.top;
|
||||||
const bottomY = this.chart.scales.linearAxis.bottom;
|
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();
|
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) {
|
for (const i in xVertical) {
|
||||||
// console.log("xVertical", xVertical)
|
const idx = Number(i);
|
||||||
// console.log("ctx", this.chart)
|
const point = meta.data[idx] as { x?: number } | undefined;
|
||||||
|
const x = point?.x ?? NaN;
|
||||||
|
if (!Number.isFinite(x)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
ctx.save();
|
ctx.save();
|
||||||
ctx.beginPath();
|
ctx.beginPath();
|
||||||
ctx.moveTo(xVertical[i] * zoom, topY);
|
ctx.moveTo(x, topY);
|
||||||
ctx.lineTo(xVertical[i] * zoom, bottomY);
|
ctx.lineTo(x, bottomY);
|
||||||
ctx.lineWidth = 3;
|
ctx.lineWidth = 3;
|
||||||
ctx.strokeStyle = "#666";
|
ctx.strokeStyle = "#666";
|
||||||
ctx.stroke();
|
ctx.stroke();
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue