-
Notifications
You must be signed in to change notification settings - Fork 55
/
Copy pathHelper.cs
164 lines (141 loc) · 5 KB
/
Helper.cs
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
using System.Diagnostics.CodeAnalysis;
using Plotly.Blazor.Traces;
using Plotly.Blazor.Traces.Scatter3DLib.ProjectionLib;
namespace Plotly.Blazor.Examples
{
public static class Helper
{
private static Random Random => new();
/// <summary>
/// Adds data to an IList.
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="list"></param>
/// <param name="items"></param>
public static void AddRange<T>(this IList<T> list, IEnumerable<T> items)
{
if (list == null)
{
throw new ArgumentNullException(nameof(list));
}
if (items == null)
{
throw new ArgumentNullException(nameof(items));
}
if (list is List<T> asList)
{
asList.AddRange(items);
}
else
{
foreach (var item in items)
{
list.Add(item);
}
}
}
/// <summary>
/// Generates the data.
/// </summary>
/// <param name="reference">The reference.</param>
/// <param name="startIndex">The start index.</param>
/// <param name="stopIndex">Index of the stop.</param>
/// <param name="method">The method.</param>
/// <returns>Scatter.</returns>
[SuppressMessage("Style", "IDE0060:Remove unused parameter", Justification = "<Pending>")]
public static Scatter GenerateData(this Scatter reference, int startIndex, int stopIndex,
GenerateMethod method = GenerateMethod.Sin)
{
(reference.X, reference.Y) = GenerateData(startIndex, stopIndex);
return reference;
}
/// <summary>
/// Generates the data.
/// </summary>
/// <param name="startIndex">The start index.</param>
/// <param name="stopIndex">Index of the stop.</param>
/// <param name="method">The method.</param>
/// <returns>
/// System.ValueTuple<List<System.Nullable<System.Double>>, List<System.Nullable<
/// System.Double>>>.
/// </returns>
public static (List<object> X, List<object> Y) GenerateData(int startIndex, int stopIndex,
GenerateMethod method = GenerateMethod.Sin)
{
var x = new List<object>();
var y = new List<object>();
var start = Math.Min(startIndex, stopIndex);
var stop = Math.Max(startIndex, stopIndex);
for (var i = start; i < stop; i++)
{
x.Add(i);
y.Add(i.Randomize(method));
}
return (x, y);
}
/// <summary>
/// Generates the data.
/// </summary>
/// <param name="startIndex">The start index.</param>
/// <param name="stopIndex">Index of the stop.</param>
/// <param name="method">The method.</param>
/// <returns>
/// System.ValueTuple<List<System.Nullable<System.Double>>, List<System.Nullable<
/// System.Double>>, List<System.Nullable<System.Double>>>.
/// </returns>
public static (List<object> X, List<object> Y, List<object> Z) GenerateData3D(int startIndex, int stopIndex,
GenerateMethod method = GenerateMethod.Sin)
{
var x = new List<object>();
var y = new List<object>();
var z = new List<object>();
var start = Math.Min(startIndex, stopIndex);
var stop = Math.Max(startIndex, stopIndex);
for (var i = start; i < stop; i++)
{
x.Add(MathF.Sin(i));
y.Add(MathF.Cos(i));
z.Add(i);
}
return (x, y, z);
}
private static double Randomize(this int number, GenerateMethod method = GenerateMethod.Sin)
{
var a = 0.0;
var b = 0.0;
var c = 0.0;
if (number % 100 == 0)
{
a = 2 * Random.NextDouble();
}
if (number % 1000 == 0)
{
b = 2 * Random.NextDouble();
}
if (number % 10000 == 0)
{
c = 2 * Random.NextDouble();
}
var spike = number % 1000 == 0 ? 10 : 0;
if (method == GenerateMethod.Sin)
{
return 2 * Math.Sin(number / 100.0) + a + b + c + spike + Random.NextDouble();
}
return 2 * Math.Cos(number / 100.0) + a + b + c + spike + Random.NextDouble();
}
}
/// <summary>
/// Enum GenerateMethod
/// </summary>
public enum GenerateMethod
{
/// <summary>
/// Use sinus
/// </summary>
Sin,
/// <summary>
/// Use cosinus
/// </summary>
Cos
}
}