Skip to content

Commit

Permalink
Updated forecast visualizer to inherit BufferedVisualizer
Browse files Browse the repository at this point in the history
  • Loading branch information
ncguilbeault committed May 22, 2024
1 parent 24d9609 commit 18f6670
Showing 1 changed file with 13 additions and 14 deletions.
27 changes: 13 additions & 14 deletions src/Bonsai.ML.Visualizers/ForecastVisualizer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.Drawing;
using OxyPlot;
using OxyPlot.Series;
using System.Reactive;

[assembly: TypeVisualizer(typeof(ForecastVisualizer), Target = typeof(Forecast))]

Expand All @@ -16,7 +17,7 @@ namespace Bonsai.ML.Visualizers
/// <summary>
/// Provides a type visualizer to display the forecast of a Kalman Filter kinematics model.
/// </summary>
public class ForecastVisualizer : DialogTypeVisualizer
public class ForecastVisualizer : BufferedVisualizer
{

private DateTime? _startTime;
Expand All @@ -26,16 +27,6 @@ public class ForecastVisualizer : DialogTypeVisualizer
private LineSeries lineSeries;
private AreaSeries areaSeries;

/// <summary>
/// Update frequency of the plot
/// </summary>
public TimeSpan UpdateFrequency { get; set; } = TimeSpan.FromSeconds(1/30);

/// <summary>
/// Size of the window when loaded
/// </summary>
public Size Size { get; set; } = new Size(320, 240);

/// <summary>
/// Capacity or length of time shown along the x axis of the plot during automatic updating
/// </summary>
Expand Down Expand Up @@ -73,7 +64,11 @@ public override void Load(IServiceProvider provider)
/// <inheritdoc/>
public override void Show(object value)
{
var time = DateTime.Now;
}

/// <inheritdoc/>
public override void Show(DateTime time, object value)
{
if (!_startTime.HasValue)
{
_startTime = time;
Expand Down Expand Up @@ -112,10 +107,14 @@ public override void Show(object value)
}

Plot.SetAxes(minTime: forecastTime.AddSeconds(-Capacity), maxTime: forecastTime);
}

if (lastUpdate is null || time - lastUpdate > UpdateFrequency)
/// <inheritdoc/>
protected override void ShowBuffer(IList<Timestamped<object>> values)
{
base.ShowBuffer(values);
if (values.Count > 0)
{
lastUpdate = time;
Plot.UpdatePlot();
}
}
Expand Down

0 comments on commit 18f6670

Please sign in to comment.