@x-cmd/draw 0.2.5 → 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 +80 -166
- package/dist/lib.d.ts +27 -1
- package/dist/lib.js +39 -1
- package/dist/node/cli.js +109 -11
- 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 +157 -0
- package/dist/render/archmap.js +683 -0
- package/dist/render/area.js +20 -14
- package/dist/render/bar-grouped.js +8 -5
- package/dist/render/bar-stacked.js +11 -7
- package/dist/render/bar.js +8 -3
- 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 +16 -8
- 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 +51 -0
- package/dist/render/echarts-ssr.js +511 -0
- package/dist/render/gantt.d.ts +46 -0
- package/dist/render/gantt.js +415 -0
- 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 +7 -5
- package/dist/render/line.js +9 -5
- package/dist/render/maps.d.ts +46 -0
- package/dist/render/maps.js +237 -0
- package/dist/render/measure.d.ts +0 -1
- package/dist/render/measure.js +0 -1
- package/dist/render/mermaid.d.ts +30 -0
- package/dist/render/mermaid.js +277 -0
- package/dist/render/mindmap.d.ts +10 -0
- package/dist/render/mindmap.js +388 -0
- package/dist/render/orgicon.d.ts +12 -0
- package/dist/render/orgicon.js +31 -0
- package/dist/render/pie.js +1 -1
- package/dist/render/png.d.ts +21 -0
- package/dist/render/png.js +109 -0
- 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 +108 -1
- package/dist/render/route.d.ts +86 -0
- package/dist/render/route.js +1077 -0
- package/dist/render/scatter.js +87 -12
- package/dist/render/seq.d.ts +41 -0
- package/dist/render/seq.js +248 -0
- package/dist/render/svg.d.ts +34 -2
- package/dist/render/svg.js +159 -20
- 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/mermaid-flow-parser.js +1164 -0
- package/dist/render/vendor/mermaid-gantt-parser.js +810 -0
- package/dist/render/vendor/us-states.js +11 -0
- 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 +16 -0
- package/dist/specs/base.js +34 -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/fonts-banner.d.ts +5 -0
- package/dist/styles/fonts-banner.js +9 -0
- package/dist/styles/fonts-cjk.d.ts +2 -0
- package/dist/styles/fonts-cjk.js +6 -0
- package/dist/styles/fonts-ttf.d.ts +2 -0
- package/dist/styles/fonts-ttf.js +6 -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/theme.d.ts +1 -1
- package/dist/theme.js +3 -4
- package/dist/types/dagre.d.ts +39 -0
- package/dist/types/dagre.js +3 -0
- package/package.json +28 -3
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
// /draw/tokei —— 代码统计图:把 tokei 的统计结果画成「代码 / 注释 / 空行」三段堆叠柱。
|
|
2
|
+
//
|
|
3
|
+
// 输入是 tokei --output json 的输出(整份或裁剪过的子集都行):
|
|
4
|
+
// {"TypeScript":{"code":1200,"comments":300,"blanks":150}, ...}
|
|
5
|
+
// 每种语言一根柱,三段自下而上:代码、注释、空行。
|
|
6
|
+
import { ApiError } from '../specs/index.js';
|
|
7
|
+
import { renderBarStacked } from './bar-stacked.js';
|
|
8
|
+
import { renderCombo } from './combo.js';
|
|
9
|
+
import { renderButterfly } from './butterfly.js';
|
|
10
|
+
import { resolveSkin } from '../styles/index.js';
|
|
11
|
+
import { clampInt, schemeParam } from './query.js';
|
|
12
|
+
const EXAMPLE = 'd={"TypeScript":{"code":1200,"comments":300,"blanks":150}}';
|
|
13
|
+
const total = (c) => c.code + c.comments + c.blanks;
|
|
14
|
+
const num = (v) => typeof v === 'number' && Number.isFinite(v) && v > 0 ? Math.round(v) : 0;
|
|
15
|
+
/**
|
|
16
|
+
* 解析 tokei 的 JSON,转成堆叠柱要用的多系列 spec。
|
|
17
|
+
*
|
|
18
|
+
* 接受 tokei 的完整输出(含每个文件的 reports / children)——这里只取每门语言的
|
|
19
|
+
* 三项合计;也接受裁剪过的 {"TypeScript":{"code":…,"comments":…,"blanks":…}}。
|
|
20
|
+
*/
|
|
21
|
+
export function parseTokei(raw) {
|
|
22
|
+
if (!raw || !raw.trim()) {
|
|
23
|
+
throw new ApiError(400, `Missing data. Use ?${EXAMPLE}`);
|
|
24
|
+
}
|
|
25
|
+
let obj;
|
|
26
|
+
try {
|
|
27
|
+
obj = JSON.parse(raw);
|
|
28
|
+
}
|
|
29
|
+
catch {
|
|
30
|
+
throw new ApiError(400, `"d" is not valid JSON (remember to URL-encode it). Example: ?${EXAMPLE}`);
|
|
31
|
+
}
|
|
32
|
+
if (typeof obj !== 'object' || obj === null || Array.isArray(obj)) {
|
|
33
|
+
throw new ApiError(400, `"d" must be an object of language → {code, comments, blanks}. Example: ?${EXAMPLE}`);
|
|
34
|
+
}
|
|
35
|
+
const rows = [];
|
|
36
|
+
for (const [name, v] of Object.entries(obj)) {
|
|
37
|
+
if (name === 'Total')
|
|
38
|
+
continue; // 合计行不画成一根柱
|
|
39
|
+
if (!v || typeof v !== 'object' || Array.isArray(v))
|
|
40
|
+
continue;
|
|
41
|
+
const r = v;
|
|
42
|
+
const c = { code: num(r.code), comments: num(r.comments), blanks: num(r.blanks), files: num(r.files) };
|
|
43
|
+
if (total(c) === 0)
|
|
44
|
+
continue;
|
|
45
|
+
rows.push([name, c]);
|
|
46
|
+
}
|
|
47
|
+
if (!rows.length) {
|
|
48
|
+
throw new ApiError(400, `No language with any code in "d". Example: ?${EXAMPLE}`);
|
|
49
|
+
}
|
|
50
|
+
// 总量大的在前 —— 柱状图从大到小读起来最顺
|
|
51
|
+
rows.sort((a, b) => total(b[1]) - total(a[1]));
|
|
52
|
+
const labels = rows.map(([name]) => name);
|
|
53
|
+
const values = (k) => rows.map(([, c]) => c[k]);
|
|
54
|
+
return {
|
|
55
|
+
labels,
|
|
56
|
+
series: [
|
|
57
|
+
{ name: 'code', values: values('code') },
|
|
58
|
+
{ name: 'comments', values: values('comments') },
|
|
59
|
+
{ name: 'blanks', values: values('blanks') },
|
|
60
|
+
],
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* 一门语言的文件数:
|
|
65
|
+
* - 直接写了 files(裁剪过的 JSON 可以自己填)
|
|
66
|
+
* - tokei 整份输出里是 reports(每个文件一条),老版本是 children(一个对象)
|
|
67
|
+
*/
|
|
68
|
+
function fileCountOf(r) {
|
|
69
|
+
if (typeof r.files === 'number' && Number.isFinite(r.files))
|
|
70
|
+
return Math.max(0, Math.round(r.files));
|
|
71
|
+
const reports = r.reports;
|
|
72
|
+
if (Array.isArray(reports))
|
|
73
|
+
return reports.length;
|
|
74
|
+
const kids = r.children;
|
|
75
|
+
if (kids && typeof kids === 'object' && !Array.isArray(kids))
|
|
76
|
+
return Object.keys(kids).length;
|
|
77
|
+
return 0;
|
|
78
|
+
}
|
|
79
|
+
/** 解析 tokei 的 JSON(整份或裁剪过的),顺带把文件数取出来 */
|
|
80
|
+
export function parseTokeiData(raw) {
|
|
81
|
+
const spec = parseTokei(raw);
|
|
82
|
+
let obj;
|
|
83
|
+
try {
|
|
84
|
+
obj = JSON.parse(raw);
|
|
85
|
+
}
|
|
86
|
+
catch {
|
|
87
|
+
return { spec, files: null };
|
|
88
|
+
}
|
|
89
|
+
const rows = [];
|
|
90
|
+
let any = false;
|
|
91
|
+
for (const [name, v] of Object.entries(obj)) {
|
|
92
|
+
if (name === 'Total' || !v || typeof v !== 'object' || Array.isArray(v))
|
|
93
|
+
continue;
|
|
94
|
+
const r = v;
|
|
95
|
+
const n = fileCountOf(r);
|
|
96
|
+
if (n > 0)
|
|
97
|
+
any = true;
|
|
98
|
+
rows.push([name, n]);
|
|
99
|
+
}
|
|
100
|
+
if (!any)
|
|
101
|
+
return { spec, files: null };
|
|
102
|
+
// 跟着柱的顺序排(柱按总量从大到小)
|
|
103
|
+
const byName = new Map(rows);
|
|
104
|
+
const files = spec.labels.map((l) => byName.get(l) ?? 0);
|
|
105
|
+
return { spec, files };
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* /draw/tokei 入口:GET ?d=<tokei json>,或 POST(body 就是 tokei 的 json)。
|
|
109
|
+
*/
|
|
110
|
+
/**
|
|
111
|
+
* property 形态:langs=TypeScript:4820:1180:940,JavaScript:1687:298:71
|
|
112
|
+
* 每项是 语言:代码:注释:空行,后两个可省。主推这个 —— 短,而且一眼能读。
|
|
113
|
+
*/
|
|
114
|
+
function parseLangs(raw) {
|
|
115
|
+
const out = {};
|
|
116
|
+
for (const item of raw.split(',')) {
|
|
117
|
+
const s = item.trim();
|
|
118
|
+
if (!s)
|
|
119
|
+
continue;
|
|
120
|
+
const f = s.split(':').map((x) => x.trim());
|
|
121
|
+
if (f.length < 2) {
|
|
122
|
+
throw new ApiError(400, `"langs" must be "lang:code[:comments[:blanks][:files]]" per language, comma separated. Example: langs=TypeScript:4820:1180:940:45,Shell:640:120:88:6`);
|
|
123
|
+
}
|
|
124
|
+
const name = f[0];
|
|
125
|
+
if (!name) {
|
|
126
|
+
throw new ApiError(400, `"langs": language name is missing. Example: langs=TypeScript:4820:1180:940`);
|
|
127
|
+
}
|
|
128
|
+
const nums = f.slice(1).map((x) => Number(x));
|
|
129
|
+
if (nums.some((n) => !Number.isFinite(n) || n < 0)) {
|
|
130
|
+
throw new ApiError(400, `"langs": counts must be numbers ≥ 0. Example: langs=TypeScript:4820:1180:940`);
|
|
131
|
+
}
|
|
132
|
+
out[name] = {
|
|
133
|
+
code: Math.round(nums[0]),
|
|
134
|
+
comments: Math.round(nums[1] ?? 0),
|
|
135
|
+
blanks: Math.round(nums[2] ?? 0),
|
|
136
|
+
files: Math.round(nums[3] ?? 0),
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
if (!Object.keys(out).length) {
|
|
140
|
+
throw new ApiError(400, `"langs" is empty. Example: langs=TypeScript:4820:1180:940`);
|
|
141
|
+
}
|
|
142
|
+
return out;
|
|
143
|
+
}
|
|
144
|
+
export function renderTokeiFromUrl(url, body) {
|
|
145
|
+
const params = url.searchParams;
|
|
146
|
+
const langs = params.get('langs');
|
|
147
|
+
const raw = langs !== null && langs !== ''
|
|
148
|
+
? JSON.stringify(parseLangs(langs))
|
|
149
|
+
: (body ?? params.get('d') ?? '');
|
|
150
|
+
const { spec, files } = parseTokeiData(raw);
|
|
151
|
+
const title = params.get('title')?.trim();
|
|
152
|
+
const unit = params.get('unit')?.trim();
|
|
153
|
+
const layout = (params.get('layout') ?? 'bar').toLowerCase();
|
|
154
|
+
if (!['bar', 'butterfly', 'files', 'tb'].includes(layout)) {
|
|
155
|
+
throw new ApiError(400, `"layout" must be one of bar, butterfly, files, tb. Got: ${JSON.stringify(layout)}`);
|
|
156
|
+
}
|
|
157
|
+
const butterflyLayout = layout === 'butterfly' || layout === 'files' || layout === 'tb';
|
|
158
|
+
// 双翼的摆法用双翼自己的风格家族(t=track/grid/scale,缺省是干净的);
|
|
159
|
+
// 柱状用柱状家族。两边同一张图,t= 的意思也就一致了。
|
|
160
|
+
const skin = resolveSkin(butterflyLayout ? 'butterfly' : 'bar', params.get('t'), schemeParam(params));
|
|
161
|
+
const o = {
|
|
162
|
+
width: clampInt(params, 'w', 760, 200, 2400),
|
|
163
|
+
height: clampInt(params, 'h', 420, 140, 2000),
|
|
164
|
+
version: 1,
|
|
165
|
+
skin,
|
|
166
|
+
};
|
|
167
|
+
const withTitle = { ...spec, ...(title ? { title } : {}), ...(unit ? { unit } : {}) };
|
|
168
|
+
const svg = layout === 'butterfly' || layout === 'files' || layout === 'tb'
|
|
169
|
+
? renderTokeiButterfly(withTitle, files, layout, o)
|
|
170
|
+
: renderTokeiBar(withTitle, files, o);
|
|
171
|
+
return { svg, version: o.version, cacheControl: 'public, max-age=300' };
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* 柱状:三项堆叠的柱,文件数有的话叠一条自己的标尺的折线
|
|
175
|
+
* (文件数和行数不是一个量级 —— 放同一根轴上会骗人)。
|
|
176
|
+
*/
|
|
177
|
+
function renderTokeiBar(spec, files, o) {
|
|
178
|
+
if (!files)
|
|
179
|
+
return renderBarStacked(spec, o);
|
|
180
|
+
const combo = {
|
|
181
|
+
labels: spec.labels,
|
|
182
|
+
stack: true,
|
|
183
|
+
series: [
|
|
184
|
+
...spec.series.map((s) => ({ ...s, kind: 'bar' })),
|
|
185
|
+
{ name: 'files', values: files, kind: 'line' },
|
|
186
|
+
],
|
|
187
|
+
};
|
|
188
|
+
return renderCombo(combo, { ...o, skin: resolveSkin('combo', null, 'light') });
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* 双翼(#55 的做法):数据往左右(或上下)展开。
|
|
192
|
+
* butterfly —— 左代码、右注释+空行(同一个量级,长度可比),文件数叠一条折线
|
|
193
|
+
* files —— 左文件数、右三项行数(两侧各一套标尺)
|
|
194
|
+
* tb —— butterfly 站起来
|
|
195
|
+
*/
|
|
196
|
+
function renderTokeiButterfly(spec, files, layout, o) {
|
|
197
|
+
const [code, comments, blanks] = spec.series;
|
|
198
|
+
const tb = layout === 'tb';
|
|
199
|
+
const bfly = {
|
|
200
|
+
labels: spec.labels,
|
|
201
|
+
dir: tb ? 'tb' : 'lr',
|
|
202
|
+
...(spec.title ? { title: spec.title } : {}),
|
|
203
|
+
};
|
|
204
|
+
if (layout === 'files') {
|
|
205
|
+
// 左:文件数;右:三项行数(两侧各一套标尺 —— 单位不一样)
|
|
206
|
+
bfly.scale = 'each';
|
|
207
|
+
bfly.left = { name: 'files', values: files ?? spec.labels.map(() => 0) };
|
|
208
|
+
bfly.right = {
|
|
209
|
+
segments: [
|
|
210
|
+
{ name: 'code', values: code.values },
|
|
211
|
+
{ name: 'comments', values: comments.values },
|
|
212
|
+
{ name: 'blanks', values: blanks.values },
|
|
213
|
+
],
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
else {
|
|
217
|
+
// 左:代码;右:注释+空行(同一个量级,共用标尺,长度可比)
|
|
218
|
+
bfly.left = { name: 'code', values: code.values };
|
|
219
|
+
bfly.right = {
|
|
220
|
+
segments: [
|
|
221
|
+
{ name: 'comments', values: comments.values },
|
|
222
|
+
{ name: 'blanks', values: blanks.values },
|
|
223
|
+
],
|
|
224
|
+
};
|
|
225
|
+
// 文件数叠在左侧(自己的标尺)
|
|
226
|
+
if (files)
|
|
227
|
+
bfly.line = { name: 'files', values: files, side: 'left' };
|
|
228
|
+
}
|
|
229
|
+
return renderButterfly(bfly, o);
|
|
230
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import type { ArchBoundary } from './archmap.js';
|
|
2
|
+
import { resolveSkin } from '../styles/index.js';
|
|
3
|
+
import { type DrawResult } from './query.js';
|
|
4
|
+
interface UcNode {
|
|
5
|
+
id: string;
|
|
6
|
+
kind: 'actor' | 'uc';
|
|
7
|
+
label: string;
|
|
8
|
+
sub?: string;
|
|
9
|
+
x: number;
|
|
10
|
+
y: number;
|
|
11
|
+
w: number;
|
|
12
|
+
h: number;
|
|
13
|
+
/** 位置:和架构图同一套(不写就自己排) */
|
|
14
|
+
grid?: {
|
|
15
|
+
row: number;
|
|
16
|
+
col: number;
|
|
17
|
+
w: number;
|
|
18
|
+
h: number;
|
|
19
|
+
};
|
|
20
|
+
px?: {
|
|
21
|
+
x: number;
|
|
22
|
+
y: number;
|
|
23
|
+
w?: number;
|
|
24
|
+
h?: number;
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
interface UcEdge {
|
|
28
|
+
from: string;
|
|
29
|
+
to: string;
|
|
30
|
+
label?: string;
|
|
31
|
+
dep: boolean;
|
|
32
|
+
}
|
|
33
|
+
export interface UcOpts {
|
|
34
|
+
nodes: UcNode[];
|
|
35
|
+
edges: UcEdge[];
|
|
36
|
+
/** b= 画出来的边界(可以有多层) */
|
|
37
|
+
boundaries: ArchBoundary[];
|
|
38
|
+
/** 原始 URL 查询串:角标直链 explore 落地页用 */
|
|
39
|
+
tagQuery?: string;
|
|
40
|
+
/** 参与方摆在右边(默认在左边) */
|
|
41
|
+
actorsRight?: boolean;
|
|
42
|
+
title?: string;
|
|
43
|
+
interactive: boolean;
|
|
44
|
+
version: number;
|
|
45
|
+
cacheControl: string;
|
|
46
|
+
skin: ReturnType<typeof resolveSkin>;
|
|
47
|
+
minW?: number;
|
|
48
|
+
minH?: number;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* 渲染用例图。
|
|
52
|
+
*/
|
|
53
|
+
export declare function renderUcCore(o: UcOpts): DrawResult;
|
|
54
|
+
/**
|
|
55
|
+
* `/draw/uc` 入口:GET ?n=…&e=…&b=…
|
|
56
|
+
*/
|
|
57
|
+
export declare function renderUcFromUrl(url: URL, interactive?: boolean): DrawResult;
|
|
58
|
+
export {};
|
|
@@ -0,0 +1,319 @@
|
|
|
1
|
+
// /draw/uc —— 用例图:左边是参与者(火柴人),里面是用例(椭圆),外面一圈系统边界。
|
|
2
|
+
//
|
|
3
|
+
// 模型:
|
|
4
|
+
// n=id;actor|label 参与者
|
|
5
|
+
// n=id;uc|label 用例
|
|
6
|
+
// e=from;to[;label] 关联;label 写 <<include>> / <<extend>> 就是虚线依赖
|
|
7
|
+
// b=label;id id … 系统边界(用例在里面)
|
|
8
|
+
//
|
|
9
|
+
// 画法:参与者排成一列(左),用例排成一行(右),参与者和用例之间连线;
|
|
10
|
+
// 用例外面套一个系统边界框。
|
|
11
|
+
import { ApiError } from '../specs/index.js';
|
|
12
|
+
import { GRID_POS_RE, PX_POS_RE, parseBoundaries, splitFields } from './archmap.js';
|
|
13
|
+
import { resolveSkin } from '../styles/index.js';
|
|
14
|
+
import { clampInt, schemeParam } from './query.js';
|
|
15
|
+
import { esc, r2, roundedPath, svgDoc, textW } from './svg.js';
|
|
16
|
+
const PAD = 44;
|
|
17
|
+
const ACTOR_H = 92; // 火柴人 + 名字占的高度
|
|
18
|
+
const UC_H = 54; // 椭圆高
|
|
19
|
+
const COL_GAP = 78;
|
|
20
|
+
const ROW_GAP = 18;
|
|
21
|
+
const UC_ROW_GAP = 46;
|
|
22
|
+
/**
|
|
23
|
+
* 节点语法和架构图完全一致:id;类型;标签[;副标][;位置]
|
|
24
|
+
* —— 位置可省(用例图自己排),给了就按给的摆。
|
|
25
|
+
*/
|
|
26
|
+
function parseNodes(raw) {
|
|
27
|
+
return raw.map((v, i) => {
|
|
28
|
+
const f = splitFields(v).map((x) => x.trim());
|
|
29
|
+
if (f.length < 3 || f.length > 5) {
|
|
30
|
+
throw new ApiError(400, `"n" #${i + 1} must be "id;actor|label[;sub][;pos]". Example: n=caller;actor;Your app`);
|
|
31
|
+
}
|
|
32
|
+
const kind = f[1];
|
|
33
|
+
if (kind !== 'actor' && kind !== 'uc') {
|
|
34
|
+
throw new ApiError(400, `"n" #${i + 1}: kind must be "actor" or "uc", got ${JSON.stringify(kind)}`);
|
|
35
|
+
}
|
|
36
|
+
if (!f[2])
|
|
37
|
+
throw new ApiError(400, `"n" #${i + 1}: label is required`);
|
|
38
|
+
let sub;
|
|
39
|
+
let pos;
|
|
40
|
+
if (f.length === 4) {
|
|
41
|
+
if (GRID_POS_RE.test(f[3]) || PX_POS_RE.test(f[3]))
|
|
42
|
+
pos = f[3];
|
|
43
|
+
else
|
|
44
|
+
sub = f[3];
|
|
45
|
+
}
|
|
46
|
+
else if (f.length === 5) {
|
|
47
|
+
sub = f[3];
|
|
48
|
+
pos = f[4];
|
|
49
|
+
}
|
|
50
|
+
const node = { id: f[0], kind, label: f[2], ...(sub ? { sub } : {}), x: 0, y: 0, w: 0, h: 0 };
|
|
51
|
+
if (pos) {
|
|
52
|
+
const g = GRID_POS_RE.exec(pos);
|
|
53
|
+
if (g) {
|
|
54
|
+
node.grid = { row: +g[1], col: +g[2], w: g[3] ? +g[3] : 1, h: g[4] ? +g[4] : 1 };
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
const px = PX_POS_RE.exec(pos);
|
|
58
|
+
if (!px)
|
|
59
|
+
throw new ApiError(400, `"n" #${i + 1}: pos must look like r0c1[w2][h2] or p40,80[,120x48]`);
|
|
60
|
+
node.px = { x: +px[1], y: +px[2], ...(px[3] ? { w: +px[3], h: +px[4] } : {}) };
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return node;
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
function parseEdges(raw, ids) {
|
|
67
|
+
return raw.map((v, i) => {
|
|
68
|
+
const f = v.split(';').map((x) => x.trim());
|
|
69
|
+
if (f.length < 2 || !ids.has(f[0]) || !ids.has(f[1])) {
|
|
70
|
+
throw new ApiError(400, `"e" #${i + 1} must be "from;to[;label]" and both ids must exist. Example: e=caller;uc1`);
|
|
71
|
+
}
|
|
72
|
+
const label = f[2] || undefined;
|
|
73
|
+
return { from: f[0], to: f[1], label, dep: !!label && /^<<.+>>$/.test(label) };
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
/** 火柴人:头 + 身子 + 两条胳膊 + 两条腿 */
|
|
77
|
+
function drawActor(n, color, interactive = false) {
|
|
78
|
+
const cx = n.x + n.w / 2;
|
|
79
|
+
const headR = 11;
|
|
80
|
+
const headY = n.y + 4 + headR;
|
|
81
|
+
const bodyTop = headY + headR + 3;
|
|
82
|
+
const bodyBot = bodyTop + 26;
|
|
83
|
+
const armY = bodyTop + 9;
|
|
84
|
+
const labelY = n.y + n.h - 16;
|
|
85
|
+
const ia = interactive ? ` data-node="${esc(n.id)}" data-tip="${esc(`actor · ${n.label}${n.sub ? ` · ${n.sub}` : ''}`)}" tabindex="0"` : '';
|
|
86
|
+
return (`<g${ia}>` +
|
|
87
|
+
`<circle cx="${r2(cx)}" cy="${r2(headY)}" r="${headR}" fill="none" stroke="${color}" stroke-width="1.6"/>` +
|
|
88
|
+
`<path d="M${r2(cx)} ${r2(bodyTop)}L${r2(cx)} ${r2(bodyBot)}" stroke="${color}" stroke-width="1.6" fill="none"/>` +
|
|
89
|
+
`<path d="M${r2(cx - 13)} ${r2(armY)}L${r2(cx + 13)} ${r2(armY)}" stroke="${color}" stroke-width="1.6" fill="none"/>` +
|
|
90
|
+
`<path d="M${r2(cx - 11)} ${r2(bodyBot)}L${r2(cx)} ${r2(bodyTop + 12)}M${r2(cx + 11)} ${r2(bodyBot)}L${r2(cx)} ${r2(bodyTop + 12)}" stroke="${color}" stroke-width="1.6" fill="none"/>` +
|
|
91
|
+
`<text x="${r2(cx)}" y="${r2(labelY)}" text-anchor="middle" font-size="13" font-weight="600" fill="var(--d-ink)">${esc(n.label)}</text>` +
|
|
92
|
+
(n.sub ? `<text x="${r2(cx)}" y="${r2(labelY + 15)}" text-anchor="middle" font-size="11" fill="var(--d-muted)">${esc(n.sub)}</text>` : '') +
|
|
93
|
+
`</g>`);
|
|
94
|
+
}
|
|
95
|
+
/** 用例:椭圆 */
|
|
96
|
+
function drawUseCase(n, color, interactive = false) {
|
|
97
|
+
const cx = n.x + n.w / 2;
|
|
98
|
+
const cy = n.y + n.h / 2;
|
|
99
|
+
const labelY = n.sub ? cy - 2 : cy + 5;
|
|
100
|
+
const ia = interactive ? ` data-node="${esc(n.id)}" data-tip="${esc(`use case · ${n.label}${n.sub ? ` · ${n.sub}` : ''}`)}" tabindex="0"` : '';
|
|
101
|
+
return (`<g${ia}>` +
|
|
102
|
+
`<ellipse cx="${r2(cx)}" cy="${r2(cy)}" rx="${r2(n.w / 2)}" ry="${r2(n.h / 2)}" fill="${color}" fill-opacity="0.1" stroke="${color}" stroke-opacity="0.6" stroke-width="1.3"/>` +
|
|
103
|
+
`<text x="${r2(cx)}" y="${r2(labelY)}" text-anchor="middle" font-size="13" font-weight="500" fill="var(--d-ink)">${esc(n.label)}</text>` +
|
|
104
|
+
(n.sub ? `<text x="${r2(cx)}" y="${r2(labelY + 15)}" text-anchor="middle" font-size="11" fill="var(--d-muted)">${esc(n.sub)}</text>` : '') +
|
|
105
|
+
`</g>`);
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* 渲染用例图。
|
|
109
|
+
*/
|
|
110
|
+
export function renderUcCore(o) {
|
|
111
|
+
const titleH = o.title ? 40 : 0;
|
|
112
|
+
const actors = o.nodes.filter((n) => n.kind === 'actor');
|
|
113
|
+
const ucs = o.nodes.filter((n) => n.kind === 'uc');
|
|
114
|
+
// 参与者一列(左),用例一行(右)
|
|
115
|
+
const actorW = Math.max(120, ...actors.map((a) => textW(a.label, 13) + 36));
|
|
116
|
+
const ucW = Math.max(150, ...ucs.map((u) => Math.max(textW(u.label, 13) + 64, u.sub ? textW(u.sub, 11) + 64 : 0)));
|
|
117
|
+
let maxY = PAD + titleH;
|
|
118
|
+
actors.forEach((a) => { a.w = actorW; });
|
|
119
|
+
// 用例排成一列,参与者在另一侧 —— 中间留出一条「脊柱」通道走线,
|
|
120
|
+
// 这样同一个参与方连多个用例时,线各走各的,不横穿别人的椭圆。
|
|
121
|
+
const ucColH = ucs.length * (UC_H + UC_ROW_GAP) - UC_ROW_GAP;
|
|
122
|
+
const actorColH = actors.length * (ACTOR_H + ROW_GAP) - ROW_GAP;
|
|
123
|
+
const colH = Math.max(ucColH, actorColH);
|
|
124
|
+
const top = PAD + titleH;
|
|
125
|
+
const ucTop = top + Math.max(0, (colH - ucColH) / 2);
|
|
126
|
+
const actorTop = top + Math.max(0, (colH - actorColH) / 2);
|
|
127
|
+
const ucX = o.actorsRight ? PAD : PAD + actorW + COL_GAP;
|
|
128
|
+
const actorX = o.actorsRight ? PAD + actorW + COL_GAP + ucW + COL_GAP : PAD;
|
|
129
|
+
ucs.forEach((u, i) => {
|
|
130
|
+
u.x = ucX;
|
|
131
|
+
u.y = ucTop + i * (UC_H + UC_ROW_GAP);
|
|
132
|
+
u.w = ucW;
|
|
133
|
+
u.h = UC_H;
|
|
134
|
+
maxY = Math.max(maxY, u.y + u.h);
|
|
135
|
+
});
|
|
136
|
+
actors.forEach((a, i) => {
|
|
137
|
+
a.x = actorX;
|
|
138
|
+
a.y = actorTop + i * (ACTOR_H + ROW_GAP);
|
|
139
|
+
a.w = actorW;
|
|
140
|
+
a.h = ACTOR_H;
|
|
141
|
+
maxY = Math.max(maxY, a.y + a.h);
|
|
142
|
+
});
|
|
143
|
+
// 给了位置的按位置摆(和架构图同一套格子)
|
|
144
|
+
const placed = [...ucs, ...actors];
|
|
145
|
+
const gridNodes = placed.filter((n) => n.grid);
|
|
146
|
+
// 脊柱:参与方和用例之间的空档正中
|
|
147
|
+
const spineX = o.actorsRight
|
|
148
|
+
? ucX + ucW + COL_GAP / 2
|
|
149
|
+
: PAD + actorW + COL_GAP / 2;
|
|
150
|
+
let width = Math.max(320, (o.actorsRight ? actorX + actorW : ucX + ucW + 30) + PAD);
|
|
151
|
+
let height = maxY + PAD;
|
|
152
|
+
if (gridNodes.length) {
|
|
153
|
+
const rows = Math.max(...gridNodes.map((n) => n.grid.row + n.grid.h));
|
|
154
|
+
const cols = Math.max(...gridNodes.map((n) => n.grid.col + n.grid.w));
|
|
155
|
+
const colX = new Array(cols).fill(0);
|
|
156
|
+
const rowY = new Array(rows).fill(0);
|
|
157
|
+
for (const n of gridNodes) {
|
|
158
|
+
colX[n.grid.col] = Math.max(colX[n.grid.col], n.kind === 'actor' ? actorW : ucW);
|
|
159
|
+
rowY[n.grid.row] = Math.max(rowY[n.grid.row], n.kind === 'actor' ? ACTOR_H : UC_H);
|
|
160
|
+
}
|
|
161
|
+
const trackX = [];
|
|
162
|
+
const trackY = [];
|
|
163
|
+
let gx = PAD;
|
|
164
|
+
for (let c = 0; c < cols; c++) {
|
|
165
|
+
trackX[c] = gx;
|
|
166
|
+
gx += colX[c] + COL_GAP;
|
|
167
|
+
}
|
|
168
|
+
let gy = PAD + titleH;
|
|
169
|
+
for (let r = 0; r < rows; r++) {
|
|
170
|
+
trackY[r] = gy;
|
|
171
|
+
gy += rowY[r] + ROW_GAP;
|
|
172
|
+
}
|
|
173
|
+
for (const n of gridNodes) {
|
|
174
|
+
const g = n.grid;
|
|
175
|
+
n.x = trackX[g.col];
|
|
176
|
+
n.y = trackY[g.row];
|
|
177
|
+
n.w = n.kind === 'actor' ? actorW : ucW;
|
|
178
|
+
n.h = n.kind === 'actor' ? ACTOR_H : UC_H;
|
|
179
|
+
width = Math.max(width, n.x + n.w + PAD);
|
|
180
|
+
maxY = Math.max(maxY, n.y + n.h);
|
|
181
|
+
}
|
|
182
|
+
// 没给位置的用例回到用例列;没给位置的参与方留在原处
|
|
183
|
+
for (const n of placed) {
|
|
184
|
+
if (n.grid)
|
|
185
|
+
continue;
|
|
186
|
+
if (n.kind === 'uc')
|
|
187
|
+
n.x = ucX;
|
|
188
|
+
}
|
|
189
|
+
height = Math.max(height, maxY + PAD);
|
|
190
|
+
}
|
|
191
|
+
// 系统边界:把用例框起来(可以有多层)
|
|
192
|
+
let boundarySvg = '';
|
|
193
|
+
for (const b of o.boundaries) {
|
|
194
|
+
const bs = b.ids.map((id) => o.nodes.find((n) => n.id === id)).filter(Boolean);
|
|
195
|
+
if (!bs.length)
|
|
196
|
+
continue;
|
|
197
|
+
const bx = Math.min(...bs.map((x) => x.x)) - 26;
|
|
198
|
+
const by = Math.min(...bs.map((x) => x.y)) - 26;
|
|
199
|
+
const bw = Math.max(...bs.map((x) => x.x + x.w)) + 26 - bx;
|
|
200
|
+
const bh = Math.max(...bs.map((x) => x.y + x.h)) + 26 - by;
|
|
201
|
+
const label = b.label.toUpperCase();
|
|
202
|
+
const lw = textW(label, 10) + b.label.length * 1.2 + 20;
|
|
203
|
+
width = Math.max(width, bx + bw + PAD);
|
|
204
|
+
height = Math.max(height, by + bh + PAD);
|
|
205
|
+
boundarySvg +=
|
|
206
|
+
`<g data-boundary="${esc(b.ids.join(' '))}">` +
|
|
207
|
+
`<rect x="${r2(bx)}" y="${r2(by)}" width="${r2(bw)}" height="${r2(bh)}" rx="14" fill="none" stroke="var(--d-border)" stroke-width="1.3" stroke-dasharray="7 5"/>` +
|
|
208
|
+
`<rect x="${r2(bx + 14)}" y="${r2(by - 9)}" width="${r2(lw)}" height="20" rx="6" fill="var(--d-card)"/>` +
|
|
209
|
+
`<text x="${r2(bx + 14 + lw / 2)}" y="${r2(by + 4)}" text-anchor="middle" font-size="10" font-weight="600" letter-spacing="1.2" fill="var(--d-faint)">${esc(label)}</text>` +
|
|
210
|
+
`</g>`;
|
|
211
|
+
}
|
|
212
|
+
// 连线:参与方 → 脊柱 → 用例,三段正交。同一个参与方连多个用例时,
|
|
213
|
+
// 每条线在参与方那边错开一点、在脊柱上各走各的一段,互不压。
|
|
214
|
+
const byId = new Map(o.nodes.map((n) => [n.id, n]));
|
|
215
|
+
const exitSeen = new Map();
|
|
216
|
+
const edges = [];
|
|
217
|
+
let labelRight = 0; // 标签往右伸出去多少(画布要留出这段)
|
|
218
|
+
for (const e of o.edges) {
|
|
219
|
+
const a = byId.get(e.from);
|
|
220
|
+
const b = byId.get(e.to);
|
|
221
|
+
const stroke = e.dep ? 'var(--d-faint)' : 'var(--d-muted)';
|
|
222
|
+
const dash = e.dep ? ' stroke-dasharray="5 4"' : '';
|
|
223
|
+
const ia = o.interactive ? ` data-from="${esc(e.from)}" data-to="${esc(e.to)}"` : '';
|
|
224
|
+
const n = (exitSeen.get(e.from) ?? 0);
|
|
225
|
+
exitSeen.set(e.from, n + 1);
|
|
226
|
+
let pts;
|
|
227
|
+
let lx = 0;
|
|
228
|
+
let ly = 0;
|
|
229
|
+
// 标签贴在哪:start = 从 lx 往右排,end = 往左排
|
|
230
|
+
let lanchor = 'start';
|
|
231
|
+
if (a.kind === 'actor' && b.kind === 'uc') {
|
|
232
|
+
const ax = o.actorsRight ? a.x - n * 9 : a.x + a.w + n * 9;
|
|
233
|
+
const ay = a.y + 30;
|
|
234
|
+
const bx = o.actorsRight ? b.x + b.w : b.x;
|
|
235
|
+
const by = b.y + b.h / 2;
|
|
236
|
+
pts = [[ax, ay], [spineX, ay], [spineX, by], [bx, by]];
|
|
237
|
+
// 标签贴在用例左边,不压在椭圆上
|
|
238
|
+
lx = bx - 6;
|
|
239
|
+
ly = by;
|
|
240
|
+
lanchor = 'end';
|
|
241
|
+
}
|
|
242
|
+
else if (a.kind === 'uc' && b.kind === 'actor') {
|
|
243
|
+
const ax = o.actorsRight ? a.x : a.x + a.w;
|
|
244
|
+
const ay = a.y + a.h / 2;
|
|
245
|
+
// 参与方在哪一侧,就从哪一侧接线(脊柱在参与方的右边还是左边)
|
|
246
|
+
const bx = o.actorsRight ? b.x - n * 9 : b.x + b.w + n * 9;
|
|
247
|
+
const by = b.y + 30;
|
|
248
|
+
pts = [[ax, ay], [spineX, ay], [spineX, by], [bx, by]];
|
|
249
|
+
lx = bx + 6;
|
|
250
|
+
ly = by;
|
|
251
|
+
lanchor = 'start';
|
|
252
|
+
}
|
|
253
|
+
else {
|
|
254
|
+
// 用例之间的依赖(<<include>>):绕到用例列右边的一条通道上,
|
|
255
|
+
// 不从两个椭圆中间斜穿过去
|
|
256
|
+
const depX = ucX + ucW + 18;
|
|
257
|
+
const ax = a.x + a.w;
|
|
258
|
+
const ay = a.y + a.h / 2;
|
|
259
|
+
const bx = b.x + b.w;
|
|
260
|
+
const by = b.y + b.h / 2;
|
|
261
|
+
pts = [[ax, ay], [depX, ay], [depX, by], [bx, by]];
|
|
262
|
+
// 标签排在通道右边,一点不碰椭圆
|
|
263
|
+
lx = depX + 6;
|
|
264
|
+
ly = (ay + by) / 2;
|
|
265
|
+
lanchor = 'start';
|
|
266
|
+
}
|
|
267
|
+
edges.push(`<path d="${roundedPath(pts, 8)}" fill="none" stroke="${stroke}" stroke-width="1.3"${dash}${ia}/>`);
|
|
268
|
+
if (e.label) {
|
|
269
|
+
const w = textW(e.label, 10.5) + 12;
|
|
270
|
+
const rx = lanchor === 'end' ? lx - w : lx;
|
|
271
|
+
const tx = lx;
|
|
272
|
+
labelRight = Math.max(labelRight, rx + w);
|
|
273
|
+
edges.push(`<rect x="${r2(rx)}" y="${r2(ly - 15)}" width="${r2(w)}" height="17" rx="5" fill="var(--d-card)" stroke="var(--d-border)" stroke-width="1"/>`, `<text x="${r2(tx)}" y="${r2(ly - 3)}" text-anchor="${lanchor}" font-size="10.5" fill="var(--d-text)">${esc(e.label)}</text>`);
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
width = Math.max(width, labelRight + PAD);
|
|
277
|
+
const titleSvg = o.title
|
|
278
|
+
? `<text x="${PAD}" y="${PAD + 16}" font-size="18" font-weight="600" letter-spacing="-0.02em" fill="var(--d-ink)">${esc(o.title)}</text>`
|
|
279
|
+
: '';
|
|
280
|
+
const nodes = o.nodes.map((n) => n.kind === 'actor'
|
|
281
|
+
? drawActor(n, 'var(--d-muted)', o.interactive)
|
|
282
|
+
: drawUseCase(n, 'var(--d-s2)', o.interactive)).join('');
|
|
283
|
+
const spec = { type: 'uc', title: o.title, nodes: o.nodes, edges: o.edges };
|
|
284
|
+
const svg = svgDoc(width, height, 'uc', o.version, o.title ?? `use case diagram, ${o.nodes.length} elements`, spec, o.skin, titleSvg + boundarySvg + edges.join('') + nodes, o.tagQuery, 'uc');
|
|
285
|
+
return { svg, version: o.version, cacheControl: o.cacheControl };
|
|
286
|
+
}
|
|
287
|
+
/**
|
|
288
|
+
* `/draw/uc` 入口:GET ?n=…&e=…&b=…
|
|
289
|
+
*/
|
|
290
|
+
export function renderUcFromUrl(url, interactive = false) {
|
|
291
|
+
const params = url.searchParams;
|
|
292
|
+
const nRaw = params.getAll('n');
|
|
293
|
+
if (!nRaw.length) {
|
|
294
|
+
throw new ApiError(400, `at least one element is required. Example: /draw/uc?n=caller;actor;Your app&n=uc1;uc;Render a chart&e=caller;uc1`);
|
|
295
|
+
}
|
|
296
|
+
const nodes = parseNodes(nRaw);
|
|
297
|
+
const ids = new Set(nodes.map((n) => n.id));
|
|
298
|
+
if (ids.size !== nodes.length)
|
|
299
|
+
throw new ApiError(400, 'duplicate element id');
|
|
300
|
+
const edges = parseEdges(params.getAll('e'), ids);
|
|
301
|
+
const boundaries = parseBoundaries(params.getAll('b'), ids);
|
|
302
|
+
const v = parseInt(params.get('v') ?? '1', 10) || 1;
|
|
303
|
+
const side = (params.get('actors') ?? 'left').toLowerCase();
|
|
304
|
+
if (side !== 'left' && side !== 'right') {
|
|
305
|
+
throw new ApiError(400, `"actors" must be "left" (default) or "right". Got: ${JSON.stringify(side)}`);
|
|
306
|
+
}
|
|
307
|
+
const skin = resolveSkin('sankey', params.get('t'), schemeParam(params));
|
|
308
|
+
return renderUcCore({
|
|
309
|
+
nodes, edges, boundaries, tagQuery: url.search,
|
|
310
|
+
actorsRight: side === 'right',
|
|
311
|
+
title: params.get('title')?.trim() || undefined,
|
|
312
|
+
interactive,
|
|
313
|
+
version: v,
|
|
314
|
+
cacheControl: 'public, max-age=300',
|
|
315
|
+
skin,
|
|
316
|
+
minW: clampInt(params, 'w', 0, 200, 2400),
|
|
317
|
+
minH: clampInt(params, 'h', 0, 140, 2400),
|
|
318
|
+
});
|
|
319
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
export interface FooterItem {
|
|
2
|
+
/** 小标题 */
|
|
3
|
+
label: string;
|
|
4
|
+
/** 值(跟在 label 后面) */
|
|
5
|
+
value?: string;
|
|
6
|
+
/** 值前面的色点 */
|
|
7
|
+
color?: string;
|
|
8
|
+
}
|
|
9
|
+
export interface TipRow {
|
|
10
|
+
/** 主文案 */
|
|
11
|
+
text: string;
|
|
12
|
+
/** 右边的小字(时间、日期) */
|
|
13
|
+
sub?: string;
|
|
14
|
+
/** 前面的小圆点颜色 */
|
|
15
|
+
color?: string;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* 页头:标题那一行的右边,挂一句摘要(多少个日程、什么口径)。
|
|
19
|
+
*/
|
|
20
|
+
export declare function headerMeta(meta: string | undefined, x: number, y: number, width: number): string;
|
|
21
|
+
/**
|
|
22
|
+
* 页脚:一行小字。
|
|
23
|
+
* 左边若干项(中间用「·」隔开),右边一句备注(来源、口径)。
|
|
24
|
+
*/
|
|
25
|
+
export declare function footerUnit(items: FooterItem[], note: string | undefined, x: number, y: number, width: number): string;
|
|
26
|
+
/**
|
|
27
|
+
* 提示单元:主体里塞不下、但又不该丢掉的明细 —— 列成一块小面板。
|
|
28
|
+
* 两列排(条目多的时候不至于拉得太高)。
|
|
29
|
+
*/
|
|
30
|
+
export declare function tipUnit(rows: TipRow[], x: number, y: number, width: number, title?: string): string;
|
|
31
|
+
/** 提示单元要占多高(画之前先问一遍,好留位置) */
|
|
32
|
+
export declare function tipHeight(rows: number, width: number, hasTitle?: boolean): number;
|