Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -766,3 +766,76 @@ test('Theme base theme integration arrays in themes are replaced entirely, not m
expect(serialized.algorithm).not.toContain(ThemeAlgorithm.COMPACT);
expect(serialized.algorithm).not.toContain(ThemeAlgorithm.DEFAULT);
});

test('Theme includes echartsOptionsOverrides from top-level config', () => {
const config = {
token: {
colorPrimary: '#ff0000',
},
echartsOptionsOverrides: {
grid: { left: '10%' },
tooltip: { trigger: 'axis' },
},
};

const theme = Theme.fromConfig(config as AnyThemeConfig);

expect((theme.theme as any).echartsOptionsOverrides).toEqual({
grid: { left: '10%' },
tooltip: { trigger: 'axis' },
});
});

test('Theme includes echartsOptionsOverridesByChartType from top-level config', () => {
const config = {
token: {
colorPrimary: '#ff0000',
},
echartsOptionsOverridesByChartType: {
echarts_timeseries_bar: {
series: { itemStyle: { borderRadius: [4, 4, 0, 0] } },
},
echarts_pie: {
legend: { orient: 'vertical', right: 10 },
},
},
};

const theme = Theme.fromConfig(config as AnyThemeConfig);

expect((theme.theme as any).echartsOptionsOverridesByChartType).toEqual({
echarts_timeseries_bar: {
series: { itemStyle: { borderRadius: [4, 4, 0, 0] } },
},
echarts_pie: {
legend: { orient: 'vertical', right: 10 },
},
});
});

test('Theme includes both echartsOptionsOverrides and echartsOptionsOverridesByChartType', () => {
const config = {
token: {
colorPrimary: '#ff0000',
},
echartsOptionsOverrides: {
grid: { left: '10%' },
},
echartsOptionsOverridesByChartType: {
echarts_bar: {
series: { itemStyle: { borderRadius: 4 } },
},
},
};

const theme = Theme.fromConfig(config as AnyThemeConfig);

expect((theme.theme as any).echartsOptionsOverrides).toEqual({
grid: { left: '10%' },
});
expect((theme.theme as any).echartsOptionsOverridesByChartType).toEqual({
echarts_bar: {
series: { itemStyle: { borderRadius: 4 } },
},
});
});
14 changes: 14 additions & 0 deletions superset-frontend/packages/superset-core/src/ui/theme/Theme.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,25 @@ export class Theme {
// First phase: Let Ant Design compute the tokens
const tokens = Theme.getFilteredAntdTheme(antdConfig);

// Extract Superset-specific properties from top-level config.
// These are custom properties that aren't part of Ant Design's token system
// but need to be passed through to the SupersetTheme for ECharts customization.
const { echartsOptionsOverrides, echartsOptionsOverridesByChartType } =
config as AnyThemeConfig & {
echartsOptionsOverrides?: any;
echartsOptionsOverridesByChartType?: Record<string, any>;
};

// Set the base theme properties
this.antdConfig = antdConfig;
this.theme = {
...tokens, // First apply Ant Design computed tokens
...antdConfig.token, // Then override with our custom tokens
// Include Superset-specific properties from top-level config
...(echartsOptionsOverrides && { echartsOptionsOverrides }),
...(echartsOptionsOverridesByChartType && {
echartsOptionsOverridesByChartType,
}),
} as SupersetTheme;

// Update the providers with the fully formed theme
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import {
} from 'react';
import { useSelector } from 'react-redux';

import { mergeReplaceArrays } from '@superset-ui/core';
import { styled, useTheme } from '@apache-superset/core/ui';
import { use, init, EChartsType, registerLocale } from 'echarts/core';
import {
Expand Down Expand Up @@ -66,6 +65,7 @@ import {
import { LabelLayout } from 'echarts/features';
import { EchartsHandler, EchartsProps, EchartsStylesProps } from '../types';
import { DEFAULT_LOCALE } from '../constants';
import { mergeEchartsThemeOverrides } from '../utils/themeOverrides';

// Define this interface here to avoid creating a dependency back to superset-frontend,
// TODO: to move the type to @superset-ui/core
Expand Down Expand Up @@ -258,7 +258,7 @@ function Echart(
}
: {};

const themedEchartOptions = mergeReplaceArrays(
const themedEchartOptions = mergeEchartsThemeOverrides(
baseTheme,
echartOptions,
globalOverrides,
Expand Down
Loading
Loading