/** * Stack-mode config transform: marks every series with `stack: 'total'` so * ECharts stacks them vertically (bar) or by value (line). Module-level * constant so identity is stable across renders — no `useCallback` needed. * * Widgets that bake series into options at build time get marked in place. * Widgets that build series at data-fusion time (`bar`, `histogram`, * `timeseries`) have no `series` array yet at config-transform time, so we * also emit a single-entry **broadcast template** (`[{ stack: 'total' }]`). * Their option factories merge that template into every series they emit * at fusion time, so the `stack` mark survives end-to-end. */ export const addStack = (option: unknown): unknown => { if (option == null || typeof option !== 'object') return option const cfg = option as Record const existing = Array.isArray(cfg.series) ? cfg.series : [] const series = existing.length === 0 ? [{ stack: 'total' }] : existing.map((s: unknown): unknown => { if (s == null || typeof s !== 'object') return s return { ...s, stack: 'total' } }) return { ...cfg, series } }