@using TaskTrackingSystem.WebApp.Components.Shared.Charts
@if (Points.Count < 2) {
@EmptyText
} else { @for (var i = 0; i < 5; i++) { var y = 60 + (i * 55); } @for (var i = 0; i < 6; i++) { var x = 60 + (i * 125); } @foreach (var point in SvgPoints) { }
@foreach (var point in Points) { @point.Label }
}
@code { private readonly string GradientId = $"lineFill{Guid.NewGuid():N}"; [Parameter] public IReadOnlyList Points { get; set; } = Array.Empty(); [Parameter] public string Color { get; set; } = "#2563eb"; [Parameter] public string EmptyText { get; set; } = "No data available"; [Parameter] public string WrapperClass { get; set; } = string.Empty; private IReadOnlyList<(double X, double Y)> SvgPoints => BuildSvgPoints(); private string LinePath => BuildLinePath(); private string AreaPath => string.IsNullOrWhiteSpace(LinePath) ? string.Empty : $"{LinePath} L {SvgPoints.Last().X:0},{280:0} L {SvgPoints.First().X:0},{280:0} Z"; private IReadOnlyList<(double X, double Y)> BuildSvgPoints() { const double left = 48; const double right = 730; const double top = 48; const double bottom = 280; var max = Math.Max(1, Points.Select(point => point.Value).DefaultIfEmpty(0).Max()); return Points.Select((point, index) => { var x = left + (index * ((right - left) / Math.Max(Points.Count - 1, 1))); var y = bottom - Math.Min(point.Value, max) / max * (bottom - top); return (x, y); }).ToList(); } private string BuildLinePath() { if (!SvgPoints.Any()) { return string.Empty; } return $"M {string.Join(" L ", SvgPoints.Select(point => $"{point.X:0},{point.Y:0}"))}"; } }