static void DisplayMonitorPlot(ArduiPi_OLED.Wrapper wrapper, IMonitorDataSet ds,
short graphX0, short graphW, short graphY0, short graphH, bool normalize)
{
var pts = ds.Points.ToList();
if (ds.SizeMax != graphW) throw new Exception($"graph width must match dataset points max {graphW} != {ds.SizeMax}");
// baseline track
for (int i = graphX0; i < graphX0 + graphW; i += 1)
{
wrapper.DrawPixel((short)i, (short)(graphY0), 1);
}
var max = 1.0;
if (normalize)
{
foreach (var k in pts) max = Math.Max(max, k.Value);
}
for (int i = 0; i < pts.Count; ++i)
{
var pt = pts[i];
var f = pt.Value;
if (normalize) f = f / max;
var x1 = (short)(graphX0 + i);
var y1 = (short)(graphY0 - (f * graphH));
wrapper.DrawPixel(x1, y1, 1);
if (i > 0) // glue (x1,y1) with previous point (x0,y0)
{
var ptPrev = pts[i - 1];
var fPrev = ptPrev.Value;
if (normalize) fPrev = fPrev / max;
var x0 = (short)(graphX0 + i - 1);
var y0 = (short)(graphY0 - (fPrev * graphH));
wrapper.DrawLine(x0, y0, x1, y1, 1);
}
}
}