namespace PlotLine.Services; /// Stable defaults for older lines which all inherited the original green. public static class PlotLineColours { public static string ForLine(int plotLineId, string? colour) { if (!string.IsNullOrWhiteSpace(colour) && !colour.Equals("#2f6f63", StringComparison.OrdinalIgnoreCase)) return colour; // Identity, never selection order, determines the default. Explicit choices are preserved. var hue = ((uint)plotLineId * 137.508) % 360 / 60; const double chroma = .48; var secondary = chroma * (1 - Math.Abs(hue % 2 - 1)); var (r, g, b) = hue switch { < 1 => (chroma, secondary, 0d), < 2 => (secondary, chroma, 0d), < 3 => (0d, chroma, secondary), < 4 => (0d, secondary, chroma), < 5 => (secondary, 0d, chroma), _ => (chroma, 0d, secondary) }; return $"#{(int)((r + .30) * 255):x2}{(int)((g + .30) * 255):x2}{(int)((b + .30) * 255):x2}"; } }