Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 12 additions & 11 deletions colorMapping.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@
// When the source file changes, update this file to match.
// Source: monoscope/web-components/src/colorMapping.ts

// The brightest values that clear 3:1 on Monoscope's light chart surface.
const LIGHT_THEME_COLORS = [
'#2563eb', '#dc2626', '#15803d', '#b45309', '#9333ea', '#0f766e',
'#c2410c', '#0369a1', '#e11d48', '#4d7c0f', '#4f46e5', '#a16207',
'#be185d', '#047857', '#7c3aed', '#0e7490', '#a21caf', '#475569',
'#1d4ed8', '#b91c1c'
'#3b82f6', '#ef4444', '#16a34a', '#d97706', '#a855f7', '#0d9488',
'#ea580c', '#0284c7', '#f43f5e', '#5f9c0b', '#6366f1', '#bd7d00',
'#ec4899', '#059669', '#8b5cf6', '#0891b2', '#d946ef', '#64748b',
'#5470c6', '#e05d44'
];
const DARK_THEME_COLORS = [
'#60a5fa', '#f87171', '#4ade80', '#fbbf24', '#c084fc', '#2dd4bf',
Expand Down Expand Up @@ -38,18 +39,18 @@ function hashString(str: string): number {
function getStatusCodeColor(code: number | string, theme: Theme): string {
const grouped = typeof code === 'string' && /^[2-5]xx$/i.test(code) ? Number(code[0]) * 100 : Number(code);
const dark = theme === 'dark';
if (grouped >= 200 && grouped < 300) return dark ? '#34d399' : '#047857';
if (grouped >= 300 && grouped < 400) return dark ? '#38bdf8' : '#0369a1';
if (grouped >= 400 && grouped < 500) return dark ? '#fbbf24' : '#b45309';
if (grouped >= 500 && grouped < 600) return dark ? '#f87171' : '#dc2626';
if (grouped >= 200 && grouped < 300) return dark ? '#34d399' : '#059669';
if (grouped >= 300 && grouped < 400) return dark ? '#38bdf8' : '#0284c7';
if (grouped >= 400 && grouped < 500) return dark ? '#fbbf24' : '#d97706';
if (grouped >= 500 && grouped < 600) return dark ? '#f87171' : '#ef4444';
return themeColors(theme)[4]!;
}

function getPercentileColor(percentile: string, theme: Theme): string {
const key = percentile.toLowerCase().trim();
const colors: Record<string, string> = theme === 'dark'
? { p50: '#4ade80', median: '#4ade80', p75: '#34d399', q1: '#34d399', p90: '#fbbf24', p95: '#fb923c', q3: '#fb923c', p99: '#f87171', p100: '#fb7185', max: '#fb7185', min: '#4ade80' }
: { p50: '#15803d', median: '#15803d', p75: '#047857', q1: '#047857', p90: '#a16207', p95: '#c2410c', q3: '#c2410c', p99: '#dc2626', p100: '#be123c', max: '#be123c', min: '#15803d' };
: { p50: '#16a34a', median: '#16a34a', p75: '#059669', q1: '#059669', p90: '#bd7d00', p95: '#ea580c', q3: '#ea580c', p99: '#ef4444', p100: '#f43f5e', max: '#f43f5e', min: '#16a34a' };
const palette = themeColors(theme);
return colors[key] ?? palette[hashString(percentile) % palette.length]!;
}
Expand All @@ -58,7 +59,7 @@ function getLogLevelColor(text: string, theme: Theme): string {
const normalized = text.toLowerCase().trim();
const semantic = theme === 'dark'
? { error: '#f87171', warning: '#fbbf24', warn: '#fbbf24', success: '#4ade80', ok: '#4ade80', info: '#60a5fa' }
: { error: '#dc2626', warning: '#b45309', warn: '#b45309', success: '#15803d', ok: '#15803d', info: '#2563eb' };
: { error: '#ef4444', warning: '#d97706', warn: '#d97706', success: '#16a34a', ok: '#16a34a', info: '#3b82f6' };
for (const [pattern, color] of Object.entries({ ...LOG_LEVEL_COLORS, ...semantic })) {
if (normalized === pattern || normalized.includes(pattern)) return color;
}
Expand All @@ -70,7 +71,7 @@ export function getSeriesColor(value: string, theme: Theme = 'light'): string {
const palette = themeColors(theme);
if (!value || value.trim() === '') return palette[0]!;
const lv = value.toLowerCase();
if (lv === 'null' || lv === 'undefined' || lv === 'unknown') return theme === 'dark' ? '#9ca3af' : '#4b5563';
if (lv === 'null' || lv === 'undefined' || lv === 'unknown') return theme === 'dark' ? '#9ca3af' : '#64748b';
if (/^[2-5]\d{2}$/.test(value) || /^[2-5]xx$/i.test(value)) return getStatusCodeColor(value, theme);
if (/^(p|q)\d+|median|max|min/i.test(value)) return getPercentileColor(value, theme);
for (const pattern of Object.keys(LOG_LEVEL_COLORS)) {
Expand Down