An open source alternative to Tableau. Embeddable visual analytic
TypeScript bidatadata-analysisdata-miningdata-visualizationedak6skanarieslow-codepivot-tablereacttableautableau-alternativetypescriptvegavega-litevisualization
feat: configure the initial GraphicWalker tab (#525)
hsWang72c89e6a7e2e
diff --git a/README.md b/README.mdindex 966a8ea5..f87de37a 100644--- a/README.md+++ b/README.md@@ -123,6 +123,7 @@ const YourEmbeddingApp: React.FC<IYourEmbeddingAppProps> = props => {fields={fields}chart={graphicWalkerSpec}i18nLang={langStore.lang}+ defaultTab="data"/>;}diff --git a/packages/graphic-walker/src/App.tsx b/packages/graphic-walker/src/App.tsxindex 2a6d794d..b4ea20bc 100644--- a/packages/graphic-walker/src/App.tsx+++ b/packages/graphic-walker/src/App.tsx@@ -308,7 +308,7 @@ export const VizApp = observer(function VizApp(props: BaseVizProps) {});export function VizAppWithContext(props: IVizAppProps & IComputationProps) {- const { computation, onMetaChange, fieldKeyGuard, keepAlive, storeRef, defaultConfig, defaultRenderer, ...rest } = props;+ const { computation, onMetaChange, fieldKeyGuard, keepAlive, storeRef, defaultConfig, defaultTab, defaultRenderer, ...rest } = props;// @TODO remove deprecated propsconst appearance = props.appearance ?? props.dark;const data = props.data ?? props.dataSource;@@ -354,6 +354,7 @@ export function VizAppWithContext(props: IVizAppProps & IComputationProps) {keepAlive={keepAlive}storeRef={storeRef}defaultConfig={defaultConfig}+ defaultTab={defaultTab}defaultRenderer={defaultRenderer}><VizApp darkMode={darkMode} computation={safeComputation} {...rest} />diff --git a/packages/graphic-walker/src/interfaces.ts b/packages/graphic-walker/src/interfaces.tsindex 83dad732..a5a3f8c2 100644--- a/packages/graphic-walker/src/interfaces.ts+++ b/packages/graphic-walker/src/interfaces.ts@@ -983,6 +983,8 @@ export interface IVizProps {hideChartNav?: boolean;/** hide the segment navigation so make user can only edit on the only segment. */hideSegmentNav?: boolean;+ /** The tab to show when GraphicWalker is first opened. Defaults to 'visualization'. */+ defaultTab?: 'data' | 'visualization';geographicData?: IGeographicData & {key: string;};diff --git a/packages/graphic-walker/src/store/index.tsx b/packages/graphic-walker/src/store/index.tsxindex 9af26b43..c9bfc1a6 100644--- a/packages/graphic-walker/src/store/index.tsx+++ b/packages/graphic-walker/src/store/index.tsx@@ -1,6 +1,6 @@import React, { useContext, useMemo, useEffect, createContext } from 'react';import { VizSpecStore } from './visualSpecStore';-import { IComputationFunction, IDefaultConfig, IMutField, IRow } from '../interfaces';+import { IComputationFunction, IDefaultConfig, IMutField, IRow, ISegmentKey } from '../interfaces';function createKeepAliveContext<T, U extends any[]>(create: (...args: U) => T) {const dict: Record<string, T> = {};@@ -21,8 +21,9 @@ const getVizStore = createKeepAliveContext(empty?: boolean;onMetaChange?: (fid: string, diffMeta: Partial<IMutField>) => void;defaultConfig?: IDefaultConfig;+ defaultTab?: 'data' | 'visualization';}- ) => new VizSpecStore(meta, opts)+ ) => new VizSpecStore(meta, { ...opts, initialSegment: opts?.defaultTab === 'data' ? ISegmentKey.data : ISegmentKey.vis }));export const VisContext = React.createContext<VizSpecStore>(null!);@@ -36,6 +37,7 @@ interface VizStoreWrapperProps {meta: IMutField[];onMetaChange?: (fid: string, meta: Partial<IMutField>) => void;defaultConfig?: IDefaultConfig;+ defaultTab?: 'data' | 'visualization';defaultRenderer?: 'vega-lite' | 'observable-plot';}@@ -48,7 +50,7 @@ export const VizStoreWrapper = (props: VizStoreWrapperProps) => {layout: { renderer: props.defaultRenderer, ...(props.defaultConfig?.layout ?? {}) },}: props.defaultConfig;- return getVizStore(storeKey, props.meta, { onMetaChange: props.onMetaChange, defaultConfig });+ return getVizStore(storeKey, props.meta, { onMetaChange: props.onMetaChange, defaultConfig, defaultTab: props.defaultTab });// IMPORTANT the store is only associated with the storeKey}, [storeKey]);diff --git a/packages/graphic-walker/src/store/visualSpecStore.test.ts b/packages/graphic-walker/src/store/visualSpecStore.test.tsindex 4be499ee..d2913a7b 100644--- a/packages/graphic-walker/src/store/visualSpecStore.test.ts+++ b/packages/graphic-walker/src/store/visualSpecStore.test.ts@@ -1,4 +1,4 @@-import type { IMutField } from '../interfaces';+import { ISegmentKey, type IMutField } from '../interfaces';import { newChart } from '../models/visSpecHistory';import { VizSpecStore } from './visualSpecStore';@@ -176,3 +176,17 @@ describe('VizSpecStore metadata updates', () => {expect(store.currentVis.layout.renderer).toBe('observable-plot');});});++describe('VizSpecStore initial segment', () => {+ test('opens on the data segment when requested', () => {+ const store = new VizSpecStore(META, { initialSegment: ISegmentKey.data });++ expect(store.segmentKey).toBe(ISegmentKey.data);+ });++ test('defaults to the visualization segment', () => {+ const store = new VizSpecStore(META);++ expect(store.segmentKey).toBe(ISegmentKey.vis);+ });+});diff --git a/packages/graphic-walker/src/store/visualSpecStore.ts b/packages/graphic-walker/src/store/visualSpecStore.tsindex b1e8e06a..a2e00d90 100644--- a/packages/graphic-walker/src/store/visualSpecStore.ts+++ b/packages/graphic-walker/src/store/visualSpecStore.ts@@ -105,9 +105,11 @@ export class VizSpecStore {empty?: boolean;onMetaChange?: (fid: string, diffMeta: Partial<IMutField>) => void;defaultConfig?: IDefaultConfig;+ initialSegment?: ISegmentKey;},) {this.meta = meta;+ this.segmentKey = options?.initialSegment ?? ISegmentKey.vis;this.visList = options?.empty ? [] : [fromFields(meta, 'Chart 1', options?.defaultConfig)];this.pristineInitialCharts = meta.length === 0 ? new Set(this.visList) : new Set();this.createdVis = this.visList.length;