import type { Theme } from '@mui/material' /** * Resolve a colour string against the MUI theme palette. * * - `'primary.main'`, `'secondary.dark'`, `'success.contrastText'`, … → * walks `theme.palette` along the dot-separated path and returns the * resolved string when traversal succeeds. * - `'#ff0000'`, `'rgb(255, 0, 0)'`, `'red'` → returned as-is (assumed * raw CSS; ECharts consumes them directly). * - `undefined` → `undefined` (callers fall back to ECharts' palette). * * Used by the echart option factories (Bar, Pie, Histogram, Scatterplot, * Timeseries) so per-series colours specified as theme paths in the * unified `WidgetSeries` shape paint correctly. Category, Formula, and * Spread render colours through MUI's `sx` resolver, which already * handles theme paths — they don't need this helper. */ export function resolveThemeColor( theme: Theme, raw: string | undefined, ): string | undefined { if (raw == null) return undefined if (!raw.includes('.')) return raw const parts = raw.split('.') let cursor: unknown = theme.palette for (const part of parts) { if (cursor == null || typeof cursor !== 'object') { return raw } cursor = (cursor as Record)[part] } return typeof cursor === 'string' ? cursor : raw }