An open source alternative to Tableau. Embeddable visual analytic
TypeScript bidatadata-analysisdata-miningdata-visualizationedak6skanarieslow-codepivot-tablereacttableautableau-alternativetypescriptvegavega-litevisualization
docs: introduce TerseSpec in README (en/zh/ja)
Elwynn Chen388b0ef6740d
diff --git a/README.ja-JP.md b/README.ja-JP.mdindex d87a3939..d1329b64 100644--- a/README.ja-JP.md+++ b/README.ja-JP.md@@ -128,6 +128,31 @@ const YourChart: React.FC = props => {export default YourChart;```+### TerseSpec:手書きできるチャート記述文法 🆕++Graphic Walker が内部で保存するチャート仕様(`IChart`)は、生成された id や明示的なチャネル・レイアウト項目を持つ、機械向けの冗長な形式です。**TerseSpec** はその上に載る手書き用の文法で、フィールドを*名前*で参照し、`normalize()` がどのコンポーネントでも受け付けられる完全なチャートに展開します:++```typescript+import { GraphicRenderer, normalize } from '@kanaries/graphic-walker';++const YourChart = ({ data, fields }) => {+ const chart = normalize(+ {+ mark: 'bar',+ x: 'Manufacturer',+ y: 'mean(Price_in_thousands)',+ color: 'Vehicle_type',+ },+ fields+ );+ return <GraphicRenderer data={data} fields={fields} chart={[chart]} />;+};+```++集計ショートハンド(`mean(...)` など)、インライン計算フィールド(`computed`)、行フィルタ(`filters`)、クエリレベルの日付ドリル(`timeUnit`)などをサポートします。TerseSpec は記述専用であり、永続化とエクスポート/インポートは従来どおり canonical 形式を使うため、保存済みのチャートには一切影響しません。++👉 [playground](https://graphic-walker.kanaries.net/examples/TerseSpec) で対話的な文法サンプルを試せます。詳細な仕様は [docs/terse-spec-design.md](./docs/terse-spec-design.md) を参照してください。+### ローカルに試す (dev mode)```bash# packages/graphic-walkerdiff --git a/README.md b/README.mdindex d6c6aa50..966a8ea5 100644--- a/README.md+++ b/README.md@@ -27,6 +27,7 @@ It is extremely easy to embed in your apps just as a React component 🎉! The o+ Spatial visualization. (supports GeoJSON, TopoJSON)+ Natural language / Chat interface. Ask question about your data!+ A grammar of graphics based visual analytic user interface where users can build visualizations from low-level visual channel encodings. (based on [vega-lite](https://vega.github.io/vega-lite/))++ A hand-writable chart spec (TerseSpec): describe charts with field names and `agg(field)` shorthand, then expand with `normalize()`. See [TerseSpec](#tersespec-write-charts-by-hand-). 🆕https://github.com/Kanaries/graphic-walker/assets/22167673/15d34bed-9ccc-42da-a2f4-9859ea36fa65@@ -180,6 +181,46 @@ const YourChart: React.FC<IYourChartProps> = props => {export default YourChart;```+### TerseSpec: write charts by hand 🆕++Charts in Graphic Walker are stored in a canonical spec format (`IChart`) that is verbose and machine-oriented: fields carry generated ids, and every channel, pool and layout knob is explicit. **TerseSpec** is a hand-writable authoring grammar on top of it — you reference fields by *name*, and `normalize()` expands the terse spec into a full canonical chart that any component accepts:++```typescript+import { GraphicRenderer, normalize } from '@kanaries/graphic-walker';++const YourChart = ({ data, fields }) => {+ const chart = normalize(+ {+ mark: 'bar',+ x: 'Manufacturer',+ y: 'mean(Price_in_thousands)',+ color: 'Vehicle_type',+ },+ fields+ );+ return <GraphicRenderer data={data} fields={fields} chart={[chart]} />;+};+```++The grammar at a glance:++| Syntax | Meaning |+| --- | --- |+| `"x": "Manufacturer"` | reference a field by name |+| `"y": "mean(Price_in_thousands)"` | aggregation shorthand: `sum` / `mean` / `count` / `median` / `min` / `max` / `variance` / `stdev` |+| `"x": "fid:col_0_64"` | `fid:` prefix bypasses name resolution |+| `{ "field", "aggregate", "sort", "timeUnit" }` | object form for per-channel options; `timeUnit` performs a real query-level date drill |+| `"computed": [{ "name", "expr" \| "bin" \| "log" }]` | inline computed fields; quote refs inside `expr` like `'"Horsepower" / "Curb_weight"'` |+| `"filters": [{ "field", "oneOf" \| "notIn" \| "range" \| "timeRange" }]` | row filters; `timeRange` takes epoch milliseconds |+| `"aggregate": false` / `"stack"` / `"limit"` / `"sort"` | chart-level knobs |+| `"config"` / `"layout"` | canonical escape hatches, merged last with the highest priority |++`normalize(input, fields)` is a unified entry: besides TerseSpec it also accepts canonical charts, partial charts, legacy persisted specs and Vega-Lite-like specs, always returning a complete canonical `IChart` (stamped with `$schema`) and validating computed-field references along the way — an unknown field name fails fast with nearest-candidate suggestions.++TerseSpec is authoring-only. Persistence and export/import keep using the canonical format, so nothing changes for previously saved charts.++👉 Try the interactive grammar lessons in the [playground](https://graphic-walker.kanaries.net/examples/TerseSpec), read the full contract in [docs/terse-spec-design.md](./docs/terse-spec-design.md), or validate against the JSON Schema at `https://graphic-walker.kanaries.net/tersespec_v1.json`.+### try local (dev mode)```bash# packages/graphic-walker@@ -284,7 +325,7 @@ Array of fields(columns) of the data. Provide this prop with `data` prop togethe#### ~~`spec`: optional _{ [`Specification`](./packages/graphic-walker/src/interfaces.ts) }_~~-Visualization specification. This is an internal prop, you should not provide this prop directly. If you want to control the visualization specification, you can use [`storeRef`](#storeref) prop.+Visualization specification. This is an internal prop, you should not provide this prop directly. If you want to control the visualization specification, you can use [`storeRef`](#storeref) prop. To describe charts programmatically, prefer [TerseSpec + `normalize()`](#tersespec-write-charts-by-hand-) with the `chart` prop.#### `i18nLang`: optional _{ `string = 'en-US'` }_diff --git a/README.zh-CN.md b/README.zh-CN.mdindex 52f8820c..5eaaeacd 100644--- a/README.zh-CN.md+++ b/README.zh-CN.md@@ -22,6 +22,7 @@ Graphic Walker 是一个非常规的tableau的开源替代,它可以帮助数+ 一个提供数据中异常模式的归因解释器(tableau数据解释器/salesforce einstein)。+ 极其简单的嵌入方式,你可以像引入一个react组件一样简单的将graphic-walker嵌入到你的应用中。+ graphic-walker将重型计算放入web-worker中,充分利用客户端算力,使得其可以支持纯客户端部署。++ 可手写的图表描述文法(TerseSpec):按字段名 + `agg(field)` 简写描述图表,经 `normalize()` 展开为完整图表。🆕> Graphic Walker 是一个轻量级的可嵌入的可视化分析组件。 如果你对更未来的数据分析工具感兴趣,可以了解我们在做的另一个开源工具 [RATH](https://github.com/Kanaries/Rath), 一个增强分析BI应用,支持全自动的数据洞察发现,因果分析和智能可视化生成。@@ -163,6 +164,46 @@ npm i veaury -S完成。+### TerseSpec:可手写的图表描述文法 🆕++Graphic Walker 内部存储图表使用的是一种冗长的、面向机器的规范格式(`IChart`):字段带生成的 id,每个通道、字段池、布局项都是显式的。**TerseSpec** 是叠在它上面的一层可手写文法——按字段*名*引用,由 `normalize()` 展开为任何组件都能接受的完整图表:++```typescript+import { GraphicRenderer, normalize } from '@kanaries/graphic-walker';++const YourChart = ({ data, fields }) => {+ const chart = normalize(+ {+ mark: 'bar',+ x: 'Manufacturer',+ y: 'mean(Price_in_thousands)',+ color: 'Vehicle_type',+ },+ fields+ );+ return <GraphicRenderer data={data} fields={fields} chart={[chart]} />;+};+```++文法速览:++| 语法 | 含义 |+| --- | --- |+| `"x": "Manufacturer"` | 按字段名引用 |+| `"y": "mean(Price_in_thousands)"` | 聚合简写:`sum` / `mean` / `count` / `median` / `min` / `max` / `variance` / `stdev` |+| `"x": "fid:col_0_64"` | `fid:` 前缀绕过按名解析 |+| `{ "field", "aggregate", "sort", "timeUnit" }` | 通道级选项的对象形式;`timeUnit` 是真正的查询级日期钻取 |+| `"computed": [{ "name", "expr" \| "bin" \| "log" }]` | 内联计算字段;`expr` 里的字段引用需加引号,如 `'"Horsepower" / "Curb_weight"'` |+| `"filters": [{ "field", "oneOf" \| "notIn" \| "range" \| "timeRange" }]` | 行过滤;`timeRange` 只接受 epoch 毫秒 |+| `"aggregate": false` / `"stack"` / `"limit"` / `"sort"` | 图表级开关 |+| `"config"` / `"layout"` | canonical 直通逃生舱,最后合并、优先级最高 |++`normalize(input, fields)` 是统一入口:除 TerseSpec 外也接受完整图表、部分图表、旧版持久化格式与 Vega-Lite 风格输入,始终返回带 `$schema` 的完整 `IChart`,并顺带校验计算字段引用——未知字段名会快速报错并附近似候选。++TerseSpec 只用于书写。持久化与导入导出仍使用 canonical 格式,已保存的图表不受任何影响。++👉 在 [playground](https://graphic-walker.kanaries.net/examples/TerseSpec) 里试玩交互式文法示例;完整契约见 [docs/terse-spec-design.md](./docs/terse-spec-design.md);JSON Schema:`https://graphic-walker.kanaries.net/tersespec_v1.json`。+### 本地测试```bash# packages/graphic-walker