From 084df77547faf37754cab4cb5c2a58de0fde220f Mon Sep 17 00:00:00 2001 From: streamcode9 Date: Fri, 27 Feb 2026 21:44:58 +0100 Subject: [PATCH] fix: resolve d3-raw cumulative x-axis misalignment by snapshotting cycling data source Snapshot original NY and SF values at initialization instead of using shared-reference originalData. This prevents mutations from shift()/push() in addDataPoint from degrading the values array during long-running cycling, which caused asymmetric value corruptions between series and cumulative temporal drift appearance. --- samples/competitors/d3-raw/index.ts | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/samples/competitors/d3-raw/index.ts b/samples/competitors/d3-raw/index.ts index aed7a562..dc02e76d 100644 --- a/samples/competitors/d3-raw/index.ts +++ b/samples/competitors/d3-raw/index.ts @@ -126,15 +126,18 @@ async function initChart(): Promise { clearInterval(intervalId); } let j = 0; - const originalData = { series, dates }; + // Snapshot the original values so the cycling source is immune to addDataPoint mutations + const originalNyValues = [...series[0]!.values]; + const originalSfValues = [...series[1]!.values]; + const originalLength = dates.length; intervalId = setInterval(function () { - const dataIndex = j % originalData.dates.length; + const dataIndex = j % originalLength; const newDate = new Date( dates[dates.length - 1]!.getTime() + (dates[1]!.getTime() - dates[0]!.getTime()), ); - const newNyValue = originalData.series[0]!.values[dataIndex]!; - const newSfValue = originalData.series[1]!.values[dataIndex]!; + const newNyValue = originalNyValues[dataIndex]!; + const newSfValue = originalSfValues[dataIndex]!; // Add new data point to each series chartControls.addDataPoint(newDate, [newNyValue, newSfValue]);