@x-cmd/draw 0.3.0 → 0.4.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/README.md +79 -297
- package/dist/lib.d.ts +23 -3
- package/dist/lib.js +28 -4
- package/dist/node/cli.js +1 -1
- package/dist/render/anno.d.ts +50 -0
- package/dist/render/anno.js +589 -0
- package/dist/render/arch.d.ts +106 -0
- package/dist/render/arch.js +1011 -0
- package/dist/render/archmap.d.ts +90 -3
- package/dist/render/archmap.js +174 -102
- package/dist/render/area.js +9 -7
- package/dist/render/bar-grouped.js +3 -2
- package/dist/render/bar-stacked.js +3 -2
- package/dist/render/bar.js +3 -2
- package/dist/render/butterfly.d.ts +3 -0
- package/dist/render/butterfly.js +355 -0
- package/dist/render/calendar.d.ts +6 -0
- package/dist/render/calendar.js +448 -0
- package/dist/render/combo.js +3 -2
- package/dist/render/compass.d.ts +6 -0
- package/dist/render/compass.js +77 -0
- package/dist/render/dispatch.js +26 -1
- package/dist/render/echarts-ssr.d.ts +30 -0
- package/dist/render/echarts-ssr.js +337 -16
- package/dist/render/gantt.d.ts +11 -0
- package/dist/render/gantt.js +12 -19
- package/dist/render/gantt2.d.ts +24 -0
- package/dist/render/gantt2.js +198 -0
- package/dist/render/hbar.js +8 -4
- package/dist/render/icons.d.ts +3 -0
- package/dist/render/icons.js +78 -0
- package/dist/render/kinds.d.ts +11 -0
- package/dist/render/kinds.js +176 -0
- package/dist/render/ladder.d.ts +21 -0
- package/dist/render/ladder.js +230 -0
- package/dist/render/layout.d.ts +46 -0
- package/dist/render/layout.js +57 -0
- package/dist/render/line-multi.js +2 -2
- package/dist/render/line.js +2 -2
- package/dist/render/maps.d.ts +34 -0
- package/dist/render/maps.js +197 -2
- package/dist/render/mermaid.js +25 -6
- package/dist/render/mindmap.js +3 -2
- package/dist/render/orgicon.d.ts +12 -0
- package/dist/render/orgicon.js +31 -0
- package/dist/render/png.js +3 -1
- package/dist/render/quadrant.d.ts +6 -0
- package/dist/render/quadrant.js +201 -0
- package/dist/render/query.d.ts +2 -0
- package/dist/render/query.js +100 -1
- package/dist/render/route.d.ts +86 -0
- package/dist/render/route.js +1077 -0
- package/dist/render/scatter.js +73 -7
- package/dist/render/seq.d.ts +41 -0
- package/dist/render/seq.js +248 -0
- package/dist/render/svg.d.ts +16 -2
- package/dist/render/svg.js +85 -7
- package/dist/render/table.d.ts +30 -0
- package/dist/render/table.js +134 -0
- package/dist/render/tokei.d.ts +18 -0
- package/dist/render/tokei.js +230 -0
- package/dist/render/uc.d.ts +58 -0
- package/dist/render/uc.js +319 -0
- package/dist/render/units.d.ts +32 -0
- package/dist/render/units.js +84 -0
- package/dist/render/vendor/au.js +10 -0
- package/dist/render/vendor/br.js +10 -0
- package/dist/render/vendor/china.js +11 -0
- package/dist/render/vendor/de.js +10 -0
- package/dist/render/vendor/eu.js +10 -0
- package/dist/render/vendor/japan.js +10 -0
- package/dist/render/vendor/kr.js +10 -0
- package/dist/render/vendor/us-states.js +4 -6
- package/dist/render/vendor/world-geo.d.ts +22 -0
- package/dist/render/vendor/world-geo.js +9 -0
- package/dist/render/vendor/world.d.ts +13 -0
- package/dist/render/vendor/world.js +12 -0
- package/dist/specs/base.d.ts +5 -0
- package/dist/specs/base.js +14 -1
- package/dist/specs/butterfly.d.ts +46 -0
- package/dist/specs/butterfly.js +241 -0
- package/dist/specs/calendar.d.ts +90 -0
- package/dist/specs/calendar.js +296 -0
- package/dist/specs/compass.d.ts +27 -0
- package/dist/specs/compass.js +111 -0
- package/dist/specs/index.d.ts +5 -0
- package/dist/specs/index.js +5 -0
- package/dist/specs/ladder.d.ts +43 -0
- package/dist/specs/ladder.js +261 -0
- package/dist/specs/quadrant.d.ts +41 -0
- package/dist/specs/quadrant.js +200 -0
- package/dist/specs/scatter.d.ts +14 -8
- package/dist/specs/scatter.js +54 -5
- package/dist/specs/table.d.ts +24 -0
- package/dist/specs/table.js +154 -0
- package/dist/store.d.ts +1 -1
- package/dist/store.js +1 -1
- package/dist/styles/butterfly.d.ts +2 -0
- package/dist/styles/butterfly.js +74 -0
- package/dist/styles/calendar.d.ts +2 -0
- package/dist/styles/calendar.js +51 -0
- package/dist/styles/compass.d.ts +2 -0
- package/dist/styles/compass.js +19 -0
- package/dist/styles/index.js +13 -0
- package/dist/styles/ladder.d.ts +3 -0
- package/dist/styles/ladder.js +66 -0
- package/dist/styles/quadrant.d.ts +2 -0
- package/dist/styles/quadrant.js +19 -0
- package/dist/styles/table.d.ts +2 -0
- package/dist/styles/table.js +12 -0
- package/dist/styles/types.d.ts +1 -0
- package/dist/styles/types.js +1 -0
- package/dist/types/dagre.d.ts +39 -0
- package/dist/types/dagre.js +3 -0
- package/package.json +17 -1
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
// 四种新图种:dataflow / lifecycle / erd / class。
|
|
2
|
+
//
|
|
3
|
+
// 都是同一套引擎(架构图 v2 那张脸),只换「语义类型词汇」和「形状」:
|
|
4
|
+
// /draw/dataflow 数据流:处理 / 存储 / 外部源汇
|
|
5
|
+
// /draw/lifecycle 生命周期:状态 / 判断 / 终态
|
|
6
|
+
// /draw/erd 实体关系:表(字段表在节点里)
|
|
7
|
+
// /draw/class 类图:类(字段与方法在节点里)
|
|
8
|
+
//
|
|
9
|
+
// 参数语法和架构图一致:n=id;type;label;sub;pos、e=from;to;label、b=label;id id。
|
|
10
|
+
// 节点里的多行内容用 \n 分隔(URL 里写 %0A)—— ERD 的字段表、class 的成员表靠它。
|
|
11
|
+
import { ApiError } from '../specs/index.js';
|
|
12
|
+
import { GRID_POS_RE, ID_RE, PX_POS_RE, parseBoundaries, parseEdges, splitFields } from './archmap.js';
|
|
13
|
+
import { renderArchCore } from './arch.js';
|
|
14
|
+
import { boundaryStyleParam } from './arch.js';
|
|
15
|
+
import { resolveSkin } from '../styles/index.js';
|
|
16
|
+
import { clampInt, dirParam, schemeParam } from './query.js';
|
|
17
|
+
/* ---------------------------------------------------------------- 词汇 */
|
|
18
|
+
const DATAFLOW = {
|
|
19
|
+
meta: {
|
|
20
|
+
process: { name: 'Process', badge: 'P', color: 1 },
|
|
21
|
+
store: { name: 'Store', badge: 'S', color: 2 },
|
|
22
|
+
source: { name: 'Source', badge: 'X', color: -1 },
|
|
23
|
+
sink: { name: 'Sink', badge: 'X', color: -1 },
|
|
24
|
+
},
|
|
25
|
+
order: ['process', 'store', 'source', 'sink'],
|
|
26
|
+
shape: { process: 'rect', store: 'cylinder', source: 'round', sink: 'round' },
|
|
27
|
+
};
|
|
28
|
+
const LIFECYCLE = {
|
|
29
|
+
meta: {
|
|
30
|
+
state: { name: 'State', badge: 'T', color: 3 },
|
|
31
|
+
decision: { name: 'Decision', badge: 'D', color: 4 },
|
|
32
|
+
terminal: { name: 'Terminal', badge: 'E', color: 1 },
|
|
33
|
+
},
|
|
34
|
+
order: ['state', 'decision', 'terminal'],
|
|
35
|
+
shape: { state: 'round', decision: 'diamond', terminal: 'round' },
|
|
36
|
+
};
|
|
37
|
+
const ERD = {
|
|
38
|
+
meta: {
|
|
39
|
+
table: { name: 'Table', badge: 'T', color: 2 },
|
|
40
|
+
view: { name: 'View', badge: 'V', color: 3 },
|
|
41
|
+
},
|
|
42
|
+
order: ['table', 'view'],
|
|
43
|
+
rows: 'fields', // 字段表:键标记 + 名字(左)+ 类型(右)
|
|
44
|
+
crows: 'erd', // 边按 1:N 画鱼尾记号
|
|
45
|
+
};
|
|
46
|
+
const CLASS = {
|
|
47
|
+
meta: {
|
|
48
|
+
class: { name: 'Class', badge: 'C', color: 2 },
|
|
49
|
+
iface: { name: 'Interface', badge: 'I', color: 3 },
|
|
50
|
+
enum: { name: 'Enum', badge: 'E', color: 4 },
|
|
51
|
+
},
|
|
52
|
+
order: ['class', 'iface', 'enum'],
|
|
53
|
+
rows: 'fields', // 成员表:可见性标记 + 名字(左)+ 类型(右)
|
|
54
|
+
uml: true, // extends / implements 画 UML 的空心三角
|
|
55
|
+
};
|
|
56
|
+
/* ---------------------------------------------------------------- 节点解析
|
|
57
|
+
和 archmap 同一套语法,只是类型不限定在那八种里(每种图有自己的一套)。 */
|
|
58
|
+
function parseKindNodes(raw, allowed) {
|
|
59
|
+
return raw.map((v, i) => {
|
|
60
|
+
const f = splitFields(v).map((x) => x.trim());
|
|
61
|
+
if (f.length < 3 || f.length > 5) {
|
|
62
|
+
throw new ApiError(400, `"n" #${i + 1} must be "id;type;label[;sub][;pos]". Example: ${f[0]}`);
|
|
63
|
+
}
|
|
64
|
+
const [id, type, label] = f;
|
|
65
|
+
if (!ID_RE.test(id))
|
|
66
|
+
throw new ApiError(400, `"n" #${i + 1}: id must be alnum/dot/dash/underscore`);
|
|
67
|
+
if (!allowed.includes(type)) {
|
|
68
|
+
throw new ApiError(400, `"n" #${i + 1}: type must be one of ${allowed.join(', ')}; got "${type}"`);
|
|
69
|
+
}
|
|
70
|
+
if (!label)
|
|
71
|
+
throw new ApiError(400, `"n" #${i + 1}: label is required`);
|
|
72
|
+
let sub;
|
|
73
|
+
let pos;
|
|
74
|
+
if (f.length === 4) {
|
|
75
|
+
if (GRID_POS_RE.test(f[3]) || PX_POS_RE.test(f[3]))
|
|
76
|
+
pos = f[3];
|
|
77
|
+
else
|
|
78
|
+
sub = f[3];
|
|
79
|
+
}
|
|
80
|
+
else if (f.length === 5) {
|
|
81
|
+
sub = f[3];
|
|
82
|
+
pos = f[4];
|
|
83
|
+
}
|
|
84
|
+
const node = { id, type: type, label, ...(sub ? { sub } : {}) };
|
|
85
|
+
if (pos) {
|
|
86
|
+
const g = GRID_POS_RE.exec(pos);
|
|
87
|
+
if (g) {
|
|
88
|
+
node.grid = { row: +g[1], col: +g[2], w: g[3] ? +g[3] : 1, h: g[4] ? +g[4] : 1 };
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
const px = PX_POS_RE.exec(pos);
|
|
92
|
+
if (!px)
|
|
93
|
+
throw new ApiError(400, `"n" #${i + 1}: pos must look like r0c1[w2][h2] or p40,80[,120x48]`);
|
|
94
|
+
node.px = { x: +px[1], y: +px[2], ...(px[3] ? { w: +px[3], h: +px[4] } : {}) };
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
return node;
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
const KINDS = {
|
|
101
|
+
dataflow: {
|
|
102
|
+
name: 'Data flow',
|
|
103
|
+
types: DATAFLOW,
|
|
104
|
+
allowed: ['process', 'store', 'source', 'sink'],
|
|
105
|
+
example: 'n=extract;process;Extract rows;read the CSV;r0c0&n=raw;source;raw/orders.csv;;r1c0&e=raw;extract;rows&e=extract;store;write parquet',
|
|
106
|
+
},
|
|
107
|
+
lifecycle: {
|
|
108
|
+
name: 'Lifecycle',
|
|
109
|
+
types: LIFECYCLE,
|
|
110
|
+
allowed: ['state', 'decision', 'terminal'],
|
|
111
|
+
example: 'n=new;state;New;;r0c0&n=paid;state;Paid;;r1c0&n=ok;terminal;Fulfilled;;r1c1&e=new;paid&e=paid;ok',
|
|
112
|
+
},
|
|
113
|
+
erd: {
|
|
114
|
+
name: 'ERD',
|
|
115
|
+
types: ERD,
|
|
116
|
+
allowed: ['table', 'view'],
|
|
117
|
+
example: 'n=users;table;users;id:int (pk)%0Aname:text%0Acreated_at:timestamp;r0c0&n=orders;table;orders;id:int (pk)%0Auser_id:int (fk)%0Atotal:int;r1c0&e=users;orders;1:N',
|
|
118
|
+
},
|
|
119
|
+
class: {
|
|
120
|
+
name: 'Class',
|
|
121
|
+
types: CLASS,
|
|
122
|
+
allowed: ['class', 'iface', 'enum'],
|
|
123
|
+
example: 'n=user;class;User;id:int%0Aname:string%0Agreet(): void;r0c0&n=repo;iface;Repository;find(id): User?;r1c0&e=user;repo;implements',
|
|
124
|
+
},
|
|
125
|
+
};
|
|
126
|
+
/**
|
|
127
|
+
* 画一种图:解析 n=/e=/b=,套上那套词汇。
|
|
128
|
+
*/
|
|
129
|
+
export function renderKindFromUrl(kind, url, interactive = false, opts = {}) {
|
|
130
|
+
const spec = KINDS[kind];
|
|
131
|
+
if (!spec)
|
|
132
|
+
throw new ApiError(400, `unknown diagram kind "${kind}"`);
|
|
133
|
+
const params = url.searchParams;
|
|
134
|
+
const nRaw = params.getAll('n');
|
|
135
|
+
if (!nRaw.length) {
|
|
136
|
+
throw new ApiError(400, `at least one node is required. Example: /draw/${kind}?${spec.example}`);
|
|
137
|
+
}
|
|
138
|
+
const nodes = parseKindNodes(nRaw, spec.allowed);
|
|
139
|
+
for (const n of nodes) {
|
|
140
|
+
if (!spec.allowed.includes(n.type)) {
|
|
141
|
+
throw new ApiError(400, `"${kind}" node type must be one of ${spec.allowed.join(', ')}; got "${n.type}". Example: /draw/${kind}?${spec.example}`);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
const seen = new Set();
|
|
145
|
+
for (const n of nodes) {
|
|
146
|
+
if (seen.has(n.id))
|
|
147
|
+
throw new ApiError(400, `duplicate node id "${n.id}"`);
|
|
148
|
+
seen.add(n.id);
|
|
149
|
+
}
|
|
150
|
+
const edges = parseEdges(params.getAll('e'), seen);
|
|
151
|
+
const boundaries = parseBoundaries(params.getAll('b'), seen);
|
|
152
|
+
const v = parseInt(params.get('v') ?? '1', 10) || 1;
|
|
153
|
+
const skin = resolveSkin('sankey', params.get('t'), schemeParam(params));
|
|
154
|
+
return renderArchCore({
|
|
155
|
+
nodes, edges, boundaries,
|
|
156
|
+
types: spec.types,
|
|
157
|
+
template: kind, tagQuery: url.search,
|
|
158
|
+
title: params.get('title')?.trim() || undefined,
|
|
159
|
+
gridCols: clampInt(params, 'grid', 0, 1, 12),
|
|
160
|
+
gridForced: clampInt(params, 'grid', 0, 1, 12) > 0,
|
|
161
|
+
dir: dirParam(params),
|
|
162
|
+
boundaryStyle: boundaryStyleParam(params),
|
|
163
|
+
layout: opts.layout,
|
|
164
|
+
routing: opts.routing,
|
|
165
|
+
legend: params.get('legend') !== '0',
|
|
166
|
+
paper: params.get('paper') === '1' || params.get('paper') === 'true',
|
|
167
|
+
interactive,
|
|
168
|
+
version: v,
|
|
169
|
+
cacheControl: 'public, max-age=300',
|
|
170
|
+
skin,
|
|
171
|
+
minW: clampInt(params, 'w', 0, 200, 2400),
|
|
172
|
+
minH: clampInt(params, 'h', 0, 140, 2400),
|
|
173
|
+
aria: `${spec.name} diagram, ${nodes.length} nodes`,
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
export const KIND_NAMES = Object.keys(KINDS);
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { LadderSpec } from '../specs/ladder.js';
|
|
2
|
+
import { type RenderOpts } from './svg.js';
|
|
3
|
+
/**
|
|
4
|
+
* 天梯图(单边)。
|
|
5
|
+
*
|
|
6
|
+
* 行从上到下按值排(调用方排好,这里只画);同一档的行连在一起,
|
|
7
|
+
* 档与档之间一条分隔线,档名在左边那一列。
|
|
8
|
+
*/
|
|
9
|
+
export declare function renderLadder(spec: LadderSpec, o: RenderOpts): string;
|
|
10
|
+
/**
|
|
11
|
+
* 双翼天梯图:左边 N 卡、右边 AMD/Intel。
|
|
12
|
+
*
|
|
13
|
+
* 两翼的卡合成**一条**梯子,整体按强弱排:
|
|
14
|
+
* rank(缺省)—— **完全错位**:每一行只有一张卡,在它自己那一侧
|
|
15
|
+
* value —— **匹配排序**:值相近的排在同一行,两翼都有
|
|
16
|
+
*
|
|
17
|
+
* 两翼共用一把标尺 —— 不然跨翼的长度没法比。
|
|
18
|
+
*/
|
|
19
|
+
export declare function renderButterflyLadder(spec: LadderSpec, o: RenderOpts): string;
|
|
20
|
+
/** 给 draw 的注册表用:这个 spec 该走哪个渲染器 */
|
|
21
|
+
export declare function isButterflyLadder(spec: LadderSpec): boolean;
|
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
import { matchLadderRows } from '../specs/ladder.js';
|
|
2
|
+
import { TAB, card } from '../theme.js';
|
|
3
|
+
import { esc, fmtFull, fmtNum, niceTicks, r2, sVar, svgDoc, textW, titleBlock, trunc, } from './svg.js';
|
|
4
|
+
const PAD = 24;
|
|
5
|
+
const LEGEND_H = 26;
|
|
6
|
+
const VALUE_W = 54; // 外端数值那一列的宽
|
|
7
|
+
const TIER_W = 34; // 档位名列的宽
|
|
8
|
+
const BAR_H = 18;
|
|
9
|
+
/** 连续同档的行算一组 */
|
|
10
|
+
function tierGroups(tiers) {
|
|
11
|
+
const out = [];
|
|
12
|
+
let i = 0;
|
|
13
|
+
while (i < tiers.length) {
|
|
14
|
+
const t = tiers[i];
|
|
15
|
+
let j = i;
|
|
16
|
+
while (j + 1 < tiers.length && tiers[j + 1] === t)
|
|
17
|
+
j++;
|
|
18
|
+
out.push({ tier: t, from: i, to: j });
|
|
19
|
+
i = j + 1;
|
|
20
|
+
}
|
|
21
|
+
return out;
|
|
22
|
+
}
|
|
23
|
+
/** 档位名列:组名竖排在组中间(组太矮就排在组首行上) */
|
|
24
|
+
function tierLabels(groups, yOf, pitch) {
|
|
25
|
+
const parts = [];
|
|
26
|
+
for (const g of groups) {
|
|
27
|
+
if (!g.tier)
|
|
28
|
+
continue;
|
|
29
|
+
const y = yOf(g.from);
|
|
30
|
+
const h = (g.to - g.from) * pitch;
|
|
31
|
+
const yy = h > 26 ? y + h / 2 : y + pitch / 2;
|
|
32
|
+
parts.push(`<text x="${r2(PAD + TIER_W / 2)}" y="${r2(yy + 4)}" text-anchor="middle" font-size="12" font-weight="600" fill="var(--d-muted)">${esc(g.tier)}</text>`);
|
|
33
|
+
}
|
|
34
|
+
return parts;
|
|
35
|
+
}
|
|
36
|
+
/** 一根柱 */
|
|
37
|
+
function bar(x0, y, len, h, color, tip) {
|
|
38
|
+
return [
|
|
39
|
+
`<rect x="${r2(x0)}" y="${r2(y)}" width="${r2(Math.max(len, 1))}" height="${r2(h)}" rx="4" fill="${color}"${tip ? ` data-tip="${esc(tip)}"` : ''}/>`,
|
|
40
|
+
];
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* 天梯图(单边)。
|
|
44
|
+
*
|
|
45
|
+
* 行从上到下按值排(调用方排好,这里只画);同一档的行连在一起,
|
|
46
|
+
* 档与档之间一条分隔线,档名在左边那一列。
|
|
47
|
+
*/
|
|
48
|
+
export function renderLadder(spec, o) {
|
|
49
|
+
const { width, version, skin } = o;
|
|
50
|
+
const cap = spec.labelmax ?? 22;
|
|
51
|
+
const side = spec.side;
|
|
52
|
+
const items = side?.items ?? [];
|
|
53
|
+
const n = items.length;
|
|
54
|
+
if (!n)
|
|
55
|
+
return svgDoc(width, o.height, 'ladder', version, 'ladder', spec, skin, '');
|
|
56
|
+
// 行多的时候自动拉高 —— 行距压到 16 以下,行标签就叠在一起了
|
|
57
|
+
let height = o.height;
|
|
58
|
+
if (o.autoHeight) {
|
|
59
|
+
const head = PAD + (spec.title ? 32 : 0) + 8 + (side?.name ? LEGEND_H : 0);
|
|
60
|
+
const need = head + PAD + 26 + n * 16;
|
|
61
|
+
if (height < need)
|
|
62
|
+
height = Math.min(need, 4000);
|
|
63
|
+
}
|
|
64
|
+
const titleH = spec.title ? titleBlock(spec.title).length / 40 : 0; // 粗略,下面重算
|
|
65
|
+
const legendItems = side?.name ? [{ name: side.name, color: 'var(--d-s1)' }] : [];
|
|
66
|
+
const contentTop = PAD + (spec.title ? 32 : 0) + 8 + (legendItems.length ? LEGEND_H : 0);
|
|
67
|
+
const avail = height - contentTop - PAD - 26;
|
|
68
|
+
const pitch = Math.max(12, Math.min(26, avail / Math.max(n, 1)));
|
|
69
|
+
const barH = Math.min(BAR_H, Math.max(6, pitch * 0.62));
|
|
70
|
+
const labelW = Math.min(190 + Math.max(0, cap - 22) * 7, Math.max(...items.map((it) => textW(trunc(it.label ?? '', cap), 12.5))) + 6);
|
|
71
|
+
const left = PAD + TIER_W + labelW + 14;
|
|
72
|
+
const right = width - PAD - VALUE_W;
|
|
73
|
+
const max = Math.max(...items.map((it) => it.value));
|
|
74
|
+
const ticks = niceTicks(max, 4);
|
|
75
|
+
const xMax = ticks[ticks.length - 1] || max;
|
|
76
|
+
const x = (v) => left + (v / xMax) * (right - left);
|
|
77
|
+
const bg = card(width, height);
|
|
78
|
+
const parts = [];
|
|
79
|
+
for (const t of ticks) {
|
|
80
|
+
const gx = r2(x(t));
|
|
81
|
+
if (t > 0) {
|
|
82
|
+
parts.push(`<line x1="${gx}" y1="${r2(contentTop)}" x2="${gx}" y2="${r2(height - PAD - 26)}" stroke="var(--d-grid)" stroke-width="1"/>`);
|
|
83
|
+
}
|
|
84
|
+
parts.push(`<text x="${gx}" y="${r2(height - PAD - 26 + 16)}" text-anchor="middle" font-size="12" fill="var(--d-muted)" style="${TAB}">${fmtNum(t)}</text>`);
|
|
85
|
+
}
|
|
86
|
+
const yOf = (i) => contentTop + i * pitch + (pitch - barH) / 2;
|
|
87
|
+
const groups = tierGroups(items.map((it) => it.tier));
|
|
88
|
+
// 档位:组与组之间一条分隔线,档名在左边那一列
|
|
89
|
+
for (const g of groups) {
|
|
90
|
+
if (g.from === 0)
|
|
91
|
+
continue;
|
|
92
|
+
const y = contentTop + g.from * pitch;
|
|
93
|
+
parts.push(`<line x1="${r2(PAD)}" y1="${r2(y)}" x2="${r2(right)}" y2="${r2(y)}" stroke="var(--d-border)" stroke-width="1"/>`);
|
|
94
|
+
}
|
|
95
|
+
parts.push(...tierLabels(groups, yOf, pitch));
|
|
96
|
+
items.forEach((it, i) => {
|
|
97
|
+
const y = yOf(i);
|
|
98
|
+
const len = x(it.value) - left;
|
|
99
|
+
const color = sVar(0);
|
|
100
|
+
const tip = o.interactive
|
|
101
|
+
? ` data-tip="${esc(`${it.label ?? ''} · ${fmtFull(it.value)}${spec.unit ? ' ' + spec.unit : ''}`)}"`
|
|
102
|
+
: '';
|
|
103
|
+
parts.push(...bar(left, y, len, barH, color, tip));
|
|
104
|
+
if (it.label) {
|
|
105
|
+
parts.push(`<text x="${r2(PAD + TIER_W + labelW)}" y="${r2(y + barH / 2 + 4)}" text-anchor="end" font-size="12.5" fill="var(--d-text)">${esc(trunc(it.label, cap))}</text>`);
|
|
106
|
+
}
|
|
107
|
+
parts.push(`<text x="${r2(right + 8)}" y="${r2(y + barH / 2 + 4)}" font-size="12" font-weight="600" fill="var(--d-text)"${tip}>${fmtNum(it.value)}</text>`);
|
|
108
|
+
});
|
|
109
|
+
const legend = legendItems.length
|
|
110
|
+
? `<g data-legend="types">${legendItems.map((l, i) => `<rect x="${r2(PAD + i * 110)}" y="${r2(contentTop - LEGEND_H + 4)}" width="14" height="14" rx="4" fill="${l.color}" fill-opacity="0.2" stroke="${l.color}" stroke-opacity="0.55"/><text x="${r2(PAD + i * 110 + 20)}" y="${r2(contentTop - LEGEND_H + 15)}" font-size="11.5" fill="var(--d-muted)">${esc(l.name)}</text>`).join('')}</g>`
|
|
111
|
+
: '';
|
|
112
|
+
return svgDoc(width, height, 'ladder', version, 'ladder', spec, skin, bg + titleBlock(spec.title) + legend + parts.join(''));
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* 双翼天梯图:左边 N 卡、右边 AMD/Intel。
|
|
116
|
+
*
|
|
117
|
+
* 两翼的卡合成**一条**梯子,整体按强弱排:
|
|
118
|
+
* rank(缺省)—— **完全错位**:每一行只有一张卡,在它自己那一侧
|
|
119
|
+
* value —— **匹配排序**:值相近的排在同一行,两翼都有
|
|
120
|
+
*
|
|
121
|
+
* 两翼共用一把标尺 —— 不然跨翼的长度没法比。
|
|
122
|
+
*/
|
|
123
|
+
export function renderButterflyLadder(spec, o) {
|
|
124
|
+
const { width, version, skin } = o;
|
|
125
|
+
const cap = spec.labelmax ?? 22;
|
|
126
|
+
const leftItems = spec.left?.items ?? [];
|
|
127
|
+
const rightItems = spec.right?.items ?? [];
|
|
128
|
+
const rows = matchLadderRows(leftItems, rightItems, spec.match ?? 'rank');
|
|
129
|
+
const n = rows.length;
|
|
130
|
+
if (!n) {
|
|
131
|
+
return svgDoc(width, o.height, 'butterfly-ladder', version, 'butterfly ladder', spec, skin, '');
|
|
132
|
+
}
|
|
133
|
+
// 行多的时候自动拉高(同上)
|
|
134
|
+
let height = o.height;
|
|
135
|
+
if (o.autoHeight) {
|
|
136
|
+
const legend = (spec.left?.name ? 1 : 0) + (spec.right?.name ? 1 : 0);
|
|
137
|
+
const head = PAD + (spec.title ? 32 : 0) + 8 + (legend ? LEGEND_H : 0);
|
|
138
|
+
const need = head + PAD + 26 + n * 16;
|
|
139
|
+
if (height < need)
|
|
140
|
+
height = Math.min(need, 4000);
|
|
141
|
+
}
|
|
142
|
+
const legendItems = [
|
|
143
|
+
spec.left?.name ? { name: spec.left.name, color: 'var(--d-s1)' } : null,
|
|
144
|
+
spec.right?.name ? { name: spec.right.name, color: 'var(--d-s2)' } : null,
|
|
145
|
+
].filter(Boolean);
|
|
146
|
+
const contentTop = PAD + (spec.title ? 32 : 0) + 8 + (legendItems.length ? LEGEND_H : 0);
|
|
147
|
+
const avail = height - contentTop - PAD - 26;
|
|
148
|
+
const pitch = Math.max(12, Math.min(26, avail / Math.max(n, 1)));
|
|
149
|
+
const barH = Math.min(BAR_H, Math.max(6, pitch * 0.62));
|
|
150
|
+
const lLabels = leftItems.map((it) => it.label ?? '');
|
|
151
|
+
const rLabels = rightItems.map((it) => it.label ?? '');
|
|
152
|
+
const lW = Math.max(0, ...lLabels.map((l) => textW(trunc(l, cap), 12.5)));
|
|
153
|
+
const rW = Math.max(0, ...rLabels.map((l) => textW(trunc(l, cap), 12.5)));
|
|
154
|
+
const plotL = PAD + TIER_W + lW + 10 + VALUE_W;
|
|
155
|
+
const plotR = width - PAD - rW - 10 - VALUE_W;
|
|
156
|
+
const centre = (plotL + plotR) / 2;
|
|
157
|
+
const half = (plotR - plotL) / 2;
|
|
158
|
+
// **一把标尺**:两翼合起来是一条梯子,长度要能跨着比
|
|
159
|
+
const lMax = Math.max(...leftItems.map((it) => it.value), 0);
|
|
160
|
+
const rMax = Math.max(...rightItems.map((it) => it.value), 0);
|
|
161
|
+
const leftMax = Math.max(lMax, rMax);
|
|
162
|
+
const rightMax = leftMax;
|
|
163
|
+
const bg = card(width, height);
|
|
164
|
+
const parts = [];
|
|
165
|
+
// 刻度:两侧同一套(共用一把标尺)
|
|
166
|
+
const grid = (max, dir) => {
|
|
167
|
+
if (max <= 0)
|
|
168
|
+
return;
|
|
169
|
+
const ticks = niceTicks(max, 4);
|
|
170
|
+
const tickMax = ticks[ticks.length - 1] || max;
|
|
171
|
+
for (const t of ticks) {
|
|
172
|
+
if (t === 0)
|
|
173
|
+
continue;
|
|
174
|
+
const dx = (t / tickMax) * half;
|
|
175
|
+
const x = dir < 0 ? centre - dx : centre + dx;
|
|
176
|
+
parts.push(`<line x1="${r2(x)}" y1="${r2(contentTop)}" x2="${r2(x)}" y2="${r2(height - PAD - 26)}" stroke="var(--d-grid)"/>`);
|
|
177
|
+
}
|
|
178
|
+
};
|
|
179
|
+
grid(leftMax, -1);
|
|
180
|
+
grid(rightMax, 1);
|
|
181
|
+
parts.push(`<line x1="${r2(centre)}" y1="${r2(contentTop)}" x2="${r2(centre)}" y2="${r2(height - PAD - 26)}" stroke="var(--d-border)"/>`);
|
|
182
|
+
const yOf = (i) => contentTop + i * pitch + (pitch - barH) / 2;
|
|
183
|
+
// 档位:两侧的行是配对的,档以左边为准
|
|
184
|
+
const tiers = rows.map((r) => r[0]?.tier ?? r[1]?.tier);
|
|
185
|
+
const groups = tierGroups(tiers);
|
|
186
|
+
for (const g of groups) {
|
|
187
|
+
if (g.from === 0)
|
|
188
|
+
continue;
|
|
189
|
+
const y = contentTop + g.from * pitch;
|
|
190
|
+
parts.push(`<line x1="${r2(PAD)}" y1="${r2(y)}" x2="${r2(width - PAD)}" y2="${r2(y)}" stroke="var(--d-border)" stroke-width="1"/>`);
|
|
191
|
+
}
|
|
192
|
+
parts.push(...tierLabels(groups, yOf, pitch));
|
|
193
|
+
rows.forEach(([l, r], i) => {
|
|
194
|
+
const y = yOf(i);
|
|
195
|
+
if (l) {
|
|
196
|
+
const len = (l.value / (leftMax || 1)) * half;
|
|
197
|
+
const tip = o.interactive
|
|
198
|
+
? ` data-tip="${esc(`${l.label ?? ''} · ${fmtFull(l.value)}${spec.unit ? ' ' + spec.unit : ''}`)}"`
|
|
199
|
+
: '';
|
|
200
|
+
parts.push(...bar(centre - len, y, len, barH, sVar(0), tip));
|
|
201
|
+
if (l.label) {
|
|
202
|
+
parts.push(`<text x="${r2(plotL - VALUE_W - 10)}" y="${r2(y + barH / 2 + 4)}" text-anchor="end" font-size="12.5" fill="var(--d-text)">${esc(trunc(l.label, cap))}</text>`);
|
|
203
|
+
}
|
|
204
|
+
// 数值:柱够长**而且够粗**就画在柱里 —— 左边的柱尾紧挨着名字列,
|
|
205
|
+
// 画在外面会撞上;柱太薄的话字会糊在柱边上。
|
|
206
|
+
// 左边的柱往左长,「柱里」是尾端的**右边**,所以文字从尾端往右排(start)。
|
|
207
|
+
const inBar = len > 56 && barH >= 11;
|
|
208
|
+
parts.push(`<text x="${r2(centre - len + (inBar ? 8 : -8))}" y="${r2(y + barH / 2 + 4)}" text-anchor="${inBar ? 'start' : 'end'}" font-size="12" font-weight="600" fill="${inBar ? '#fff' : 'var(--d-text)'}">${fmtNum(l.value)}</text>`);
|
|
209
|
+
}
|
|
210
|
+
if (r) {
|
|
211
|
+
const len = (r.value / (rightMax || 1)) * half;
|
|
212
|
+
const tip = o.interactive
|
|
213
|
+
? ` data-tip="${esc(`${r.label ?? ''} · ${fmtFull(r.value)}${spec.unit ? ' ' + spec.unit : ''}`)}"`
|
|
214
|
+
: '';
|
|
215
|
+
parts.push(...bar(centre, y, len, barH, sVar(1), tip));
|
|
216
|
+
if (r.label) {
|
|
217
|
+
parts.push(`<text x="${r2(plotR + VALUE_W + 10)}" y="${r2(y + barH / 2 + 4)}" font-size="12.5" fill="var(--d-text)">${esc(trunc(r.label, cap))}</text>`);
|
|
218
|
+
}
|
|
219
|
+
parts.push(`<text x="${r2(centre + len + 8)}" y="${r2(y + barH / 2 + 4)}" font-size="12" font-weight="600" fill="var(--d-text)">${fmtNum(r.value)}</text>`);
|
|
220
|
+
}
|
|
221
|
+
});
|
|
222
|
+
const legend = legendItems.length
|
|
223
|
+
? `<g data-legend="types">${legendItems.map((l, i) => `<rect x="${r2(PAD + i * 130)}" y="${r2(contentTop - LEGEND_H + 4)}" width="14" height="14" rx="4" fill="${l.color}" fill-opacity="0.2" stroke="${l.color}" stroke-opacity="0.55"/><text x="${r2(PAD + i * 130 + 20)}" y="${r2(contentTop - LEGEND_H + 15)}" font-size="11.5" fill="var(--d-muted)">${esc(l.name)}</text>`).join('')}</g>`
|
|
224
|
+
: '';
|
|
225
|
+
return svgDoc(width, height, 'butterfly-ladder', version, 'butterfly ladder', spec, skin, bg + titleBlock(spec.title) + legend + parts.join(''));
|
|
226
|
+
}
|
|
227
|
+
/** 给 draw 的注册表用:这个 spec 该走哪个渲染器 */
|
|
228
|
+
export function isButterflyLadder(spec) {
|
|
229
|
+
return !spec.side && (spec.left !== undefined || spec.right !== undefined);
|
|
230
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { ArchBoundary, ArchEdge, ArchNode } from './archmap.js';
|
|
2
|
+
import { type Box } from './archmap.js';
|
|
3
|
+
/** 摆位引擎拿到的上下文 */
|
|
4
|
+
export interface LayoutCtx {
|
|
5
|
+
/** 待摆的节点(一个位置都没写的那种情况) */
|
|
6
|
+
nodes: ArchNode[];
|
|
7
|
+
/** 连线 */
|
|
8
|
+
edges: ArchEdge[];
|
|
9
|
+
/** 分组(边界)—— 引擎可以拿它当「簇」 */
|
|
10
|
+
boundaries: ArchBoundary[];
|
|
11
|
+
/** 节点的框有多大(渲染层量好,引擎只管摆) */
|
|
12
|
+
sizeOf: (n: ArchNode) => {
|
|
13
|
+
w: number;
|
|
14
|
+
h: number;
|
|
15
|
+
};
|
|
16
|
+
/** 层(列)与层之间的横距 */
|
|
17
|
+
gapX: number;
|
|
18
|
+
/** 层内(上下)的纵距 */
|
|
19
|
+
gapY: number;
|
|
20
|
+
/** 画布留白 */
|
|
21
|
+
pad: number;
|
|
22
|
+
/** 方向:LR = 层往右走,TB = 层往下走 */
|
|
23
|
+
dir: 'LR' | 'TB';
|
|
24
|
+
/** 边标签有多宽(渲染层按字体量好,引擎不碰字体) */
|
|
25
|
+
labelW: (e: ArchEdge) => number;
|
|
26
|
+
}
|
|
27
|
+
/** 摆完的结果:每个节点的框 + 画布多大 */
|
|
28
|
+
export interface LayoutResult {
|
|
29
|
+
/** 节点 id → 框 */
|
|
30
|
+
boxes: Map<string, Box>;
|
|
31
|
+
W: number;
|
|
32
|
+
H: number;
|
|
33
|
+
}
|
|
34
|
+
/** 摆位引擎:给一批节点,还一批框 */
|
|
35
|
+
export type LayoutEngine = (ctx: LayoutCtx) => LayoutResult;
|
|
36
|
+
/**
|
|
37
|
+
* 边标签比两个节点之间的空档还宽时,把那一列撑开 —— 让标签有地方放,
|
|
38
|
+
* 而不是压在节点的角标上。同一行、相邻两列的横边才需要(横着走的那一段最短)。
|
|
39
|
+
*/
|
|
40
|
+
export declare function labelGaps(nodes: ArchNode[], edges: ArchEdge[], labelW: (e: ArchEdge) => number): number[];
|
|
41
|
+
/**
|
|
42
|
+
* 库里自带的摆位:通用、够用,但不聪明 ——
|
|
43
|
+
* 节点按你写的顺序(或落在邻居旁边)填进格子,一层一层排开。
|
|
44
|
+
* 更好的算法在站上(私有仓),这个公开仓只留框架和这个通用实现。
|
|
45
|
+
*/
|
|
46
|
+
export declare function gridLayout(ctx: LayoutCtx): LayoutResult;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
// 布局引擎的挂载点 —— 库管「怎么画」,「怎么摆」可以换。
|
|
2
|
+
//
|
|
3
|
+
// 摆位分两种:
|
|
4
|
+
// - **写了位置的**:作者说了算,引擎不插手(格子/像素都按给的来)
|
|
5
|
+
// - **没写位置的**:交给**引擎**。库里自带一个通用的(够用但不聪明);
|
|
6
|
+
// 更好的算法(分层、簇感知那些)装在站上,不在这个公开仓里。
|
|
7
|
+
//
|
|
8
|
+
// 谁想接自己的引擎,renderArchCore({ layout }) 塞进来就行 ——
|
|
9
|
+
// URL 里没有 `engine=` 这种参数:引擎的选择是调用方的事,不是 URL 语法的一部分。
|
|
10
|
+
import { packGrid } from './archmap.js';
|
|
11
|
+
/**
|
|
12
|
+
* 边标签比两个节点之间的空档还宽时,把那一列撑开 —— 让标签有地方放,
|
|
13
|
+
* 而不是压在节点的角标上。同一行、相邻两列的横边才需要(横着走的那一段最短)。
|
|
14
|
+
*/
|
|
15
|
+
export function labelGaps(nodes, edges, labelW) {
|
|
16
|
+
const colOf = new Map();
|
|
17
|
+
for (const n of nodes)
|
|
18
|
+
if (n.grid)
|
|
19
|
+
colOf.set(n.id, n.grid);
|
|
20
|
+
const need = new Map();
|
|
21
|
+
for (const e of edges) {
|
|
22
|
+
if (!e.label)
|
|
23
|
+
continue;
|
|
24
|
+
const a = colOf.get(e.from);
|
|
25
|
+
const b = colOf.get(e.to);
|
|
26
|
+
if (!a || !b || a.row !== b.row)
|
|
27
|
+
continue;
|
|
28
|
+
const [c1, c2] = a.col < b.col ? [a.col, b.col] : [b.col, a.col];
|
|
29
|
+
if (c2 !== c1 + 1)
|
|
30
|
+
continue; // 隔了列的边,横向那一段本来就够长
|
|
31
|
+
need.set(c1, Math.max(need.get(c1) ?? 0, Math.min(labelW(e), 300)));
|
|
32
|
+
}
|
|
33
|
+
const out = [];
|
|
34
|
+
for (const [c, v] of need)
|
|
35
|
+
out[c] = v;
|
|
36
|
+
return out;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* 库里自带的摆位:通用、够用,但不聪明 ——
|
|
40
|
+
* 节点按你写的顺序(或落在邻居旁边)填进格子,一层一层排开。
|
|
41
|
+
* 更好的算法在站上(私有仓),这个公开仓只留框架和这个通用实现。
|
|
42
|
+
*/
|
|
43
|
+
export function gridLayout(ctx) {
|
|
44
|
+
// 拷贝一份:引擎不该改作者的节点(元数据里记的还是作者写的东西)
|
|
45
|
+
const nodes = ctx.nodes.map((n) => ({ ...n }));
|
|
46
|
+
const opts = {
|
|
47
|
+
gapX: ctx.gapX,
|
|
48
|
+
gapY: ctx.gapY,
|
|
49
|
+
pad: ctx.pad,
|
|
50
|
+
sizeOf: ctx.sizeOf,
|
|
51
|
+
edges: ctx.edges,
|
|
52
|
+
};
|
|
53
|
+
// 第一遍:定格子(没写位置的节点会被自动放进去);第二遍:按边标签把列撑开
|
|
54
|
+
packGrid(nodes, 0, opts);
|
|
55
|
+
const r = packGrid(nodes, 0, { ...opts, gapAfter: labelGaps(nodes, ctx.edges, ctx.labelW) });
|
|
56
|
+
return { boxes: new Map(r.placed.map((p) => [p.id, p.box])), W: r.W, H: r.H };
|
|
57
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { card } from '../theme.js';
|
|
2
|
-
import { esc, fmtFull, fmtNum, niceTicks, r2, smoothPath, textW, topLegend, trunc, LabelPlacer, pushLineLabelsAllOrNothing, pushPoints, labelStride, reserveBands, toSegments, svgDoc, titleBlock, editorialTitle, yAxisGrid, axisTitleY, findPeak, sVar, markPoints, marksLayer } from './svg.js';
|
|
2
|
+
import { esc, fmtFull, fmtNum, niceTicks, r2, smoothPath, roundedPath, textW, topLegend, trunc, LabelPlacer, pushLineLabelsAllOrNothing, pushPoints, labelStride, reserveBands, toSegments, svgDoc, titleBlock, editorialTitle, yAxisGrid, axisTitleY, findPeak, sVar, markPoints, marksLayer } from './svg.js';
|
|
3
3
|
import { lineLayout } from './line.js';
|
|
4
4
|
/**
|
|
5
5
|
* Multi-series lines; only each line peak is value-labeled to avoid clutter.
|
|
@@ -47,7 +47,7 @@ export function renderLineMulti(spec, o) {
|
|
|
47
47
|
spec.series.forEach((s, si) => {
|
|
48
48
|
const pts = s.values.map((v, i) => [xs(i), y(v)]);
|
|
49
49
|
allSegs.push(...toSegments(pts));
|
|
50
|
-
const dpath = rules.smooth ? smoothPath(pts) :
|
|
50
|
+
const dpath = rules.smooth ? smoothPath(pts) : roundedPath(pts);
|
|
51
51
|
if (rules.glow) {
|
|
52
52
|
parts.push(`<defs><filter id="d-glow" x="-20%" y="-60%" width="140%" height="220%"><feGaussianBlur stdDeviation="7"/></filter>` +
|
|
53
53
|
`<linearGradient id="dg-glow-${si}" x1="0" y1="0" x2="1" y2="0">` +
|
package/dist/render/line.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { card } from '../theme.js';
|
|
2
|
-
import { esc, fmtFull, fmtNum, niceTicks, r2, trunc, LabelPlacer, pushLineLabelsAllOrNothing, pushPoints, labelStride, toSegments, reserveBands, smoothPath, svgDoc, titleBlock, editorialTitle, yAxisGrid, axisTitleY, markPoints, marksLayer } from './svg.js';
|
|
2
|
+
import { esc, fmtFull, fmtNum, niceTicks, r2, trunc, LabelPlacer, pushLineLabelsAllOrNothing, pushPoints, labelStride, toSegments, reserveBands, smoothPath, roundedPath, svgDoc, titleBlock, editorialTitle, yAxisGrid, axisTitleY, markPoints, marksLayer } from './svg.js';
|
|
3
3
|
import { plainGeo } from './measure.js';
|
|
4
4
|
/**
|
|
5
5
|
* Single smooth line with gradient area fill.
|
|
@@ -42,7 +42,7 @@ export function renderLine(spec, o) {
|
|
|
42
42
|
const n = spec.data.length;
|
|
43
43
|
const xs = (i) => (n === 1 ? (left + right) / 2 : left + ((right - left) * i) / (n - 1));
|
|
44
44
|
const pts = spec.data.map((d, i) => [xs(i), y(d.value)]);
|
|
45
|
-
const path = rules.smooth ? smoothPath(pts) :
|
|
45
|
+
const path = rules.smooth ? smoothPath(pts) : roundedPath(pts);
|
|
46
46
|
const parts = [card(width, height, rules.canvas === 'plain')];
|
|
47
47
|
if (rules.areaGradient) {
|
|
48
48
|
parts.push(`<defs><linearGradient id="dg-area" x1="0" y1="0" x2="0" y2="1">` +
|
package/dist/render/maps.d.ts
CHANGED
|
@@ -1,9 +1,43 @@
|
|
|
1
|
+
type Obj = Record<string, unknown>;
|
|
1
2
|
/** registerMap 的最小结构面(不引 echarts 内部类型) */
|
|
2
3
|
interface MapRegistrar {
|
|
3
4
|
registerMap(name: string, geo: unknown): void;
|
|
4
5
|
}
|
|
6
|
+
/** 地图 GeoJSON(按地图名取,已翻成 echarts 认的方向):浏览器端注册地图要用同一份 */
|
|
7
|
+
export declare function loadMapGeoJson(name: string): Promise<unknown>;
|
|
8
|
+
/**
|
|
9
|
+
* US 各州的 GeoJSON(Albers USA 投影,50 州 + DC)—— 随包分发,随取随用。
|
|
10
|
+
* 浏览器端的 echarts 也要注册同一份地图数据,自己那一份没有地图 —— 用这个。
|
|
11
|
+
* 按需载入(静态 import 会把 68KB 拖进冷启动路径)。
|
|
12
|
+
*/
|
|
13
|
+
export declare function loadUsStatesGeoJson(): Promise<unknown>;
|
|
14
|
+
/** 已注册地图的纵横比(未注册返回 undefined) */
|
|
15
|
+
export declare function mapAspect(name: string): number | undefined;
|
|
5
16
|
/** option 里引用到的地图名:series.type=map 的 map 字段 + geo 组件的 map 字段 */
|
|
6
17
|
export declare function mapNamesOf(option: unknown): string[];
|
|
18
|
+
/**
|
|
19
|
+
* 世界地图的**经纬度**版本(球面用)—— 动态载入(静态 import 会拖进冷启动路径)。
|
|
20
|
+
* 坐标粗一点(球上本来就小)。
|
|
21
|
+
*/
|
|
22
|
+
export declare function loadWorldSphericalGeoJson(): Promise<unknown>;
|
|
23
|
+
/** 绕圈后的份数(底图 + 左右各一份) */
|
|
24
|
+
export declare const WORLD_WRAP_COPIES = 3;
|
|
25
|
+
/**
|
|
26
|
+
* option 里有没有「挪到某个经度」的世界地图(要绕圈的场合)。
|
|
27
|
+
* 自包含:浏览器端直接跑同一份源码。
|
|
28
|
+
*/
|
|
29
|
+
export declare function worldWrapNeeded(option: unknown): boolean;
|
|
30
|
+
/**
|
|
31
|
+
* 底图左右各加一份(整体平移一个世界宽)。
|
|
32
|
+
* 自包含:浏览器端直接跑同一份源码。
|
|
33
|
+
*/
|
|
34
|
+
export declare function worldWrapGeo(geo: unknown): unknown;
|
|
35
|
+
/**
|
|
36
|
+
* 绕圈后布局要按份数放大 —— 数据多了左右两份,地图还是原来那么大,
|
|
37
|
+
* 不然会被压成三分之一(看着像缩小了一圈)。
|
|
38
|
+
* 自包含:浏览器端直接跑同一份源码。
|
|
39
|
+
*/
|
|
40
|
+
export declare function worldWrapLayout(option: Obj): void;
|
|
7
41
|
/**
|
|
8
42
|
* Register the map data an ECharts option refers to. Must run before `setOption`:
|
|
9
43
|
* echarts resolves `series.map` / `geo.map` against its registered map table.
|