Class ScopeMonitor

Real-time multi-channel scope backed by ScottPlot. Ingest, flush coalescing, channel reconfigure, pause/resume and the monotonic clock live in ChannelRingMonitorBase; this class supplies only the ScottPlot rendering, axis management and stacked/overlapped logic.

Inherited Members
Namespace: MOSAIC.Visualization.ScopeMonitor
Assembly: MOSAIC.dll
Syntax
public class ScopeMonitor : ChannelRingMonitorBase, INotifyPropertyChanged, INotifyPropertyChanging, IMonitor, IDisposable

Fields

AutoOffsetSettleFlushes

Declaration
private const int AutoOffsetSettleFlushes = 5
Field Value
Type Description
int

AutoOffsetSpacing

Declaration
private const double AutoOffsetSpacing = 1.3
Field Value
Type Description
double

ChannelColors

Declaration
public static readonly SKColor[] ChannelColors
Field Value
Type Description
SKColor[]

DefaultDataPoints

Declaration
private const int DefaultDataPoints = 2000
Field Value
Type Description
int

MaxDataPointsCap

Declaration
private const int MaxDataPointsCap = 10000
Field Value
Type Description
int

MaxPaletteChannels

Palette size (also the effective max channel count).

Declaration
private const int MaxPaletteChannels = 128
Field Value
Type Description
int

MinDataPoints

Declaration
private const int MinDataPoints = 200
Field Value
Type Description
int

YEaseFactor

Fraction of the remaining gap the Y axis closes per flush when tightening.

Declaration
private const double YEaseFactor = 0.15
Field Value
Type Description
double
Remarks

Only ever applied to a shrink — growth is immediate so a transient is never clipped. At the 30 fps flush rate this settles a correction in roughly half a second, slow enough to read as a glide rather than a step and fast enough not to leave the trace small.

YEaseSettled

Per-frame movement, as a fraction of span, below which a tighten counts as arrived.

Declaration
private const double YEaseSettled = 0.002
Field Value
Type Description
double

YRescaleDeadband

Fractional Y-range change below which the axis is held steady (anti-jitter deadband).

Declaration
private const double YRescaleDeadband = 0.12
Field Value
Type Description
double

YShrinkEveryNFlushes

Declaration
private const int YShrinkEveryNFlushes = 60
Field Value
Type Description
int

YShrinkFactor

Declaration
private const double YShrinkFactor = 0.92
Field Value
Type Description
double

_autoOffsetLocked

Declaration
private bool _autoOffsetLocked
Field Value
Type Description
bool

_batchYMax

Declaration
private double _batchYMax
Field Value
Type Description
double

_batchYMin

Declaration
private double _batchYMin
Field Value
Type Description
double

_channelOffset

Declaration
[ObservableProperty]
private double _channelOffset
Field Value
Type Description
double

_currentXMax

Declaration
private double _currentXMax
Field Value
Type Description
double

_flushCount

Declaration
private int _flushCount
Field Value
Type Description
int

_growYMax

Declaration
private double _growYMax
Field Value
Type Description
double

_growYMin

Declaration
private double _growYMin
Field Value
Type Description
double

_isReading

Declaration
[ObservableProperty]
private bool _isReading
Field Value
Type Description
bool

_lastTickInterval

Declaration
private double _lastTickInterval
Field Value
Type Description
double

_lastTickXMax

Declaration
private double _lastTickXMax
Field Value
Type Description
double

_lastXMax

Declaration
private double _lastXMax
Field Value
Type Description
double

_lastXMin

Declaration
private double _lastXMin
Field Value
Type Description
double

_lastYMax

Declaration
private double _lastYMax
Field Value
Type Description
double

_lastYMin

Declaration
private double _lastYMin
Field Value
Type Description
double

_manualDataPoints

Declaration
private bool _manualDataPoints
Field Value
Type Description
bool

_numberOfDataPoints

Declaration
private int _numberOfDataPoints
Field Value
Type Description
int

_plot

Declaration
private Plot? _plot
Field Value
Type Description
Plot

_refreshCallback

Declaration
private Action? _refreshCallback
Field Value
Type Description
Action

_settleFlushCount

Declaration
private int _settleFlushCount
Field Value
Type Description
int

_settleMax

Declaration
private double[]? _settleMax
Field Value
Type Description
double[]

