mirror of
https://github.com/QuantumNous/new-api.git
synced 2026-09-06 17:46:23 +00:00
refactor(theme): update color classes
This commit is contained in:
+1
-9
@@ -102,17 +102,9 @@ export function ConsumptionDistributionChart(
|
||||
props.loading ? [] : props.data,
|
||||
timeGranularity,
|
||||
t,
|
||||
customization.preset,
|
||||
chartRadius
|
||||
),
|
||||
[
|
||||
props.data,
|
||||
props.loading,
|
||||
timeGranularity,
|
||||
t,
|
||||
customization.preset,
|
||||
chartRadius,
|
||||
]
|
||||
[props.data, props.loading, timeGranularity, t, chartRadius]
|
||||
)
|
||||
const spec = chartType === 'bar' ? chartData.spec_line : chartData.spec_area
|
||||
const specType = typeof spec?.type === 'string' ? spec.type : chartType
|
||||
|
||||
@@ -100,17 +100,9 @@ export function ModelCharts(props: ModelChartsProps) {
|
||||
props.loading ? [] : props.data,
|
||||
timeGranularity,
|
||||
t,
|
||||
customization.preset,
|
||||
chartRadius
|
||||
),
|
||||
[
|
||||
props.data,
|
||||
props.loading,
|
||||
timeGranularity,
|
||||
t,
|
||||
customization.preset,
|
||||
chartRadius,
|
||||
]
|
||||
[props.data, props.loading, timeGranularity, t, chartRadius]
|
||||
)
|
||||
|
||||
const spec = chartData[CHART_SPEC_KEYS[activeTab]]
|
||||
|
||||
@@ -30,10 +30,10 @@ import type {
|
||||
import { PanelWrapper } from '../ui/panel-wrapper'
|
||||
|
||||
const STATUS_COLOR_MAP: Record<number, string> = {
|
||||
1: 'bg-success',
|
||||
0: 'bg-destructive',
|
||||
2: 'bg-warning',
|
||||
3: 'bg-info',
|
||||
1: 'bg-emerald-500',
|
||||
0: 'bg-red-500',
|
||||
2: 'bg-amber-500',
|
||||
3: 'bg-blue-500',
|
||||
}
|
||||
const DEFAULT_STATUS_COLOR = 'bg-muted-foreground/40'
|
||||
|
||||
|
||||
@@ -23,7 +23,6 @@ import { Users, Loader2 } from 'lucide-react'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { getRollingDateRange, type TimeGranularity } from '@/lib/time'
|
||||
import { VCHART_OPTION } from '@/lib/vchart'
|
||||
import { useThemeCustomization } from '@/context/theme-customization-provider'
|
||||
import { useTheme } from '@/context/theme-provider'
|
||||
import { Skeleton } from '@/components/ui/skeleton'
|
||||
import { Tabs, TabsList, TabsTrigger } from '@/components/ui/tabs'
|
||||
@@ -66,7 +65,6 @@ const TOP_USER_LIMIT_OPTIONS = [5, 10, 20, 50]
|
||||
export function UserCharts() {
|
||||
const { t } = useTranslation()
|
||||
const { resolvedTheme } = useTheme()
|
||||
const { customization } = useThemeCustomization()
|
||||
const [themeReady, setThemeReady] = useState(false)
|
||||
const themeManagerRef = useRef<
|
||||
(typeof import('@visactor/vchart'))['ThemeManager'] | null
|
||||
@@ -138,18 +136,9 @@ export function UserCharts() {
|
||||
isLoading ? [] : (userData ?? []),
|
||||
timeGranularity,
|
||||
t,
|
||||
topUserLimit,
|
||||
customization.preset
|
||||
topUserLimit
|
||||
),
|
||||
[
|
||||
userData,
|
||||
isLoading,
|
||||
timeGranularity,
|
||||
t,
|
||||
topUserLimit,
|
||||
customization.preset,
|
||||
customization.radius,
|
||||
]
|
||||
[userData, isLoading, timeGranularity, t, topUserLimit]
|
||||
)
|
||||
|
||||
return (
|
||||
@@ -240,7 +229,7 @@ export function UserCharts() {
|
||||
themeReady &&
|
||||
spec && (
|
||||
<VChart
|
||||
key={`user-${chart.value}-${topUserLimit}-${resolvedTheme}-${customization.preset}`}
|
||||
key={`user-${chart.value}-${topUserLimit}-${resolvedTheme}`}
|
||||
spec={{
|
||||
...spec,
|
||||
theme: resolvedTheme === 'dark' ? 'dark' : 'light',
|
||||
|
||||
+3
-3
@@ -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
@@ -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
|
||||
},
|
||||
{}
|
||||
|
||||
Reference in New Issue
Block a user