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
164
165
166
167
168
169
170
171
172
173
174
175
176
|
using RealTimeGraphEx.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Media;
namespace RealTimeGraphEx.DataSeries
{
public class DataYSeries : DependencyObject
{
#region Cross Thread Fields
internal Brush stroke;
internal Brush fill;
internal String name;
internal bool isVisible;
internal bool useFillandStroke;
internal double currentValue;
#endregion
public Brush Stroke
{
get { return (Brush)GetValue(StrokeProperty); }
set { SetValue(StrokeProperty, value); }
}
public static readonly DependencyProperty StrokeProperty =
DependencyProperty.Register("Stroke", typeof(Brush), typeof(DataYSeries), new PropertyMetadata(null, new PropertyChangedCallback(SetCrossThreadFields)));
public Brush Fill
{
get { return (Brush)GetValue(FillProperty); }
set { SetValue(FillProperty, value); }
}
public static readonly DependencyProperty FillProperty =
DependencyProperty.Register("Fill", typeof(Brush), typeof(DataYSeries), new PropertyMetadata(null, new PropertyChangedCallback(SetCrossThreadFields)));
public String Name
{
get { return (String)GetValue(NameProperty); }
set { SetValue(NameProperty, value); }
}
public static readonly DependencyProperty NameProperty =
DependencyProperty.Register("Name", typeof(String), typeof(DataYSeries), new PropertyMetadata(null, new PropertyChangedCallback(SetCrossThreadFields)));
public double CurrentValue
{
get { return (double)GetValue(CurrentValueProperty); }
set { SetValue(CurrentValueProperty, value); }
}
public static readonly DependencyProperty CurrentValueProperty =
DependencyProperty.Register("CurrentValue", typeof(double), typeof(DataYSeries), new PropertyMetadata(0.0,new PropertyChangedCallback(OnCurrentValueChanged)));
private static void OnCurrentValueChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
var control = d as DataYSeries;
control.currentValue = control.CurrentValue;
}
public bool IsVisible
{
get { return (bool)GetValue(IsVisibleProperty); }
set { SetValue(IsVisibleProperty, value); }
}
public static readonly DependencyProperty IsVisibleProperty =
DependencyProperty.Register("IsVisible", typeof(bool), typeof(DataYSeries), new PropertyMetadata(true,new PropertyChangedCallback(SetCrossThreadFields)));
public bool UseFillAndStroke
{
get { return (bool)GetValue(UseFillAndStrokeProperty); }
set { SetValue(UseFillAndStrokeProperty, value); }
}
public static readonly DependencyProperty UseFillAndStrokeProperty =
DependencyProperty.Register("UseFillAndStroke", typeof(bool), typeof(DataYSeries), new PropertyMetadata(false));
private static void SetCrossThreadFields(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
(d as DataYSeries).OnSetCrossThreadFields();
}
internal ConcurrentpointsList Points { get; private set; }
public DataYSeries()
{
Points = new ConcurrentpointsList();
}
internal void ClearPoints()
{
Points.Clear();
SetCurrentValue(0);
}
internal void PushData(List<double> values)
{
if (values.Count == 0) return;
SetCurrentValue(values[values.Count - 1]);
Points.AddRange(values);
}
internal void PushData(double[] values)
{
if (values.Length == 0) return;
SetCurrentValue(values[values.Length - 1]);
Points.AddRange(values);
}
internal void PushData(double value)
{
SetCurrentValue(value);
Points.Add(value);
}
protected virtual void OnSetCrossThreadFields()
{
this.Dispatcher.Invoke(() =>
{
name = Name;
stroke = Stroke;
if (stroke != null) stroke.Freeze();
fill = Fill;
if (fill != null) fill.Freeze();
isVisible = IsVisible;
useFillandStroke = UseFillAndStroke;
}, System.Windows.Threading.DispatcherPriority.Send);
}
protected virtual void SetCurrentValue(double value)
{
this.Dispatcher.Invoke(() =>
{
CurrentValue = value;
}, System.Windows.Threading.DispatcherPriority.Send);
}
internal Color? GetStrokeColor()
{
SolidColorBrush strokeBrush = stroke as SolidColorBrush;
if (strokeBrush != null)
{
return strokeBrush.Color;
}
else
{
return null;
}
}
internal Color? GetFillColor()
{
SolidColorBrush fillBrush = fill as SolidColorBrush;
if (fillBrush != null)
{
return fillBrush.Color;
}
else
{
return null;
}
}
public List<double> GetPoints()
{
return Points.GetPoints();
}
}
}
|