Skip to content

Commit 4ba533b

Browse files
committed
Fix indexing issues in graph pages
1 parent 66aa598 commit 4ba533b

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

RasterPropMonitor/Handlers/JSIVariableGraph.cs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -244,11 +244,12 @@ public void Draw(Rect screenRect, double time)
244244

245245
for (int pointIndex = 0; pointIndex < pointCount; ++pointIndex)
246246
{
247-
var dataPoint = points[pointIndex];
248-
if (dataPoint.x > mintime)
249-
actualXY[pointIndex] = new Vector2(
250-
(float)JUtil.DualLerp(screenRect.xMin, screenRect.xMax, mintime, time, dataPoint.x),
251-
(float)JUtil.DualLerp(screenRect.yMin, screenRect.yMax, verticalSpan.x, verticalSpan.y, dataPoint.y));
247+
int sourcePointIndex = (nextPoint + pointIndex - pointCount + maxPoints) % maxPoints;
248+
249+
var dataPoint = points[sourcePointIndex];
250+
actualXY[pointIndex] = new Vector2(
251+
(float)JUtil.DualLerp(screenRect.xMin, screenRect.xMax, mintime, time, dataPoint.x),
252+
(float)JUtil.DualLerp(screenRect.yMin, screenRect.yMax, verticalSpan.x, verticalSpan.y, dataPoint.y));
252253
}
253254
DrawVector(actualXY, pointCount, lineColor);
254255
}
@@ -261,11 +262,15 @@ public void Update(double time)
261262
return;
262263
}
263264
points[nextPoint++] = new Vector2d(time, value);
264-
++pointCount;
265+
266+
if (pointCount < maxPoints)
267+
{
268+
++pointCount;
269+
}
270+
265271
if (nextPoint == maxPoints)
266272
{
267273
nextPoint = 0;
268-
pointCount = maxPoints;
269274
}
270275
}
271276

0 commit comments

Comments
 (0)