_settleMin

Declaration
private double[]? _settleMin
Field Value
Type Description
double[]

_signalRate

Declaration
private double _signalRate
Field Value
Type Description
double

_streamers

Declaration
private readonly List<DataStreamer> _streamers
Field Value
Type Description
List<DataStreamer>

_suppressViewModeHandler

Declaration
private volatile bool _suppressViewModeHandler
Field Value
Type Description
bool

_viewMode

Declaration
[ObservableProperty]
private ScopeViewMode _viewMode
Field Value
Type Description
ScopeViewMode

_window

Declaration
private TimeSpan _window
Field Value
Type Description
TimeSpan

_yAutoScale

Declaration
private bool _yAutoScale
Field Value
Type Description
bool

_yFixedMax

Declaration
private double _yFixedMax
Field Value
Type Description
double

_yFixedMin

Declaration
private double _yFixedMin
Field Value
Type Description
double

_yTightening

True while a tighten is in progress, so it is allowed to finish. See the gate below.

Declaration
private bool _yTightening
Field Value
Type Description
bool

Properties

AcceptInterval

When non-null, EnqueueData(Vector<double>) drops samples that arrive closer together than this interval (decimation gate). EnqueueBatch(Matrix<double>, int) is never throttled.

Declaration
protected override TimeSpan? AcceptInterval { get; }
Property Value
Type Description
TimeSpan?
Overrides
ChannelRingMonitorBase.AcceptInterval

AutoOffset

Declaration
public bool AutoOffset { get; set; }
Property Value
Type Description
bool

ChannelOffset

Declaration
[ExcludeFromCodeCoverage]
public double ChannelOffset { get; set; }
Property Value
Type Description
double

IsAutoScale

Declaration
public bool IsAutoScale { get; }
Property Value
Type Description
bool

IsReading

Declaration
[ExcludeFromCodeCoverage]
public bool IsReading { get; set; }
Property Value
Type Description
bool

IsRenderReady

Whether the render surface is ready to draw. The base skips flushing while false.

Declaration
protected override bool IsRenderReady { get; }
Property Value
Type Description
bool
Overrides
ChannelRingMonitorBase.IsRenderReady

MaxChannels

Upper bound on channel count. Defaults to 128.

Declaration
protected override int MaxChannels { get; }
Property Value
Type Description
int
Overrides
ChannelRingMonitorBase.MaxChannels

MaxDataPoints

Buffer size per channel. Setting this disables rate-based auto-scaling.

Declaration
public int MaxDataPoints { get; set; }
Property Value
Type Description
int

SampleAcceptInterval

Decimation gate for per-sample ingest (window / dataPoints, floored at 1 ms).

Declaration
private TimeSpan SampleAcceptInterval { get; }
Property Value
Type Description
TimeSpan

SamplePeriodSec

True sample period for the time axis; sub-millisecond at high signal rates.

Declaration
private double SamplePeriodSec { get; }
Property Value
Type Description
double

SamplePeriodSeconds

Seconds the x-axis advances per plotted row — the value handed to every streamer's ScottPlot.Plottables.DataStreamer.Period.

Declaration
public double SamplePeriodSeconds { get; }
Property Value
Type Description
double
Remarks

Exposed so the time base can be asserted directly. This is the whole correctness condition for the scope: it must equal one over the true sample rate, and it only does when some block called UpdateSignalRate(double). Otherwise it silently degrades to the window/buffer fallback below, which is a display constant rather than a property of the signal.

SignalRate

The upstream signal rate (Hz) this scope is currently sized for, or 0 if unknown.

Declaration
public double SignalRate { get; }
Property Value
Type Description
double

ViewMode

Declaration
[ExcludeFromCodeCoverage]
public ScopeViewMode ViewMode { get; set; }
Property Value
Type Description
ScopeViewMode

Window

Declaration
public TimeSpan Window { get; set; }
Property Value
Type Description
TimeSpan

Methods

ApplyPeriodToStreamers()

Retargets the live streamers' time base, keeping the samples already buffered.

Declaration
private void ApplyPeriodToStreamers()
Remarks

Used when the signal rate changes but the buffer size does not. The x-axis span the existing samples occupy changes with the period, so the cached tick labels are dropped and regenerated on the next flush.

