@x-cmd/draw 0.0.0-stage → 0.2.0
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/LICENSE +228 -0
- package/README.cn.md +235 -0
- package/README.md +235 -2
- package/dist/lib.d.ts +25 -0
- package/dist/lib.js +50 -0
- package/dist/node/cli.d.ts +2 -0
- package/dist/node/cli.js +79 -0
- package/dist/render/area.d.ts +8 -0
- package/dist/render/area.js +414 -0
- package/dist/render/bar-grid.d.ts +3 -0
- package/dist/render/bar-grid.js +52 -0
- package/dist/render/bar-grouped.d.ts +3 -0
- package/dist/render/bar-grouped.js +131 -0
- package/dist/render/bar-stacked.d.ts +3 -0
- package/dist/render/bar-stacked.js +142 -0
- package/dist/render/bar.d.ts +3 -0
- package/dist/render/bar.js +74 -0
- package/dist/render/combo.d.ts +3 -0
- package/dist/render/combo.js +256 -0
- package/dist/render/dispatch.d.ts +3 -0
- package/dist/render/dispatch.js +69 -0
- package/dist/render/gauge.d.ts +3 -0
- package/dist/render/gauge.js +216 -0
- package/dist/render/hbar-spec.d.ts +7 -0
- package/dist/render/hbar-spec.js +265 -0
- package/dist/render/hbar.d.ts +3 -0
- package/dist/render/hbar.js +55 -0
- package/dist/render/line-multi.d.ts +3 -0
- package/dist/render/line-multi.js +89 -0
- package/dist/render/line.d.ts +11 -0
- package/dist/render/line.js +123 -0
- package/dist/render/measure.d.ts +60 -0
- package/dist/render/measure.js +75 -0
- package/dist/render/pie.d.ts +5 -0
- package/dist/render/pie.js +439 -0
- package/dist/render/qr.d.ts +8 -0
- package/dist/render/qr.js +52 -0
- package/dist/render/query.d.ts +14 -0
- package/dist/render/query.js +220 -0
- package/dist/render/radar.d.ts +5 -0
- package/dist/render/radar.js +221 -0
- package/dist/render/sankey.d.ts +3 -0
- package/dist/render/sankey.js +280 -0
- package/dist/render/scatter.d.ts +3 -0
- package/dist/render/scatter.js +98 -0
- package/dist/render/svg.d.ts +93 -0
- package/dist/render/svg.js +471 -0
- package/dist/specs/base.d.ts +34 -0
- package/dist/specs/base.js +159 -0
- package/dist/specs/combo.d.ts +15 -0
- package/dist/specs/combo.js +135 -0
- package/dist/specs/csv.d.ts +1 -0
- package/dist/specs/csv.js +40 -0
- package/dist/specs/gauge.d.ts +15 -0
- package/dist/specs/gauge.js +108 -0
- package/dist/specs/index.d.ts +8 -0
- package/dist/specs/index.js +9 -0
- package/dist/specs/input.d.ts +11 -0
- package/dist/specs/input.js +33 -0
- package/dist/specs/multi.d.ts +12 -0
- package/dist/specs/multi.js +112 -0
- package/dist/specs/sankey.d.ts +13 -0
- package/dist/specs/sankey.js +112 -0
- package/dist/specs/scatter.d.ts +20 -0
- package/dist/specs/scatter.js +121 -0
- package/dist/store.d.ts +15 -0
- package/dist/store.js +121 -0
- package/dist/styles/area.d.ts +2 -0
- package/dist/styles/area.js +106 -0
- package/dist/styles/bar.d.ts +2 -0
- package/dist/styles/bar.js +52 -0
- package/dist/styles/combo.d.ts +2 -0
- package/dist/styles/combo.js +37 -0
- package/dist/styles/common.d.ts +34 -0
- package/dist/styles/common.js +259 -0
- package/dist/styles/gauge.d.ts +2 -0
- package/dist/styles/gauge.js +51 -0
- package/dist/styles/handlee.d.ts +1 -0
- package/dist/styles/handlee.js +2 -0
- package/dist/styles/hbar.d.ts +2 -0
- package/dist/styles/hbar.js +66 -0
- package/dist/styles/index.d.ts +7 -0
- package/dist/styles/index.js +79 -0
- package/dist/styles/inter.d.ts +3 -0
- package/dist/styles/inter.js +10 -0
- package/dist/styles/line.d.ts +2 -0
- package/dist/styles/line.js +97 -0
- package/dist/styles/pie.d.ts +2 -0
- package/dist/styles/pie.js +163 -0
- package/dist/styles/qr.d.ts +2 -0
- package/dist/styles/qr.js +12 -0
- package/dist/styles/radar.d.ts +2 -0
- package/dist/styles/radar.js +50 -0
- package/dist/styles/sankey.d.ts +2 -0
- package/dist/styles/sankey.js +29 -0
- package/dist/styles/scatter.d.ts +2 -0
- package/dist/styles/scatter.js +21 -0
- package/dist/styles/types.d.ts +105 -0
- package/dist/styles/types.js +70 -0
- package/dist/theme.d.ts +3 -0
- package/dist/theme.js +11 -0
- package/dist/types.d.ts +17 -0
- package/dist/types.js +1 -0
- package/dist/version.d.ts +6 -0
- package/dist/version.js +16 -0
- package/package.json +53 -4
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
// 散点图(scatter):x,y 点对;单系列扁平 x=/y=(或 JSON points),多系列重复 x=/y= 参数(或 JSON series)。
|
|
2
|
+
import { ApiError, LIMITS, clip } from './base.js';
|
|
3
|
+
const SCATTER_EXAMPLE = 'x=1,2,3&y=4,5,6';
|
|
4
|
+
export function scatterSpecFromParams(params) {
|
|
5
|
+
const d = params.get('d');
|
|
6
|
+
if (d !== null && d !== '')
|
|
7
|
+
return d;
|
|
8
|
+
if (!params.has('x') && !params.has('y'))
|
|
9
|
+
return null;
|
|
10
|
+
// 重复 x=/y= 参数 = 多系列(第 i 个 x 对应第 i 个 y)
|
|
11
|
+
const xsAll = params.getAll('x');
|
|
12
|
+
const ysAll = params.getAll('y');
|
|
13
|
+
if (xsAll.length > 1 || ysAll.length > 1) {
|
|
14
|
+
if (xsAll.length !== ysAll.length) {
|
|
15
|
+
throw new ApiError(400, `got ${xsAll.length} "x" series but ${ysAll.length} "y" series — they must match`);
|
|
16
|
+
}
|
|
17
|
+
const series = xsAll.map((xv, i) => ({ name: `S${i + 1}`, points: pairs(xv, ysAll[i]) }));
|
|
18
|
+
return JSON.stringify({
|
|
19
|
+
series,
|
|
20
|
+
...(params.get('title') ? { title: params.get('title') } : {}),
|
|
21
|
+
...(params.get('unit') ? { unit: params.get('unit') } : {}),
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
const xs = (xsAll[0] ?? '').split(',').filter(Boolean);
|
|
25
|
+
const ys = (ysAll[0] ?? '').split(',').filter(Boolean);
|
|
26
|
+
if (xs.length === 0 || ys.length === 0) {
|
|
27
|
+
throw new ApiError(400, `both "x" and "y" are required. Example: ?type=scatter&${SCATTER_EXAMPLE}`);
|
|
28
|
+
}
|
|
29
|
+
if (xs.length !== ys.length) {
|
|
30
|
+
throw new ApiError(400, `got ${xs.length} x values but ${ys.length} y values — they must match`);
|
|
31
|
+
}
|
|
32
|
+
return JSON.stringify({
|
|
33
|
+
points: xs.map((x, i) => [Number(x), Number(ys[i])]),
|
|
34
|
+
...(params.get('title') ? { title: params.get('title') } : {}),
|
|
35
|
+
...(params.get('unit') ? { unit: params.get('unit') } : {}),
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
function pairs(xRaw, yRaw) {
|
|
39
|
+
const xs = xRaw.split(',').filter(Boolean);
|
|
40
|
+
const ys = yRaw.split(',').filter(Boolean);
|
|
41
|
+
if (xs.length !== ys.length) {
|
|
42
|
+
throw new ApiError(400, `x has ${xs.length} values but y has ${ys.length} — they must match`);
|
|
43
|
+
}
|
|
44
|
+
return xs.map((x, i) => {
|
|
45
|
+
const nx = Number(x);
|
|
46
|
+
const ny = Number(ys[i]);
|
|
47
|
+
if (!Number.isFinite(nx) || !Number.isFinite(ny))
|
|
48
|
+
throw new ApiError(400, `points must be numbers, got ${JSON.stringify(x)}/${JSON.stringify(ys[i])}`);
|
|
49
|
+
return { x: nx, y: ny };
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
function parsePoints(rawPoints, at) {
|
|
53
|
+
if (rawPoints.length > LIMITS.maxScatter) {
|
|
54
|
+
throw new ApiError(400, `${at} has ${rawPoints.length} entries; scatter supports at most ${LIMITS.maxScatter} per series`);
|
|
55
|
+
}
|
|
56
|
+
return rawPoints.map((p, i) => {
|
|
57
|
+
let x;
|
|
58
|
+
let y;
|
|
59
|
+
if (Array.isArray(p)) {
|
|
60
|
+
[x, y] = p;
|
|
61
|
+
}
|
|
62
|
+
else if (typeof p === 'object' && p !== null) {
|
|
63
|
+
x = p.x;
|
|
64
|
+
y = p.y;
|
|
65
|
+
}
|
|
66
|
+
if (typeof x !== 'number' || !Number.isFinite(x) || typeof y !== 'number' || !Number.isFinite(y)) {
|
|
67
|
+
throw new ApiError(400, `${at}[${i}] must be [x,y] numbers, got: ${JSON.stringify(p)}`);
|
|
68
|
+
}
|
|
69
|
+
return { x, y };
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
export function parseScatterSpec(raw) {
|
|
73
|
+
if (raw === null || raw === '') {
|
|
74
|
+
throw new ApiError(400, `Missing data. Use ?type=scatter&${SCATTER_EXAMPLE} — or ?d= with {"points":[[1,4],[2,5]]}`);
|
|
75
|
+
}
|
|
76
|
+
let obj;
|
|
77
|
+
try {
|
|
78
|
+
obj = JSON.parse(raw);
|
|
79
|
+
}
|
|
80
|
+
catch {
|
|
81
|
+
throw new ApiError(400, `"d" is not valid JSON. Example: {"points":[[1,4],[2,5]]}`);
|
|
82
|
+
}
|
|
83
|
+
const o = obj;
|
|
84
|
+
let spec;
|
|
85
|
+
if (Array.isArray(o.series)) {
|
|
86
|
+
if (o.series.length === 0)
|
|
87
|
+
throw new ApiError(400, `"series" must be a non-empty array like [{"name":"A","points":[[1,4]]}]`);
|
|
88
|
+
if (o.series.length > LIMITS.maxSeries)
|
|
89
|
+
throw new ApiError(400, `at most ${LIMITS.maxSeries} series, got ${o.series.length}`);
|
|
90
|
+
spec = {
|
|
91
|
+
series: o.series.map((it, i) => {
|
|
92
|
+
if (typeof it !== 'object' || it === null)
|
|
93
|
+
throw new ApiError(400, `series[${i}] must be an object with "name" and "points"`);
|
|
94
|
+
const s = it;
|
|
95
|
+
if (typeof s.name !== 'string' || s.name === '')
|
|
96
|
+
throw new ApiError(400, `series[${i}].name must be a non-empty string`);
|
|
97
|
+
if (!Array.isArray(s.points))
|
|
98
|
+
throw new ApiError(400, `series[${i}].points must be a non-empty array like [[1,4],[2,5]]`);
|
|
99
|
+
return { name: clip(s.name, LIMITS.seriesName), points: parsePoints(s.points, `series[${i}].points`) };
|
|
100
|
+
}),
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
else {
|
|
104
|
+
const rawPoints = Array.isArray(o.points) ? o.points : Array.isArray(o.data) ? o.data : null;
|
|
105
|
+
if (!rawPoints || rawPoints.length === 0) {
|
|
106
|
+
throw new ApiError(400, `"points" must be a non-empty array like [[1,4],[2,5]] or [{"x":1,"y":4}]`);
|
|
107
|
+
}
|
|
108
|
+
spec = { points: parsePoints(rawPoints, 'points') };
|
|
109
|
+
}
|
|
110
|
+
if (o.title !== undefined) {
|
|
111
|
+
if (typeof o.title !== 'string')
|
|
112
|
+
throw new ApiError(400, `"title" must be a string`);
|
|
113
|
+
spec.title = clip(o.title, LIMITS.title);
|
|
114
|
+
}
|
|
115
|
+
if (o.unit !== undefined) {
|
|
116
|
+
if (typeof o.unit !== 'string')
|
|
117
|
+
throw new ApiError(400, `"unit" must be a string`);
|
|
118
|
+
spec.unit = clip(o.unit, LIMITS.unit);
|
|
119
|
+
}
|
|
120
|
+
return spec;
|
|
121
|
+
}
|
package/dist/store.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { DrawEnv } from './types.js';
|
|
2
|
+
export declare const CHART_TEMPLATES: readonly ["pie", "bar", "hbar", "line", "area", "radar", "gauge", "scatter", "combo", "sankey", "qr"];
|
|
3
|
+
export type ChartTemplate = (typeof CHART_TEMPLATES)[number];
|
|
4
|
+
export interface StoredChart {
|
|
5
|
+
template: ChartTemplate;
|
|
6
|
+
theme: string;
|
|
7
|
+
stack?: boolean;
|
|
8
|
+
spec: unknown;
|
|
9
|
+
}
|
|
10
|
+
export declare function assertHash(hash: string): void;
|
|
11
|
+
export declare function canonicalJson(v: unknown): string;
|
|
12
|
+
export declare function fingerprint(doc: StoredChart): Promise<string>;
|
|
13
|
+
export declare function putChart(env: DrawEnv, hash: string, doc: StoredChart): Promise<void>;
|
|
14
|
+
export declare function getChart(env: DrawEnv, hash: string): Promise<StoredChart>;
|
|
15
|
+
export declare function readBody(request: Request): Promise<string>;
|
package/dist/store.js
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
// 短链接存储层:图表 JSON 存在 GitHub 公开仓(charts/<指纹>.json),内容寻址、永不过期。
|
|
2
|
+
// 读取走 raw(免 token);写入需 GITHUB_TOKEN(secret,fine-grained PAT 仅授本仓 Contents 写)。
|
|
3
|
+
// 可见性:公开仓任何人都可浏览目录,请勿存放敏感数据(私有方案规划中,将收费提供)。
|
|
4
|
+
import { ApiError } from './specs/index.js';
|
|
5
|
+
export const CHART_TEMPLATES = ['pie', 'bar', 'hbar', 'line', 'area', 'radar', 'gauge', 'scatter', 'combo', 'sankey', 'qr'];
|
|
6
|
+
const HASH_RE = /^[0-9a-f]{16}$/;
|
|
7
|
+
const MAX_BODY = 64 * 1024;
|
|
8
|
+
export function assertHash(hash) {
|
|
9
|
+
if (!HASH_RE.test(hash)) {
|
|
10
|
+
throw new ApiError(400, `short-link id must be 16 hex characters, got: ${JSON.stringify(hash)}`);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
// 规范化 JSON(递归排序 key),让"相同数据"得到相同指纹
|
|
14
|
+
export function canonicalJson(v) {
|
|
15
|
+
const walk = (x) => {
|
|
16
|
+
if (Array.isArray(x))
|
|
17
|
+
return x.map(walk);
|
|
18
|
+
if (x !== null && typeof x === 'object') {
|
|
19
|
+
const o = {};
|
|
20
|
+
for (const k of Object.keys(x).sort()) {
|
|
21
|
+
o[k] = walk(x[k]);
|
|
22
|
+
}
|
|
23
|
+
return o;
|
|
24
|
+
}
|
|
25
|
+
return x;
|
|
26
|
+
};
|
|
27
|
+
return JSON.stringify(walk(v));
|
|
28
|
+
}
|
|
29
|
+
export async function fingerprint(doc) {
|
|
30
|
+
const data = new TextEncoder().encode(canonicalJson(doc));
|
|
31
|
+
const digest = await crypto.subtle.digest('SHA-256', data);
|
|
32
|
+
return [...new Uint8Array(digest)].slice(0, 8).map((b) => b.toString(16).padStart(2, '0')).join('');
|
|
33
|
+
}
|
|
34
|
+
function base64(s) {
|
|
35
|
+
const bytes = new TextEncoder().encode(s);
|
|
36
|
+
let bin = '';
|
|
37
|
+
for (const b of bytes)
|
|
38
|
+
bin += String.fromCharCode(b);
|
|
39
|
+
return btoa(bin);
|
|
40
|
+
}
|
|
41
|
+
function requireRepo(env) {
|
|
42
|
+
if (!env.DATA_REPO) {
|
|
43
|
+
throw new ApiError(400, 'server is not configured: set DATA_REPO ("owner/name") and GITHUB_TOKEN first');
|
|
44
|
+
}
|
|
45
|
+
return { repo: env.DATA_REPO, branch: env.DATA_BRANCH || 'main' };
|
|
46
|
+
}
|
|
47
|
+
// 写入(幂等):已存在视为成功
|
|
48
|
+
export async function putChart(env, hash, doc) {
|
|
49
|
+
const { repo, branch } = requireRepo(env);
|
|
50
|
+
const token = env.GITHUB_TOKEN;
|
|
51
|
+
if (!token)
|
|
52
|
+
throw new ApiError(400, 'server is not configured: set GITHUB_TOKEN secret first');
|
|
53
|
+
const res = await fetch(`https://api.github.com/repos/${repo}/contents/charts/${hash}.json`, {
|
|
54
|
+
method: 'PUT',
|
|
55
|
+
headers: {
|
|
56
|
+
authorization: `Bearer ${token}`,
|
|
57
|
+
accept: 'application/vnd.github+json',
|
|
58
|
+
'content-type': 'application/json',
|
|
59
|
+
'user-agent': 'draw-worker',
|
|
60
|
+
},
|
|
61
|
+
body: JSON.stringify({
|
|
62
|
+
message: `chart ${hash} (${doc.template})`,
|
|
63
|
+
branch,
|
|
64
|
+
content: base64(JSON.stringify(doc)),
|
|
65
|
+
}),
|
|
66
|
+
});
|
|
67
|
+
if (res.ok)
|
|
68
|
+
return;
|
|
69
|
+
if (res.status === 409 || res.status === 422)
|
|
70
|
+
return; // 已存在(无 sha 的 PUT)→ 幂等成功
|
|
71
|
+
throw new ApiError(502, `failed to store chart (GitHub ${res.status})`);
|
|
72
|
+
}
|
|
73
|
+
// 读取:恒走 raw(公开仓免 token、CDN 友好)。GITHUB_TOKEN 只是 Worker 的写入凭证
|
|
74
|
+
// (GitHub 对任何仓的写操作都要求认证),读取不再耗 API 配额(5000 req/h 仅剩创建消耗)。
|
|
75
|
+
export async function getChart(env, hash) {
|
|
76
|
+
const { repo, branch } = requireRepo(env);
|
|
77
|
+
// 内容寻址短链:给 Cloudflare 边缘缓存(同 hash 永同内容,缓存安全),
|
|
78
|
+
// 免每请求回源 raw(延迟 200-800ms)
|
|
79
|
+
// 只缓 200-299:cacheEverything 会连 404/403 一起负缓存(坏哈希可被"预热"、限流瞬态被固化)
|
|
80
|
+
const cfCache = { cacheEverything: true, cacheTtlByStatus: { '200-299': 86400, '300-499': 0, '500-599': 0 } };
|
|
81
|
+
// `cf` 是 Workers 专属 fetch 选项(undici 忽略未知 init 键),cast 让两种运行时类型都通过
|
|
82
|
+
const res = await fetch(`https://raw.githubusercontent.com/${repo}/${branch}/charts/${hash}.json`, { cf: cfCache });
|
|
83
|
+
if (res.status === 404)
|
|
84
|
+
throw new ApiError(404, `chart ${hash} not found`);
|
|
85
|
+
if (!res.ok)
|
|
86
|
+
throw new ApiError(502, `failed to load chart data (upstream ${res.status})`);
|
|
87
|
+
const text = await res.text();
|
|
88
|
+
if (text.length > MAX_BODY)
|
|
89
|
+
throw new ApiError(502, 'stored chart data is unexpectedly large');
|
|
90
|
+
let obj;
|
|
91
|
+
try {
|
|
92
|
+
obj = JSON.parse(text);
|
|
93
|
+
}
|
|
94
|
+
catch {
|
|
95
|
+
throw new ApiError(502, `stored chart ${hash} is corrupted (invalid JSON)`);
|
|
96
|
+
}
|
|
97
|
+
const o = obj;
|
|
98
|
+
if (typeof o.template !== 'string' || !CHART_TEMPLATES.includes(o.template)) {
|
|
99
|
+
throw new ApiError(502, `stored chart ${hash} has an invalid template`);
|
|
100
|
+
}
|
|
101
|
+
const doc = {
|
|
102
|
+
template: o.template,
|
|
103
|
+
theme: typeof o.theme === 'string' ? o.theme : 'base',
|
|
104
|
+
...(o.stack === true ? { stack: true } : {}),
|
|
105
|
+
spec: o.spec,
|
|
106
|
+
};
|
|
107
|
+
// 内容寻址完整性:存档被篡改/误编辑时指纹不再匹配 URL,拒绝渲染
|
|
108
|
+
if ((await fingerprint(doc)) !== hash) {
|
|
109
|
+
throw new ApiError(502, `stored chart ${hash} failed integrity check (content hash mismatch)`);
|
|
110
|
+
}
|
|
111
|
+
return doc;
|
|
112
|
+
}
|
|
113
|
+
export async function readBody(request) {
|
|
114
|
+
const declared = Number(request.headers.get('content-length') ?? '0');
|
|
115
|
+
if (declared > MAX_BODY)
|
|
116
|
+
throw new ApiError(400, `body too large (max ${MAX_BODY / 1024}KB)`);
|
|
117
|
+
const text = await request.text();
|
|
118
|
+
if (text.length > MAX_BODY)
|
|
119
|
+
throw new ApiError(400, `body too large (max ${MAX_BODY / 1024}KB)`);
|
|
120
|
+
return text;
|
|
121
|
+
}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
// 面积图风格变体(规范:面积图 1-3)。默认 = evil(规范第 1 个)。
|
|
2
|
+
import { duo, makeVariant } from './types.js';
|
|
3
|
+
import { C_evil, C_star, C_openArea } from './common.js';
|
|
4
|
+
export const AREA_VARIANTS = [
|
|
5
|
+
// 面积图 1 · Evil:渐变面积 + 虚线描边 + 大实心点 + 右上图例(方块)
|
|
6
|
+
makeVariant({
|
|
7
|
+
family: 'evil',
|
|
8
|
+
label: 'Evil Charts 风格',
|
|
9
|
+
series: [
|
|
10
|
+
duo(C_evil['green-deep'], C_evil['green']),
|
|
11
|
+
duo(C_evil['red-deep'], C_evil['red']),
|
|
12
|
+
],
|
|
13
|
+
size: [960, 520],
|
|
14
|
+
rules: {
|
|
15
|
+
canvas: 'plain',
|
|
16
|
+
grid: 'dashed', gridDash: '3 7', baseline: 'none',
|
|
17
|
+
points: 'filled', pointR: 6, lineWidth: 1.7, lineDash: '5 5', smooth: false,
|
|
18
|
+
areaGradient: true, areaTop: 0.22, areaBottom: 0.015,
|
|
19
|
+
legend: 'top-right', legendShape: 'square',
|
|
20
|
+
num: 'none',
|
|
21
|
+
},
|
|
22
|
+
}),
|
|
23
|
+
// 面积图 2 · GitHub Star:手绘滤镜 + 手写字体 + 黑色粗坐标轴 + 端点标注
|
|
24
|
+
makeVariant({
|
|
25
|
+
family: 'star',
|
|
26
|
+
label: 'GitHub Star 风格',
|
|
27
|
+
series: [duo(C_star['orange-red'])],
|
|
28
|
+
neutrals: {
|
|
29
|
+
ink: duo('#000000', '#FAFAFA'),
|
|
30
|
+
text: duo('#000000', '#D4D4D8'),
|
|
31
|
+
muted: duo('#000000', '#A1A1AA'),
|
|
32
|
+
grid: duo('#EEEEEE', C_star['grid-dark']),
|
|
33
|
+
baseline: duo('#222222', '#4A4F57'),
|
|
34
|
+
border: duo('#000000', '#4A4F57'),
|
|
35
|
+
halo: duo('#FFFFFF', '#0E0F11'),
|
|
36
|
+
},
|
|
37
|
+
size: [800, 533],
|
|
38
|
+
rules: {
|
|
39
|
+
canvas: 'card', // 手绘风自带白底画布(规范原版不透明)
|
|
40
|
+
title: 'center',
|
|
41
|
+
grid: 'solid', baseline: 'line',
|
|
42
|
+
points: 'none', lineWidth: 3, smooth: true,
|
|
43
|
+
areaGradient: true, areaTop: 0.22, areaBottom: 0.02,
|
|
44
|
+
legend: 'none', sketch: true, axisTitle: true,
|
|
45
|
+
num: 'none',
|
|
46
|
+
},
|
|
47
|
+
}),
|
|
48
|
+
// 面积图 5 · OpenData:浓渐变面积 + 实网格 + Y 轴标题 + 小点 + 编辑式标题
|
|
49
|
+
makeVariant({
|
|
50
|
+
family: 'opendata',
|
|
51
|
+
label: 'OpenData 风格',
|
|
52
|
+
series: [duo(C_openArea['cyan']), duo(C_openArea['red']), duo(C_openArea['slate'])],
|
|
53
|
+
neutrals: {
|
|
54
|
+
grid: duo('rgba(0,0,0,0.08)', 'rgba(255,255,255,0.08)'),
|
|
55
|
+
},
|
|
56
|
+
size: [766, 500],
|
|
57
|
+
rules: {
|
|
58
|
+
canvas: 'plain',
|
|
59
|
+
title: 'editorial',
|
|
60
|
+
grid: 'solid', baseline: 'none', axisTitle: true, axisInline: true,
|
|
61
|
+
points: 'filled', pointR: 3, lineWidth: 2, smooth: true,
|
|
62
|
+
areaGradient: true, areaTop: 0.85, areaBottom: 0.1,
|
|
63
|
+
legend: 'none',
|
|
64
|
+
yFromZero: false, // 规范 area-3:Y 轴 120-240,不强制从 0
|
|
65
|
+
refAvg: true, // 均值参考虚线
|
|
66
|
+
endValue: true, // 末点标注
|
|
67
|
+
tickFont: 14,
|
|
68
|
+
num: 'none',
|
|
69
|
+
},
|
|
70
|
+
}),
|
|
71
|
+
// 面积图 3 · 像素 GitHub Star:100×46 像素格 + 发光轨迹 + 手写标题(规范 area-3,900×470)
|
|
72
|
+
makeVariant({
|
|
73
|
+
family: 'pixel',
|
|
74
|
+
label: '像素 GitHub Star',
|
|
75
|
+
series: [duo('#8FEA2A')],
|
|
76
|
+
neutrals: {
|
|
77
|
+
grid: duo('#C9DCC4', '#183019'),
|
|
78
|
+
},
|
|
79
|
+
size: [900, 470],
|
|
80
|
+
rules: {
|
|
81
|
+
canvas: 'plain',
|
|
82
|
+
areaMode: 'pixel',
|
|
83
|
+
title: 'center',
|
|
84
|
+
grid: 'none', baseline: 'none',
|
|
85
|
+
num: 'none',
|
|
86
|
+
},
|
|
87
|
+
}),
|
|
88
|
+
// 面积图 4 · 波点 GitHub Star:双系列阶梯面积,点阵 pattern 填充(规范 area-4,900×470)
|
|
89
|
+
makeVariant({
|
|
90
|
+
family: 'polka',
|
|
91
|
+
label: '波点 GitHub Star',
|
|
92
|
+
series: [duo('#B6F000'), duo('#3B82F6')],
|
|
93
|
+
neutrals: {
|
|
94
|
+
ink: duo('#27272A', '#E4E4E7'),
|
|
95
|
+
},
|
|
96
|
+
size: [900, 470],
|
|
97
|
+
rules: {
|
|
98
|
+
canvas: 'plain',
|
|
99
|
+
areaMode: 'polka',
|
|
100
|
+
grid: 'solid', baseline: 'line',
|
|
101
|
+
smooth: false,
|
|
102
|
+
legend: 'none',
|
|
103
|
+
num: 'none',
|
|
104
|
+
},
|
|
105
|
+
}),
|
|
106
|
+
];
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
// 柱状图(base 待设计补充;规范款:bar-1 evil 分组柱、bar-2 grid 单元格柱)。
|
|
2
|
+
import { duo, makeVariant } from './types.js';
|
|
3
|
+
import { C_shadcn, C_barEvil, C_gridMono, C_sankey } from './common.js';
|
|
4
|
+
export const BAR_VARIANTS = [
|
|
5
|
+
makeVariant({
|
|
6
|
+
family: 'evil',
|
|
7
|
+
label: 'Evil Charts 分组柱',
|
|
8
|
+
series: [
|
|
9
|
+
duo(C_barEvil['green-deep'], C_barEvil['green']),
|
|
10
|
+
duo(C_barEvil['red-deep'], C_barEvil['red']),
|
|
11
|
+
],
|
|
12
|
+
size: [960, 520],
|
|
13
|
+
rules: {
|
|
14
|
+
canvas: 'plain',
|
|
15
|
+
grid: 'dashed', gridDash: '4 6', baseline: 'none',
|
|
16
|
+
legend: 'top-right', legendShape: 'square',
|
|
17
|
+
barCorner: 4, num: 'none', tickFont: 11,
|
|
18
|
+
},
|
|
19
|
+
}),
|
|
20
|
+
makeVariant({
|
|
21
|
+
family: 'base',
|
|
22
|
+
label: 'shadcn 蓝阶',
|
|
23
|
+
// 单系列沿用品牌蓝;多系列(分组/堆叠)换多色相,避免同族蓝分不清段
|
|
24
|
+
series: [
|
|
25
|
+
duo(C_shadcn['blue3']),
|
|
26
|
+
duo(C_sankey['green']),
|
|
27
|
+
duo(C_sankey['orange']),
|
|
28
|
+
duo(C_sankey['purple']),
|
|
29
|
+
duo(C_sankey['cyan']),
|
|
30
|
+
duo(C_sankey['rose']),
|
|
31
|
+
],
|
|
32
|
+
ramp: [duo(C_shadcn['blue3']), duo(C_shadcn['blue1'])], // 单系列柱渐变保持蓝阶
|
|
33
|
+
}),
|
|
34
|
+
// 柱状图 1 · Evil 分组柱:圆角矩形柱(四角)+虚线网格+右上方块图例,无数值标注(规范 bar-1)
|
|
35
|
+
// 柱状图 2 · Grid 单元格柱:每列自底向上点亮,一格一个单位;等宽字体表头(规范 bar-2)
|
|
36
|
+
makeVariant({
|
|
37
|
+
family: 'grid',
|
|
38
|
+
label: 'Evil Charts 网格柱',
|
|
39
|
+
series: [duo(C_gridMono['black'], C_gridMono['white'])],
|
|
40
|
+
neutrals: {
|
|
41
|
+
text: duo('#52525B', '#E4E4E7'),
|
|
42
|
+
grid: duo(C_gridMono['gray-light'], C_barEvil['gray-deep']),
|
|
43
|
+
faint: duo(C_gridMono['gray-light'], C_gridMono['gray-deep']),
|
|
44
|
+
},
|
|
45
|
+
size: [960, 520],
|
|
46
|
+
rules: {
|
|
47
|
+
canvas: 'plain',
|
|
48
|
+
barMode: 'grid', grid: 'none', baseline: 'none',
|
|
49
|
+
legend: 'none', num: 'none',
|
|
50
|
+
},
|
|
51
|
+
}),
|
|
52
|
+
];
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
// 混合图(base 待设计补充;规范款:combo-1 evil 柱线组合)。
|
|
2
|
+
import { duo, makeVariant } from './types.js';
|
|
3
|
+
import { C_shadcn, C_comboEvil, C_sankey } from './common.js';
|
|
4
|
+
export const COMBO_VARIANTS = [
|
|
5
|
+
makeVariant({
|
|
6
|
+
family: 'base',
|
|
7
|
+
label: 'shadcn 蓝阶',
|
|
8
|
+
// 多系列换多色相,避免同族蓝分不清柱段
|
|
9
|
+
series: [
|
|
10
|
+
duo(C_shadcn['blue3']),
|
|
11
|
+
duo(C_sankey['green']),
|
|
12
|
+
duo(C_sankey['orange']),
|
|
13
|
+
duo(C_sankey['purple']),
|
|
14
|
+
duo(C_sankey['cyan']),
|
|
15
|
+
duo(C_sankey['rose']),
|
|
16
|
+
],
|
|
17
|
+
ramp: [duo(C_shadcn['blue3']), duo(C_shadcn['blue1'])],
|
|
18
|
+
}),
|
|
19
|
+
// 混合图 1 · Evil 柱线组合(规范 combo-1,960×500):紫柱+绿线双轴,圆角柱,右上图例
|
|
20
|
+
makeVariant({
|
|
21
|
+
family: 'evil',
|
|
22
|
+
label: 'Evil Charts 柱线组合',
|
|
23
|
+
series: [
|
|
24
|
+
duo(C_comboEvil['purple-deep'], C_comboEvil['purple']),
|
|
25
|
+
duo(C_comboEvil['green-deep'], C_comboEvil['green']),
|
|
26
|
+
],
|
|
27
|
+
size: [960, 500],
|
|
28
|
+
rules: {
|
|
29
|
+
canvas: 'plain',
|
|
30
|
+
comboMode: 'evil',
|
|
31
|
+
grid: 'dashed', gridDash: '4 6',
|
|
32
|
+
legend: 'top-right', legendShape: 'square',
|
|
33
|
+
barCorner: 5,
|
|
34
|
+
num: 'none',
|
|
35
|
+
},
|
|
36
|
+
}),
|
|
37
|
+
];
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
export interface Swatch {
|
|
2
|
+
name: string;
|
|
3
|
+
value: string;
|
|
4
|
+
role: string;
|
|
5
|
+
}
|
|
6
|
+
export declare const SWATCHES: Record<string, Swatch[]>;
|
|
7
|
+
export declare const C_shadcn: Record<string, string>;
|
|
8
|
+
export declare const C_evil: Record<string, string>;
|
|
9
|
+
export declare const C_evilGlow: Record<string, string>;
|
|
10
|
+
export declare const C_evilMono: Record<string, string>;
|
|
11
|
+
export declare const C_star: Record<string, string>;
|
|
12
|
+
export declare const C_openArea: Record<string, string>;
|
|
13
|
+
export declare const C_openLine: Record<string, string>;
|
|
14
|
+
export declare const C_openPie: Record<string, string>;
|
|
15
|
+
export declare const C_evilPie: Record<string, string>;
|
|
16
|
+
export declare const C_marketMono: Record<string, string>;
|
|
17
|
+
export declare const C_progress: Record<string, string>;
|
|
18
|
+
export declare const C_reliability: Record<string, string>;
|
|
19
|
+
export declare const C_revenue: Record<string, string>;
|
|
20
|
+
export declare const C_barEvil: Record<string, string>;
|
|
21
|
+
export declare const C_gridMono: Record<string, string>;
|
|
22
|
+
export declare const C_openHbar: Record<string, string>;
|
|
23
|
+
export declare const C_xcmd: Record<string, string>;
|
|
24
|
+
export declare const C_scoreHbar: Record<string, string>;
|
|
25
|
+
export declare const C_radarEvil: Record<string, string>;
|
|
26
|
+
export declare const C_xcmdRadar: Record<string, string>;
|
|
27
|
+
export declare const C_gauge: Record<string, string>;
|
|
28
|
+
export declare const C_gaugeGradient: Record<string, string>;
|
|
29
|
+
export declare const C_comboEvil: Record<string, string>;
|
|
30
|
+
export declare const C_scatterBlue: Record<string, string>;
|
|
31
|
+
export declare const C_qrBlue: Record<string, string>;
|
|
32
|
+
export declare const C_sankey: Record<string, string>;
|
|
33
|
+
export declare const C_sankeyGradient: Record<string, string>;
|
|
34
|
+
export declare const C_sankeyPipeline: Record<string, string>;
|