@using System.Drawing @using System.Runtime.InteropServices @using System.Diagnostics @if (Data is { Count: > 0 }) { @* 12*5=60 *@
@* row 0: month labels with colspan *@ @* @foreach (var month in Enumerable.Range(1, 12)) *@ @* { *@ @*
*@ @* *@ @*
*@ @* } *@ @* column 0: day labels *@ @* @for (var i = 0; i < 7; i++) *@ @* { *@ @*
*@ @* @(((DayOfWeek)i).ToString()[..3]) *@ @*
*@ @* } *@
Jan
Feb
Mar
Apr
May
Jun
Jul
Aug
Sep
Oct
Nov
Dec
Sun
Mon
Tue
Wed
Thu
Fri
Sat
@* pad activity cell dates... *@
@* the actual activity cells *@ @code{ bool needsBorder = false; } @for (DateOnly date = new DateOnly(Data.Keys.First().Year, 1, 1); date <= new DateOnly(Data.Keys.First().Year, 1, 1).AddYears(1).AddDays(-1); date = date.AddDays(1)) { var hasData = Data.TryGetValue(date, out var color); var needsTopBorder = date.Day == 1 && date.Month != 1 && date.DayOfWeek != DayOfWeek.Sunday; if (date.DayOfWeek == DayOfWeek.Sunday) needsBorder = date.AddDays(7).Day <= 7 && date.Month != 12; var needsLeftBorder = date.Day <= 7;
@if (hasData) {
} else {
}
}
} @code { private Dictionary _data = new(); private RGB? _globalMax = null; [Parameter] public Dictionary Data { get => _data; set { // var sw = Stopwatch.StartNew(); if (value is not { Count: > 0 }) return; // Console.WriteLine($"Recalculating activity graph ({value.Count} datapoints)..."); // var year = (int)value.Keys.Average(x => x.Year); // value = value // .Where(x => x.Key.Year == year) // .OrderBy(x => x.Key) // .ToDictionary(x => x.Key, x => x.Value); _data = value; // Console.WriteLine($"Recalculated activity graph in {sw.Elapsed}"); // StateHasChanged(); } } [Parameter] public RGB GlobalMax { get { if (_globalMax is not null) return _globalMax.Value; if (Data is not { Count: > 0 }) return new RGB() { R = 255, G = 255, B = 255 }; return new RGB() { R = Data.Values.Max(x => x.R), G = Data.Values.Max(x => x.G), B = Data.Values.Max(x => x.B) }; } set => _globalMax = value; } [Parameter] public string RLabel { get; set; } = "R"; [Parameter] public string GLabel { get; set; } = "G"; [Parameter] public string BLabel { get; set; } = "B"; [StructLayout(LayoutKind.Sequential, Size = sizeof(float) * 3, Pack = 1)] public struct RGB() { public float R = 0; public float G = 0; public float B = 0; public RGB(float r, float g, float b) : this() { R = r; G = g; B = b; } } }