An open source alternative to Tableau. Embeddable visual analytic
TypeScript bidatadata-analysisdata-miningdata-visualizationedak6skanarieslow-codepivot-tablereacttableautableau-alternativetypescriptvegavega-litevisualization
feat(): built-in themes
kyusho1e9ad63ff80c
diff --git a/packages/graphic-walker/src/App.tsx b/packages/graphic-walker/src/App.tsxindex ffaddc2d..19b4a6bd 100644--- a/packages/graphic-walker/src/App.tsx+++ b/packages/graphic-walker/src/App.tsx@@ -36,6 +36,7 @@ export interface IGWProps {* auto parse field key into a safe string. default is true*/fieldKeyGuard?: boolean;+ themeKey?: 'vega' | 'antv';}const App: React.FC<IGWProps> = (props) => {@@ -47,6 +48,7 @@ const App: React.FC<IGWProps> = (props) => {i18nResources,hideDataSourceConfig,fieldKeyGuard = true,+ themeKey = 'antv',} = props;const { commonStore, vizStore } = useGlobalStore();const [insightReady, setInsightReady] = useState<boolean>(true);@@ -153,7 +155,7 @@ const App: React.FC<IGWProps> = (props) => {vizEmbededMenu.show && commonStore.closeEmbededMenu();}}>- {datasets.length > 0 && <ReactiveRenderer ref={rendererRef} />}+ {datasets.length > 0 && <ReactiveRenderer ref={rendererRef} themeKey={themeKey} />}<InsightBoard />{vizEmbededMenu.show && (<ClickMenu x={vizEmbededMenu.position[0]} y={vizEmbededMenu.position[1]}>diff --git a/packages/graphic-walker/src/components/dropdownContext/index.tsx b/packages/graphic-walker/src/components/dropdownContext/index.tsxindex 2131f816..89fc4ba8 100644--- a/packages/graphic-walker/src/components/dropdownContext/index.tsx+++ b/packages/graphic-walker/src/components/dropdownContext/index.tsx@@ -38,7 +38,7 @@ const DropdownContext: React.FC<IDropdownContextProps> = (props) => {<Menu.Items className="absolute left-0 z-50 mt-2 w-56 origin-top-right rounded-md bg-white dark:bg-zinc-900 shadow-lg border border-gray-50 dark:border-gray-800 ring-1 ring-black ring-opacity-5 focus:outline-none"><div className="py-1">{options.map((option, index) => (- <Menu.Item>+ <Menu.Item key={option.value}>{(p) => (<spanclassName={classNames(diff --git a/packages/graphic-walker/src/components/toolbar/components.tsx b/packages/graphic-walker/src/components/toolbar/components.tsxindex 274398a5..4ffc442e 100644--- a/packages/graphic-walker/src/components/toolbar/components.tsx+++ b/packages/graphic-walker/src/components/toolbar/components.tsx@@ -114,5 +114,13 @@ export const ToolbarItemContainerElement = styled.div<{ split: boolean }>`}}}+ @media (prefers-color-scheme: dark) {+ color: var(--dark-mode-color);+ :hover, :focus, &.open {+ background-image: linear-gradient(#202020CC, #262626CC);+ --background-color: #202020;+ color: var(--dark-mode-color-hover);+ }+ }transition: color 100ms, background-image 100ms;`;diff --git a/packages/graphic-walker/src/renderer/index.tsx b/packages/graphic-walker/src/renderer/index.tsxindex ffd26ab3..c416bdfd 100644--- a/packages/graphic-walker/src/renderer/index.tsx+++ b/packages/graphic-walker/src/renderer/index.tsx@@ -7,7 +7,7 @@ import { useGlobalStore } from '../store';import ReactVega, { IReactVegaHandler } from '../vis/react-vega';-const ReactiveRenderer = forwardRef<IReactVegaHandler, {}>(function ReactiveRenderer (props, ref) {+const ReactiveRenderer = forwardRef<IReactVegaHandler, { themeKey?: 'vega' | 'antv' }>(function ReactiveRenderer ({ themeKey }, ref) {const { vizStore, commonStore } = useGlobalStore();const { draggableFieldState, visualConfig } = vizStore;const { geoms, interactiveScale, defaultAggregated, stack, showActions, size, exploration } = visualConfig;@@ -105,6 +105,7 @@ const ReactiveRenderer = forwardRef<IReactVegaHandler, {}>(function ReactiveRendbrushEncoding={exploration.mode === 'brush' ? exploration.brushDirection : 'none'}selectEncoding={exploration.mode === 'point' ? 'default' : 'none'}onGeomClick={handleGeomClick}+ themeKey={themeKey}/></Resizable>});diff --git a/packages/graphic-walker/src/vis/react-vega.tsx b/packages/graphic-walker/src/vis/react-vega.tsxindex 803bb73e..8d22ff2f 100644--- a/packages/graphic-walker/src/vis/react-vega.tsx+++ b/packages/graphic-walker/src/vis/react-vega.tsx@@ -11,7 +11,7 @@ import { COUNT_FIELD_ID } from '../constants';import { IViewField, IRow, IStackMode } from '../interfaces';import { useTranslation } from 'react-i18next';import { getVegaTimeFormatRules } from './temporalFormat';-import { DEFAULT_DARK_THEME, DEFAULT_THEME } from './theme';+import { builtInThemes } from './theme';import { useCurrentMediaTheme } from '../utils/media';const CanvaContainer = styled.div<{rowSize: number; colSize: number;}>`@@ -48,6 +48,8 @@ interface ReactVegaProps {onGeomClick?: (values: any, e: any) => voidselectEncoding: SingleViewProps['selectEncoding'];brushEncoding: SingleViewProps['brushEncoding'];+ /** @default "vega" */+ themeKey?: 'vega' | 'antv';}const NULL_FIELD: IViewField = {dragId: '',@@ -380,13 +382,14 @@ const ReactVega = forwardRef<IReactVegaHandler, ReactVegaProps>(function ReactVeheight,selectEncoding,brushEncoding,+ themeKey = 'vega',} = props;// const container = useRef<HTMLDivElement>(null);// const containers = useRef<(HTMLDivElement | null)[]>([]);const [viewPlaceholders, setViewPlaceholders] = useState<React.MutableRefObject<HTMLDivElement>[]>([]);const { i18n } = useTranslation();const mediaTheme = useCurrentMediaTheme();- const themeConfig = mediaTheme === 'dark' ? DEFAULT_DARK_THEME : DEFAULT_THEME;+ const themeConfig = builtInThemes[themeKey]?.[mediaTheme];useEffect(() => {const clickSub = geomClick$.subscribe(([values, e]) => {if (onGeomClick) {@@ -677,6 +680,7 @@ const ReactVega = forwardRef<IReactVegaHandler, ReactVegaProps>(function ReactVeselectEncoding,brushEncoding,crossFilterTriggerIdx,+ themeConfig,]);useImperativeHandle(ref, () => ({diff --git a/packages/graphic-walker/src/vis/theme.ts b/packages/graphic-walker/src/vis/theme.tsindex 744dfbd9..9aa21136 100644--- a/packages/graphic-walker/src/vis/theme.ts+++ b/packages/graphic-walker/src/vis/theme.ts@@ -1,99 +1,126 @@const DEFAULT_COLOR = "#5B8FF9";-export const DEFAULT_THEME: any = {- area: { fill: DEFAULT_COLOR },- bar: { fill: DEFAULT_COLOR },- circle: { fill: DEFAULT_COLOR },- line: { stroke: DEFAULT_COLOR },- point: { stroke: DEFAULT_COLOR },- rect: { fill: DEFAULT_COLOR },- tick: { stroke: DEFAULT_COLOR },- boxplot: { fill: DEFAULT_COLOR },- errorbar: { stroke: DEFAULT_COLOR },- errorband: { fill: DEFAULT_COLOR },- arc: { fill: DEFAULT_COLOR },- background: "transparent",- range: {- category: [- "#5B8FF9",- "#61DDAA",- "#65789B",- "#F6BD16",- "#7262FD",- "#78D3F8",- "#9661BC",- "#F6903D",- "#008685",- "#F08BB4",- ],- diverging: ["#7b3294", "#c2a5cf", "#f7f7f7", "#a6dba0", "#008837"],- heatmap: ["#000000", "#7b3294", "#c2a5cf", "#f7f7f7", "#a6dba0", "#008837"],- ramp: [- "#EBCCFF",- "#CCB0FF",- "#AE95FF",- "#907BFF",- "#7262FD",- "#5349E0",- "#2F32C3",- "#001BA7",- "#00068C"- ],- },- scale: {- continuous: { range: ["#f7fbff", "#08306b"] },- },-};-export const DEFAULT_DARK_THEME: any = {- area: { fill: DEFAULT_COLOR },- bar: { fill: DEFAULT_COLOR },- circle: { fill: DEFAULT_COLOR },- line: { stroke: DEFAULT_COLOR },- point: { stroke: DEFAULT_COLOR },- rect: { fill: DEFAULT_COLOR },- tick: { stroke: DEFAULT_COLOR },- boxplot: { fill: DEFAULT_COLOR },- errorbar: { stroke: DEFAULT_COLOR },- errorband: { fill: DEFAULT_COLOR },- arc: { fill: DEFAULT_COLOR },- background: "transparent", // change background color to dark gray- axis: {- domainColor: "#d1d5db", // change axis color to white- tickColor: "#d1d5db", // change tick color to white- labelColor: "#d1d5db", // change label color to white+export const VegaTheme = {+ light: {+ background: "transparent",},- legend: {- labelColor: "#d1d5db", // change legend label color to white- titleColor: "#d1d5db" // change legend title color to white+ dark: {+ background: "transparent",+ axis: {+ gridColor: "#666",+ domainColor: "#d1d5db", // change axis color to white+ tickColor: "#d1d5db", // change tick color to white+ labelColor: "#d1d5db", // change label color to white+ },+ legend: {+ labelColor: "#d1d5db", // change legend label color to white+ titleColor: "#d1d5db" // change legend title color to white+ },},- range: {- category: [- "#5B8FF9",- "#61DDAA",- "#65789B",- "#F6BD16",- "#7262FD",- "#78D3F8",- "#9661BC",- "#F6903D",- "#008685",- "#F08BB4",- ],- diverging: ["#7b3294", "#c2a5cf", "#f7f7f7", "#a6dba0", "#008837"],- heatmap: ["#000000", "#7b3294", "#c2a5cf", "#f7f7f7", "#a6dba0", "#008837"],- ramp: [- "#EBCCFF",- "#CCB0FF",- "#AE95FF",- "#907BFF",- "#7262FD",- "#5349E0",- "#2F32C3",- "#001BA7",- "#00068C"- ],+} as const;++export const AntVTheme = {+ light: {+ area: { fill: DEFAULT_COLOR },+ bar: { fill: DEFAULT_COLOR },+ circle: { fill: DEFAULT_COLOR },+ line: { stroke: DEFAULT_COLOR },+ point: { stroke: DEFAULT_COLOR },+ rect: { fill: DEFAULT_COLOR },+ tick: { stroke: DEFAULT_COLOR },+ boxplot: { fill: DEFAULT_COLOR },+ errorbar: { stroke: DEFAULT_COLOR },+ errorband: { fill: DEFAULT_COLOR },+ arc: { fill: DEFAULT_COLOR },+ background: "transparent",+ range: {+ category: [+ "#5B8FF9",+ "#61DDAA",+ "#65789B",+ "#F6BD16",+ "#7262FD",+ "#78D3F8",+ "#9661BC",+ "#F6903D",+ "#008685",+ "#F08BB4",+ ],+ diverging: ["#7b3294", "#c2a5cf", "#f7f7f7", "#a6dba0", "#008837"],+ heatmap: ["#000000", "#7b3294", "#c2a5cf", "#f7f7f7", "#a6dba0", "#008837"],+ ramp: [+ "#EBCCFF",+ "#CCB0FF",+ "#AE95FF",+ "#907BFF",+ "#7262FD",+ "#5349E0",+ "#2F32C3",+ "#001BA7",+ "#00068C"+ ],+ },+ scale: {+ continuous: { range: ["#f7fbff", "#08306b"] },+ },},- scale: {- continuous: { range: ["#f7fbff", "#08306b"] },+ dark: {+ area: { fill: DEFAULT_COLOR },+ bar: { fill: DEFAULT_COLOR },+ circle: { fill: DEFAULT_COLOR },+ line: { stroke: DEFAULT_COLOR },+ point: { stroke: DEFAULT_COLOR },+ rect: { fill: DEFAULT_COLOR },+ tick: { stroke: DEFAULT_COLOR },+ boxplot: { fill: DEFAULT_COLOR },+ errorbar: { stroke: DEFAULT_COLOR },+ errorband: { fill: DEFAULT_COLOR },+ arc: { fill: DEFAULT_COLOR },+ background: "transparent", // change background color to dark gray+ axis: {+ gridColor: "#666",+ domainColor: "#d1d5db", // change axis color to white+ tickColor: "#d1d5db", // change tick color to white+ labelColor: "#d1d5db", // change label color to white+ },+ legend: {+ labelColor: "#d1d5db", // change legend label color to white+ titleColor: "#d1d5db" // change legend title color to white+ },+ range: {+ category: [+ "#5B8FF9",+ "#61DDAA",+ "#65789B",+ "#F6BD16",+ "#7262FD",+ "#78D3F8",+ "#9661BC",+ "#F6903D",+ "#008685",+ "#F08BB4",+ ],+ diverging: ["#7b3294", "#c2a5cf", "#f7f7f7", "#a6dba0", "#008837"],+ heatmap: ["#000000", "#7b3294", "#c2a5cf", "#f7f7f7", "#a6dba0", "#008837"],+ ramp: [+ "#EBCCFF",+ "#CCB0FF",+ "#AE95FF",+ "#907BFF",+ "#7262FD",+ "#5349E0",+ "#2F32C3",+ "#001BA7",+ "#00068C"+ ],+ },+ scale: {+ continuous: { range: ["#f7fbff", "#08306b"] },+ },},+} as const;++export const builtInThemes: { [themeKey: string]: { light: any; dark: any; } } = {+ vega: VegaTheme,+ antv: AntVTheme,};diff --git a/packages/graphic-walker/src/visualSettings/index.tsx b/packages/graphic-walker/src/visualSettings/index.tsxindex 716654ce..677df43c 100644--- a/packages/graphic-walker/src/visualSettings/index.tsx+++ b/packages/graphic-walker/src/visualSettings/index.tsx@@ -336,14 +336,14 @@ const VisualSettings: React.FC<IVisualSettings> = ({ rendererHandler }) => {form: (<FormContainer><button- className="text-xs pt-1 pb-1 pl-6 pr-6 bg-white dark:bg-zinc-900 hover:bg-gray-200"+ className="text-xs pt-1 pb-1 pl-6 pr-6 bg-white dark:bg-zinc-900 hover:bg-gray-200 text-gray-800 dark:text-gray-100 dark:hover:bg-gray-700"aria-label={t('button.export_chart_as', { type: 'png' })}onClick={() => downloadPNG()}>{t('button.export_chart_as', { type: 'png' })}</button><button- className="text-xs pt-1 pb-1 pl-6 pr-6 bg-white dark:bg-zinc-900 hover:bg-gray-200"+ className="text-xs pt-1 pb-1 pl-6 pr-6 bg-white dark:bg-zinc-900 hover:bg-gray-200 text-gray-800 dark:text-gray-100 dark:hover:bg-gray-700"aria-label={t('button.export_chart_as', { type: 'svg' })}onClick={() => downloadSVG()}>@@ -360,9 +360,12 @@ const VisualSettings: React.FC<IVisualSettings> = ({ rendererHandler }) => {items={items}styles={{root: {- '--background-color': 'inherit',- // '--color': '#777',- // '--color-hover': '#555',+ '--background-color': '#fff',+ '--dark-background-color': '#000',+ '--color': '#777',+ '--color-hover': '#555',+ '--dark-color': '#999',+ '--dark-color-hover': '#bbb','--blue': 'rgb(79,70,229)','--blue-dark': 'rgb(9, 6, 65)',},