An open source alternative to Tableau. Embeddable visual analytic
TypeScript bidatadata-analysisdata-miningdata-visualizationedak6skanarieslow-codepivot-tablereacttableautableau-alternativetypescriptvegavega-litevisualization
feat: support customize Theme
observedobserver90c946d66a97
diff --git a/packages/graphic-walker/src/App.tsx b/packages/graphic-walker/src/App.tsxindex bec2ab9d..a2826acd 100644--- a/packages/graphic-walker/src/App.tsx+++ b/packages/graphic-walker/src/App.tsx@@ -38,6 +38,7 @@ export interface IGWProps {fieldKeyGuard?: boolean;/** @default "vega" */themeKey?: IThemeKey;+ themeConfig?: any;dark?: IDarkMode;storeRef?: React.MutableRefObject<IGlobalStore | null>;computation?: IComputationFunction;@@ -67,6 +68,7 @@ const App = observer<IGWProps>(function App(props) {hideDataSourceConfig,fieldKeyGuard = true,themeKey = 'vega',+ themeConfig,dark = 'media',computation,toolbar,@@ -209,7 +211,7 @@ const App = observer<IGWProps>(function App(props) {// }}>{datasets.length > 0 && (- <ReactiveRenderer ref={rendererRef} themeKey={themeKey} dark={dark} computationFunction={vizStore.computationFunction} />+ <ReactiveRenderer ref={rendererRef} themeKey={themeKey} themeConfig={themeConfig} dark={dark} computationFunction={vizStore.computationFunction} />)}{/* {vizEmbededMenu.show && (<ClickMenu x={vizEmbededMenu.position[0]} y={vizEmbededMenu.position[1]}>diff --git a/packages/graphic-walker/src/renderer/index.tsx b/packages/graphic-walker/src/renderer/index.tsxindex 26e2ae23..a5f2b271 100644--- a/packages/graphic-walker/src/renderer/index.tsx+++ b/packages/graphic-walker/src/renderer/index.tsx@@ -15,6 +15,7 @@ import { initVisualConfig } from '../utils/save';interface RendererProps {themeKey?: IThemeKey;+ themeConfig?: any;dark?: IDarkMode;computationFunction: IComputationFunction;}@@ -23,7 +24,7 @@ interface RendererProps {* Depending on global store.*/const Renderer = forwardRef<IReactVegaHandler, RendererProps>(function (props, ref) {- const { themeKey, dark, computationFunction } = props;+ const { themeKey, dark, computationFunction, themeConfig } = props;const { vizStore, commonStore } = useGlobalStore();const {allFields,@@ -131,6 +132,7 @@ const Renderer = forwardRef<IReactVegaHandler, RendererProps>(function (props, rdata={viewData}ref={ref}themeKey={themeKey}+ themeConfig={themeConfig}dark={dark}locale={i18n.language}draggableFieldState={encodings}diff --git a/packages/graphic-walker/src/renderer/pureRenderer.tsx b/packages/graphic-walker/src/renderer/pureRenderer.tsxindex 11e24a35..31aac4c5 100644--- a/packages/graphic-walker/src/renderer/pureRenderer.tsx+++ b/packages/graphic-walker/src/renderer/pureRenderer.tsx@@ -23,6 +23,7 @@ type IPureRendererProps =| {name?: string;themeKey?: IThemeKey;+ themeConfig?: any;dark?: IDarkMode;visualState: DraggableFieldState;visualConfig: IVisualConfig;diff --git a/packages/graphic-walker/src/renderer/specRenderer.tsx b/packages/graphic-walker/src/renderer/specRenderer.tsxindex b0313c96..c0b02619 100644--- a/packages/graphic-walker/src/renderer/specRenderer.tsx+++ b/packages/graphic-walker/src/renderer/specRenderer.tsx@@ -9,6 +9,7 @@ import { DeepReadonly, DraggableFieldState, IDarkMode, IRow, IThemeKey, IVisualCimport LoadingLayer from '../components/loadingLayer';import { useCurrentMediaTheme } from '../utils/media';import { builtInThemes } from '../vis/theme';+import { useTheme } from '../utils/useTheme';interface SpecRendererProps {name?: string;@@ -22,13 +23,14 @@ interface SpecRendererProps {onChartResize?: ((width: number, height: number) => void) | undefined;locale?: string;computationFunction: IComputationFunction;+ themeConfig?: any;}/*** Sans-store renderer of GraphicWalker.* This is a pure component, which means it will not depend on any global state.*/const SpecRenderer = forwardRef<IReactVegaHandler, SpecRendererProps>(function (- { name, themeKey, dark, data, loading, draggableFieldState, visualConfig, onGeomClick, onChartResize, locale, computationFunction },+ { name, themeKey, dark, data, loading, draggableFieldState, visualConfig, onGeomClick, onChartResize, locale, computationFunction, themeConfig: customizedThemeConfig },ref) {// const { draggableFieldState, visualConfig } = vizStore;@@ -58,7 +60,11 @@ const SpecRenderer = forwardRef<IReactVegaHandler, SpecRendererProps>(function (const enableResize = size.mode === 'fixed' && !hasFacet && Boolean(onChartResize);const mediaTheme = useCurrentMediaTheme(dark);- const themeConfig = builtInThemes[themeKey ?? 'vega']?.[mediaTheme];+ const themeConfig = useTheme({+ themeKey,+ mediaTheme,+ themeConfig: customizedThemeConfig+ })const vegaConfig = useMemo<VegaGlobalConfig>(() => {const config: VegaGlobalConfig = {diff --git a/packages/graphic-walker/src/utils/useTheme.ts b/packages/graphic-walker/src/utils/useTheme.tsnew file mode 100644index 00000000..12d66456--- /dev/null+++ b/packages/graphic-walker/src/utils/useTheme.ts@@ -0,0 +1,8 @@+import { IThemeKey } from "../interfaces";+import { builtInThemes } from "../vis/theme";++export function useTheme (props: { themeKey?: IThemeKey; themeConfig?: any; mediaTheme: 'dark' | 'light' }) {+ const { themeConfig, themeKey, mediaTheme } = props;+ const config = (themeConfig ?? builtInThemes[themeKey ?? 'vega'])?.[mediaTheme];+ return config+}\ No newline at end of file