An open source alternative to Tableau. Embeddable visual analytic
TypeScript bidatadata-analysisdata-miningdata-visualizationedak6skanarieslow-codepivot-tablereacttableautableau-alternativetypescriptvegavega-litevisualization
feat: support value format
jojocys339580bee455
diff --git a/packages/graphic-walker/src/App.tsx b/packages/graphic-walker/src/App.tsxindex 4b72961c..f5cc47cd 100644--- a/packages/graphic-walker/src/App.tsx+++ b/packages/graphic-walker/src/App.tsx@@ -18,6 +18,7 @@ import SegmentNav from './segments/segmentNav';import DatasetConfig from './dataSource/datasetConfig';import { useCurrentMediaTheme } from './utils/media';import CodeExport from './components/codeExport';+import VisualConfig from './components/visualConfig';export interface IGWProps {dataSource?: IRow[];@@ -125,6 +126,7 @@ const App = observer<IGWProps>(function App(props) {><VisualSettings rendererHandler={rendererRef} darkModePreference={dark} /><CodeExport />+ <VisualConfig /><div className="md:grid md:grid-cols-12 xl:grid-cols-6"><div className="md:col-span-3 xl:col-span-1"><DatasetFields />diff --git a/packages/graphic-walker/src/components/visualConfig/index.tsx b/packages/graphic-walker/src/components/visualConfig/index.tsxnew file mode 100644index 00000000..ea05e383--- /dev/null+++ b/packages/graphic-walker/src/components/visualConfig/index.tsx@@ -0,0 +1,75 @@+import { observer } from 'mobx-react-lite';+import React, { useState } from 'react';+import { useGlobalStore } from '../../store';+import Modal from '../modal';+import { IVisualConfig } from '../../interfaces';+import PrimaryButton from '../button/primary';+import DefaultButton from '../button/default';+import { useTranslation } from 'react-i18next';++const VisualConfigPanel: React.FC = (props) => {+ const { commonStore, vizStore } = useGlobalStore();+ const { showVisualConfigPanel } = commonStore;+ const { visualConfig } = vizStore;+ const { t } = useTranslation();+ const formatConfigList: (keyof IVisualConfig['format'])[] = [+ 'numberFormat',+ 'timeFormat',+ 'normalizedNumberFormat',+ ];+ const [format, setFormat] = useState<IVisualConfig['format']>({+ numberFormat: visualConfig.format.numberFormat,+ timeFormat: visualConfig.format.timeFormat,+ normalizedNumberFormat: visualConfig.format.normalizedNumberFormat,+ });++ return (+ <Modal+ show={showVisualConfigPanel}+ onClose={() => {+ commonStore.setShowVisualConfigPanel(false);+ }}+ >+ <div>+ <h2 className='text-lg mb-4'>{t('config.format')}</h2>+ {formatConfigList.map((fc) => (+ <div className="my-2" key={fc}>+ <label className="block text-xs font-medium leading-6 text-gray-900">{t(`config.${fc}`)}</label>+ <div className="mt-1">+ <input+ type="text"+ className="block w-full rounded-md border-0 py-1 px-2 text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 placeholder:text-gray-400 focus:ring-1 focus:ring-inset focus:ring-indigo-600 sm:text-sm sm:leading-6"+ value={format[fc] ?? ''}+ onChange={(e) => {+ setFormat((f) => ({+ ...f,+ [fc]: e.target.value,+ }));+ }}+ />+ </div>+ </div>+ ))}+ <div className='mt-4'>+ <PrimaryButton+ text={t('actions.confirm')}+ className='mr-2'+ onClick={() => {+ vizStore.setVisualConfig('format', format);+ commonStore.setShowVisualConfigPanel(false);+ }}+ />+ <DefaultButton+ text={t('actions.cancel')}+ className='mr-2'+ onClick={() => {+ commonStore.setShowVisualConfigPanel(false);+ }}+ />+ </div>+ </div>+ </Modal>+ );+};++export default observer(VisualConfigPanel);diff --git a/packages/graphic-walker/src/interfaces.ts b/packages/graphic-walker/src/interfaces.tsindex cd6831aa..b938a5cf 100644--- a/packages/graphic-walker/src/interfaces.ts+++ b/packages/graphic-walker/src/interfaces.ts@@ -192,6 +192,11 @@ export interface IVisualConfig {showActions: boolean;interactiveScale: boolean;sorted: 'none' | 'ascending' | 'descending';+ format: {+ numberFormat?: string;+ timeFormat?: string;+ normalizedNumberFormat?: string;+ };size: {mode: 'auto' | 'fixed';width: number;diff --git a/packages/graphic-walker/src/locales/en-US.json b/packages/graphic-walker/src/locales/en-US.jsonindex 06267426..6d6dba5a 100644--- a/packages/graphic-walker/src/locales/en-US.json+++ b/packages/graphic-walker/src/locales/en-US.json@@ -1,4 +1,10 @@{+ "config": {+ "format": "Format",+ "numberFormat": "Number format",+ "timeFormat": "Time format",+ "normalizedNumberFormat": "Normalized number format"+ },"constant": {"row_count": "Row count","analytic_type": {diff --git a/packages/graphic-walker/src/locales/ja-JP.json b/packages/graphic-walker/src/locales/ja-JP.jsonindex 7da9bcd9..04c6994e 100644--- a/packages/graphic-walker/src/locales/ja-JP.json+++ b/packages/graphic-walker/src/locales/ja-JP.json@@ -1,200 +1,206 @@{+ "config": {+ "format": "形式",+ "numberFormat": "数字の形式",+ "timeFormat": "時間の形式",+ "normalizedNumberFormat": "正規化された数字の形式"+ },"constant": {- "row_count": "行数",- "analytic_type": {- "dimension": "次元",- "measure": "尺度"- },- "semantic_type": {- "nominal": "名義尺度",- "ordinal": "順序尺度",- "temporal": "時間尺度",- "quantitative": "数量尺度"- },- "mark_type": {- "__enum__": "マークタイプ",- "auto": "自動",- "bar": "バー",- "line": "ライン",- "area": "エリア",- "trail": "トレイル",- "point": "散布図",- "circle": "円",- "tick": "棒線図",- "rect": "長方形",- "arc": "アーク",- "boxplot": "ボックスプロット",- "table": "表",- "text": "本文"- },- "stack_mode": {- "__enum__": "スタックモード",- "none": "なし",- "stack": "スタック",- "normalize": "正規化"- },- "layout_type": {- "__enum__": "レイアウトタイプ",- "auto": "自動",- "fixed": "固定"- },- "exploration_mode": {- "__enum__": "探索モード",- "none": "オフ",- "brush": "ブラシ",- "point": "ポイント"- },- "brush_mode": {- "__enum__": "ブラシの方向",- "default": "両方",- "x": "X軸のみ",- "y": "Y軸のみ"- },- "draggable_key": {- "fields": "フィールド",- "columns": "X軸",- "rows": "Y軸",- "color": "色",- "opacity": "不透明度",- "size": "大きさ",- "shape": "形状",- "theta": "角度",- "radius": "半径",- "filters": "フィルター",- "text": "本文"- },- "aggregator": {- "sum": "合計",- "mean": "平均",- "count": "件数",- "median": "中央値",- "min": "最小値",- "max": "最大値",- "q1": "第一四分位数",- "q3": "第三四分位数",- "stdev": "標準偏差",- "variance": "分散"- },- "filter_type": {- "one_of": "1つ以上",- "range": "範囲",- "temporal_range": "日付範囲"- }+ "row_count": "行数",+ "analytic_type": {+ "dimension": "次元",+ "measure": "尺度"+ },+ "semantic_type": {+ "nominal": "名義尺度",+ "ordinal": "順序尺度",+ "temporal": "時間尺度",+ "quantitative": "数量尺度"+ },+ "mark_type": {+ "__enum__": "マークタイプ",+ "auto": "自動",+ "bar": "バー",+ "line": "ライン",+ "area": "エリア",+ "trail": "トレイル",+ "point": "散布図",+ "circle": "円",+ "tick": "棒線図",+ "rect": "長方形",+ "arc": "アーク",+ "boxplot": "ボックスプロット",+ "table": "表",+ "text": "本文"+ },+ "stack_mode": {+ "__enum__": "スタックモード",+ "none": "なし",+ "stack": "スタック",+ "normalize": "正規化"+ },+ "layout_type": {+ "__enum__": "レイアウトタイプ",+ "auto": "自動",+ "fixed": "固定"+ },+ "exploration_mode": {+ "__enum__": "探索モード",+ "none": "オフ",+ "brush": "ブラシ",+ "point": "ポイント"+ },+ "brush_mode": {+ "__enum__": "ブラシの方向",+ "default": "両方",+ "x": "X軸のみ",+ "y": "Y軸のみ"+ },+ "draggable_key": {+ "fields": "フィールド",+ "columns": "X軸",+ "rows": "Y軸",+ "color": "色",+ "opacity": "不透明度",+ "size": "大きさ",+ "shape": "形状",+ "theta": "角度",+ "radius": "半径",+ "filters": "フィルター",+ "text": "本文"+ },+ "aggregator": {+ "sum": "合計",+ "mean": "平均",+ "count": "件数",+ "median": "中央値",+ "min": "最小値",+ "max": "最大値",+ "q1": "第一四分位数",+ "q3": "第三四分位数",+ "stdev": "標準偏差",+ "variance": "分散"+ },+ "filter_type": {+ "one_of": "1つ以上",+ "range": "範囲",+ "temporal_range": "日付範囲"+ }},"App": {- "labels": {- "data_interpretation": "データ解釈"- },- "segments": {- "vis": "可視化",- "data": "データ"- }+ "labels": {+ "data_interpretation": "データ解釈"+ },+ "segments": {+ "vis": "可視化",+ "data": "データ"+ }},"DataSource": {- "labels": {- "cur_dataset": "現在のデータセット"- },- "buttons": {- "create_dataset": "データセットを作成",- "export_as_file": "ファイルとして保存",- "import_file": "Graphic Walkerファイルをインポート"- },- "dialog": {- "create_data_source": "新しいデータソース",- "data_types": "データソースの種類",- "text_file_data": "ローカルファイル",- "public_data": "公開データセット",- "data_source_type": "データソースの種類:{{sourceType}}",- "file": {- "open": "開く...",- "submit": "提出する",- "dataset_name": "データセット名",- "choose_file": "データファイルを選択してください",- "get_start_desc": "データセットの作成を始めましょう。"+ "labels": {+ "cur_dataset": "現在のデータセット"+ },+ "buttons": {+ "create_dataset": "データセットを作成",+ "export_as_file": "ファイルとして保存",+ "import_file": "Graphic Walkerファイルをインポート"},- "public": {- "submit": "提出する"+ "dialog": {+ "create_data_source": "新しいデータソース",+ "data_types": "データソースの種類",+ "text_file_data": "ローカルファイル",+ "public_data": "公開データセット",+ "data_source_type": "データソースの種類:{{sourceType}}",+ "file": {+ "open": "開く...",+ "submit": "提出する",+ "dataset_name": "データセット名",+ "choose_file": "データファイルを選択してください",+ "get_start_desc": "データセットの作成を始めましょう。"+ },+ "public": {+ "submit": "提出する"+ }}- }},"main": {- "tablist": {- "new": "+ 新規作成",- "auto_title": "グラフ {{idx}}",- "chart_name": "グラフ名"- },- "tabpanel": {- "menubar": {- "undo": "元に戻す",- "redo": "やり直し"- },- "settings": {- "toggle": {- "aggregation": "集計",- "stack": "スタック",- "axes_resize": "軸のサイズ変更",- "debug": "デバッグ"- },- "sort": "並べ替えの順序",- "button": {- "ascending": "昇順に並べ替える",- "descending": "降順に並べ替える",- "transpose": "転置",- "export_chart": "エクスポート",- "export_chart_as": "{{type}}としてエクスポート"- },- "size": "サイズ変更",- "size_setting": {- "width": "幅",- "height": "高さ"- }+ "tablist": {+ "new": "+ 新規作成",+ "auto_title": "グラフ {{idx}}",+ "chart_name": "グラフ名"},- "DatasetFields": {- "field_list": "フィールド一覧"+ "tabpanel": {+ "menubar": {+ "undo": "元に戻す",+ "redo": "やり直し"+ },+ "settings": {+ "toggle": {+ "aggregation": "集計",+ "stack": "スタック",+ "axes_resize": "軸のサイズ変更",+ "debug": "デバッグ"+ },+ "sort": "並べ替えの順序",+ "button": {+ "ascending": "昇順に並べ替える",+ "descending": "降順に並べ替える",+ "transpose": "転置",+ "export_chart": "エクスポート",+ "export_chart_as": "{{type}}としてエクスポート"+ },+ "size": "サイズ変更",+ "size_setting": {+ "width": "幅",+ "height": "高さ"+ }+ },+ "DatasetFields": {+ "field_list": "フィールド一覧"+ }}- }},"filters": {- "to_edit": "このルールを編集",- "empty_rule": "! (空のルール)",- "editing": "ルールを編集",- "form": {- "name": "フィールド",- "rule": "ルール"- },- "header": {- "visibility": "表示",- "value": "ラベル",- "count": "件数"- },- "selected_keys": "{{ count }}件が選択されました",- "btn": {- "select_all": "すべて選択",- "unselect_all": "すべての選択を解除",- "reverse": "選択を反転する",- "confirm": "確認",- "cancel": "キャンセル"- }+ "to_edit": "このルールを編集",+ "empty_rule": "! (空のルール)",+ "editing": "ルールを編集",+ "form": {+ "name": "フィールド",+ "rule": "ルール"+ },+ "header": {+ "visibility": "表示",+ "value": "ラベル",+ "count": "件数"+ },+ "selected_keys": "{{ count }}件が選択されました",+ "btn": {+ "select_all": "すべて選択",+ "unselect_all": "すべての選択を解除",+ "reverse": "選択を反転する",+ "confirm": "確認",+ "cancel": "キャンセル"+ }},"explain": {- "lg_than": "より大きい",- "sm_than": "より小さい",- "expection": "期待値",- "unrecognized": "未認識",- "score": "スコア",- "contains": "を含む",- "reason": {- "selection_dim_distribution": "次元のヒント",- "selection_mea_distribution": "尺度のヒント",- "children_major_factor": "主要要因",- "children_outlier": "外れ値"- }+ "lg_than": "より大きい",+ "sm_than": "より小さい",+ "expection": "期待値",+ "unrecognized": "未認識",+ "score": "スコア",+ "contains": "を含む",+ "reason": {+ "selection_dim_distribution": "次元のヒント",+ "selection_mea_distribution": "尺度のヒント",+ "children_major_factor": "主要要因",+ "children_outlier": "外れ値"+ }},"actions": {- "prev": "前へ",- "next": "次へ",- "drop_field": "ここにフィールドをドロップ",- "confirm": "確認",- "cancel": "キャンセル"+ "prev": "前へ",+ "next": "次へ",+ "drop_field": "ここにフィールドをドロップ",+ "confirm": "確認",+ "cancel": "キャンセル"}- }\ No newline at end of file+}\ No newline at end of filediff --git a/packages/graphic-walker/src/locales/zh-CN.json b/packages/graphic-walker/src/locales/zh-CN.jsonindex 0ed7fa27..8161e01d 100644--- a/packages/graphic-walker/src/locales/zh-CN.json+++ b/packages/graphic-walker/src/locales/zh-CN.json@@ -1,4 +1,10 @@{+ "config": {+ "format": "格式",+ "numberFormat": "数字格式",+ "timeFormat": "时间格式",+ "normalizedNumberFormat": "标准化数字格式"+ },"constant": {"row_count": "行数","analytic_type": {diff --git a/packages/graphic-walker/src/renderer/specRenderer.tsx b/packages/graphic-walker/src/renderer/specRenderer.tsxindex ca63d8fb..8ff59f84 100644--- a/packages/graphic-walker/src/renderer/specRenderer.tsx+++ b/packages/graphic-walker/src/renderer/specRenderer.tsx@@ -1,4 +1,4 @@-import { runInAction } from 'mobx';+import { runInAction, toJS } from 'mobx';import { Resizable } from 're-resizable';import React, { useCallback, forwardRef, useMemo } from 'react';@@ -21,7 +21,7 @@ const SpecRenderer = forwardRef<IReactVegaHandler, SpecRendererProps>(function () {const { vizStore, commonStore } = useGlobalStore();// const { draggableFieldState, visualConfig } = vizStore;- const { geoms, interactiveScale, defaultAggregated, stack, showActions, size } = visualConfig;+ const { geoms, interactiveScale, defaultAggregated, stack, showActions, size, format: _format } = visualConfig;const rows = draggableFieldState.rows;const columns = draggableFieldState.columns;@@ -33,6 +33,7 @@ const SpecRenderer = forwardRef<IReactVegaHandler, SpecRendererProps>(function (const sizeChannel = draggableFieldState.size;const details = draggableFieldState.details;const text = draggableFieldState.text;+ const format = toJS(_format)const rowLeftFacetFields = useMemo(() => rows.slice(0, -1).filter((f) => f.analyticType === 'dimension'), [rows]);const colLeftFacetFields = useMemo(@@ -86,6 +87,7 @@ const SpecRenderer = forwardRef<IReactVegaHandler, SpecRendererProps>(function (>{loading && <LoadingLayer />}<ReactVega+ format={format}layoutMode={size.mode}interactiveScale={interactiveScale}geomType={geoms[0]}diff --git a/packages/graphic-walker/src/store/commonStore.ts b/packages/graphic-walker/src/store/commonStore.tsindex dc87459a..1e23271c 100644--- a/packages/graphic-walker/src/store/commonStore.ts+++ b/packages/graphic-walker/src/store/commonStore.ts@@ -14,6 +14,7 @@ export class CommonStore {public vizEmbededMenu: { show: boolean; position: [number, number] } = { show: false, position: [0, 0] };public showDataConfig: boolean = false;public showCodeExportPanel: boolean = false;+ public showVisualConfigPanel: boolean = false;public filters: Filters = {};public segmentKey: ISegmentKey = ISegmentKey.vis;constructor () {@@ -64,6 +65,9 @@ export class CommonStore {public setShowCodeExportPanel (show: boolean) {this.showCodeExportPanel = show;}+ public setShowVisualConfigPanel (show: boolean) {+ this.showVisualConfigPanel = show;+ }public closeEmbededMenu () {this.vizEmbededMenu.show = false;}diff --git a/packages/graphic-walker/src/store/visualSpecStore.ts b/packages/graphic-walker/src/store/visualSpecStore.tsindex f14ff645..588c76aa 100644--- a/packages/graphic-walker/src/store/visualSpecStore.ts+++ b/packages/graphic-walker/src/store/visualSpecStore.ts@@ -75,6 +75,11 @@ export function initVisualConfig(): IVisualConfig {width: 320,height: 200,},+ format: {+ numberFormat: undefined,+ timeFormat: undefined,+ normalizedNumberFormat: undefined+ }};}@@ -369,6 +374,9 @@ export class VizSpecStore {case configKey === "stack": {return (config[configKey] = value);}+ case configKey === 'format' && typeof value === "object": {+ return config[configKey] = value+ }default: {console.error("unknown key" + configKey);}@@ -620,6 +628,9 @@ export class VizSpecStore {encodings[destinationKey].push(cloneField);});}+ public setVizFormatConfig (formatKey: keyof IVisualConfig['format'], value?: string) {+ this.visualConfig[formatKey] = value+ }public renderSpec(spec: Specification) {const tab = this.visList[this.visIndex];diff --git a/packages/graphic-walker/src/vis/react-vega.tsx b/packages/graphic-walker/src/vis/react-vega.tsxindex 4b41439d..f7738685 100644--- a/packages/graphic-walker/src/vis/react-vega.tsx+++ b/packages/graphic-walker/src/vis/react-vega.tsx@@ -1,11 +1,11 @@import React, { useEffect, useState, useMemo, forwardRef, useImperativeHandle, useRef } from 'react';-import embed from 'vega-embed';+import embed, { vega } from 'vega-embed';import { Subject, Subscription } from 'rxjs'import * as op from 'rxjs/operators';import type { ScenegraphEvent, View } from 'vega';import styled from 'styled-components';-import { IViewField, IRow, IStackMode, IDarkMode, IThemeKey } from '../interfaces';+import { IViewField, IRow, IStackMode, IDarkMode, IThemeKey, IVisualConfig } from '../interfaces';import { useTranslation } from 'react-i18next';import { getVegaTimeFormatRules } from './temporalFormat';import { builtInThemes } from './theme';@@ -27,6 +27,7 @@ export interface IReactVegaHandler {downloadPNG: (filename?: string) => Promise<string[]>;}interface ReactVegaProps {+ format: IVisualConfig['format'];rows: Readonly<IViewField[]>;columns: Readonly<IViewField[]>;dataSource: IRow[];@@ -98,12 +99,30 @@ const ReactVega = forwardRef<IReactVegaHandler, ReactVegaProps>(function ReactVeheight,details = [],themeKey = 'vega',- dark = 'media'+ dark = 'media',+ format} = props;const [viewPlaceholders, setViewPlaceholders] = useState<React.MutableRefObject<HTMLDivElement>[]>([]);const { i18n } = useTranslation();const mediaTheme = useCurrentMediaTheme(dark);const themeConfig = builtInThemes[themeKey]?.[mediaTheme];++ const vegaConfig = useMemo(() => {+ const config: any = {+ ...themeConfig,+ }+ if (format.normalizedNumberFormat && format.normalizedNumberFormat.length > 0) {+ config.normalizedNumberFormat = format.normalizedNumberFormat;+ }+ if (format.numberFormat && format.numberFormat.length > 0) {+ config.numberFormat = format.numberFormat;+ }+ if (format.timeFormat && format.timeFormat.length > 0) {+ config.timeFormat = format.timeFormat;+ }+ return config;+ }, [themeConfig, format.normalizedNumberFormat, format.numberFormat, format.timeFormat])+useEffect(() => {const clickSub = geomClick$.subscribe(([values, e]) => {if (onGeomClick) {@@ -202,7 +221,7 @@ const ReactVega = forwardRef<IReactVegaHandler, ReactVegaProps>(function ReactVe}if (viewPlaceholders.length > 0 && viewPlaceholders[0].current) {- embed(viewPlaceholders[0].current, spec, { mode: 'vega-lite', actions: showActions, timeFormatLocale: getVegaTimeFormatRules(i18n.language), config: themeConfig }).then(res => {+ embed(viewPlaceholders[0].current, spec, { mode: 'vega-lite', actions: showActions, timeFormatLocale: getVegaTimeFormatRules(i18n.language), config: vegaConfig }).then(res => {vegaRefs.current = [res.view];try {res.view.addEventListener('click', (e) => {@@ -267,7 +286,7 @@ const ReactVega = forwardRef<IReactVegaHandler, ReactVegaProps>(function ReactVeans.params = commonSpec.params;}if (node) {- embed(node, ans, { mode: 'vega-lite', actions: showActions, timeFormatLocale: getVegaTimeFormatRules(i18n.language), config: themeConfig }).then(res => {+ embed(node, ans, { mode: 'vega-lite', actions: showActions, timeFormatLocale: getVegaTimeFormatRules(i18n.language), config: vegaConfig }).then(res => {vegaRefs.current.push(res.view);const paramStores = (res.vgSpec.data?.map(d => d.name) ?? []).filter(name => [BRUSH_SIGNAL_NAME, POINT_SIGNAL_NAME].map(p => `${p}_store`).includes(name)@@ -354,7 +373,7 @@ const ReactVega = forwardRef<IReactVegaHandler, ReactVegaProps>(function ReactVelayoutMode,width,height,- themeConfig,+ vegaConfig,details,text]);diff --git a/packages/graphic-walker/src/visualSettings/index.tsx b/packages/graphic-walker/src/visualSettings/index.tsxindex 8a24309d..ce278ff8 100644--- a/packages/graphic-walker/src/visualSettings/index.tsx+++ b/packages/graphic-walker/src/visualSettings/index.tsx@@ -18,6 +18,7 @@ import {ArrowsUpDownIcon,LightBulbIcon,CodeBracketSquareIcon,+ Cog6ToothIcon,} from '@heroicons/react/24/outline';import { observer } from 'mobx-react-lite';import React, { SVGProps, useCallback, useMemo } from 'react';@@ -280,6 +281,14 @@ const VisualSettings: React.FC<IVisualSettings> = ({ rendererHandler, darkModePr</FormContainer>),},+ {+ key: 'config',+ label: 'config',+ icon: Cog6ToothIcon,+ onClick: () => {+ commonStore.setShowVisualConfigPanel(true);+ }+ },{key: 'export_code',label: t('button.export_code'),