Skip to content

Commit 01c1879

Browse files
committed
optimized graph drawing
1 parent 050068b commit 01c1879

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

SmartFilterViewer/MainWindow.xaml.cs

+18-2
Original file line numberDiff line numberDiff line change
@@ -174,11 +174,22 @@ private void ProcessTimerTick(object sender, ElapsedEventArgs e)
174174

175175
private void DrawDataToGraph()
176176
{
177+
var startTime = RelativeToDataTime(graphOffset);
178+
var endTime = RelativeToDataTime(graphOffset + 1/graphZoomfactor);
179+
177180
foreach (var info in ValidSensorInfos)
178181
{
182+
var startIdx = (int)Math.Floor(info.DataList.FindLerpIndex(startTime));
183+
var endIdx = (int)Math.Ceiling(info.DataList.FindLerpIndex(endTime));
184+
185+
startIdx = Math.Max(startIdx, 0);
186+
endIdx = Math.Min(endIdx, info.DataList.Count-1);
187+
179188
var points = new StylusPointCollection();
180-
foreach (var dataPoint in info.DataList)
189+
for (int i = startIdx; i <= endIdx; i++)
181190
{
191+
SensorData dataPoint = info.DataList[i];
192+
182193
var xFactor = (dataPoint.DateTime - dataStartTime).TotalMilliseconds / dataTimeInMillisec;
183194
var yFactor = 1 - GetValue(dataPoint) / maxValue;
184195

@@ -238,9 +249,14 @@ private double GetValue(SensorData data)
238249
return (double)propInfo.GetValue(data);
239250
}
240251

252+
private DateTime RelativeToDataTime(double relTime)
253+
{
254+
return dataStartTime + TimeSpan.FromMilliseconds(dataTimeInMillisec * relTime);
255+
}
256+
241257
private void JumpToRelPos(double pos)
242258
{
243-
currentDataTime = dataStartTime + TimeSpan.FromMilliseconds(dataTimeInMillisec * pos);
259+
currentDataTime = RelativeToDataTime(pos);
244260
DrawTimeStroke();
245261
}
246262

0 commit comments

Comments
 (0)