Class HeatMapMonitor
Real-time heatmap visualization backed by LiveCharts LiveChartsCore.SkiaSharpView.HeatSeries<TModel>. Renders a rows × columns color grid where each cell's color encodes a scalar value mapped through a pluggable IHeatmapScaler.
Data flow: Call EnqueueFrame(ReadOnlySpan<double>) or EnqueueFrame(Vector<double>) from any thread. The newest frame is handed off via a lock-free LatestFrameSlot; the internal VisualizationTimer tick reads it on the UI thread at 60 fps, maps values through the active scaler, and nudges LiveCharts to repaint.
Grid layout: Defaults to 8 × 16 (128 cells). Call ConfigureGrid(int, int, int[]?) to change layout. When an incoming frame has a different length to the current grid, the grid auto-reconfigures to a single-row 1 × N layout on the next UI tick.
Scaling: Set via UseGlobalAuto(double, double, double), UseGlobalFixed(double, double),
UsePerSensorFixedForAll(double, double, double), UsePerSensorFixed(double[], double[], double), or
UsePerSensorAdaptiveRms(double, double, double). Default after construction is no scaler —
call UseGlobalAuto(double, double, double) (or another mode) before feeding data, or use
BlockVisualization which calls UseGlobalAuto() automatically.
Colormap: Set via extension methods in HeatmapColormaps
(e.g., hm.UseViridis()). Default is a 4-stop Viridis approximation.
Colorbar: ColorbarBitmap, ColorbarMinLabel, ColorbarMaxLabel, and ColorbarCaption are updated each flush and bound by HeatMapView to the legend sidebar.
Lifecycle: VisualizationPanel (or HeatMapView directly) calls Pause() and Resume(). Do not call these yourself when using BlockVisualization.
Inherited Members
Namespace: MOSAIC.Visualization.Heatmap
Assembly: MOSAIC.dll
Syntax
public class HeatMapMonitor : ObservableObject, INotifyPropertyChanged, INotifyPropertyChanging, IDisposable, IMonitor
Constructors
HeatMapMonitor()
Declaration
public HeatMapMonitor()
Fields
_anchorMax
Declaration
private WeightedPoint? _anchorMax
Field Value
| Type | Description |
|---|---|
| WeightedPoint |
_anchorMin
Declaration
private WeightedPoint? _anchorMin
Field Value
| Type | Description |
|---|---|
| WeightedPoint |
_chartReady
Declaration
private volatile bool _chartReady
Field Value
| Type | Description |
|---|---|
| bool |
_columns
Declaration
[ObservableProperty]
private int _columns
Field Value
| Type | Description |
|---|---|
| int |
_consumerFrame
Declaration
private double[] _consumerFrame
Field Value
| Type | Description |
|---|---|
| double[] |
_disposed
Declaration
private volatile bool _disposed
Field Value
| Type | Description |
|---|---|
| bool |
_flushScheduled
Declaration
private int _flushScheduled
Field Value
| Type | Description |
|---|---|
| int |
_heatSeries
Declaration
private HeatSeries<WeightedPoint>? _heatSeries
Field Value
| Type | Description |
|---|---|
| HeatSeries<WeightedPoint> |
_isActive
Declaration
private volatile bool _isActive
Field Value
| Type | Description |
|---|---|
| bool |
_isUpdating
Declaration
private volatile bool _isUpdating
Field Value
| Type | Description |
|---|---|
| bool |
_pendingCellCount
Declaration
private int _pendingCellCount
Field Value
| Type | Description |
|---|---|
| int |
_points
Declaration
private WeightedPoint[]? _points
Field Value
| Type | Description |
|---|---|
| WeightedPoint[] |
_producerScratch
Declaration
private double[] _producerScratch
Field Value
| Type | Description |
|---|---|
| double[] |
_reconfigureScheduled
Declaration
private int _reconfigureScheduled
Field Value
| Type | Description |
|---|---|
| int |
_rows
Declaration
[ObservableProperty]
private int _rows
Field Value
| Type | Description |
|---|---|
| int |
_scaler
Declaration
private IHeatmapScaler? _scaler
Field Value
| Type | Description |
|---|---|
| IHeatmapScaler |
_series
Declaration
[ObservableProperty]
private List<ISeries> _series
Field Value
| Type | Description |
|---|---|
| List<ISeries> |
_slot
Declaration
private LatestFrameSlot? _slot
Field Value
| Type | Description |
|---|---|
| LatestFrameSlot |
_sync
Declaration
private readonly object _sync
Field Value
| Type | Description |
|---|---|
| object |
_syncContext
Declaration
[ObservableProperty]
private object _syncContext
Field Value
| Type | Description |
|---|---|
| object |
_timerCallback
Declaration
private readonly Action _timerCallback
Field Value
| Type | Description |
|---|---|
| Action |
_xAxes
Declaration
[ObservableProperty]
private Axis[] _xAxes
Field Value
| Type | Description |
|---|---|
| Axis[] |
_yAxes
Declaration
[ObservableProperty]
private Axis[] _yAxes
Field Value
| Type | Description |
|---|---|
| Axis[] |
Properties
ColorbarBitmap
Declaration
public Bitmap? ColorbarBitmap { get; private set; }
Property Value
| Type | Description |
|---|---|
| Bitmap |
ColorbarCaption
Declaration
public string ColorbarCaption { get; private set; }
Property Value
| Type | Description |
|---|---|
| string |
ColorbarHighAtTop
Declaration
public bool ColorbarHighAtTop { get; set; }
Property Value
| Type | Description |
|---|---|
| bool |
ColorbarMaxLabel
Declaration
public string ColorbarMaxLabel { get; private set; }
Property Value
| Type | Description |
|---|---|
| string |
ColorbarMinLabel
Declaration
public string ColorbarMinLabel { get; private set; }
Property Value
| Type | Description |
|---|---|
| string |
Columns
Declaration
[ExcludeFromCodeCoverage]
public int Columns { get; set; }
Property Value
| Type | Description |
|---|---|
| int |
IndexMap
Declaration
public int[]? IndexMap { get; set; }
Property Value
| Type | Description |
|---|---|
| int[] |
IsActive
Declaration
public bool IsActive { get; }
Property Value
| Type | Description |
|---|---|
| bool |
PinColorDomain
Declaration
public bool PinColorDomain { get; set; }
Property Value
| Type | Description |
|---|---|
| bool |
Rows
Declaration
[ExcludeFromCodeCoverage]
public int Rows { get; set; }
Property Value
| Type | Description |
|---|---|
| int |
Series
Declaration
[ExcludeFromCodeCoverage]
public List<ISeries> Series { get; set; }
Property Value
| Type | Description |
|---|---|
| List<ISeries> |
SyncContext
Declaration
[ExcludeFromCodeCoverage]
public object SyncContext { get; set; }
Property Value
| Type | Description |
|---|---|
| object |
ValueTransform
Declaration
public Func<double, double>? ValueTransform { get; set; }
Property Value
| Type | Description |
|---|---|
| Func<double, double> |
XAxes
Declaration
[ExcludeFromCodeCoverage]
public Axis[] XAxes { get; set; }
Property Value
| Type | Description |
|---|---|
| Axis[] |
YAxes
Declaration
[ExcludeFromCodeCoverage]
public Axis[] YAxes { get; set; }
Property Value
| Type | Description |
|---|---|
| Axis[] |
Methods
ConfigureGrid(int, int, int[]?)
Reconfigures the grid dimensions and optional channel mapping. Safe to call from any thread — marshals to the UI thread internally. Drains the queue and resets scaler state for the new cell count.
Declaration
public void ConfigureGrid(int rows, int cols, int[]? indexMap = null)
Parameters
| Type | Name | Description |
|---|---|---|
| int | rows | Number of rows (must be ≥ 1). |
| int | cols | Number of columns (must be ≥ 1). |
| int[] | indexMap | Optional remapping: value at input index |
Dispose()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
Declaration
public void Dispose()
DrainQueue()
Declaration
private void DrainQueue()
EnqueueFrame(Vector<double>)
Enqueues a frame from a MathNet MathNet.Numerics.LinearAlgebra.Vector<T> of double. Convenience overload for blocks that already have a Vector.
Declaration
public void EnqueueFrame(Vector<double> vec)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector<double> | vec | Vector of sensor values; length must equal |
EnqueueFrame(ReadOnlySpan<double>)
Enqueues a frame of sensor values for the next render tick.
Thread-safe; call from any thread (typically the processing thread inside OnReceive).
If the frame length does not match Rows × Columns, the grid auto-reconfigures
to a 1 × N layout on the next UI tick.
Declaration
public void EnqueueFrame(ReadOnlySpan<double> values)
Parameters
| Type | Name | Description |
|---|---|---|
| ReadOnlySpan<double> | values | Sensor values; length must equal |
FlushToChart()
Declaration
private void FlushToChart()
InitializeChart()
Declaration
private void InitializeChart()
NotifyChartReady()
Called by HeatMapView from the LiveChartsCore.SkiaSharpView.Avalonia.CartesianChart
AttachedToVisualTree event (at Loaded priority), confirming LiveCharts
has completed at least one Measure() pass and its internal state is safe.
This is the single global gate against premature flush crashes.
Declaration
public void NotifyChartReady()
OnColumnsChanged(int)
Executes the logic for when Columns just changed.
Declaration
private void OnColumnsChanged(int value)
Parameters
| Type | Name | Description |
|---|---|---|
| int | value | The new property value that was set. |
Remarks
This method is invoked right after the value of Columns is changed.
OnColumnsChanged(int, int)
Executes the logic for when Columns just changed.
Declaration
private void OnColumnsChanged(int oldValue, int newValue)
Parameters
| Type | Name | Description |
|---|---|---|
| int | oldValue | The previous property value that was replaced. |
| int | newValue | The new property value that was set. |
Remarks
This method is invoked right after the value of Columns is changed.
OnColumnsChanging(int)
Executes the logic for when Columns is changing.
Declaration
private void OnColumnsChanging(int value)
Parameters
| Type | Name | Description |
|---|---|---|
| int | value | The new property value being set. |
Remarks
This method is invoked right before the value of Columns is changed.
OnColumnsChanging(int, int)
Executes the logic for when Columns is changing.
Declaration
private void OnColumnsChanging(int oldValue, int newValue)
Parameters
| Type | Name | Description |
|---|---|---|
| int | oldValue | The previous property value that is being replaced. |
| int | newValue | The new property value being set. |
Remarks
This method is invoked right before the value of Columns is changed.
OnRowsChanged(int)
Executes the logic for when Rows just changed.
Declaration
private void OnRowsChanged(int value)
Parameters
| Type | Name | Description |
|---|---|---|
| int | value | The new property value that was set. |
Remarks
This method is invoked right after the value of Rows is changed.
OnRowsChanged(int, int)
Executes the logic for when Rows just changed.
Declaration
private void OnRowsChanged(int oldValue, int newValue)
Parameters
| Type | Name | Description |
|---|---|---|
| int | oldValue | The previous property value that was replaced. |
| int | newValue | The new property value that was set. |
Remarks
This method is invoked right after the value of Rows is changed.
OnRowsChanging(int)
Executes the logic for when Rows is changing.
Declaration
private void OnRowsChanging(int value)
Parameters
| Type | Name | Description |
|---|---|---|
| int | value | The new property value being set. |
Remarks
This method is invoked right before the value of Rows is changed.
OnRowsChanging(int, int)
Executes the logic for when Rows is changing.
Declaration
private void OnRowsChanging(int oldValue, int newValue)
Parameters
| Type | Name | Description |
|---|---|---|
| int | oldValue | The previous property value that is being replaced. |
| int | newValue | The new property value being set. |
Remarks
This method is invoked right before the value of Rows is changed.
OnSeriesChanged(List<ISeries>)
Executes the logic for when Series just changed.
Declaration
private void OnSeriesChanged(List<ISeries> value)
Parameters
| Type | Name | Description |
|---|---|---|
| List<ISeries> | value | The new property value that was set. |
Remarks
This method is invoked right after the value of Series is changed.
OnSeriesChanged(List<ISeries>?, List<ISeries>)
Executes the logic for when Series just changed.
Declaration
private void OnSeriesChanged(List<ISeries>? oldValue, List<ISeries> newValue)
Parameters
| Type | Name | Description |
|---|---|---|
| List<ISeries> | oldValue | The previous property value that was replaced. |
| List<ISeries> | newValue | The new property value that was set. |
Remarks
This method is invoked right after the value of Series is changed.
OnSeriesChanging(List<ISeries>)
Executes the logic for when Series is changing.
Declaration
private void OnSeriesChanging(List<ISeries> value)
Parameters
| Type | Name | Description |
|---|---|---|
| List<ISeries> | value | The new property value being set. |
Remarks
This method is invoked right before the value of Series is changed.
OnSeriesChanging(List<ISeries>?, List<ISeries>)
Executes the logic for when Series is changing.
Declaration
private void OnSeriesChanging(List<ISeries>? oldValue, List<ISeries> newValue)
Parameters
| Type | Name | Description |
|---|---|---|
| List<ISeries> | oldValue | The previous property value that is being replaced. |
| List<ISeries> | newValue | The new property value being set. |
Remarks
This method is invoked right before the value of Series is changed.
OnSyncContextChanged(object)
Executes the logic for when SyncContext just changed.
Declaration
private void OnSyncContextChanged(object value)
Parameters
| Type | Name | Description |
|---|---|---|
| object | value | The new property value that was set. |
Remarks
This method is invoked right after the value of SyncContext is changed.
OnSyncContextChanged(object?, object)
Executes the logic for when SyncContext just changed.
Declaration
private void OnSyncContextChanged(object? oldValue, object newValue)
Parameters
| Type | Name | Description |
|---|---|---|
| object | oldValue | The previous property value that was replaced. |
| object | newValue | The new property value that was set. |
Remarks
This method is invoked right after the value of SyncContext is changed.
OnSyncContextChanging(object)
Executes the logic for when SyncContext is changing.
Declaration
private void OnSyncContextChanging(object value)
Parameters
| Type | Name | Description |
|---|---|---|
| object | value | The new property value being set. |
Remarks
This method is invoked right before the value of SyncContext is changed.
OnSyncContextChanging(object?, object)
Executes the logic for when SyncContext is changing.
Declaration
private void OnSyncContextChanging(object? oldValue, object newValue)
Parameters
| Type | Name | Description |
|---|---|---|
| object | oldValue | The previous property value that is being replaced. |
| object | newValue | The new property value being set. |
Remarks
This method is invoked right before the value of SyncContext is changed.
OnXAxesChanged(Axis[])
Executes the logic for when XAxes just changed.
Declaration
private void OnXAxesChanged(Axis[] value)
Parameters
| Type | Name | Description |
|---|---|---|
| Axis[] | value | The new property value that was set. |
Remarks
This method is invoked right after the value of XAxes is changed.
OnXAxesChanged(Axis[]?, Axis[])
Executes the logic for when XAxes just changed.
Declaration
private void OnXAxesChanged(Axis[]? oldValue, Axis[] newValue)
Parameters
| Type | Name | Description |
|---|---|---|
| Axis[] | oldValue | The previous property value that was replaced. |
| Axis[] | newValue | The new property value that was set. |
Remarks
This method is invoked right after the value of XAxes is changed.
OnXAxesChanging(Axis[])
Executes the logic for when XAxes is changing.
Declaration
private void OnXAxesChanging(Axis[] value)
Parameters
| Type | Name | Description |
|---|---|---|
| Axis[] | value | The new property value being set. |
Remarks
This method is invoked right before the value of XAxes is changed.
OnXAxesChanging(Axis[]?, Axis[])
Executes the logic for when XAxes is changing.
Declaration
private void OnXAxesChanging(Axis[]? oldValue, Axis[] newValue)
Parameters
| Type | Name | Description |
|---|---|---|
| Axis[] | oldValue | The previous property value that is being replaced. |
| Axis[] | newValue | The new property value being set. |
Remarks
This method is invoked right before the value of XAxes is changed.
OnYAxesChanged(Axis[])
Executes the logic for when YAxes just changed.
Declaration
private void OnYAxesChanged(Axis[] value)
Parameters
| Type | Name | Description |
|---|---|---|
| Axis[] | value | The new property value that was set. |
Remarks
This method is invoked right after the value of YAxes is changed.
OnYAxesChanged(Axis[]?, Axis[])
Executes the logic for when YAxes just changed.
Declaration
private void OnYAxesChanged(Axis[]? oldValue, Axis[] newValue)
Parameters
| Type | Name | Description |
|---|---|---|
| Axis[] | oldValue | The previous property value that was replaced. |
| Axis[] | newValue | The new property value that was set. |
Remarks
This method is invoked right after the value of YAxes is changed.
OnYAxesChanging(Axis[])
Executes the logic for when YAxes is changing.
Declaration
private void OnYAxesChanging(Axis[] value)
Parameters
| Type | Name | Description |
|---|---|---|
| Axis[] | value | The new property value being set. |
Remarks
This method is invoked right before the value of YAxes is changed.
OnYAxesChanging(Axis[]?, Axis[])
Executes the logic for when YAxes is changing.
Declaration
private void OnYAxesChanging(Axis[]? oldValue, Axis[] newValue)
Parameters
| Type | Name | Description |
|---|---|---|
| Axis[] | oldValue | The previous property value that is being replaced. |
| Axis[] | newValue | The new property value being set. |
Remarks
This method is invoked right before the value of YAxes is changed.
Pause()
Stops data ingestion and unsubscribes from the visualization timer. Any pending frame is discarded. Called automatically by VisualizationPanel when the heatmap toggle is turned off.
Declaration
public void Pause()
RebuildColorbar(int, int, bool)
Rebuilds ColorbarBitmap from the current colormap using a SkiaSharp linear gradient. Called automatically after SetColormap(SKColor[], double[]?) and when a new HeatMapMonitor is bound by HeatMapView. Only needs to be called manually if you change the colormap outside of the extension methods.
Declaration
public void RebuildColorbar(int width = 18, int height = 180, bool vertical = true)
Parameters
| Type | Name | Description |
|---|---|---|
| int | width | Pixel width of the colorbar image. |
| int | height | Pixel height of the colorbar image. |
| bool | vertical |
RebuildGrid()
Declaration
private void RebuildGrid()
RequestFlush()
Declaration
private void RequestFlush()
RequestGridReconfigure(int)
Auto-reconfigures grid when incoming data has a different cell count. Maps to a 1×N grid (single row) by default — callers can use ConfigureGrid() for custom row/column layouts.
Declaration
private void RequestGridReconfigure(int newCellCount)
Parameters
| Type | Name | Description |
|---|---|---|
| int | newCellCount |
ResetData()
Resets chart to clean state. Called by VisualizationPanel on attach/toggle.
Declaration
public void ResetData()
ResetDataCore()
Declaration
private void ResetDataCore()
Resume()
Subscribes to the visualization timer (60 fps) and discards any stale frame. Called automatically by VisualizationPanel when the heatmap toggle is turned on. Do not call this yourself when using BlockVisualization.
Declaration
public void Resume()
SetColormap(SKColor[], double[]?)
Applies a custom colormap directly. Prefer the extension methods in HeatmapColormaps
(e.g., hm.UseViridis()) over calling this directly.
Safe to call from any thread.
Declaration
public void SetColormap(SKColor[] colors, double[]? stops01 = null)
Parameters
| Type | Name | Description |
|---|---|---|
| SKColor[] | colors | Array of SkiaSharp colors from low (index 0) to high (last index). |
| double[] | stops01 | Optional non-uniform stop positions in [0..1], same length as |
SetColormapCore(SKColor[], double[]?)
Declaration
private void SetColormapCore(SKColor[] colors, double[]? stops01)
Parameters
| Type | Name | Description |
|---|---|---|
| SKColor[] | colors | |
| double[] | stops01 |
UpdateThemeColors()
Re-applies theme-dependent colours to the monitor's paints.
Declaration
public void UpdateThemeColors()
UseGlobalAuto(double, double, double)
Sets scaler to GlobalAutoScaler (expand fast, contract slow). Best when the signal range is unknown or slowly drifting. This is the default when using BlockVisualization.
Declaration
public void UseGlobalAuto(double expandAlpha = 0.6, double contractAlpha = 0.08, double minSpan = 1E-09)
Parameters
| Type | Name | Description |
|---|---|---|
| double | expandAlpha | EMA weight when range expands (0..1). Higher = faster tracking of peaks. |
| double | contractAlpha | EMA weight when range contracts (0..1). Lower = steadier baseline. |
| double | minSpan | Minimum span to avoid color collapse for constant signals. |
UseGlobalFixed(double, double)
Sets scaler to GlobalFixedScaler: maps [min..max]
uniformly to [0..1] for every cell. Best for signals with a known stable range (e.g., ±1 V, 0..100%).
Declaration
public void UseGlobalFixed(double min, double max)
Parameters
| Type | Name | Description |
|---|---|---|
| double | min | Minimum value — mapped to color index 0 (bottom of colormap). |
| double | max | Maximum value — mapped to color index 1 (top of colormap). |
UsePerSensorAdaptiveRms(double, double, double)
Sets scaler to PerSensorAdaptiveRmsScaler: each cell independently tracks its own RMS envelope and maps [-RMSk .. +RMSk] → [0..1]. Best for zero-mean signals of unknown amplitude (EMG, EEG, accelerometer).
Declaration
public void UsePerSensorAdaptiveRms(double emaAlpha = 0.12, double k = 1.414, double halfLifeSeconds = 0.6)
Parameters
| Type | Name | Description |
|---|---|---|
| double | emaAlpha | EMA weight for RMS update (0..1). Higher = faster envelope tracking. |
| double | k | Scale multiplier relative to RMS. √2 clips sine-wave peaks at ±1. |
| double | halfLifeSeconds | Peak-hold decay half-life. Shorter = faster re-centering after bursts. |
UsePerSensorFixed(double[], double[], double)
Sets scaler to PerSensorFixedScaler with individual [min, max] per cell.
Each element of mins/maxs corresponds to one grid cell
in row-major order. Useful for calibrated multi-electrode or multi-sensor arrays.
Declaration
public void UsePerSensorFixed(double[] mins, double[] maxs, double epsilon = 1E-09)
Parameters
| Type | Name | Description |
|---|---|---|
| double[] | mins | Per-cell minimum values. Length must equal |
| double[] | maxs | Per-cell maximum values. Length must equal |
| double | epsilon | Minimum span guard. |
UsePerSensorFixedForAll(double, double, double)
Sets scaler to PerSensorFixedScaler with the same [min, max] for every cell. Each cell is scaled independently but using the same range. Use UsePerSensorFixed(double[], double[], double) if cells have different calibrated ranges.
Declaration
public void UsePerSensorFixedForAll(double min, double max, double epsilon = 1E-09)
Parameters
| Type | Name | Description |
|---|---|---|
| double | min | Fixed minimum for every cell. |
| double | max | Fixed maximum for every cell. |
| double | epsilon | Minimum span guard to avoid divide-by-zero. |