blob: 7e51e2c5245589fe0c5f66f44313eedbda8a8c72 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
|
using Newtonsoft.Json;
using RealTimeGraphX.DataPoints;
using RealTimeGraphX.WPF;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Media;
using Tango.BL.Entities;
using Tango.BL.Enumerations;
using Tango.Core.Commands;
using Tango.FSE.Common.Diagnostics;
namespace Tango.FSE.Diagnostics.Project.Widgets.RealTimeGraph
{
public abstract class RealTimeGraphWidgetBase<T> : DiagnosticsConfigurableWidget<T>, ISupportsComponentSelection<TechMonitors> where T : RealTimeGraphWidgetSettings, new()
{
public TechMonitors Monitor { get; set; }
private TechMonitor _techMonitor;
[JsonIgnore]
public TechMonitor TechMonitor
{
get { return _techMonitor; }
set { _techMonitor = value; RaisePropertyChangedAuto(); RaisePropertyChanged(nameof(DisplayName)); }
}
[JsonIgnore]
public override string DisplayName
{
get
{
return this.TechMonitor != null ? this.TechMonitor.Description : String.Empty;
}
}
[JsonIgnore]
public WpfGraphController<TimeSpanDataPoint, DoubleDataPoint> Controller { get; set; }
[JsonIgnore]
public RelayCommand ClearCommand { get; set; }
public RealTimeGraphWidgetBase()
{
Controller = new WpfGraphController<TimeSpanDataPoint, DoubleDataPoint>();
Controller.Range.MinimumY = Settings.Min;
Controller.Range.MaximumY = Settings.Max;
Controller.Range.AutoY = Settings.AutoRange;
Controller.Range.MaximumX = Settings.Duration;
Controller.RefreshRate = TimeSpan.FromMilliseconds(300);
Controller.DisableRendering = true;
Controller.DataSeriesCollection.Add(new WpfGraphDataSeries()
{
Stroke = Settings.Color
});
ClearCommand = new RelayCommand(Clear);
}
public void Clear()
{
Controller?.Clear();
}
public override async Task Init()
{
Clear();
int monitor = (int)Monitor;
TechMonitor = await Services.TechComponentsService.Monitors.FindOne(x => x.Code == monitor);
}
public override FrameworkElement GetView()
{
return new RealTimeGraphWidgetView();
}
protected override void OnVisibleChanged(bool isVisible)
{
base.OnVisibleChanged(isVisible);
Controller.DisableRendering = !isVisible;
}
protected override void OnSettingsChanged()
{
base.OnSettingsChanged();
if (Controller != null)
{
Controller.Range.MinimumY = Settings.Min;
Controller.Range.MaximumY = Settings.Max;
Controller.Range.AutoY = Settings.AutoRange;
Controller.Range.MaximumX = Settings.Duration;
if (Controller.DataSeriesCollection.Count > 0)
{
Controller.DataSeriesCollection[0].Stroke = Settings.Color;
}
}
}
public override void OnDiagnosticsData(DiagnosticsPackage package)
{
var points = package.GetMonitorArray(Monitor);
if (points.Count > 0)
{
List<TimeSpanDataPoint> dates = new List<TimeSpanDataPoint>();
var dPoints = points.Select(x => new DoubleDataPoint(x)).ToList();
DateTime dayStart = new DateTime(package.Frame.DiagnosticsTime.Year, package.Frame.DiagnosticsTime.Month, package.Frame.DiagnosticsTime.Day);
TimeSpan offset = package.Frame.DiagnosticsTime - dayStart;
for (int i = 0; i < points.Count; i++)
{
dates.Add(
offset
.Add(TimeSpan.FromMilliseconds(-package.Frame.Delta.TotalMilliseconds))
.Add(TimeSpan.FromMilliseconds(package.Frame.Delta.TotalMilliseconds * (i / (double)points.Count))));
}
Controller.PushData(dates, dPoints);
}
}
#region Component Selection
public virtual List<DiagnosticsWidgetComponent<TechMonitors>> Components
{
get
{
return Services.TechComponentsService.Monitors.FindAll().Result.Where(x => !x.MultiChannel).Select(x => new DiagnosticsWidgetComponent<TechMonitors>()
{
DisplayName = x.Description,
Object = (TechMonitors)x.Code,
}).OrderByAlphaNumeric(x => x.DisplayName).ToList();
}
}
public TechMonitors SelectedComponent
{
get
{
return Monitor;
}
set
{
if (Monitor != value)
{
Monitor = value;
InitAsync();
}
}
}
public bool EnableComponentSelection { get; set; }
#endregion
}
}
|