An open source alternative to Tableau. Embeddable visual analytic
TypeScript bidatadata-analysisdata-miningdata-visualizationedak6skanarieslow-codepivot-tablereacttableautableau-alternativetypescriptvegavega-litevisualization
feat(gw): configurable exploration settings
kyusho5aaaf51cf904
diff --git a/packages/graphic-walker/src/config.ts b/packages/graphic-walker/src/config.tsindex b6591aae..da0b0780 100644--- a/packages/graphic-walker/src/config.ts+++ b/packages/graphic-walker/src/config.ts@@ -25,6 +25,18 @@ export const CHART_LAYOUT_TYPE: Readonly<string[]> = ['fixed',] as const;+export const EXPLORATION_TYPES = [+ 'none',+ 'brush',+ 'point',+] as const;++export const BRUSH_DIRECTIONS = [+ 'default',+ 'x',+ 'y',+] as const;+export const COLORS = {// tableau style// dimension: 'rgb(73, 150, 178)',diff --git a/packages/graphic-walker/src/interfaces.ts b/packages/graphic-walker/src/interfaces.tsindex 63f1396a..7ea7ca88 100644--- a/packages/graphic-walker/src/interfaces.ts+++ b/packages/graphic-walker/src/interfaces.ts@@ -144,6 +144,11 @@ export interface IVisualConfig {width: number;height: number;}+ exploration: {+ mode: 'none' | 'brush' | 'point';+ /** works when mode is 'brush' */+ brushDirection: 'default' | 'x' | 'y';+ };}export interface IVisSpec {diff --git a/packages/graphic-walker/src/locales/en-US.json b/packages/graphic-walker/src/locales/en-US.jsonindex 21b82521..9100060d 100644--- a/packages/graphic-walker/src/locales/en-US.json+++ b/packages/graphic-walker/src/locales/en-US.json@@ -30,6 +30,18 @@"auto": "Auto","fixed": "Fixed"},+ "exploration_mode": {+ "__enum__": "Exploration Mode",+ "none": "Off",+ "brush": "Brush",+ "point": "Point"+ },+ "brush_mode": {+ "__enum__": "Brush Direction",+ "default": "Both",+ "x": "X-Only",+ "y": "Y-Only"+ },"draggable_key": {"fields": "Fields","columns": "Columns",diff --git a/packages/graphic-walker/src/locales/zh-CN.json b/packages/graphic-walker/src/locales/zh-CN.jsonindex 01297a8c..6feab058 100644--- a/packages/graphic-walker/src/locales/zh-CN.json+++ b/packages/graphic-walker/src/locales/zh-CN.json@@ -24,6 +24,18 @@"auto": "自动","fixed": "固定"},+ "exploration_mode": {+ "__enum__": "探索交互",+ "none": "关",+ "brush": "范围",+ "point": "目标"+ },+ "brush_mode": {+ "__enum__": "框选方向",+ "default": "所有",+ "x": "仅 X 轴",+ "y": "仅 Y 轴"+ },"stack_mode": {"__enum__": "堆叠模式","none": "关闭",diff --git a/packages/graphic-walker/src/renderer/index.tsx b/packages/graphic-walker/src/renderer/index.tsxindex 93437196..2cfc4418 100644--- a/packages/graphic-walker/src/renderer/index.tsx+++ b/packages/graphic-walker/src/renderer/index.tsx@@ -10,7 +10,7 @@ import ReactVega from '../vis/react-vega';const ReactiveRenderer: React.FC = props => {const { vizStore, commonStore } = useGlobalStore();const { draggableFieldState, visualConfig } = vizStore;- const { geoms, interactiveScale, defaultAggregated, stack, showActions, size } = visualConfig;+ const { geoms, interactiveScale, defaultAggregated, stack, showActions, size, exploration } = visualConfig;const { currentDataset } = commonStore;const { filters } = draggableFieldState;@@ -27,14 +27,17 @@ const ReactiveRenderer: React.FC = props => {const colLeftFacetFields = columns.slice(0, -1).filter(f => f.analyticType === 'dimension');const hasFacet = rowLeftFacetFields.length > 0 || colLeftFacetFields.length > 0;++ const shouldTriggerMenu = exploration.mode === 'none';- // TODO: find a better place for this feature s.v.p.- // const __onImpossibleInteractionForDataInterpretation = useCallback((values: any, e: any) => {- // runInAction(() => {- // commonStore.showEmbededMenu([e.pageX, e.pageY])- // commonStore.setFilters(values);- // })- // }, [])+ const handleGeomClick = useCallback((values: any, e: any) => {+ if (shouldTriggerMenu) {+ runInAction(() => {+ commonStore.showEmbededMenu([e.pageX, e.pageY])+ commonStore.setFilters(values);+ });+ }+ }, [shouldTriggerMenu]);// apply filtersconst { dataSource } = currentDataset;@@ -94,12 +97,12 @@ const ReactiveRenderer: React.FC = props => {shape={shape[0]}opacity={opacity[0]}size={sizeChannel[0]}- showActions={showActions || true}+ showActions={showActions}width={size.width - 12 * 4}height={size.height - 12 * 4}- // TODO: configurable- selectEncoding="default"- brushEncoding="none"+ brushEncoding={exploration.mode === 'brush' ? exploration.brushDirection : 'none'}+ selectEncoding={exploration.mode === 'point' ? 'default' : 'none'}+ onGeomClick={handleGeomClick}/></Resizable>}diff --git a/packages/graphic-walker/src/store/visualSpecStore.ts b/packages/graphic-walker/src/store/visualSpecStore.tsindex a796becd..06c01bf8 100644--- a/packages/graphic-walker/src/store/visualSpecStore.ts+++ b/packages/graphic-walker/src/store/visualSpecStore.ts@@ -2,7 +2,7 @@ import { IReactionDisposer, makeAutoObservable, observable, reaction, toJS } froimport produce from 'immer';import { v4 as uuidv4 } from 'uuid';import { Specification } from "visual-insights";-import { DataSet, DraggableFieldState, IFilterRule, IViewField, IVisualConfig } from "../interfaces";+import { DataSet, DraggableFieldState, IFilterRule, IViewField, IVisSpec, IVisualConfig } from "../interfaces";import { CHANNEL_LIMIT, GEMO_TYPES, MetaFieldKeys } from "../config";import { makeBinField, makeLogField } from "../utils/normalization";import { VisSpecWithHistory } from "../models/visSpecHistory";@@ -69,7 +69,11 @@ function initVisualConfig (): IVisualConfig {mode: 'auto',width: 320,height: 200- }+ },+ exploration: {+ mode: 'brush',+ brushDirection: 'default',+ },}}@@ -77,6 +81,16 @@ type DeepReadonly<T extends Record<keyof any, any>> = {readonly [K in keyof T]: T[K] extends Record<keyof any, any> ? DeepReadonly<T[K]> : T[K];};+const forwardVisualConfigs = (backwards: ReturnType<typeof parseGWContent>['specList']): IVisSpec[] => {+ return backwards.map(content => ({+ ...content,+ config: {+ ...initVisualConfig(),+ ...content.config,+ },+ }));+};+export class VizSpecStore {// public fields: IViewField[] = [];@@ -363,6 +377,16 @@ export class VizSpecStore {config.size.height = height;});}+ public setExploration(value: Partial<IVisualConfig['exploration']>) {+ this.useMutable(({ config }) => {+ if (value.mode) {+ config.exploration.mode = value.mode;+ }+ if (value.brushDirection) {+ config.exploration.brushDirection = value.brushDirection;+ }+ });+ }public reorderField(stateKey: keyof DraggableFieldState, sourceIndex: number, destinationIndex: number) {if (MetaFieldKeys.includes(stateKey)) return;if (sourceIndex === destinationIndex) return;@@ -580,7 +604,8 @@ export class VizSpecStore {this.commonStore.datasets = content.datasets;this.commonStore.dataSources = content.dataSources;this.commonStore.dsIndex = Math.max(content.datasets.length - 1, 0);- this.visList = parseGWPureSpec(content.specList)+ // 补上初始化新版本特性+ this.visList = parseGWPureSpec(forwardVisualConfigs(content.specList));this.visIndex = 0;}}\ No newline at end of filediff --git a/packages/graphic-walker/src/utils/save.ts b/packages/graphic-walker/src/utils/save.tsindex 93afff02..57d20d2a 100644--- a/packages/graphic-walker/src/utils/save.ts+++ b/packages/graphic-walker/src/utils/save.ts@@ -12,7 +12,10 @@ export function parseGWPureSpec (list: IVisSpec[]): VisSpecWithHistory[] {interface IStoInfo {datasets: IDataSet[];- specList: IVisSpec[];+ specList: ({+ /** 由于 gw 内部实现暂时未锁版本,这里获取到的信息可能会与当前实例内容有偏差,需要用初始值合入 */+ [K in keyof IVisSpec]: K extends 'config' ? Partial<IVisSpec[K]> : IVisSpec[K];+ })[];dataSources: IDataSource[]}diff --git a/packages/graphic-walker/src/vis/react-vega.tsx b/packages/graphic-walker/src/vis/react-vega.tsxindex 21c4970a..c1c8f5c3 100644--- a/packages/graphic-walker/src/vis/react-vega.tsx+++ b/packages/graphic-walker/src/vis/react-vega.tsx@@ -232,9 +232,9 @@ function getSingleView(props: SingleViewProps) {...encoding.color,test: 'false',},- value: '#8884',+ value: '#8882',} : {- value: '#8884',+ value: '#8882',},},},@@ -264,7 +264,7 @@ function getSingleView(props: SingleViewProps) {...encoding.color,param: BRUSH_SIGNAL_NAME,},- value: '#8884',+ value: '#8882',},},};@@ -284,7 +284,7 @@ function getSingleView(props: SingleViewProps) {...encoding.color,param: POINT_SIGNAL_NAME,},- value: '#8884',+ value: '#8882',},},};@@ -324,7 +324,7 @@ const ReactVega: React.FC<ReactVegaProps> = props => {return () => {clickSub.unsubscribe();}- }, []);+ }, [onGeomClick]);const rowDims = useMemo(() => rows.filter(f => f.analyticType === 'dimension'), [rows]);const colDims = useMemo(() => columns.filter(f => f.analyticType === 'dimension'), [columns]);const rowMeas = useMemo(() => rows.filter(f => f.analyticType === 'measure'), [rows]);diff --git a/packages/graphic-walker/src/visualSettings/index.tsx b/packages/graphic-walker/src/visualSettings/index.tsxindex 387956be..effde4ea 100644--- a/packages/graphic-walker/src/visualSettings/index.tsx+++ b/packages/graphic-walker/src/visualSettings/index.tsx@@ -6,7 +6,7 @@ import { ArrowPathIcon } from '@heroicons/react/24/solid';import { useTranslation } from 'react-i18next';import { LiteForm } from '../components/liteForm';import SizeSetting from '../components/sizeSetting';-import { CHART_LAYOUT_TYPE, GEMO_TYPES, STACK_MODE } from '../config';+import { BRUSH_DIRECTIONS, CHART_LAYOUT_TYPE, EXPLORATION_TYPES, GEMO_TYPES, STACK_MODE } from '../config';import { useGlobalStore } from '../store';import { IStackMode } from '../interfaces';@@ -226,6 +226,68 @@ const VisualSettings: React.FC = () => {{t('size')}</label></div>+ <div className="item">+ <label+ id="dropdown:exploration_mode:label"+ htmlFor="dropdown:exploration_mode"+ >+ {tGlobal(`constant.exploration_mode.__enum__`)}+ </label>+ <select+ className="border border-gray-500 rounded-sm text-xs pt-0.5 pb-0.5 pl-2 pr-2 cursor-pointer"+ id="dropdown:exploration_mode"+ aria-describedby="dropdown:exploration_mode:label"+ value={visualConfig.exploration.mode}+ onChange={e => {+ vizStore.setExploration({+ mode: e.target.value as (typeof EXPLORATION_TYPES)[number]+ });+ }}+ >+ {EXPLORATION_TYPES.map(g => (+ <option+ key={g}+ value={g}+ className="cursor-pointer"+ aria-selected={visualConfig.exploration.mode === g}+ >+ {tGlobal(`constant.exploration_mode.${g}`)}+ </option>+ ))}+ </select>+ </div>+ <div className="item" style={{ opacity: visualConfig.exploration.mode !== 'brush' ? 0.3 : undefined }}>+ <label+ id="dropdown:brush_mode:label"+ htmlFor="dropdown:brush_mode"+ >+ {tGlobal(`constant.brush_mode.__enum__`)}+ </label>+ <select+ className="border border-gray-500 rounded-sm text-xs pt-0.5 pb-0.5 pl-2 pr-2 cursor-pointer"+ id="dropdown:brush_mode"+ aria-describedby="dropdown:brush_mode:label"+ disabled={visualConfig.exploration.mode !== 'brush'}+ aria-disabled={visualConfig.exploration.mode !== 'brush'}+ value={visualConfig.exploration.brushDirection}+ onChange={e => {+ vizStore.setExploration({+ brushDirection: e.target.value as (typeof BRUSH_DIRECTIONS)[number]+ });+ }}+ >+ {BRUSH_DIRECTIONS.map(g => (+ <option+ key={g}+ value={g}+ className="cursor-pointer"+ aria-selected={visualConfig.exploration.brushDirection === g}+ >+ {tGlobal(`constant.brush_mode.${g}`)}+ </option>+ ))}+ </select>+ </div><div className="item"><inputtype="checkbox"