refactor(theme): update color classes

This commit is contained in:
CaIon
2026-06-19 14:53:44 +08:00
parent 490395b2f8
commit 0c806db996
12 changed files with 50 additions and 118 deletions
+3 -3
View File
@@ -23,12 +23,12 @@ import type { PingStatus } from '@/features/dashboard/types'
*/
export function getLatencyColorClass(latency: number): string {
if (latency < 200) {
return 'text-success'
return 'text-green-600 dark:text-green-400'
}
if (latency < 500) {
return 'text-warning'
return 'text-yellow-600 dark:text-yellow-400'
}
return 'text-destructive'
return 'text-red-600 dark:text-red-400'
}
/**
+7 -50
View File
@@ -38,37 +38,7 @@ type TooltipLineItem = {
shapeSize?: number
}
const THEME_CHART_COLOR_VARIABLES = [
'--chart-1',
'--chart-2',
'--chart-3',
'--chart-4',
'--chart-5',
] as const
function getThemeChartColors(themeKey?: string): string[] {
if (typeof document === 'undefined') return []
void themeKey
const bodyStyle = window.getComputedStyle(document.body)
const rootStyle = window.getComputedStyle(document.documentElement)
return THEME_CHART_COLOR_VARIABLES.map((name) => {
return (
bodyStyle.getPropertyValue(name) || rootStyle.getPropertyValue(name)
).trim()
}).filter(Boolean)
}
function getVChartDefaultColors(domainLength: number, themeKey?: string) {
const themeColors = getThemeChartColors(themeKey)
if (themeColors.length > 0) {
return Array.from(
{ length: Math.max(domainLength, themeColors.length) },
(_, index) => themeColors[index % themeColors.length]
)
}
function getVChartDefaultColors(domainLength: number) {
const scheme =
vchartDefaultDataScheme.find(
(item) => !item.maxDomainLength || domainLength <= item.maxDomainLength
@@ -98,7 +68,6 @@ export function processChartData(
data: QuotaDataItem[],
timeGranularity: TimeGranularity = 'day',
t?: TFunction,
themeKey?: string,
chartCornerRadius?: number
): ProcessedChartData {
const tt: TFunction = t ?? ((x) => x)
@@ -290,10 +259,7 @@ export function processChartData(
const sortedTimes = Array.from(timeModelMap.keys()).sort()
const sortedModels = [...allModels].sort()
const modelColorDomain = Array.from(new Set([...sortedModels, otherLabel]))
const modelColorRange = getVChartDefaultColors(
modelColorDomain.length,
themeKey
)
const modelColorRange = getVChartDefaultColors(modelColorDomain.length)
const otherColor = modelColorRange[modelColorDomain.indexOf(otherLabel)]
const otherTooltipColor =
typeof otherColor === 'string' ? otherColor : '#FF8A00'
@@ -719,7 +685,7 @@ export function processChartData(
}
}
const USER_COLOR_FALLBACKS = [
const USER_COLORS = [
'#5B8FF9',
'#5AD8A6',
'#F6BD16',
@@ -736,20 +702,11 @@ export function processUserChartData(
data: QuotaDataItem[],
timeGranularity: TimeGranularity = 'day',
t?: TFunction,
limit = 10,
themeKey?: string
limit = 10
): ProcessedUserChartData {
const tt: TFunction = t ?? ((x) => x)
const { config } = getCurrencyDisplay()
const quotaPerUnit = config.quotaPerUnit
const themeUserColors = getThemeChartColors(themeKey)
const userColorRange =
themeUserColors.length > 0
? Array.from(
{ length: Math.max(limit, themeUserColors.length) },
(_, index) => themeUserColors[index % themeUserColors.length]
)
: USER_COLOR_FALLBACKS
const formatVal = (raw: number) => renderQuotaCompat(raw, 2)
@@ -767,7 +724,7 @@ export function processUserChartData(
subtext: tt('No data available'),
},
legends: { visible: false },
color: { type: 'ordinal', range: userColorRange },
color: { type: 'ordinal', range: USER_COLORS },
background: { fill: 'transparent' },
},
spec_user_trend: {
@@ -782,7 +739,7 @@ export function processUserChartData(
subtext: tt('No data available'),
},
legends: { visible: true, selectMode: 'single' },
color: { type: 'ordinal', range: userColorRange },
color: { type: 'ordinal', range: USER_COLORS },
point: { visible: false },
background: { fill: 'transparent' },
},
@@ -812,7 +769,7 @@ export function processUserChartData(
const userColorMap = topUsers.reduce<Record<string, string>>(
(acc, user, i) => {
acc[user] = userColorRange[i % userColorRange.length]
acc[user] = USER_COLORS[i % USER_COLORS.length]
return acc
},
{}