public GraphicValues(ISensor sensor, GraphicValues Prev = null) { if (sensor == null || sensor.Value == null || sensor.Max == null || sensor.Min == null || sensor.Hardware == null) { return; } Sensor = sensor; SensorType = sensor.SensorType; CurrentValue = (float)Math.Round(sensor.Value.Value, 2); Max = (float)Math.Round(sensor.Max.Value, 2); //Min = (float)Math.Round(sensor.Min.Value, 2); Min = 0; HardName = sensor.Name; if (Prev != null) { if (Prev.PrevValues.Count > MaxGraphValues) { Prev.PrevValues.RemoveAt(0); } PrevValues = Prev.PrevValues; PrevValues.Add(Prev.CurrentValue); Max = PrevValues.Max(); //Min = PrevValues.Min(); } else { PrevValues = new List <float> { }; PrevValues.Add(CurrentValue); } Points = GetPoints(MaxGraphPixels); GetUnitType(); }
public PointCollection GetPoints(int MaxPixelSpan) { if (PrevValues == null) { return(null); } if (Max == Min) { return(null); } var k = (Max - Min) / MaxPixelSpan; var Points = PrevValues.Select((x, index) => new Point(index * 10, (MaxPixelSpan - ((x - Min) / k)))).ToList(); var pc = new PointCollection(Points); pc.Freeze(); return(pc); }