(userOptions: ChartGPUOptions = {})
| 710 | }; |
| 711 | |
| 712 | export function resolveOptions(userOptions: ChartGPUOptions = {}): ResolvedChartGPUOptions { |
| 713 | const baseTheme = resolveTheme(userOptions.theme); |
| 714 | |
| 715 | // runtime safety for JS callers |
| 716 | const autoScrollRaw = (userOptions as unknown as { readonly autoScroll?: unknown }).autoScroll; |
| 717 | const autoScroll = typeof autoScrollRaw === 'boolean' ? autoScrollRaw : defaultOptions.autoScroll; |
| 718 | |
| 719 | // runtime safety for JS callers |
| 720 | const animationRaw = (userOptions as unknown as { readonly animation?: unknown }).animation; |
| 721 | const animationCandidate: ChartGPUOptions['animation'] = |
| 722 | typeof animationRaw === 'boolean' || |
| 723 | (animationRaw !== null && typeof animationRaw === 'object' && !Array.isArray(animationRaw)) |
| 724 | ? (animationRaw as ChartGPUOptions['animation']) |
| 725 | : undefined; |
| 726 | // Default: animation enabled (with defaults) unless explicitly disabled. |
| 727 | const animation: ChartGPUOptions['animation'] = animationCandidate ?? true; |
| 728 | |
| 729 | // Backward compatibility: |
| 730 | // - If `userOptions.palette` is provided (non-empty), treat it as an override for the theme palette. |
| 731 | const paletteOverride = sanitizePalette(userOptions.palette); |
| 732 | |
| 733 | const themeCandidate: ThemeConfig = |
| 734 | paletteOverride.length > 0 ? { ...baseTheme, colorPalette: paletteOverride } : baseTheme; |
| 735 | |
| 736 | // Ensure palette used for modulo indexing is never empty. |
| 737 | const paletteFromTheme = sanitizePalette(themeCandidate.colorPalette); |
| 738 | const safePalette = |
| 739 | paletteFromTheme.length > 0 |
| 740 | ? paletteFromTheme |
| 741 | : sanitizePalette(defaultOptions.palette ?? defaultPalette).length > 0 |
| 742 | ? sanitizePalette(defaultOptions.palette ?? defaultPalette) |
| 743 | : Array.from(defaultPalette); |
| 744 | |
| 745 | const paletteForIndexing = safePalette.length > 0 ? safePalette : ['#000000']; |
| 746 | const theme: ThemeConfig = { ...themeCandidate, colorPalette: paletteForIndexing.slice() }; |
| 747 | |
| 748 | const grid: ResolvedGridConfig = { |
| 749 | left: userOptions.grid?.left ?? defaultOptions.grid.left, |
| 750 | right: userOptions.grid?.right ?? defaultOptions.grid.right, |
| 751 | top: userOptions.grid?.top ?? defaultOptions.grid.top, |
| 752 | bottom: userOptions.grid?.bottom ?? defaultOptions.grid.bottom, |
| 753 | }; |
| 754 | |
| 755 | const xAxis: AxisConfig = userOptions.xAxis |
| 756 | ? { |
| 757 | ...defaultOptions.xAxis, |
| 758 | ...userOptions.xAxis, |
| 759 | // runtime safety for JS callers |
| 760 | type: (userOptions.xAxis as unknown as Partial<AxisConfig>).type ?? defaultOptions.xAxis.type, |
| 761 | autoBounds: |
| 762 | normalizeAxisAutoBounds((userOptions.xAxis as unknown as { readonly autoBounds?: unknown }).autoBounds) ?? |
| 763 | (defaultOptions.xAxis as AxisConfig).autoBounds, |
| 764 | } |
| 765 | : { ...defaultOptions.xAxis }; |
| 766 | |
| 767 | const yAxis: AxisConfig = userOptions.yAxis |
| 768 | ? { |
| 769 | ...defaultOptions.yAxis, |
no test coverage detected