using System; using Sonex.Data.Records; using Windows.UI; namespace Sonex.Client.Controls.TimelineGrid; public sealed class TimelineGridFunctionDefinition { public int Id { get; set; } public string Name { get; set; } = string.Empty; public Color LineColor { get; set; } public Color PointColor { get; set; } public Color BorderColor { get; set; } public double? AverageValue { get; set; } public string? Description { get; set; } public string? Symbol { get; set; } public int BaseColorArgb { get; set; } public bool IsGap { get; set; } public static TimelineGridFunctionDefinition FromRecord(OperationTypesRecord record) { var baseColor = ColorFromArgbInt(record.BaseColorArgb); return new TimelineGridFunctionDefinition { Id = record.Id, Name = record.Name, Description = record.Description, Symbol = record.Symbol, BaseColorArgb = record.BaseColorArgb, LineColor = Darken(baseColor, 0.16f), PointColor = baseColor, BorderColor = Lighten(baseColor, 0.22f), AverageValue = record.ExpectedValue, IsGap = string.Equals(record.Name, "Gap", StringComparison.OrdinalIgnoreCase) }; } private static Color ColorFromArgbInt(int argb) { unchecked { return Color.FromArgb( (byte)((argb >> 24) & 0xFF), (byte)((argb >> 16) & 0xFF), (byte)((argb >> 8) & 0xFF), (byte)(argb & 0xFF)); } } private static Color Darken(Color color, float amount) { var clamped = Math.Clamp(amount, 0f, 1f); return Color.FromArgb( color.A, (byte)Math.Clamp((int)Math.Round(color.R * (1f - clamped)), 0, 255), (byte)Math.Clamp((int)Math.Round(color.G * (1f - clamped)), 0, 255), (byte)Math.Clamp((int)Math.Round(color.B * (1f - clamped)), 0, 255)); } private static Color Lighten(Color color, float amount) { var clamped = Math.Clamp(amount, 0f, 1f); return Color.FromArgb( color.A, (byte)Math.Clamp((int)Math.Round(color.R + ((255 - color.R) * clamped)), 0, 255), (byte)Math.Clamp((int)Math.Round(color.G + ((255 - color.G) * clamped)), 0, 255), (byte)Math.Clamp((int)Math.Round(color.B + ((255 - color.B) * clamped)), 0, 255)); } }