Charts - Add faint background grid (0.75px, #E0E0E0) to all live charts; matches PDF report style - Show min/max tolerance bands on P1/P2 pressure charts during test runs (previously only Q-Delivery/Q-Over) - Broaden BenchService.ToleranceUpdated to fire for every phase receive; UI routes by name - Clear P1/P2 traces on PhaseChanged alongside Delivery/Over CAN - Normalize QDelivery flow rate to 1000 RPM reference before IIR filter so RPM spikes are low-pass filtered with flow-rate transients (matches old_source behavior) Pump page - Reorder columns: identification left, commands center, live data right - PreIn control always visible; disabled when pump lacks pre-injection (rename IsPreInVisible -> IsPreInAvailable) - Swap value/label order in command cards - Remove redundant KlineErrors row from identification card Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
128 lines
4.2 KiB
C#
128 lines
4.2 KiB
C#
using System;
|
|
using System.Collections.ObjectModel;
|
|
using CommunityToolkit.Mvvm.ComponentModel;
|
|
using LiveChartsCore;
|
|
using LiveChartsCore.Defaults;
|
|
using LiveChartsCore.SkiaSharpView;
|
|
using LiveChartsCore.SkiaSharpView.Painting;
|
|
using SkiaSharp;
|
|
|
|
namespace HC_APTBS.ViewModels
|
|
{
|
|
/// <summary>
|
|
/// Reusable ViewModel for a single real-time scrolling line chart.
|
|
/// Backed by LiveChartsCore with a fixed-width sample window.
|
|
/// </summary>
|
|
public sealed partial class SingleFlowChartViewModel : ObservableObject
|
|
{
|
|
private const int DefaultMaxSamples = 200;
|
|
|
|
private readonly ObservableCollection<double> _values = new();
|
|
private readonly int _maxSamples;
|
|
|
|
/// <summary>Chart title label.</summary>
|
|
[ObservableProperty] private string _title = string.Empty;
|
|
|
|
/// <summary>Most recent sample value, displayed as a numeric label alongside the chart.</summary>
|
|
[ObservableProperty] private double _currentValue;
|
|
|
|
/// <summary>Series array bound to the CartesianChart.</summary>
|
|
public ISeries[] Series { get; }
|
|
|
|
/// <summary>X axes for the chart (auto-scrolling, no labels).</summary>
|
|
public Axis[] XAxes { get; }
|
|
|
|
/// <summary>Y axes for the chart.</summary>
|
|
public Axis[] YAxes { get; }
|
|
|
|
/// <summary>
|
|
/// Tolerance band sections overlaid on the chart.
|
|
/// Updated when <see cref="SetTolerance"/> is called.
|
|
/// </summary>
|
|
[ObservableProperty] private RectangularSection[] _sections = Array.Empty<RectangularSection>();
|
|
|
|
/// <summary>
|
|
/// Creates a new chart ViewModel.
|
|
/// </summary>
|
|
/// <param name="title">Display title for the chart.</param>
|
|
/// <param name="lineColor">SKColor for the line series.</param>
|
|
/// <param name="maxSamples">Maximum number of samples before the oldest is dropped.</param>
|
|
public SingleFlowChartViewModel(string title, SKColor lineColor, int maxSamples = DefaultMaxSamples)
|
|
{
|
|
_title = title;
|
|
_maxSamples = maxSamples;
|
|
|
|
Series = new ISeries[]
|
|
{
|
|
new LineSeries<double>
|
|
{
|
|
Values = _values,
|
|
Fill = null,
|
|
GeometrySize = 0,
|
|
Stroke = new SolidColorPaint(lineColor, 2),
|
|
LineSmoothness = 0,
|
|
AnimationsSpeed = TimeSpan.Zero
|
|
}
|
|
};
|
|
|
|
XAxes = new Axis[]
|
|
{
|
|
new Axis
|
|
{
|
|
IsVisible = false,
|
|
AnimationsSpeed = TimeSpan.Zero
|
|
}
|
|
};
|
|
|
|
YAxes = new Axis[]
|
|
{
|
|
new Axis
|
|
{
|
|
AnimationsSpeed = TimeSpan.Zero,
|
|
MinLimit = 0,
|
|
SeparatorsPaint = new SolidColorPaint(new SKColor(224, 224, 224), 0.75f)
|
|
}
|
|
};
|
|
}
|
|
|
|
/// <summary>
|
|
/// Appends a value to the chart. Drops the oldest value when the window is full.
|
|
/// Must be called on the UI thread.
|
|
/// </summary>
|
|
public void AddValue(double value)
|
|
{
|
|
_values.Add(value);
|
|
CurrentValue = value;
|
|
if (_values.Count > _maxSamples)
|
|
_values.RemoveAt(0);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Sets the tolerance band (displayed as a shaded region on the chart).
|
|
/// </summary>
|
|
/// <param name="target">Center value of the tolerance band.</param>
|
|
/// <param name="tolerance">Half-width of the tolerance band.</param>
|
|
public void SetTolerance(double target, double tolerance)
|
|
{
|
|
Sections = new[]
|
|
{
|
|
new RectangularSection
|
|
{
|
|
Yi = target - tolerance,
|
|
Yj = target + tolerance,
|
|
Fill = new SolidColorPaint(SKColors.LimeGreen.WithAlpha(40))
|
|
}
|
|
};
|
|
}
|
|
|
|
/// <summary>
|
|
/// Clears all sample data and tolerance bands.
|
|
/// </summary>
|
|
public void Clear()
|
|
{
|
|
_values.Clear();
|
|
Sections = Array.Empty<RectangularSection>();
|
|
}
|
|
}
|
|
}
|