2026-10-25 05:59:18 +01:00
|
|
|
@inject Heimdall.Web.Services.UiText Text
|
|
|
|
|
@inject Heimdall.Web.Services.UiLanguageService Language
|
|
|
|
|
|
2026-10-25 02:19:01 +02:00
|
|
|
<MudPaper Elevation="0" Class="pa-3" Style="border: 1px solid var(--mud-palette-lines-default); border-radius: 8px; height: 100%;">
|
|
|
|
|
<MudText Typo="Typo.subtitle2">@Title</MudText>
|
|
|
|
|
@if (Points.Count == 0 || !Points.Any(point => point.Value.HasValue))
|
|
|
|
|
{
|
2026-10-25 05:59:18 +01:00
|
|
|
<MudText Typo="Typo.caption" Color="Color.Secondary" Class="mt-4">@Text["SharedMetricHistory_NoData"]</MudText>
|
2026-10-25 02:19:01 +02:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
<svg viewBox="0 0 720 160" role="img" aria-label="@Title" style="width:100%;height:150px;overflow:visible;">
|
|
|
|
|
<line x1="40" y1="14" x2="710" y2="14" stroke="var(--mud-palette-lines-default)" />
|
|
|
|
|
<line x1="40" y1="130" x2="710" y2="130" stroke="var(--mud-palette-lines-default)" />
|
|
|
|
|
<text x="2" y="18" fill="var(--mud-palette-text-secondary)" font-size="11">@FormatValue(UpperBound)</text>
|
|
|
|
|
<text x="2" y="134" fill="var(--mud-palette-text-secondary)" font-size="11">@FormatValue(LowerBound)</text>
|
|
|
|
|
@foreach (var segment in GetSegments())
|
|
|
|
|
{
|
|
|
|
|
<polyline points="@segment" fill="none" stroke="var(--mud-palette-primary)" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round" />
|
|
|
|
|
}
|
|
|
|
|
</svg>
|
|
|
|
|
<div class="d-flex justify-space-between">
|
2026-10-25 05:59:18 +01:00
|
|
|
<MudText Typo="Typo.caption" Color="Color.Secondary">@Points[0].TimestampUtc.ToLocalTime().ToString("g", Language.Culture)</MudText>
|
|
|
|
|
<MudText Typo="Typo.caption" Color="Color.Secondary">@Points[^1].TimestampUtc.ToLocalTime().ToString("g", Language.Culture)</MudText>
|
2026-10-25 02:19:01 +02:00
|
|
|
</div>
|
|
|
|
|
}
|
|
|
|
|
</MudPaper>
|
|
|
|
|
|
|
|
|
|
@code {
|
|
|
|
|
[Parameter, EditorRequired] public string Title { get; set; } = "";
|
|
|
|
|
[Parameter, EditorRequired] public IReadOnlyList<MetricChartPoint> Points { get; set; } = [];
|
|
|
|
|
[Parameter] public string Unit { get; set; } = "%";
|
|
|
|
|
[Parameter] public double? Minimum { get; set; }
|
|
|
|
|
[Parameter] public double? Maximum { get; set; }
|
|
|
|
|
|
|
|
|
|
private double LowerBound
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
if (Minimum.HasValue) return Minimum.Value;
|
|
|
|
|
var values = Points.Where(point => point.Value.HasValue).Select(point => point.Value!.Value).ToArray();
|
|
|
|
|
return values.Length == 0 ? 0 : Math.Floor(values.Min());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private double UpperBound
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
if (Maximum.HasValue) return Maximum.Value;
|
|
|
|
|
var values = Points.Where(point => point.Value.HasValue).Select(point => point.Value!.Value).ToArray();
|
|
|
|
|
if (values.Length == 0) return 1;
|
|
|
|
|
var max = Math.Ceiling(values.Max());
|
|
|
|
|
return max <= LowerBound ? LowerBound + 1 : max;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private IEnumerable<string> GetSegments()
|
|
|
|
|
{
|
|
|
|
|
const double left = 40;
|
|
|
|
|
const double right = 710;
|
|
|
|
|
const double top = 14;
|
|
|
|
|
const double bottom = 130;
|
|
|
|
|
var span = Math.Max(UpperBound - LowerBound, double.Epsilon);
|
|
|
|
|
var segment = new List<string>();
|
|
|
|
|
for (var index = 0; index < Points.Count; index++)
|
|
|
|
|
{
|
|
|
|
|
if (Points[index].Value is not { } value)
|
|
|
|
|
{
|
|
|
|
|
if (segment.Count > 0) { yield return string.Join(" ", segment); segment.Clear(); }
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var x = Points.Count <= 1 ? left : left + (right - left) * index / (Points.Count - 1);
|
|
|
|
|
var y = bottom - (bottom - top) * (value - LowerBound) / span;
|
|
|
|
|
segment.Add($"{x.ToString("0.##", System.Globalization.CultureInfo.InvariantCulture)},{y.ToString("0.##", System.Globalization.CultureInfo.InvariantCulture)}");
|
|
|
|
|
}
|
|
|
|
|
if (segment.Count > 0) yield return string.Join(" ", segment);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private string FormatValue(double value) => $"{value:0.##}{Unit}";
|
|
|
|
|
}
|