using NEIntelligentControl2.Models.Datas; using OxyPlot; using OxyPlot.Axes; using OxyPlot.Series; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace NEIntelligentControl2.Models.AGC { /// /// AGC曲线模型 /// public class ViewModel : PlotModel { private List _ActPower; // 实发有功数据 public List ActPower { get => _ActPower; } private List _PowerSet;// 有功设定数据 public List PowerSet { get => _PowerSet; } private List _IdeaPower;// 理论功率数据 public List IdeaPower { get => _IdeaPower; } private LineSeries ls1; private LineSeries ls2; private LineSeries ls3; public DateTimeAxis AxisX; public ViewModel() { this.PlotAreaBorderThickness = new OxyThickness(0); this.Legends.Add(new OxyPlot.Legends.Legend() { Key = "power", LegendPosition = OxyPlot.Legends.LegendPosition.BottomCenter, LegendPlacement = OxyPlot.Legends.LegendPlacement.Outside, LegendOrientation = OxyPlot.Legends.LegendOrientation.Horizontal, LegendTextColor = OxyColor.Parse("#FF000000"), //LegendFontSize = 10 }); var dta2 = new LinearAxis() { Position = AxisPosition.Left }; dta2.MinorTicklineColor = OxyColors.Transparent; dta2.AxislineColor = OxyColors.Transparent; dta2.TickStyle = TickStyle.None; //dta2.MajorStep = 20; dta2.IntervalLength = 20; dta2.IsZoomEnabled = false; dta2.IsPanEnabled = false; dta2.TextColor = OxyColor.Parse("#FF000000"); this.Axes.Add(dta2); AxisX = new DateTimeAxis { Position = AxisPosition.Bottom, StringFormat = "HH:mm" }; AxisX.MinorTicklineColor = OxyColors.Transparent; AxisX.TickStyle = TickStyle.None; AxisX.IsZoomEnabled = false; AxisX.IsPanEnabled = false; //_AxisX.IntervalLength = 45; AxisX.TextColor = OxyColor.Parse("#FF000000"); this.Axes.Add(AxisX); ls1 = new LineSeries() { Title = "实发有功", Color = OxyColor.Parse("#FFF4A460"), StrokeThickness = 1.5 }; ls1.LegendKey = "power"; ls2 = new LineSeries() { Title = "有功设定", Color = OxyColor.Parse("#FF31B9FB"), StrokeThickness = 1.5 }; ls2.LegendKey = "power"; ls3 = new LineSeries() { Title = "理论功率", Color = OxyColor.Parse("#FFED937F"), StrokeThickness = 1.5 }; ls3.LegendKey = "power"; Series.Add(ls1); Series.Add(ls2); Series.Add(ls3); } /// /// AGC曲线模型 /// /// 实发有功 /// 有功设定 public ViewModel(List ap, List ps) : this() { _PowerSet = ps; AddData(ls2, ps); _ActPower = ap; AddData(ls1, ap); } internal void SetValueNow(TagInfo arg1, List arg2) { if (arg2 == null || arg2.Count < 2) return; if (arg1.Type == TagType.PowerSet) { _PowerSet = arg2; AddData(ls2, arg2); } else if(arg1.Type == TagType.ActualPower) { _ActPower = arg2; AddData(ls1, arg2); } else { _IdeaPower = arg2; AddData(ls3, arg2); } var dt = DateTime.Now; AxisX.AbsoluteMinimum = DateTimeAxis.ToDouble(dt.AddHours(-8)); AxisX.AbsoluteMaximum = DateTimeAxis.ToDouble(dt); } internal void SetValue(TagInfo arg1, List arg2) { if (arg2 == null || arg2.Count < 2) return; if (arg1.Type == TagType.PowerSet) { _PowerSet = arg2; AddData(ls2, arg2); } else if (arg1.Type == TagType.ActualPower) { _ActPower = arg2; AddData(ls1, arg2); } else { _IdeaPower = arg2; AddData(ls3, arg2); } var dts = arg2[0].Ts.GetLongDateTime(); var dte = arg2[arg2.Count - 1].Ts.GetLongDateTime(); AxisX.AbsoluteMinimum = DateTimeAxis.ToDouble(dts); AxisX.AbsoluteMaximum = DateTimeAxis.ToDouble(dte); } private void AddData(LineSeries ls, List vs) { ls.Points.Clear(); if (vs == null) return; foreach(var v in vs) { DataPoint dp = new DataPoint(DateTimeAxis.ToDouble(v.Ts.GetLongDateTime()), Math.Round(v.Value, 2)); ls.Points.Add(dp); } } } }