SPB Git forge
15commits 1branches 0releases
29.7 MBsize
maindefault branch
10 days agolast push
TypeScript 36.3% Python 31.8% Go 18% JavaScript 9.8% Shell 1.9% SQL 1.4% CSS 0.5%
2.7 KB · 67 lines typescript
Raw Blame History
1import type { ComponentId, LevelId, Trend } from './types';23/** Pressure scale — mirrors packages/config/pressure.yaml (ids/max) and the design palette (colours). */4export const LEVELS: { id: LevelId; max: number; label: string; short: string; color: string }[] = [5  { id: 'calm', max: 10, label: 'Exceptionally calm', short: 'Calm', color: '#4CC9F0' },6  { id: 'normal', max: 25, label: 'Normal', short: 'Normal', color: '#7FB77E' },7  { id: 'elevated', max: 40, label: 'Elevated', short: 'Elevated', color: '#E9C46A' },8  { id: 'stressed', max: 55, label: 'Stressed', short: 'Stressed', color: '#F4A261' },9  { id: 'high', max: 70, label: 'Highly stressed', short: 'High', color: '#E76F51' },10  { id: 'severe', max: 85, label: 'Severe disruption', short: 'Severe', color: '#D62828' },11  { id: 'extreme', max: 100, label: 'Extreme Internet event', short: 'Extreme', color: '#F72585' },12];1314export const NEUTRAL = '#0F151D';15export const ACCENT = '#5B8DEF';1617export function levelFor(value: number | null | undefined): (typeof LEVELS)[number] {18  if (value == null || Number.isNaN(value)) return LEVELS[1]!;19  return LEVELS.find((l) => value <= l.max) ?? LEVELS[LEVELS.length - 1]!;20}2122export function levelById(id: LevelId | string | null | undefined) {23  return LEVELS.find((l) => l.id === id);24}2526/** Colour for a level id or a numeric pressure value. */27export function pressureColor(levelOrValue: LevelId | number | null | undefined): string {28  if (levelOrValue == null) return '#3A4756';29  if (typeof levelOrValue === 'number') return levelFor(levelOrValue).color;30  return levelById(levelOrValue)?.color ?? '#3A4756';31}3233export function levelWord(levelOrValue: LevelId | number | null | undefined): string {34  if (levelOrValue == null) return '—';35  const l = typeof levelOrValue === 'number' ? levelFor(levelOrValue) : levelById(levelOrValue);36  return (l?.short ?? '—').toUpperCase();37}3839export const COMPONENT_ORDER: ComponentId[] = ['routing', 'latency', 'dns', 'availability', 'http_tls', 'path', 'corroboration'];40export const COMPONENT_LABEL: Record<ComponentId, string> = {41  routing: 'Routing',42  latency: 'Latency',43  dns: 'DNS',44  availability: 'Availability',45  http_tls: 'HTTP/TLS',46  path: 'Path',47  corroboration: 'Corroboration',48};4950export function trendArrow(trend: Trend | undefined, delta?: number): string {51  if (trend === 'rising' || (trend === undefined && (delta ?? 0) > 0)) return '↑';52  if (trend === 'falling' || (trend === undefined && (delta ?? 0) < 0)) return '↓';53  return '→';54}5556export const STATUS_COLOR: Record<string, string> = {57  detected: '#E9C46A',58  developing: '#F4A261',59  active: '#E76F51',60  recovering: '#4CC9F0',61  resolved: '#8B98A5',62  online: '#7FB77E',63  stale: '#E9C46A',64  offline: '#D62828',65  excluded: '#8B98A5',66};67