/** * Convert a value in range [0, max] to an RGB color using a smooth perceptually uniform gradient * This gradient goes from dark purple/blue (low values) to bright yellow/orange (high values) * Similar to the plasma colormap - attractive and perceptually linear */ export function valueToColor(value: number, max: number): string { const t = value / max; // Smooth gradient from dark purple-blue to bright yellow-orange // Carefully tuned for perceptual uniformity and attractiveness let r: number, g: number, b: number; // Red channel: smooth increase r = Math.floor(13 + 242 * Math.pow(t, 0.5)); // Green channel: gentle S-curve for smoothness g = Math.floor(8 + 247 * Math.pow(t, 1.5)); // Blue channel: decrease from purple to yellow b = Math.floor(135 * Math.pow(1 - t, 2)); // Clamp values to valid range r = Math.min(255, Math.max(0, r)); g = Math.min(255, Math.max(0, g)); b = Math.min(255, Math.max(0, b)); return `rgb(${r}, ${g}, ${b})`; } /** * Get an array of colors for the color bar */ export function getColorGradient(steps: number): string[] { const colors: string[] = []; for (let i = 0; i < steps; i++) { colors.push(valueToColor(i, steps - 1)); } return colors; }