Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ All notable changes to this project will be documented in this file.
- Update SkiaSharp to Version 2.88.6
- AxisRendererBase is now generic
- DateTimeAxis.ToDateTime(double value) is now obsolete, replacements are provided (related to #2061)
- Modify some of the examples to make them deterministic

### Removed
- Support for .NET Framework 4.0 and 4.5 (#1839)
Expand Down
20 changes: 11 additions & 9 deletions Source/Examples/ExampleLibrary/Issues/Issues.cs
Original file line number Diff line number Diff line change
Expand Up @@ -741,22 +741,24 @@ public static PlotModel DataPointsRemainVisibleOutsideBoundsOnPanning()

plotModel1.Axes.Add(verticalAxis);

var time = new DateTime(2024, 07, 20, 13, 27, 5);

var line = new LineSeries { Title = "Measurement", XAxisKey = masterAxis.Key, YAxisKey = verticalAxis.Key };
line.Points.Add(new DataPoint(DateTimeAxis.ToDouble(DateTime.Now), 10));
line.Points.Add(new DataPoint(DateTimeAxis.ToDouble(DateTime.Now.AddSeconds(1)), 10));
line.Points.Add(new DataPoint(DateTimeAxis.ToDouble(DateTime.Now.AddSeconds(2)), 45));
line.Points.Add(new DataPoint(DateTimeAxis.ToDouble(DateTime.Now.AddSeconds(3)), 17));
line.Points.Add(new DataPoint(DateTimeAxis.ToDouble(time), 10));
line.Points.Add(new DataPoint(DateTimeAxis.ToDouble(time.AddSeconds(1)), 10));
line.Points.Add(new DataPoint(DateTimeAxis.ToDouble(time.AddSeconds(2)), 45));
line.Points.Add(new DataPoint(DateTimeAxis.ToDouble(time.AddSeconds(3)), 17));

line.Points.Add(DataPoint.Undefined);

// this point should be visible
line.Points.Add(new DataPoint(DateTimeAxis.ToDouble(DateTime.Now.AddSeconds(4)), 10));
line.Points.Add(new DataPoint(DateTimeAxis.ToDouble(time.AddSeconds(4)), 10));
//// line.Points.Add(new DataPoint(DateTimeAxis.ToDouble(DateTime.Now.AddSeconds(4)), 10));

line.Points.Add(DataPoint.Undefined);

line.Points.Add(new DataPoint(DateTimeAxis.ToDouble(DateTime.Now.AddSeconds(5)), 45));
line.Points.Add(new DataPoint(DateTimeAxis.ToDouble(DateTime.Now.AddSeconds(6)), 17));
line.Points.Add(new DataPoint(DateTimeAxis.ToDouble(time.AddSeconds(5)), 45));
line.Points.Add(new DataPoint(DateTimeAxis.ToDouble(time.AddSeconds(6)), 17));

plotModel1.Series.Add(line);

Expand Down Expand Up @@ -1184,7 +1186,7 @@ public static PlotModel ImageAnnotationWithWidthHeightCrashes()
var myModel = new PlotModel { Title = "Example 1" };
myModel.Series.Add(new FunctionSeries(Math.Cos, 0, 10, 0.1, "cos(x)"));

var rng = new Random();
var rng = new Random(0);
var buf = new byte[100, 100];
for (int i = 0; i < 100; i++)
{
Expand Down Expand Up @@ -2230,7 +2232,7 @@ public static PlotModel HitTrackerIndexOutOfRangeExceptionWithHeatMapSeries()
Palette = myPalette,
});

var rand = new Random();
var rand = new Random(0);
var data = new double[yAxisLabels.Count, xAxisLabels.Count];
for (int x = 0; x < xAxisLabels.Count; ++x)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ private static Example CreateCandleStickAndVolumeSeriesExample(
};

// create bars
foreach (var bar in OhlcvItemGenerator.MRProcess(n))
foreach (var bar in OhlcvItemGenerator.MRProcess(n, new Random(0)))
{
series.Append(bar);
}
Expand Down Expand Up @@ -232,4 +232,4 @@ private static void AdjustYExtent(CandleStickAndVolumeSeries series, DateTimeAxi
yaxis.Zoom(ymin - margin, ymax + margin);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public static Example LargeDataSetWide()
var linearAxis1 = new LinearAxis { Position = AxisPosition.Left };
pm.Axes.Add(linearAxis1);
var n = 1000000;
var items = HighLowItemGenerator.MRProcess(n).ToArray();
var items = HighLowItemGenerator.MRProcess(n, new Random(0)).ToArray();
var series = new CandleStickSeries
{
Color = OxyColors.Black,
Expand Down Expand Up @@ -68,7 +68,7 @@ public static Example LargeDataSetNarrow()
var linearAxis1 = new LinearAxis { Position = AxisPosition.Left };
pm.Axes.Add(linearAxis1);
var n = 1000000;
var items = HighLowItemGenerator.MRProcess(n).ToArray();
var items = HighLowItemGenerator.MRProcess(n, new Random(1)).ToArray();
var series = new CandleStickSeries
{
Color = OxyColors.Black,
Expand Down Expand Up @@ -106,7 +106,7 @@ public static Example SmallDataSet()
var linearAxis1 = new LinearAxis { Position = AxisPosition.Left };
pm.Axes.Add(linearAxis1);
var n = 100;
var items = HighLowItemGenerator.MRProcess(n).ToArray();
var items = HighLowItemGenerator.MRProcess(n, new Random(2)).ToArray();
var series = new CandleStickSeries
{
Color = OxyColors.Black,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,6 @@ namespace ExampleLibrary
/// </summary>
public static class HighLowItemGenerator
{
/// <summary>
/// The random number generator.
/// </summary>
private static readonly Random Rand = new Random();

/// <summary>
/// Creates bars governed by a MR process
/// </summary>
Expand All @@ -36,19 +31,20 @@ public static class HighLowItemGenerator
/// <param name="kappa">Kappa.</param>
public static IEnumerable<HighLowItem> MRProcess(
int n,
Random rand,
double x0 = 100.0,
double csigma = 0.50,
double esigma = 0.70,
double kappa = 0.01)
{
double x = x0;

var baseT = DateTime.UtcNow;
var baseT = new DateTime(2024, 07, 20, 14, 26, 06);
for (int ti = 0; ti < n; ti++)
{
var dx_c = -kappa * (x - x0) + RandomNormal(0, csigma);
var dx_1 = -kappa * (x - x0) + RandomNormal(0, esigma);
var dx_2 = -kappa * (x - x0) + RandomNormal(0, esigma);
var dx_c = -kappa * (x - x0) + RandomNormal(0, csigma, rand);
var dx_1 = -kappa * (x - x0) + RandomNormal(0, esigma, rand);
var dx_2 = -kappa * (x - x0) + RandomNormal(0, esigma, rand);

var open = x;
var close = x = x + dx_c;
Expand Down Expand Up @@ -92,9 +88,9 @@ private static double Max(double a, double b, double c, double d)
/// </summary>
/// <param name="mu">Mu.</param>
/// <param name="sigma">Sigma.</param>
private static double RandomNormal(double mu, double sigma)
private static double RandomNormal(double mu, double sigma, Random rand)
{
return InverseCumNormal(Rand.NextDouble(), mu, sigma);
return InverseCumNormal(rand.NextDouble(), mu, sigma);
}

/// <summary>
Expand Down Expand Up @@ -194,4 +190,4 @@ private static double CumN0(double x)
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,6 @@ namespace ExampleLibrary
/// </summary>
public static class OhlcvItemGenerator
{
/// <summary>
/// The random number generator.
/// </summary>
private static readonly Random Rand = new Random();

/// <summary>
/// Creates bars governed by a MR process.
/// </summary>
Expand All @@ -39,19 +34,20 @@ public static class OhlcvItemGenerator
/// </returns>
public static IEnumerable<OhlcvItem> MRProcess(
int n,
Random rand,
double x0 = 100.0,
double v0 = 500,
double csigma = 0.50,
double esigma = 0.75,
double kappa = 0.01)
{
double x = x0;
var baseT = DateTime.UtcNow;
var baseT = new DateTime(2024, 07, 20, 14, 26, 06);
for (int ti = 0; ti < n; ti++)
{
var dx_c = -kappa * (x - x0) + RandomNormal(0, csigma);
var dx_1 = -kappa * (x - x0) + RandomNormal(0, esigma);
var dx_2 = -kappa * (x - x0) + RandomNormal(0, esigma);
var dx_c = -kappa * (x - x0) + RandomNormal(0, csigma, rand);
var dx_1 = -kappa * (x - x0) + RandomNormal(0, esigma, rand);
var dx_2 = -kappa * (x - x0) + RandomNormal(0, esigma, rand);

var open = x;
var close = x = x + dx_c;
Expand Down Expand Up @@ -106,9 +102,9 @@ private static double Max(double a, double b, double c, double d)
/// <param name="mu">Mu.</param>
/// <param name="sigma">Sigma.</param>
/// <returns></returns>
private static double RandomNormal(double mu, double sigma)
private static double RandomNormal(double mu, double sigma, Random rand)
{
return InverseCumNormal(Rand.NextDouble(), mu, sigma);
return InverseCumNormal(rand.NextDouble(), mu, sigma);
}

/// <summary>
Expand Down Expand Up @@ -208,4 +204,4 @@ private static double CumN0(double x)
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ namespace ExampleLibrary
using OxyPlot;
using OxyPlot.Axes;
using OxyPlot.Series;
using System;

[Examples("VolumeSeries")]
[Tags("Series")]
Expand Down Expand Up @@ -78,7 +79,7 @@ private static Example CreateVolumeSeries(
};

// create bars
foreach (var bar in OhlcvItemGenerator.MRProcess(n))
foreach (var bar in OhlcvItemGenerator.MRProcess(n, new Random(1)))
{
series.Append(bar);
}
Expand Down