forked from LayTec-AG/Plotly.Blazor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHelper.cs
103 lines (88 loc) · 3.05 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
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using Plotly.Blazor.Traces;
namespace Plotly.Blazor.Examples
{
public static class Helper
{
private static Random Random => new Random();
/// <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);
}
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
}
}