@using ArcaneLibs @if (Data.Count > 0) { $"{x.Key},{x.Value}"))" style="fill:none;stroke:black;stroke-width:3"/> @* Y min/max labels *@ @(ValueFormatter.Invoke(_minValue)) @(ValueFormatter.Invoke(_maxValue)) @* outline *@ } @code { [Parameter] public Dictionary Data { get; set; } [Parameter] public int Width { get; set; } = 100; [Parameter] public int Height { get; set; } = 100; [Parameter] public double? MinValue { get; set; } [Parameter] public double? MaxValue { get; set; } //value formatter [Parameter] public Func ValueFormatter { get; set; } = x => x.ToString("X2"); private double _minValue => MinValue ?? (Data.Count > 0 ? Data.Values.Min() : 0); private double _maxValue => MaxValue ?? (Data.Count > 0 ? Data.Values.Max() : 0); private Dictionary _points = []; protected override async Task OnParametersSetAsync() { await RebuildGraph(); await base.OnParametersSetAsync(); } private async Task RebuildGraph() { if (Data.Count == 0) return; _points.Clear(); var startTime = Data.Keys.Min(x => x).Ticks; var endTime = Data.Keys.Max(x => x).Ticks; var minValue = _minValue; var maxValue = _maxValue; Console.WriteLine($"Start: {startTime}, End: {endTime}, Min: {minValue}, Max: {maxValue}"); foreach (var item in Data) { _points.Add(Map(item.Key.Ticks, startTime, endTime, 0, Width), Map(item.Value, minValue, maxValue, Height, 0)); } } public static double Map( double value, double originalStart, double originalEnd, double newStart, double newEnd) { double num = (newEnd - newStart) / (originalEnd - originalStart); return newStart + (value - originalStart) * num; } }