@x-cmd/draw 0.2.1 → 0.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.cn.md CHANGED
@@ -2,8 +2,63 @@
2
2
 
3
3
  > [English](README.md) | 中文
4
4
 
5
+ [![JSR score](https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fapi.jsr.io%2Fscopes%2Fx-cmd%2Fpackages%2Fdraw&query=%24.score&label=JSR%20score&color=yellowgreen)](https://jsr.io/@x-cmd/draw/score)
6
+ [![OpenSSF Scorecard](https://api.securityscorecards.dev/projects/github.com/x-cmd/draw/badge)](https://securityscorecards.dev/viewer/?uri=github.com/x-cmd/draw)
7
+
5
8
  AI 时代的 SVG 图表生成服务(狗粮原型)。单端点 `/draw?type=...`,数据在 URL 里、输出带机器可读 `<metadata>`、Cloudflare Workers + TypeScript 直生成 SVG。风格体系对齐设计师规范(13 张 SVG),每图种多风格变体。
6
9
 
10
+ ## 先睹为快
11
+
12
+ 数据全在 URL 里 — 浏览器打开、`<img>` 嵌入、贴进仓库 README,SVG 直接渲染:
13
+
14
+ ### 桑基图 — PR 生命周期:类型 → 结果 → 时段 (`type=sankey&t=pipeline`)
15
+
16
+ ```text
17
+ https://x-cmd.com/draw?type=sankey&t=pipeline&labels=feat,fix,docs,chore,merged,closed,rejected,0-1y,1-2y,2y+&links=feat>merged:38;feat>closed:12;feat>rejected:8;fix>merged:33;fix>closed:6;fix>rejected:2;docs>merged:16;docs>closed:4;chore>merged:5;chore>closed:6;chore>rejected:6;merged>0-1y:52;merged>1-2y:28;merged>2y+:12;closed>0-1y:14;closed>1-2y:9;closed>2y+:5;rejected>0-1y:9;rejected>1-2y:5;rejected>2y+:2&title=Pull%20requests%20lifecycle&unit=prs
18
+ ```
19
+
20
+ ![桑基图:PR 生命周期](https://x-cmd.com/draw?type=sankey&t=pipeline&labels=feat,fix,docs,chore,merged,closed,rejected,0-1y,1-2y,2y+&links=feat>merged:38;feat>closed:12;feat>rejected:8;fix>merged:33;fix>closed:6;fix>rejected:2;docs>merged:16;docs>closed:4;chore>merged:5;chore>closed:6;chore>rejected:6;merged>0-1y:52;merged>1-2y:28;merged>2y+:12;closed>0-1y:14;closed>1-2y:9;closed>2y+:5;rejected>0-1y:9;rejected>1-2y:5;rejected>2y+:2&title=Pull%20requests%20lifecycle&unit=prs)
21
+
22
+ ### 水平柱 — 运行时吞吐,真实实测 (`type=hbar`; deno 7238 · node 6553 · bun 4972 ops/s, Apple Silicon)
23
+
24
+ ```text
25
+ https://x-cmd.com/draw?type=hbar&labels=deno,node,bun&values=7238,6553,4972&title=Runtime%20throughput&unit=ops%2Fs
26
+ ```
27
+
28
+ ![水平柱:运行时吞吐](https://x-cmd.com/draw?type=hbar&labels=deno,node,bun&values=7238,6553,4972&title=Runtime%20throughput&unit=ops%2Fs)
29
+
30
+ ### 雷达图 — 三软件对比 (`type=radar&t=evil`, 多系列)
31
+
32
+ ```text
33
+ https://x-cmd.com/draw?type=radar&t=evil&labels=startup,ecosystem,extensibility,memory,ease&series=vscode:60,95,90,55,80&series=neovim:95,65,85,95,35&series=zed:92,50,55,90,60&title=Editor%20comparison
34
+ ```
35
+
36
+ ![雷达图:编辑器对比](https://x-cmd.com/draw?type=radar&t=evil&labels=startup,ecosystem,extensibility,memory,ease&series=vscode:60,95,90,55,80&series=neovim:95,65,85,95,35&series=zed:92,50,55,90,60&title=Editor%20comparison)
37
+
38
+ ### 混合图 — 周下载 vs 星标增速 (`type=combo`, 量级差自动双 y 轴)
39
+
40
+ ```text
41
+ https://x-cmd.com/draw?type=combo&labels=Mon,Tue,Wed,Thu,Fri,Sat,Sun&series=Downloads:120,180,150,210,240,200,260&line=Star%20growth:3.1,3.4,3.2,3.8,4.1,3.9,4.5&title=Weekly%20npm%20downloads&unit=dl
42
+ ```
43
+
44
+ ![混合图:周下载与星标增速](https://x-cmd.com/draw?type=combo&labels=Mon,Tue,Wed,Thu,Fri,Sat,Sun&series=Downloads:120,180,150,210,240,200,260&line=Star%20growth:3.1,3.4,3.2,3.8,4.1,3.9,4.5&title=Weekly%20npm%20downloads&unit=dl)
45
+
46
+ ### 水平柱 — 分区 issue 开/闭蝴蝶图 (`type=hbar&t=xcmd-issue`)
47
+
48
+ ```text
49
+ https://x-cmd.com/draw?type=hbar&t=xcmd-issue&labels=cli,core,docs,ci,ui&series=open:12,8,15,4,9&series=closed:38,52,20,11,26&title=Issues%20by%20area
50
+ ```
51
+
52
+ ![水平柱:分区 issue 开闭](https://x-cmd.com/draw?type=hbar&t=xcmd-issue&labels=cli,core,docs,ci,ui&series=open:12,8,15,4,9&series=closed:38,52,20,11,26&title=Issues%20by%20area)
53
+
54
+ ### 环形图 — 语言构成 (`type=pie&t=market-mono`)
55
+
56
+ ```text
57
+ https://x-cmd.com/draw?type=pie&t=market-mono&title=Languages&unit=%25&labels=TypeScript,Shell,JavaScript,Rust,Other&values=68,14,9,6,3
58
+ ```
59
+
60
+ ![环形图:语言构成](https://x-cmd.com/draw?type=pie&t=market-mono&title=Languages&unit=%25&labels=TypeScript,Shell,JavaScript,Rust,Other&values=68,14,9,6,3)
61
+
7
62
  ## 三种使用方式(同一份渲染核心)
8
63
 
9
64
  **托管服务**(零安装):直接拼 URL — `https://x-cmd.com/draw?type=pie&labels=A,B&values=3,2`
@@ -59,19 +114,19 @@ deno task serve # 本地服
59
114
 
60
115
  **`GET /draw?type=<pie|bar|hbar|line|area|radar|gauge|scatter|combo|sankey|qr>`** — 渲染图表
61
116
 
62
- | type | 图表 | 限制 |
117
+ | type | 图表 | 示例 |
63
118
  |---|---|---|
64
- | `pie` | 环形图;`donut=0` 变实心饼 | ≤100 类(>9 自动合并 Other) |
65
- | `bar` | 柱状图/分组并排;多系列加 `stack=1` 变堆叠柱 | ≤30 组 |
66
- | `hbar` | 水平柱状图(排行场景,标签左值右) | ≤30 条,单系列(部分风格双系列) |
67
- | `line` | 折线图(平滑+渐变面积)/多折线 | ≤60 点 |
68
- | `area` | 面积图/多系列面积(渐变填充) | ≤60 点 |
69
- | `radar` | 雷达图 | 3-12 维 |
70
- | `gauge` | 仪表盘(240° 弧+中心数值) | `value`+`max`(默认100),value≤max;多环 ≤8 |
71
- | `scatter` | 散点图(双数值轴,支持负值;默认不标数值) | `x=&y=`,≤200 点 |
72
- | `combo` | 混合图:柱(`series=`)+线(`line=`)同图,`stack=1` 变堆叠柱 | ≤30 组,共 ≤6 系列 |
73
- | `sankey` | 桑基图(流向带宽) | `labels=`+`links=A>B:30`,≤24 节点/60 链接 |
74
- | `qr` | 二维码 | `d`=文本(≤1000 字符),`fg`/`bg` 配色,`title`/`unit` 标注 |
119
+ | `pie` | 环形图;`donut=0` 变实心饼<br><br>**<u>≤100 类(>9 自动合并 Other)</u>** | <a href="https://x-cmd.com/draw?type=pie&labels=TS,Py,Go,Rust&values=4821,2312,980,645&title=Stars%20by%20language"><img src="https://x-cmd.com/draw?type=pie&labels=TS,Py,Go,Rust&values=4821,2312,980,645&title=Stars%20by%20language" width="360" alt="pie example"></a> |
120
+ | `bar` | 柱状图/分组并排;多系列加 `stack=1` 变堆叠柱<br><br>**<u>≤30 组</u>** | <a href="https://x-cmd.com/draw?type=bar&labels=Mon,Tue,Wed&series=dev:12,18,9&series=ci:8,11,6"><img src="https://x-cmd.com/draw?type=bar&labels=Mon,Tue,Wed&series=dev:12,18,9&series=ci:8,11,6" width="360" alt="bar example"></a> |
121
+ | `hbar` | 水平柱状图(排行场景,标签左值右)<br><br>**<u>≤30 条,单系列(部分风格双系列)</u>** | <a href="https://x-cmd.com/draw?type=hbar&labels=cli,core,docs,ui&values=42,31,18,9&title=Commits%20by%20area"><img src="https://x-cmd.com/draw?type=hbar&labels=cli,core,docs,ui&values=42,31,18,9&title=Commits%20by%20area" width="360" alt="hbar example"></a> |
122
+ | `line` | 折线图(平滑+渐变面积)/多折线<br><br>**<u>≤60 点</u>** | <a href="https://x-cmd.com/draw?type=line&labels=Jan,Feb,Mar,Apr,May,Jun&values=12,19,15,25,22,30&title=Stars"><img src="https://x-cmd.com/draw?type=line&labels=Jan,Feb,Mar,Apr,May,Jun&values=12,19,15,25,22,30&title=Stars" width="360" alt="line example"></a> |
123
+ | `area` | 面积图/多系列面积(渐变填充)<br><br>**<u>≤60 点</u>** | <a href="https://x-cmd.com/draw?type=area&labels=Q1,Q2,Q3,Q4&values=8,14,23,37&title=Downloads"><img src="https://x-cmd.com/draw?type=area&labels=Q1,Q2,Q3,Q4&values=8,14,23,37&title=Downloads" width="360" alt="area example"></a> |
124
+ | `radar` | 雷达图<br><br>**<u>3-12 维</u>** | <a href="https://x-cmd.com/draw?type=radar&t=evil&labels=perf,docs,tests,dx&series=v1:7,5,8,6&series=v2:8,8,9,8"><img src="https://x-cmd.com/draw?type=radar&t=evil&labels=perf,docs,tests,dx&series=v1:7,5,8,6&series=v2:8,8,9,8" width="360" alt="radar example"></a> |
125
+ | `gauge` | 仪表盘(240° 弧+中心数值)<br><br>**<u>`value`+`max`(默认100),value≤max;多环 ≤8</u>** | <a href="https://x-cmd.com/draw?type=gauge&title=CI%20pass%20rate&value=87&max=100"><img src="https://x-cmd.com/draw?type=gauge&title=CI%20pass%20rate&value=87&max=100" width="360" alt="gauge example"></a> |
126
+ | `scatter` | 散点图(双数值轴,支持负值;默认不标数值)<br><br>**<u>`x=&y=`,≤200 点</u>** | <a href="https://x-cmd.com/draw?type=scatter&x=1,2,3,4,5&y=4,5,3,6,5&title=Latency"><img src="https://x-cmd.com/draw?type=scatter&x=1,2,3,4,5&y=4,5,3,6,5&title=Latency" width="360" alt="scatter example"></a> |
127
+ | `combo` | 混合图:柱(`series=`)+线(`line=`)同图,`stack=1` 变堆叠柱<br><br>**<u>≤30 组,共 ≤6 系列</u>** | <a href="https://x-cmd.com/draw?type=combo&labels=Mon,Tue,Wed,Thu,Fri&series=dl:120,180,150,210,240&line=growth:3.1,3.4,3.2,3.8,4.1&title=Downloads"><img src="https://x-cmd.com/draw?type=combo&labels=Mon,Tue,Wed,Thu,Fri&series=dl:120,180,150,210,240&line=growth:3.1,3.4,3.2,3.8,4.1&title=Downloads" width="360" alt="combo example"></a> |
128
+ | `sankey` | 桑基图(流向带宽)<br><br>**<u>`labels=`+`links=A>B:30`,≤24 节点/60 链接</u>** | <a href="https://x-cmd.com/draw?type=sankey&labels=Visitors,Stars,Forks,PRs,Merged&links=Visitors>Stars:84;Stars>Forks:17;Forks>PRs:9;PRs>Merged:7&title=Contributor%20funnel"><img src="https://x-cmd.com/draw?type=sankey&labels=Visitors,Stars,Forks,PRs,Merged&links=Visitors>Stars:84;Stars>Forks:17;Forks>PRs:9;PRs>Merged:7&title=Contributor%20funnel" width="360" alt="sankey example"></a> |
129
+ | `qr` | 二维码<br><br>**<u>`d`=文本(≤1000 字符),`fg`/`bg` 配色,`title`/`unit` 标注</u>** | <a href="https://x-cmd.com/draw?type=qr&d=https://github.com/x-cmd/draw&title=scan%20me"><img src="https://x-cmd.com/draw?type=qr&d=https://github.com/x-cmd/draw&title=scan%20me" width="360" alt="qr example"></a> |
75
130
 
76
131
  **`GET /draw`**(无参数)或 `?tab=pie` — 演示页(11 图种分类、全部风格变体、URL 双形态面板)
77
132
  **`POST /draw?type=...`** — 提交 JSON/CSV body 创建永久短链
@@ -160,49 +215,6 @@ GET /draw/c/<hash> → SVG,永久 immutable 缓存
160
215
 
161
216
  每个 SVG 内嵌 `<metadata>`(转义 JSON):`{generator, template, version, spec}`,数据与参数可直接 round-trip。文字全部用 `<text>`(真文本)。
162
217
 
163
- ## 项目结构
164
-
165
- 一次请求的路径:**handler.ts(HTTP 路由)→ render/query.ts(参数→渲染核心)→ specs/(解析)→ styles/(选皮肤)→ render/(算几何出 SVG)**。渲染核心是纯函数,三个运行时共享:Cloudflare Worker(index.ts 薄壳)、Node 服务(node/server.ts)、npm/JSR 库与 CLI(lib.ts + node/cli.ts)。
166
-
167
- ```
168
- src/
169
- ├── index.ts Cloudflare Workers 入口(薄壳:边缘缓存、限流 binding、waitUntil)
170
- ├── handler.ts 共享 HTTP 层:路由、POST 短链创建、短链渲染、演示页、错误包装
171
- ├── lib.ts npm/JSR 库入口(barrel + 高层 draw() 同步 API)
172
- ├── demo.ts 演示页(图种 tab、风格变体、URL 双形态面板)
173
- ├── theme.ts 皮肤 → CSS 变量(:root + 暗色媒体查询)
174
- ├── store.ts 短链存储(GitHub repo 读写、指纹、幂等)
175
- ├── version.ts 版本号与缓存语义
176
- ├── types.ts 跨运行时结构类型(DrawEnv/Platform)
177
- │
178
- ├── specs/ 【解析层】URL 参数 → 强类型 spec(校验、截断、上限)
179
- │ ├── base.ts ChartSpec + 扁平参数/JSON 双形态解析
180
- │ ├── multi.ts 多系列(series=)解析
181
- │ └── gauge/scatter/combo/csv.ts 图种专属解析
182
- │
183
- ├── render/ 【渲染层】spec + 皮肤 → SVG 字符串(纯计算,无布局引擎)
184
- │ ├── svg.ts 公共构造:布局几何、刻度、网格、图例、标签防碰撞、文字测量
185
- │ ├── query.ts 参数→SVG 同步核心(drawHandler/短链渲染段,库与 HTTP 共用)
186
- │ ├── dispatch.ts 短链存档 → 渲染器的模板分发
187
- │ ├── pie/line/line-multi/area/… 每图种一个渲染文件(bar 拆 3、line 拆 2)
188
- │ └── qr.ts 二维码
189
- │
190
- ├── styles/ 【风格层】设计师规范 SVG 的规则化
191
- │ ├── types.ts Rules 词汇表 + 默认值(方向/圆角/图例/虚线/标注…)
192
- │ ├── pie/line/area/… 每图种变体定义(色板明暗双值 + 规则差异 + 规范画布尺寸)
193
- │ ├── common.ts 规范色板常量
194
- │ ├── handlee.ts 手绘字体 base64(star 风格)
195
- │ └── index.ts resolveSkin:图种 + ?t= + 明暗 → 皮肤
196
- │
197
- └── node/ 【Node 入口】server.ts 本地服务 · cli.ts draw CLI
198
-
199
- test/ vitest(解析 + 渲染 + 共享 HTTP 层 + 库 API)
200
- wrangler.jsonc 部署配置(路由 x-cmd.com/draw*)
201
- deno.json JSR 发布 + Deno 任务
202
- ```
203
-
204
- 加新图种 = `specs/xxx.ts` + `render/xxx.ts` + `styles/xxx.ts` 各一个文件,再在 `render/dispatch.ts` 与 `render/query.ts` 各注册一行。
205
-
206
218
  ## 自部署(一键)
207
219
 
208
220
  部署一套自己的 draw 到你的 Cloudflare 账号(免费计划即可,只需 CF 账号):
package/README.md CHANGED
@@ -2,8 +2,63 @@
2
2
 
3
3
  > English | [中文](README.cn.md)
4
4
 
5
+ [![JSR score](https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fapi.jsr.io%2Fscopes%2Fx-cmd%2Fpackages%2Fdraw&query=%24.score&label=JSR%20score&color=yellowgreen)](https://jsr.io/@x-cmd/draw/score)
6
+ [![OpenSSF Scorecard](https://api.securityscorecards.dev/projects/github.com/x-cmd/draw/badge)](https://securityscorecards.dev/viewer/?uri=github.com/x-cmd/draw)
7
+
5
8
  SVG chart generation for the AI era. One endpoint — `/draw?type=...` — with the data in the URL, machine-readable `<metadata>` embedded in every output, and SVG rendered directly by TypeScript. The style system mirrors a designer spec (13 SVGs), with multiple style variants per chart type.
6
9
 
10
+ ## Sneak peek
11
+
12
+ All the data lives in the URL — open it in a browser, drop it into an `<img>`, paste it into your repo README: the SVG renders right away.
13
+
14
+ ### Sankey — pull-request lifecycle: type → outcome → age (`type=sankey&t=pipeline`)
15
+
16
+ ```text
17
+ https://x-cmd.com/draw?type=sankey&t=pipeline&labels=feat,fix,docs,chore,merged,closed,rejected,0-1y,1-2y,2y+&links=feat>merged:38;feat>closed:12;feat>rejected:8;fix>merged:33;fix>closed:6;fix>rejected:2;docs>merged:16;docs>closed:4;chore>merged:5;chore>closed:6;chore>rejected:6;merged>0-1y:52;merged>1-2y:28;merged>2y+:12;closed>0-1y:14;closed>1-2y:9;closed>2y+:5;rejected>0-1y:9;rejected>1-2y:5;rejected>2y+:2&title=Pull%20requests%20lifecycle&unit=prs
18
+ ```
19
+
20
+ ![Sankey: PR lifecycle](https://x-cmd.com/draw?type=sankey&t=pipeline&labels=feat,fix,docs,chore,merged,closed,rejected,0-1y,1-2y,2y+&links=feat>merged:38;feat>closed:12;feat>rejected:8;fix>merged:33;fix>closed:6;fix>rejected:2;docs>merged:16;docs>closed:4;chore>merged:5;chore>closed:6;chore>rejected:6;merged>0-1y:52;merged>1-2y:28;merged>2y+:12;closed>0-1y:14;closed>1-2y:9;closed>2y+:5;rejected>0-1y:9;rejected>1-2y:5;rejected>2y+:2&title=Pull%20requests%20lifecycle&unit=prs)
21
+
22
+ ### Hbar — runtime throughput, measured (`type=hbar`; deno 7238 · node 6553 · bun 4972 ops/s, Apple Silicon)
23
+
24
+ ```text
25
+ https://x-cmd.com/draw?type=hbar&labels=deno,node,bun&values=7238,6553,4972&title=Runtime%20throughput&unit=ops%2Fs
26
+ ```
27
+
28
+ ![Hbar: runtime throughput](https://x-cmd.com/draw?type=hbar&labels=deno,node,bun&values=7238,6553,4972&title=Runtime%20throughput&unit=ops%2Fs)
29
+
30
+ ### Radar — three-way software comparison (`type=radar&t=evil`, multi-series)
31
+
32
+ ```text
33
+ https://x-cmd.com/draw?type=radar&t=evil&labels=startup,ecosystem,extensibility,memory,ease&series=vscode:60,95,90,55,80&series=neovim:95,65,85,95,35&series=zed:92,50,55,90,60&title=Editor%20comparison
34
+ ```
35
+
36
+ ![Radar: editor comparison](https://x-cmd.com/draw?type=radar&t=evil&labels=startup,ecosystem,extensibility,memory,ease&series=vscode:60,95,90,55,80&series=neovim:95,65,85,95,35&series=zed:92,50,55,90,60&title=Editor%20comparison)
37
+
38
+ ### Combo — weekly downloads vs star-growth rate (`type=combo`, dual y-axis)
39
+
40
+ ```text
41
+ https://x-cmd.com/draw?type=combo&labels=Mon,Tue,Wed,Thu,Fri,Sat,Sun&series=Downloads:120,180,150,210,240,200,260&line=Star%20growth:3.1,3.4,3.2,3.8,4.1,3.9,4.5&title=Weekly%20npm%20downloads&unit=dl
42
+ ```
43
+
44
+ ![Combo: downloads + star growth](https://x-cmd.com/draw?type=combo&labels=Mon,Tue,Wed,Thu,Fri,Sat,Sun&series=Downloads:120,180,150,210,240,200,260&line=Star%20growth:3.1,3.4,3.2,3.8,4.1,3.9,4.5&title=Weekly%20npm%20downloads&unit=dl)
45
+
46
+ ### Hbar — open/closed issues by area, butterfly (`type=hbar&t=xcmd-issue`)
47
+
48
+ ```text
49
+ https://x-cmd.com/draw?type=hbar&t=xcmd-issue&labels=cli,core,docs,ci,ui&series=open:12,8,15,4,9&series=closed:38,52,20,11,26&title=Issues%20by%20area
50
+ ```
51
+
52
+ ![Hbar: issues by area](https://x-cmd.com/draw?type=hbar&t=xcmd-issue&labels=cli,core,docs,ci,ui&series=open:12,8,15,4,9&series=closed:38,52,20,11,26&title=Issues%20by%20area)
53
+
54
+ ### Pie — language composition (`type=pie&t=market-mono`)
55
+
56
+ ```text
57
+ https://x-cmd.com/draw?type=pie&t=market-mono&title=Languages&unit=%25&labels=TypeScript,Shell,JavaScript,Rust,Other&values=68,14,9,6,3
58
+ ```
59
+
60
+ ![Pie: languages](https://x-cmd.com/draw?type=pie&t=market-mono&title=Languages&unit=%25&labels=TypeScript,Shell,JavaScript,Rust,Other&values=68,14,9,6,3)
61
+
7
62
  ## Three ways to use it (one render core)
8
63
 
9
64
  **Hosted service** (zero install): just build a URL — `https://x-cmd.com/draw?type=pie&labels=A,B&values=3,2`
@@ -60,19 +115,19 @@ deno task serve # local serve
60
115
 
61
116
  **`GET /draw?type=<pie|bar|hbar|line|area|radar|gauge|scatter|combo|sankey|qr>`** — render a chart
62
117
 
63
- | type | chart | limits |
118
+ | type | chart | example |
64
119
  |---|---|---|
65
- | `pie` | donut; `donut=0` for a solid pie | ≤100 categories (>9 auto-merge into Other) |
66
- | `bar` | grouped columns; multi-series with `stack=1` for stacked | ≤30 groups |
67
- | `hbar` | horizontal bars (rankings; labels left, values right) | ≤30 bars, single series (some styles take two) |
68
- | `line` | smooth line + gradient area / multi-line | ≤60 points |
69
- | `area` | area / multi-series area (gradient fill) | ≤60 points |
70
- | `radar` | radar chart | 3–12 axes |
71
- | `gauge` | gauge (240° arc + center value) | `value`+`max` (default 100), value ≤ max; multi-ring ≤8 |
72
- | `scatter` | scatter (two numeric axes, negatives supported; no value labels by default) | `x=&y=`, ≤200 points |
73
- | `combo` | bars (`series=`) + line (`line=`) in one chart; `stack=1` to stack the bars | ≤30 groups, ≤6 series total |
74
- | `sankey` | flow diagram with weighted bands | `labels=`+`links=A>B:30`, ≤24 nodes/60 links |
75
- | `qr` | QR code | `d`=text (≤1000 chars), `fg`/`bg` colors, `title`/`unit` captions |
120
+ | `pie` | donut; `donut=0` for a solid pie<br><br>**<u>≤100 categories (>9 auto-merge into Other)</u>** | <a href="https://x-cmd.com/draw?type=pie&labels=TS,Py,Go,Rust&values=4821,2312,980,645&title=Stars%20by%20language"><img src="https://x-cmd.com/draw?type=pie&labels=TS,Py,Go,Rust&values=4821,2312,980,645&title=Stars%20by%20language" width="360" alt="pie example"></a> |
121
+ | `bar` | grouped columns; multi-series with `stack=1` for stacked<br><br>**<u>≤30 groups</u>** | <a href="https://x-cmd.com/draw?type=bar&labels=Mon,Tue,Wed&series=dev:12,18,9&series=ci:8,11,6"><img src="https://x-cmd.com/draw?type=bar&labels=Mon,Tue,Wed&series=dev:12,18,9&series=ci:8,11,6" width="360" alt="bar example"></a> |
122
+ | `hbar` | horizontal bars (rankings; labels left, values right)<br><br>**<u>≤30 bars, single series (some styles take two)</u>** | <a href="https://x-cmd.com/draw?type=hbar&labels=cli,core,docs,ui&values=42,31,18,9&title=Commits%20by%20area"><img src="https://x-cmd.com/draw?type=hbar&labels=cli,core,docs,ui&values=42,31,18,9&title=Commits%20by%20area" width="360" alt="hbar example"></a> |
123
+ | `line` | smooth line + gradient area / multi-line<br><br>**<u>≤60 points</u>** | <a href="https://x-cmd.com/draw?type=line&labels=Jan,Feb,Mar,Apr,May,Jun&values=12,19,15,25,22,30&title=Stars"><img src="https://x-cmd.com/draw?type=line&labels=Jan,Feb,Mar,Apr,May,Jun&values=12,19,15,25,22,30&title=Stars" width="360" alt="line example"></a> |
124
+ | `area` | area / multi-series area (gradient fill)<br><br>**<u>≤60 points</u>** | <a href="https://x-cmd.com/draw?type=area&labels=Q1,Q2,Q3,Q4&values=8,14,23,37&title=Downloads"><img src="https://x-cmd.com/draw?type=area&labels=Q1,Q2,Q3,Q4&values=8,14,23,37&title=Downloads" width="360" alt="area example"></a> |
125
+ | `radar` | radar chart<br><br>**<u>3–12 axes</u>** | <a href="https://x-cmd.com/draw?type=radar&t=evil&labels=perf,docs,tests,dx&series=v1:7,5,8,6&series=v2:8,8,9,8"><img src="https://x-cmd.com/draw?type=radar&t=evil&labels=perf,docs,tests,dx&series=v1:7,5,8,6&series=v2:8,8,9,8" width="360" alt="radar example"></a> |
126
+ | `gauge` | gauge (240° arc + center value)<br><br>**<u>`value`+`max` (default 100), value ≤ max; multi-ring ≤8</u>** | <a href="https://x-cmd.com/draw?type=gauge&title=CI%20pass%20rate&value=87&max=100"><img src="https://x-cmd.com/draw?type=gauge&title=CI%20pass%20rate&value=87&max=100" width="360" alt="gauge example"></a> |
127
+ | `scatter` | scatter (two numeric axes, negatives supported; no value labels by default)<br><br>**<u>`x=&y=`, ≤200 points</u>** | <a href="https://x-cmd.com/draw?type=scatter&x=1,2,3,4,5&y=4,5,3,6,5&title=Latency"><img src="https://x-cmd.com/draw?type=scatter&x=1,2,3,4,5&y=4,5,3,6,5&title=Latency" width="360" alt="scatter example"></a> |
128
+ | `combo` | bars (`series=`) + line (`line=`) in one chart; `stack=1` to stack the bars<br><br>**<u>≤30 groups, ≤6 series total</u>** | <a href="https://x-cmd.com/draw?type=combo&labels=Mon,Tue,Wed,Thu,Fri&series=dl:120,180,150,210,240&line=growth:3.1,3.4,3.2,3.8,4.1&title=Downloads"><img src="https://x-cmd.com/draw?type=combo&labels=Mon,Tue,Wed,Thu,Fri&series=dl:120,180,150,210,240&line=growth:3.1,3.4,3.2,3.8,4.1&title=Downloads" width="360" alt="combo example"></a> |
129
+ | `sankey` | flow diagram with weighted bands<br><br>**<u>`labels=`+`links=A>B:30`, ≤24 nodes/60 links</u>** | <a href="https://x-cmd.com/draw?type=sankey&labels=Visitors,Stars,Forks,PRs,Merged&links=Visitors>Stars:84;Stars>Forks:17;Forks>PRs:9;PRs>Merged:7&title=Contributor%20funnel"><img src="https://x-cmd.com/draw?type=sankey&labels=Visitors,Stars,Forks,PRs,Merged&links=Visitors>Stars:84;Stars>Forks:17;Forks>PRs:9;PRs>Merged:7&title=Contributor%20funnel" width="360" alt="sankey example"></a> |
130
+ | `qr` | QR code<br><br>**<u>`d`=text (≤1000 chars), `fg`/`bg` colors, `title`/`unit` captions</u>** | <a href="https://x-cmd.com/draw?type=qr&d=https://github.com/x-cmd/draw&title=scan%20me"><img src="https://x-cmd.com/draw?type=qr&d=https://github.com/x-cmd/draw&title=scan%20me" width="360" alt="qr example"></a> |
76
131
 
77
132
  **`GET /draw`** (no params) or `?tab=pie` — the demo page (11 chart types, all style variants, dual URL forms)
78
133
  **`POST /draw?type=...`** — submit a JSON/CSV body to create a permanent short link
@@ -161,49 +216,6 @@ GET /draw/c/<hash> → SVG, cached immutable forever
161
216
 
162
217
  Every SVG embeds `<metadata>` (escaped JSON): `{generator, template, version, spec}` — data and params round-trip directly. All text is real `<text>` elements.
163
218
 
164
- ## Project structure
165
-
166
- A request flows **handler.ts (HTTP routing) → render/query.ts (params → render core) → specs/ (parse) → styles/ (pick skin) → render/ (geometry → SVG)**. The render core is pure functions shared by three runtimes: the Cloudflare Worker (index.ts thin shell), the Node server (node/server.ts), and the npm/JSR library + CLI (lib.ts + node/cli.ts).
167
-
168
- ```
169
- src/
170
- ├── index.ts Cloudflare Workers entry (thin shell: edge cache, rate-limit binding, waitUntil)
171
- ├── handler.ts shared HTTP layer: routing, POST short-link creation, short-link render, demo page, error wrapper
172
- ├── lib.ts npm/JSR library entry (barrel + high-level synchronous draw())
173
- ├── demo.ts demo page (type tabs, style variants, dual URL forms)
174
- ├── theme.ts skin → CSS variables (:root + dark media query)
175
- ├── store.ts short-link storage (GitHub repo read/write, fingerprint, idempotency)
176
- ├── version.ts version numbers and cache semantics
177
- ├── types.ts cross-runtime structural types (DrawEnv/Platform)
178
- │
179
- ├── specs/ [parse] URL params → strongly-typed spec (validation, clipping, limits)
180
- │ ├── base.ts ChartSpec + both flat-params and JSON forms
181
- │ ├── multi.ts multi-series (series=) parsing
182
- │ └── gauge/scatter/combo/csv.ts per-type parsers
183
- │
184
- ├── render/ [render] spec + skin → SVG string (pure computation, no layout engine)
185
- │ ├── svg.ts shared helpers: layout geometry, scales, grid, legend, label collision, text measurement
186
- │ ├── query.ts params→SVG synchronous core (GET dispatch + short-link segment; shared by lib and HTTP)
187
- │ ├── dispatch.ts stored chart → renderer template dispatch
188
- │ ├── pie/line/line-multi/area/… one file per chart type (bar ×3, line ×2)
189
- │ └── qr.ts QR codes
190
- │
191
- ├── styles/ [style] designer-spec SVGs turned into rules
192
- │ ├── types.ts Rules vocabulary + defaults (orientation/radius/legend/dash/labels…)
193
- │ ├── pie/line/area/… per-type variants (light+dark palettes + rule deltas + spec canvas size)
194
- │ ├── common.ts spec palette constants
195
- │ ├── handlee.ts hand-drawn font, base64 (star style)
196
- │ └── index.ts resolveSkin: type + ?t= + scheme → skin
197
- │
198
- └── node/ [Node] server.ts local server · cli.ts draw CLI
199
-
200
- test/ vitest (parsing + renderers + shared HTTP layer + library API)
201
- wrangler.jsonc deploy config (route x-cmd.com/draw*)
202
- deno.json JSR publishing + Deno tasks
203
- ```
204
-
205
- Adding a chart type = one file each in `specs/xxx.ts` + `render/xxx.ts` + `styles/xxx.ts`, plus one registration line each in `render/dispatch.ts` and `render/query.ts`.
206
-
207
219
  ## One-shot self-deploy
208
220
 
209
221
  Deploy your own draw to your Cloudflare account (free tier works; you just need a CF account):
@@ -0,0 +1,94 @@
1
+ Copyright (c) 2011, Joe Prince, Vissol Ltd. (http://www.vissol.co.uk/mavenpro/)
2
+ with Reserved Font Name "Handlee".
3
+
4
+ This Font Software is licensed under the SIL Open Font License, Version 1.1.
5
+ This license is copied below, and is also available with a FAQ at:
6
+ http://scripts.sil.org/OFL
7
+
8
+
9
+ -----------------------------------------------------------
10
+ SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
11
+ -----------------------------------------------------------
12
+
13
+ PREAMBLE
14
+ The goals of the Open Font License (OFL) are to stimulate worldwide
15
+ development of collaborative font projects, to support the font creation
16
+ efforts of academic and linguistic communities, and to provide a free and
17
+ open framework in which fonts may be shared and improved in partnership
18
+ with others.
19
+
20
+ The OFL allows the licensed fonts to be used, studied, modified and
21
+ redistributed freely as long as they are not sold by themselves. The
22
+ fonts, including any derivative works, can be bundled, embedded,
23
+ redistributed and/or sold with any software provided that any reserved
24
+ names are not used by derivative works. The fonts and derivatives,
25
+ however, cannot be released under any other type of license. The
26
+ requirement for fonts to remain under this license does not apply
27
+ to any document created using the fonts or their derivatives.
28
+
29
+ DEFINITIONS
30
+ "Font Software" refers to the set of files released by the Copyright
31
+ Holder(s) under this license and clearly marked as such. This may
32
+ include source files, build scripts and documentation.
33
+
34
+ "Reserved Font Name" refers to any names specified as such after the
35
+ copyright statement(s).
36
+
37
+ "Original Version" refers to the collection of Font Software components as
38
+ distributed by the Copyright Holder(s).
39
+
40
+ "Modified Version" refers to any derivative made by adding to, deleting,
41
+ or substituting -- in part or in whole -- any of the components of the
42
+ Original Version, by changing formats or by porting the Font Software to a
43
+ new environment.
44
+
45
+ "Author" refers to any designer, engineer, programmer, technical
46
+ writer or other person who contributed to the Font Software.
47
+
48
+ PERMISSION & CONDITIONS
49
+ Permission is hereby granted, free of charge, to any person obtaining
50
+ a copy of the Font Software, to use, study, copy, merge, embed, modify,
51
+ redistribute, and sell modified and unmodified copies of the Font
52
+ Software, subject to the following conditions:
53
+
54
+ 1) Neither the Font Software nor any of its individual components,
55
+ in Original or Modified Versions, may be sold by itself.
56
+
57
+ 2) Original or Modified Versions of the Font Software may be bundled,
58
+ redistributed and/or sold with any software, provided that each copy
59
+ contains the above copyright notice and this license. These can be
60
+ included either as stand-alone text files, human-readable headers or
61
+ in the appropriate machine-readable metadata fields within text or
62
+ binary files as long as those fields can be easily viewed by the user.
63
+
64
+ 3) No Modified Version of the Font Software may use the Reserved Font
65
+ Name(s) unless explicit written permission is granted by the corresponding
66
+ Copyright Holder. This restriction only applies to the primary font name as
67
+ presented to the users.
68
+
69
+ 4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
70
+ Software shall not be used to promote, endorse or advertise any
71
+ Modified Version, except to acknowledge the contribution(s) of the
72
+ Copyright Holder(s) and the Author(s) or with their explicit written
73
+ permission.
74
+
75
+ 5) The Font Software, modified or unmodified, in part or in whole,
76
+ must be distributed entirely under this license, and must not be
77
+ distributed under any other license. The requirement for fonts to
78
+ remain under this license does not apply to any document created
79
+ using the Font Software.
80
+
81
+ TERMINATION
82
+ This license becomes null and void if any of the above conditions are
83
+ not met.
84
+
85
+ DISCLAIMER
86
+ THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
87
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
88
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
89
+ OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
90
+ COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
91
+ INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
92
+ DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
93
+ FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
94
+ OTHER DEALINGS IN THE FONT SOFTWARE.
@@ -0,0 +1,92 @@
1
+ Copyright (c) 2016 The Inter Project Authors (https://github.com/rsms/inter)
2
+
3
+ This Font Software is licensed under the SIL Open Font License, Version 1.1.
4
+ This license is copied below, and is also available with a FAQ at:
5
+ http://scripts.sil.org/OFL
6
+
7
+ -----------------------------------------------------------
8
+ SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
9
+ -----------------------------------------------------------
10
+
11
+ PREAMBLE
12
+ The goals of the Open Font License (OFL) are to stimulate worldwide
13
+ development of collaborative font projects, to support the font creation
14
+ efforts of academic and linguistic communities, and to provide a free and
15
+ open framework in which fonts may be shared and improved in partnership
16
+ with others.
17
+
18
+ The OFL allows the licensed fonts to be used, studied, modified and
19
+ redistributed freely as long as they are not sold by themselves. The
20
+ fonts, including any derivative works, can be bundled, embedded,
21
+ redistributed and/or sold with any software provided that any reserved
22
+ names are not used by derivative works. The fonts and derivatives,
23
+ however, cannot be released under any other type of license. The
24
+ requirement for fonts to remain under this license does not apply
25
+ to any document created using the fonts or their derivatives.
26
+
27
+ DEFINITIONS
28
+ "Font Software" refers to the set of files released by the Copyright
29
+ Holder(s) under this license and clearly marked as such. This may
30
+ include source files, build scripts and documentation.
31
+
32
+ "Reserved Font Name" refers to any names specified as such after the
33
+ copyright statement(s).
34
+
35
+ "Original Version" refers to the collection of Font Software components as
36
+ distributed by the Copyright Holder(s).
37
+
38
+ "Modified Version" refers to any derivative made by adding to, deleting,
39
+ or substituting -- in part or in whole -- any of the components of the
40
+ Original Version, by changing formats or by porting the Font Software to a
41
+ new environment.
42
+
43
+ "Author" refers to any designer, engineer, programmer, technical
44
+ writer or other person who contributed to the Font Software.
45
+
46
+ PERMISSION AND CONDITIONS
47
+ Permission is hereby granted, free of charge, to any person obtaining
48
+ a copy of the Font Software, to use, study, copy, merge, embed, modify,
49
+ redistribute, and sell modified and unmodified copies of the Font
50
+ Software, subject to the following conditions:
51
+
52
+ 1) Neither the Font Software nor any of its individual components,
53
+ in Original or Modified Versions, may be sold by itself.
54
+
55
+ 2) Original or Modified Versions of the Font Software may be bundled,
56
+ redistributed and/or sold with any software, provided that each copy
57
+ contains the above copyright notice and this license. These can be
58
+ included either as stand-alone text files, human-readable headers or
59
+ in the appropriate machine-readable metadata fields within text or
60
+ binary files as long as those fields can be easily viewed by the user.
61
+
62
+ 3) No Modified Version of the Font Software may use the Reserved Font
63
+ Name(s) unless explicit written permission is granted by the corresponding
64
+ Copyright Holder. This restriction only applies to the primary font name as
65
+ presented to the users.
66
+
67
+ 4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
68
+ Software shall not be used to promote, endorse or advertise any
69
+ Modified Version, except to acknowledge the contribution(s) of the
70
+ Copyright Holder(s) and the Author(s) or with their explicit written
71
+ permission.
72
+
73
+ 5) The Font Software, modified or unmodified, in part or in whole,
74
+ must be distributed entirely under this license, and must not be
75
+ distributed under any other license. The requirement for fonts to
76
+ remain under this license does not apply to any document created
77
+ using the Font Software.
78
+
79
+ TERMINATION
80
+ This license becomes null and void if any of the above conditions are
81
+ not met.
82
+
83
+ DISCLAIMER
84
+ THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
85
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
86
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
87
+ OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
88
+ COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
89
+ INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
90
+ DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
91
+ FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
92
+ OTHER DEALINGS IN THE FONT SOFTWARE.
package/dist/theme.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- export declare const FONT = "'DrawInter',Inter,ui-sans-serif,-apple-system,BlinkMacSystemFont,'Segoe UI','PingFang SC','Hiragino Sans GB','Microsoft YaHei',sans-serif";
1
+ export declare const FONT = "'DrawInter',Inter,ui-sans-serif,-apple-system,BlinkMacSystemFont,'Segoe UI','PingFang SC','Hiragino Sans GB','Microsoft YaHei','Hiragino Sans','Yu Gothic','Meiryo','Noto Sans JP','Apple SD Gothic Neo','Malgun Gothic','Noto Sans KR',sans-serif";
2
2
  export declare const TAB = "font-variant-numeric:tabular-nums";
3
3
  export declare function card(w: number, h: number, plain?: boolean): string;
package/dist/theme.js CHANGED
@@ -1,7 +1,9 @@
1
1
  // 公共字体与画布。字体栈与设计规范一致(Inter 系统栈;CJK 回退)。
2
2
  // DrawInter = 每张 SVG 内嵌的 Inter 图表子集(same 源于 styles/inter.ts),
3
3
  // 拉丁/数字/符号用它(跨平台像素一致),子集外字符(中文等)沿栈回退系统字体。
4
- export const FONT = "'DrawInter',Inter,ui-sans-serif,-apple-system,BlinkMacSystemFont,'Segoe UI','PingFang SC','Hiragino Sans GB','Microsoft YaHei',sans-serif";
4
+ // CJK 顺序注意: 汉字统一码下静态栈只能给一族字形(此处简中优先,与既有行为一致);
5
+ // 日文假名/谚文由后续 JP/KR 族接住。按文字运行选栈(检测假名/谚文切日/韩栈)见 issue #2。
6
+ export const FONT = "'DrawInter',Inter,ui-sans-serif,-apple-system,BlinkMacSystemFont,'Segoe UI','PingFang SC','Hiragino Sans GB','Microsoft YaHei','Hiragino Sans','Yu Gothic','Meiryo','Noto Sans JP','Apple SD Gothic Neo','Malgun Gothic','Noto Sans KR',sans-serif";
5
7
  export const TAB = 'font-variant-numeric:tabular-nums';
6
8
  // 卡片:canvas='card' 时白底 1px 边框 12px 圆角;plain(规范约定)透明由页面承接
7
9
  export function card(w, h, plain = false) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@x-cmd/draw",
3
- "version": "0.2.1",
3
+ "version": "0.2.3",
4
4
  "description": "SVG chart rendering as a service, a library, and a CLI — pie/bar/hbar/line/area/radar/gauge/scatter/combo/sankey/qr, same params everywhere",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",
@@ -26,7 +26,7 @@
26
26
  "node": ">=18.19"
27
27
  },
28
28
  "scripts": {
29
- "build": "tsc -p tsconfig.build.json",
29
+ "build": "tsc -p tsconfig.build.json && node scripts/copy-ofl.mjs",
30
30
  "check": "tsc -p tsconfig.json --noEmit && tsc -p tsconfig.node.json --noEmit && tsc -p tsconfig.build.json",
31
31
  "serve": "tsx src/node/server.ts",
32
32
  "start": "npm run serve",