An open source alternative to Tableau. Embeddable visual analytic
TypeScript bidatadata-analysisdata-miningdata-visualizationedak6skanarieslow-codepivot-tablereacttableautableau-alternativetypescriptvegavega-litevisualization
feat: add text mark and channel
jojocys712a8c1e19ac
diff --git a/packages/graphic-walker/src/config.ts b/packages/graphic-walker/src/config.tsindex f6a5f843..fa4c8731 100644--- a/packages/graphic-walker/src/config.ts+++ b/packages/graphic-walker/src/config.ts@@ -11,6 +11,7 @@ export const GEMO_TYPES: Readonly<string[]> = ['tick','rect','arc',+ 'text','boxplot','table'] as const;@@ -48,7 +49,9 @@ export const CHANNEL_LIMIT = {size: 1,shape: 1,theta: 1,- radius: 1+ radius: 1,+ details: Infinity,+ text: 1,}export const MetaFieldKeys: Array<keyof DraggableFieldState> = [diff --git a/packages/graphic-walker/src/fields/aestheticFields.tsx b/packages/graphic-walker/src/fields/aestheticFields.tsxindex 71a04c43..7682e1d6 100644--- a/packages/graphic-walker/src/fields/aestheticFields.tsx+++ b/packages/graphic-walker/src/fields/aestheticFields.tsx@@ -6,7 +6,7 @@ import SingleEncodeEditor from './encodeFields/singleEncodeEditor';import { observer } from 'mobx-react-lite';import { useGlobalStore } from '../store';-const aestheticFields = DRAGGABLE_STATE_KEYS.filter(f => ['color', 'opacity', 'size', 'shape', 'details'].includes(f.id));+const aestheticFields = DRAGGABLE_STATE_KEYS.filter(f => ['color', 'opacity', 'size', 'shape', 'details', 'text'].includes(f.id));const AestheticFields: React.FC = props => {const { vizStore } = useGlobalStore();@@ -14,13 +14,19 @@ const AestheticFields: React.FC = props => {const { geoms } = visualConfig;const channels = useMemo(() => {- if (geoms[0] === 'arc') {- return aestheticFields.filter(f => f.id !== 'shape');+ switch (geoms[0]) {+ case 'arc':+ case 'line':+ case 'area':+ case 'boxplot':+ return aestheticFields.filter(f => f.id !== 'shape');+ case 'text':+ return aestheticFields.filter(f => f.id === 'text' || f.id === 'color' || f.id === 'size' || f.id === 'opacity');+ case 'table':+ return []+ default:+ return aestheticFields.filter(f => f.id !== 'text');}- if (geoms[0] === 'table') {- return []- }- return aestheticFields}, [geoms[0]])return <div>{diff --git a/packages/graphic-walker/src/fields/fieldsContext.tsx b/packages/graphic-walker/src/fields/fieldsContext.tsxindex f9c30ec3..32f2a18d 100644--- a/packages/graphic-walker/src/fields/fieldsContext.tsx+++ b/packages/graphic-walker/src/fields/fieldsContext.tsx@@ -49,7 +49,8 @@ export const DRAGGABLE_STATE_KEYS: Readonly<IDraggableStateKey[]> = [{ id: 'theta', mode: 1 },{ id: 'radius', mode: 1 },{ id: 'filters', mode: 1 },- { id: 'details', mode: 1 }+ { id: 'details', mode: 1 },+ { id: 'text', mode: 1 },] as const;export const AGGREGATOR_LIST: Readonly<string[]> = [diff --git a/packages/graphic-walker/src/interfaces.ts b/packages/graphic-walker/src/interfaces.tsindex 60718ff3..cd6831aa 100644--- a/packages/graphic-walker/src/interfaces.ts+++ b/packages/graphic-walker/src/interfaces.ts@@ -161,6 +161,7 @@ export interface DraggableFieldState {radius: IViewField[];details: IViewField[];filters: IFilterField[];+ text: IViewField[];}export interface IDraggableStateKey {diff --git a/packages/graphic-walker/src/lib/insights/explainBySelection.ts b/packages/graphic-walker/src/lib/insights/explainBySelection.tsindex 6236734e..079753ff 100644--- a/packages/graphic-walker/src/lib/insights/explainBySelection.ts+++ b/packages/graphic-walker/src/lib/insights/explainBySelection.ts@@ -1,8 +1,8 @@-import { IExplainProps, IField } from '../../interfaces';-import { filterByPredicates } from '../../utils';+import { IAggregator, IExplainProps, IField } from '../../interfaces';+import { filterByPredicates, getMeaAggKey } from '../../utils';import { compareDistribution, normalizeWithParent } from '../../utils/normalization';import { aggregate } from '../op/aggregate';-import { complementaryFields, groupByAnalyticTypes, meaList2AggProps } from './utils';+import { complementaryFields, groupByAnalyticTypes } from './utils';export function explainBySelection(props: IExplainProps) {const { metas, dataSource, viewFields, predicates } = props;@@ -15,12 +15,21 @@ export function explainBySelection(props: IExplainProps) {const overallData = aggregate(dataSource, {groupBy: [extendDim.fid],op: 'aggregate',- agg: meaList2AggProps(measInView),+ measures: measInView.map((mea) => ({+ field: mea.fid,+ agg: (mea.aggName ?? 'sum') as IAggregator,+ asFieldKey: getMeaAggKey(mea.fid, (mea.aggName ?? 'sum') as IAggregator),+ })),+});const viewData = aggregate(dataSource, {groupBy: dimsInView.map((f) => f.fid),op: 'aggregate',- agg: meaList2AggProps(measInView),+ measures: measInView.map((mea) => ({+ field: mea.fid,+ agg: (mea.aggName ?? 'sum') as IAggregator,+ asFieldKey: getMeaAggKey(mea.fid, (mea.aggName ?? 'sum') as IAggregator),+ }))});const subData = filterByPredicates(viewData, predicates);diff --git a/packages/graphic-walker/src/lib/insights/utils.ts b/packages/graphic-walker/src/lib/insights/utils.tsindex 8ca02679..ebee97fa 100644--- a/packages/graphic-walker/src/lib/insights/utils.ts+++ b/packages/graphic-walker/src/lib/insights/utils.ts@@ -10,10 +10,6 @@ export function groupByAnalyticTypes(fields: IField[]) {};}-export function meaList2AggProps(measures: IField[]): IAggQuery['agg'] {- return Object.fromEntries(measures.map((mea) => [mea.fid, (mea.aggName ?? 'sum') as IAggregator]));-}-export function complementaryFields(props: { selection: IField[]; all: IField[] }): IField[] {return props.all.filter((f) => f.analyticType === 'dimension')diff --git a/packages/graphic-walker/src/locales/en-US.json b/packages/graphic-walker/src/locales/en-US.jsonindex 83c23633..06267426 100644--- a/packages/graphic-walker/src/locales/en-US.json+++ b/packages/graphic-walker/src/locales/en-US.json@@ -24,7 +24,8 @@"rect": "Rectangle","arc": "Arc","boxplot": "Box (Box Plot)",- "table": "Table"+ "table": "Table",+ "text": "Text"},"stack_mode": {"__enum__": "Stack Mode",@@ -60,7 +61,8 @@"theta": "Angle","radius": "Radius","filters": "Filters",- "details": "Details"+ "details": "Details",+ "text": "Text"},"aggregator": {"sum": "Sum",diff --git a/packages/graphic-walker/src/locales/ja-JP.json b/packages/graphic-walker/src/locales/ja-JP.jsonindex 1966fd73..7da9bcd9 100644--- a/packages/graphic-walker/src/locales/ja-JP.json+++ b/packages/graphic-walker/src/locales/ja-JP.json@@ -24,7 +24,8 @@"rect": "長方形","arc": "アーク","boxplot": "ボックスプロット",- "table": "表"+ "table": "表",+ "text": "本文"},"stack_mode": {"__enum__": "スタックモード",@@ -59,7 +60,8 @@"shape": "形状","theta": "角度","radius": "半径",- "filters": "フィルター"+ "filters": "フィルター",+ "text": "本文"},"aggregator": {"sum": "合計",diff --git a/packages/graphic-walker/src/locales/zh-CN.json b/packages/graphic-walker/src/locales/zh-CN.jsonindex 12aa2900..0ed7fa27 100644--- a/packages/graphic-walker/src/locales/zh-CN.json+++ b/packages/graphic-walker/src/locales/zh-CN.json@@ -24,7 +24,8 @@"rect": "矩形","arc": "弧形","boxplot": "统计箱",- "table": "表格"+ "table": "表格",+ "text": "文本"},"layout_type": {"__enum__": "尺寸模式",@@ -60,7 +61,8 @@"theta": "角度","radius": "半径","filters": "筛选器",- "details": "信息"+ "details": "信息",+ "text": "文本"},"aggregator": {"sum": "求和",diff --git a/packages/graphic-walker/src/renderer/specRenderer.tsx b/packages/graphic-walker/src/renderer/specRenderer.tsxindex d7f00495..ca63d8fb 100644--- a/packages/graphic-walker/src/renderer/specRenderer.tsx+++ b/packages/graphic-walker/src/renderer/specRenderer.tsx@@ -32,6 +32,7 @@ const SpecRenderer = forwardRef<IReactVegaHandler, SpecRendererProps>(function (const radius = draggableFieldState.radius;const sizeChannel = draggableFieldState.size;const details = draggableFieldState.details;+ const text = draggableFieldState.text;const rowLeftFacetFields = useMemo(() => rows.slice(0, -1).filter((f) => f.analyticType === 'dimension'), [rows]);const colLeftFacetFields = useMemo(@@ -100,6 +101,7 @@ const SpecRenderer = forwardRef<IReactVegaHandler, SpecRendererProps>(function (opacity={opacity[0]}size={sizeChannel[0]}details={details}+ text={text[0]}showActions={showActions}width={size.width - 12 * 4}height={size.height - 12 * 4}diff --git a/packages/graphic-walker/src/store/visualSpecStore.ts b/packages/graphic-walker/src/store/visualSpecStore.tsindex 5082a75a..f14ff645 100644--- a/packages/graphic-walker/src/store/visualSpecStore.ts+++ b/packages/graphic-walker/src/store/visualSpecStore.ts@@ -58,6 +58,7 @@ export function initEncoding(): DraggableFieldState {theta: [],details: [],filters: [],+ text: [],};}diff --git a/packages/graphic-walker/src/vis/react-vega.tsx b/packages/graphic-walker/src/vis/react-vega.tsxindex 0c6bb240..4b41439d 100644--- a/packages/graphic-walker/src/vis/react-vega.tsx+++ b/packages/graphic-walker/src/vis/react-vega.tsx@@ -40,6 +40,7 @@ interface ReactVegaProps {shape?: IViewField;theta?: IViewField;radius?: IViewField;+ text?: IViewField;details?: Readonly<IViewField[]>;showActions: boolean;layoutMode: string;@@ -88,6 +89,7 @@ const ReactVega = forwardRef<IReactVegaHandler, ReactVegaProps>(function ReactVetheta,radius,shape,+ text,onGeomClick,showActions,interactiveScale,@@ -183,6 +185,7 @@ const ReactVega = forwardRef<IReactVegaHandler, ReactVegaProps>(function ReactVeshape: shape ? shape : NULL_FIELD,theta: theta ? theta : NULL_FIELD,radius: radius ? radius : NULL_FIELD,+ text: text ? text : NULL_FIELD,row: rowFacetField,column: colFacetField,xOffset: NULL_FIELD,@@ -247,6 +250,7 @@ const ReactVega = forwardRef<IReactVegaHandler, ReactVegaProps>(function ReactVeradius: radius ? radius : NULL_FIELD,row: rowFacetField,column: colFacetField,+ text: text ? text : NULL_FIELD,xOffset: NULL_FIELD,yOffset: NULL_FIELD,details,@@ -351,7 +355,8 @@ const ReactVega = forwardRef<IReactVegaHandler, ReactVegaProps>(function ReactVewidth,height,themeConfig,- details+ details,+ text]);useImperativeHandle(ref, () => ({diff --git a/packages/graphic-walker/src/vis/spec/encode.ts b/packages/graphic-walker/src/vis/spec/encode.tsindex 3399b588..69af8803 100644--- a/packages/graphic-walker/src/vis/spec/encode.ts+++ b/packages/graphic-walker/src/vis/spec/encode.ts@@ -15,8 +15,12 @@ export interface IEncodeProps {theta: IViewField;radius: IViewField;details: Readonly<IViewField[]>;+ text: IViewField;}export function availableChannels(geomType: string): Set<string> {+ if (geomType === 'text') {+ return new Set(['text', 'color', 'size', 'x', 'y', 'xOffset', 'yOffset', 'opacity']);+ }if (geomType === 'arc') {return new Set(['opacity', 'color', 'size', 'theta', 'radius']);}diff --git a/packages/graphic-walker/src/vis/spec/view.ts b/packages/graphic-walker/src/vis/spec/view.tsindex 8ce1cf70..4b279e96 100644--- a/packages/graphic-walker/src/vis/spec/view.ts+++ b/packages/graphic-walker/src/vis/spec/view.ts@@ -21,6 +21,7 @@ export function getSingleView(props: SingleViewProps) {shape,theta,radius,+ text,row,column,xOffset,@@ -31,7 +32,7 @@ export function getSingleView(props: SingleViewProps) {geomType,hideLegend = false,} = props;- const fields: IViewField[] = [x, y, color, opacity, size, shape, row, column, xOffset, yOffset, theta, radius];+ const fields: IViewField[] = [x, y, color, opacity, size, shape, row, column, xOffset, yOffset, theta, radius, text];let markType = geomType;let config: any = {};if (hideLegend) {@@ -60,7 +61,8 @@ export function getSingleView(props: SingleViewProps) {yOffset,theta,radius,- details+ details,+ text});addTooltipEncode(encoding, details)if (defaultAggregated) {diff --git a/packages/graphic-walker/src/visualSettings/index.tsx b/packages/graphic-walker/src/visualSettings/index.tsxindex b717c09f..8a24309d 100644--- a/packages/graphic-walker/src/visualSettings/index.tsx+++ b/packages/graphic-walker/src/visualSettings/index.tsx@@ -155,9 +155,10 @@ const VisualSettings: React.FC<IVisualSettings> = ({ rendererHandler, darkModePrcircle: (props: SVGProps<SVGSVGElement>) => <svg stroke="none" fill="currentColor" strokeWidth="1.5" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" aria-hidden {...props}><path strokeLinecap="round" strokeLinejoin="round" d="M6,12 A6,6,0,0,1,18,12 A6,6,0,0,1,6,12" /></svg>,tick: (props: SVGProps<SVGSVGElement>) => <svg stroke="currentColor" fill="none" strokeWidth="1.5" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" aria-hidden {...props}><path strokeLinecap="round" strokeLinejoin="round" d="M5,12h14" /></svg>,rect: (props: SVGProps<SVGSVGElement>) => <svg stroke="none" fill="currentColor" strokeWidth="1.5" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" aria-hidden {...props}><path strokeLinecap="round" strokeLinejoin="round" d="M5,5v14h14v-14z" /></svg>,+ text: (props: SVGProps<SVGSVGElement>) => <svg stroke="currentColor" fill="currentColor" strokeWidth="1.5" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" aria-hidden {...props}><path strokeLinecap="round" strokeLinejoin="round" d="M10.5 21l5.25-11.25L21 21m-9-3h7.5M3 5.621a48.474 48.474 0 016-.371m0 0c1.12 0 2.233.038 3.334.114M9 5.25V3m3.334 2.364C11.176 10.658 7.69 15.08 3 17.502m9.334-12.138c.896.061 1.785.147 2.666.257m-4.589 8.495a18.023 18.023 0 01-3.827-5.802" /></svg>,arc: (props: SVGProps<SVGSVGElement>) => <svg stroke="none" fill="currentColor" strokeWidth="1.5" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" aria-hidden {...props}><path strokeLinecap="round" strokeLinejoin="round" d="M12,21l-9,-15a12,12,0,0,1,18,0Z" /></svg>,boxplot: (props: SVGProps<SVGSVGElement>) => <svg stroke="currentColor" fill="none" strokeWidth="1.5" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" aria-hidden {...props}><path strokeLinecap="round" strokeLinejoin="round" d="M7,7v9h10v-9Zm0,4h8M12,7v-6m-3,0h6M12,16v7m-3,0h6" /></svg>,- table: (props: SVGProps<SVGSVGElement>) => <svg stroke="currentColor" fill="none" strokeWidth="1.5" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" aria-hidden {...props}><path strokeLinecap="round" strokeLinejoin="round" d="M7,7v9h10v-9Zm0,4h8M12,7v-6m-3,0h6M12,16v7m-3,0h6" /></svg>,+ table: (props: SVGProps<SVGSVGElement>) => <svg stroke="currentColor" fill="none" strokeWidth="1.5" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" aria-hidden {...props}><path strokeLinecap="round" strokeLinejoin="round" d="M3.375 19.5h17.25m-17.25 0a1.125 1.125 0 01-1.125-1.125M3.375 19.5h7.5c.621 0 1.125-.504 1.125-1.125m-9.75 0V5.625m0 12.75v-1.5c0-.621.504-1.125 1.125-1.125m18.375 2.625V5.625m0 12.75c0 .621-.504 1.125-1.125 1.125m1.125-1.125v-1.5c0-.621-.504-1.125-1.125-1.125m0 3.75h-7.5A1.125 1.125 0 0112 18.375m9.75-12.75c0-.621-.504-1.125-1.125-1.125H3.375c-.621 0-1.125.504-1.125 1.125m19.5 0v1.5c0 .621-.504 1.125-1.125 1.125M2.25 5.625v1.5c0 .621.504 1.125 1.125 1.125m0 0h17.25m-17.25 0h7.5c.621 0 1.125.504 1.125 1.125M3.375 8.25c-.621 0-1.125.504-1.125 1.125v1.5c0 .621.504 1.125 1.125 1.125m17.25-3.75h-7.5c-.621 0-1.125.504-1.125 1.125m8.625-1.125c.621 0 1.125.504 1.125 1.125v1.5c0 .621-.504 1.125-1.125 1.125m-17.25 0h7.5m-7.5 0c-.621 0-1.125.504-1.125 1.125v1.5c0 .621.504 1.125 1.125 1.125M12 10.875v-1.5m0 1.5c0 .621-.504 1.125-1.125 1.125M12 10.875c0 .621.504 1.125 1.125 1.125m-2.25 0c.621 0 1.125.504 1.125 1.125M13.125 12h7.5m-7.5 0c-.621 0-1.125.504-1.125 1.125M20.625 12c.621 0 1.125.504 1.125 1.125v1.5c0 .621-.504 1.125-1.125 1.125m-17.25 0h7.5M12 14.625v-1.5m0 1.5c0 .621-.504 1.125-1.125 1.125M12 14.625c0 .621.504 1.125 1.125 1.125m-2.25 0c.621 0 1.125.504 1.125 1.125m0 1.5v-1.5m0 0c0-.621.504-1.125 1.125-1.125m0 0h7.5" /></svg>}[g],})),value: markType,