AttachPlot(Plot, Action)

Declaration
public void AttachPlot(Plot plot, Action refreshCallback)
Parameters
Type Name Description
Plot plot
Action refreshCallback

ConfigurePlotAppearance()

Declaration
private void ConfigurePlotAppearance()

DetachPlot()

Declaration
public void DetachPlot()

GenerateColorPalette(int)

Declaration
private static SKColor[] GenerateColorPalette(int count)
Parameters
Type Name Description
int count
Returns
Type Description
SKColor[]

GetChannelColor(int)

Declaration
public static SKColor GetChannelColor(int index)
Parameters
Type Name Description
int index
Returns
Type Description
SKColor

GetChannelColorHex(int)

Declaration
public static string GetChannelColorHex(int index)
Parameters
Type Name Description
int index
Returns
Type Description
string

HslToSkColor(float, float, float)

Declaration
private static SKColor HslToSkColor(float h, float s, float l)
Parameters
Type Name Description
float h
float s
float l
Returns
Type Description
SKColor

NotifyChartReady()

No-op — kept for API compatibility; still invoked by VisualizationPanel.

Declaration
public void NotifyChartReady()

OnChannelOffsetChanged(double)

Executes the logic for when ChannelOffset just changed.

Declaration
private void OnChannelOffsetChanged(double value)
Parameters
Type Name Description
double value

The new property value that was set.

Remarks

This method is invoked right after the value of ChannelOffset is changed.

OnChannelOffsetChanged(double, double)

Executes the logic for when ChannelOffset just changed.

Declaration
private void OnChannelOffsetChanged(double oldValue, double newValue)
Parameters
Type Name Description
double oldValue

The previous property value that was replaced.

double newValue

The new property value that was set.

Remarks

This method is invoked right after the value of ChannelOffset is changed.

OnChannelOffsetChanging(double)

Executes the logic for when ChannelOffset is changing.

Declaration
private void OnChannelOffsetChanging(double value)
Parameters
Type Name Description
double value

The new property value being set.

Remarks

This method is invoked right before the value of ChannelOffset is changed.

OnChannelOffsetChanging(double, double)

Executes the logic for when ChannelOffset is changing.

Declaration
private void OnChannelOffsetChanging(double oldValue, double newValue)
Parameters
Type Name Description
double oldValue

The previous property value that is being replaced.

double newValue

The new property value being set.

Remarks

This method is invoked right before the value of ChannelOffset is changed.

OnDispose()

Release surface references on dispose. Optional.

Declaration
protected override void OnDispose()
Overrides
ChannelRingMonitorBase.OnDispose()

OnFlush(SampleRingBuffer, int)

Render the frameCount fresh frames in ring (read via Peek(int, int)). The base brackets this with BeginRead/CommitRead and the IsUpdating guard — do not call those yourself.

Declaration
protected override void OnFlush(SampleRingBuffer ring, int n)
Parameters
Type Name Description
SampleRingBuffer ring
int n
Overrides
ChannelRingMonitorBase.OnFlush(SampleRingBuffer, int)

OnIsReadingChanged(bool)

Executes the logic for when IsReading just changed.

Declaration
private void OnIsReadingChanged(bool value)
Parameters
Type Name Description
bool value

The new property value that was set.

Remarks

This method is invoked right after the value of IsReading is changed.

OnIsReadingChanged(bool, bool)

Executes the logic for when IsReading just changed.

Declaration
private void OnIsReadingChanged(bool oldValue, bool newValue)
Parameters
Type Name Description
bool oldValue

The previous property value that was replaced.

bool newValue

The new property value that was set.

Remarks

This method is invoked right after the value of IsReading is changed.

OnIsReadingChanging(bool)

Executes the logic for when IsReading is changing.

Declaration
private void OnIsReadingChanging(bool value)
Parameters
Type Name Description
bool value

The new property value being set.

Remarks

This method is invoked right before the value of IsReading is changed.

OnIsReadingChanging(bool, bool)

Executes the logic for when IsReading is changing.

Declaration
private void OnIsReadingChanging(bool oldValue, bool newValue)
Parameters
Type Name Description
bool oldValue

The previous property value that is being replaced.

bool newValue

The new property value being set.

Remarks

This method is invoked right before the value of IsReading is changed.

OnRebuild()

(Re)build the render surface for the current ChannelCount. Runs on the UI thread after the ring is (re)allocated.

Declaration
protected override void OnRebuild()
Overrides
ChannelRingMonitorBase.OnRebuild()

OnResetData()

Reset display state and rebuild after a data reset. Runs on the UI thread; the ring is already cleared.

Declaration
protected override void OnResetData()
Overrides
ChannelRingMonitorBase.OnResetData()

OnResumed()

Reset transient display state on resume (e.g. auto-scale extremes). Optional.

Declaration
protected override void OnResumed()
Overrides
ChannelRingMonitorBase.OnResumed()

OnViewModeChanged(ScopeViewMode)

Executes the logic for when ViewMode just changed.

Declaration
private void OnViewModeChanged(ScopeViewMode value)
Parameters
Type Name Description
ScopeViewMode value

The new property value that was set.

Remarks

This method is invoked right after the value of ViewMode is changed.

OnViewModeChanged(ScopeViewMode, ScopeViewMode)

Executes the logic for when ViewMode just changed.

Declaration
private void OnViewModeChanged(ScopeViewMode oldValue, ScopeViewMode newValue)
Parameters
Type Name Description
ScopeViewMode oldValue

The previous property value that was replaced.

ScopeViewMode newValue

The new property value that was set.

Remarks

This method is invoked right after the value of ViewMode is changed.

OnViewModeChanging(ScopeViewMode)

Executes the logic for when ViewMode is changing.

Declaration
private void OnViewModeChanging(ScopeViewMode value)
Parameters
Type Name Description
ScopeViewMode value

The new property value being set.

Remarks

This method is invoked right before the value of ViewMode is changed.

OnViewModeChanging(ScopeViewMode, ScopeViewMode)

Executes the logic for when ViewMode is changing.

Declaration
private void OnViewModeChanging(ScopeViewMode oldValue, ScopeViewMode newValue)
Parameters
Type Name Description
ScopeViewMode oldValue

The previous property value that is being replaced.

ScopeViewMode newValue

The new property value being set.

Remarks

This method is invoked right before the value of ViewMode is changed.

RebuildStreamers()

Declaration
private void RebuildStreamers()

ResetAutoOffset()

Declaration
private void ResetAutoOffset()

ResetAutoOffsetPublic()

Declaration
public void ResetAutoOffsetPublic()

ScopeInit(int)

Declaration
public void ScopeInit(int count = 0)
Parameters
Type Name Description
int count

SetAutoScale()

Declaration
public void SetAutoScale()

SetFixedRange(double, double)

Declaration
public void SetFixedRange(double min, double max)
Parameters
Type Name Description
double min
double max

SetViewModeSilent(ScopeViewMode)

Declaration
public void SetViewModeSilent(ScopeViewMode mode)
Parameters
Type Name Description
ScopeViewMode mode

SetWindow(TimeSpan)

Sets the visible time span. Recomputes the buffer size from the current signal rate (unless MaxDataPoints was set manually) and rebuilds the streamers so the change is visible immediately. Used by the aggregate Scope Monitor window to show more history.

Declaration
public void SetWindow(TimeSpan window)
Parameters
Type Name Description
TimeSpan window

ToggleViewMode()

Declaration
public void ToggleViewMode()

UpdateAutoOffset(SampleRingBuffer, int)

Declaration
private void UpdateAutoOffset(SampleRingBuffer ring, int n)
Parameters
Type Name Description
SampleRingBuffer ring
int n

UpdateSignalRate(double)

Informs the scope of the upstream signal rate so it can auto-scale the buffer size for smooth rendering. No-op if MaxDataPoints was set manually.

Declaration
public void UpdateSignalRate(double signalRate)
Parameters
Type Name Description
double signalRate

UpdateThemeColors()

Re-applies theme-dependent colours to the monitor's paints.

Declaration
public override void UpdateThemeColors()
Overrides
ChannelRingMonitorBase.UpdateThemeColors()

UpdateTimeAxisTicksStable()

Declaration
private void UpdateTimeAxisTicksStable()

UpdateYAxisFromData()

Declaration
private void UpdateYAxisFromData()

Implements

INotifyPropertyChanged
INotifyPropertyChanging
IMonitor
IDisposable

Search documentation

Start typing to search the documentation.