@x-cmd/draw 0.4.6 → 0.5.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 +3 -3
- package/dist/client.d.ts +42 -0
- package/dist/client.js +267 -0
- package/dist/core.d.ts +86 -0
- package/dist/core.js +132 -0
- package/dist/globe.d.ts +4 -0
- package/dist/globe.js +6 -0
- package/dist/layout/cluster.d.ts +2 -0
- package/dist/layout/cluster.js +228 -0
- package/dist/layout/index.d.ts +2 -0
- package/dist/layout/index.js +6 -0
- package/dist/layout/layered.d.ts +51 -0
- package/dist/layout/layered.js +433 -0
- package/dist/layout/portsize.d.ts +18 -0
- package/dist/layout/portsize.js +34 -0
- package/dist/lib.d.ts +17 -4
- package/dist/lib.js +20 -4
- package/dist/node/cmd.d.ts +1 -0
- package/dist/node/cmd.js +3 -0
- package/dist/render/abc-parse.d.ts +75 -0
- package/dist/render/abc-parse.js +345 -0
- package/dist/render/abcjs.d.ts +10 -0
- package/dist/render/abcjs.js +90 -0
- package/dist/render/anno.d.ts +48 -2
- package/dist/render/anno.js +171 -17
- package/dist/render/ansi.d.ts +15 -0
- package/dist/render/ansi.js +142 -0
- package/dist/render/arch.js +8 -3
- package/dist/render/arch3d.d.ts +31 -0
- package/dist/render/arch3d.js +294 -0
- package/dist/render/archmap.js +2 -2
- package/dist/render/area.js +42 -11
- package/dist/render/bar-grid.js +1 -1
- package/dist/render/bar-grouped.js +25 -7
- package/dist/render/bar-stacked.js +22 -6
- package/dist/render/bar.js +27 -6
- package/dist/render/block.d.ts +56 -0
- package/dist/render/block.js +361 -0
- package/dist/render/butterfly.js +4 -1
- package/dist/render/calendar.js +49 -14
- package/dist/render/center.d.ts +26 -0
- package/dist/render/center.js +108 -0
- package/dist/render/chem.d.ts +22 -0
- package/dist/render/chem.js +205 -0
- package/dist/render/chord.d.ts +17 -0
- package/dist/render/chord.js +141 -0
- package/dist/render/combo.js +7 -7
- package/dist/render/compass.js +59 -13
- package/dist/render/echarts-ssr.d.ts +36 -2
- package/dist/render/echarts-ssr.js +77 -18
- package/dist/render/gauge.js +17 -9
- package/dist/render/gitgraph.d.ts +53 -0
- package/dist/render/gitgraph.js +324 -0
- package/dist/render/globe-areas.d.ts +21 -0
- package/dist/render/globe-areas.js +40 -0
- package/dist/render/globe-earth.d.ts +78 -0
- package/dist/render/globe-earth.js +464 -0
- package/dist/render/globe-keys.d.ts +34 -0
- package/dist/render/globe-keys.js +71 -0
- package/dist/render/globe-proj.d.ts +102 -0
- package/dist/render/globe-proj.js +332 -0
- package/dist/render/globe-regions.d.ts +23 -0
- package/dist/render/globe-regions.js +60 -0
- package/dist/render/globe.d.ts +15 -0
- package/dist/render/globe.js +306 -0
- package/dist/render/globe3d.d.ts +113 -0
- package/dist/render/globe3d.js +285 -0
- package/dist/render/hbar-spec.js +23 -10
- package/dist/render/hbar.js +30 -11
- package/dist/render/jianpu.d.ts +10 -0
- package/dist/render/jianpu.js +190 -0
- package/dist/render/journey.d.ts +54 -0
- package/dist/render/journey.js +277 -0
- package/dist/render/kanban.d.ts +50 -0
- package/dist/render/kanban.js +240 -0
- package/dist/render/kinds.js +19 -0
- package/dist/render/line-multi.js +27 -8
- package/dist/render/line.js +32 -14
- package/dist/render/maps.js +4 -2
- package/dist/render/mermaid/block.d.ts +2 -0
- package/dist/render/mermaid/block.js +256 -0
- package/dist/render/mermaid/c4.d.ts +3 -0
- package/dist/render/mermaid/c4.js +165 -0
- package/dist/render/mermaid/class.d.ts +2 -0
- package/dist/render/mermaid/class.js +185 -0
- package/dist/render/mermaid/common.d.ts +34 -0
- package/dist/render/mermaid/common.js +81 -0
- package/dist/render/mermaid/erd.d.ts +2 -0
- package/dist/render/mermaid/erd.js +103 -0
- package/dist/render/mermaid/gitgraph.d.ts +2 -0
- package/dist/render/mermaid/gitgraph.js +139 -0
- package/dist/render/mermaid/journey.d.ts +7 -0
- package/dist/render/mermaid/journey.js +68 -0
- package/dist/render/mermaid/kanban.d.ts +2 -0
- package/dist/render/mermaid/kanban.js +86 -0
- package/dist/render/mermaid/mindmap.d.ts +7 -0
- package/dist/render/mermaid/mindmap.js +74 -0
- package/dist/render/mermaid/packet.d.ts +2 -0
- package/dist/render/mermaid/packet.js +35 -0
- package/dist/render/mermaid/pie.d.ts +7 -0
- package/dist/render/mermaid/pie.js +58 -0
- package/dist/render/mermaid/quadrant.d.ts +8 -0
- package/dist/render/mermaid/quadrant.js +137 -0
- package/dist/render/mermaid/radar.d.ts +8 -0
- package/dist/render/mermaid/radar.js +69 -0
- package/dist/render/mermaid/requirement.d.ts +2 -0
- package/dist/render/mermaid/requirement.js +100 -0
- package/dist/render/mermaid/sankey.d.ts +7 -0
- package/dist/render/mermaid/sankey.js +54 -0
- package/dist/render/mermaid/seq.d.ts +2 -0
- package/dist/render/mermaid/seq.js +147 -0
- package/dist/render/mermaid/state.d.ts +2 -0
- package/dist/render/mermaid/state.js +168 -0
- package/dist/render/mermaid/timeline.d.ts +7 -0
- package/dist/render/mermaid/timeline.js +63 -0
- package/dist/render/mermaid/xychart.d.ts +7 -0
- package/dist/render/mermaid/xychart.js +94 -0
- package/dist/render/mermaid.d.ts +22 -4
- package/dist/render/mermaid.js +173 -7
- package/dist/render/mindmap.js +12 -2
- package/dist/render/nomnoml.d.ts +8 -0
- package/dist/render/nomnoml.js +47 -0
- package/dist/render/packet.d.ts +39 -0
- package/dist/render/packet.js +232 -0
- package/dist/render/params-dispatch.d.ts +20 -0
- package/dist/render/params-dispatch.js +192 -0
- package/dist/render/pie.js +29 -22
- package/dist/render/quadrant.js +38 -9
- package/dist/render/query.d.ts +11 -1
- package/dist/render/query.js +92 -16
- package/dist/render/radar.js +7 -6
- package/dist/render/requirement.d.ts +61 -0
- package/dist/render/requirement.js +355 -0
- package/dist/render/sankey.js +4 -4
- package/dist/render/scatter.js +25 -9
- package/dist/render/scene3d.d.ts +188 -0
- package/dist/render/scene3d.js +433 -0
- package/dist/render/seq.js +13 -8
- package/dist/render/simplify.d.ts +12 -0
- package/dist/render/simplify.js +105 -0
- package/dist/render/source-theme.d.ts +104 -0
- package/dist/render/source-theme.js +261 -0
- package/dist/render/svg.d.ts +81 -1
- package/dist/render/svg.js +259 -2
- package/dist/render/svgdom.d.ts +74 -0
- package/dist/render/svgdom.js +198 -0
- package/dist/render/timeline.d.ts +54 -0
- package/dist/render/timeline.js +290 -0
- package/dist/render/tty.d.ts +17 -0
- package/dist/render/tty.js +173 -0
- package/dist/render/ttycmd.d.ts +7 -0
- package/dist/render/ttycmd.js +152 -0
- package/dist/render/vendor/au.js +1 -1
- package/dist/render/vendor/br.js +1 -1
- package/dist/render/vendor/china-counties.d.ts +32 -0
- package/dist/render/vendor/china-counties.js +8 -0
- package/dist/render/vendor/china-provinces.d.ts +16 -0
- package/dist/render/vendor/china-provinces.js +8 -0
- package/dist/render/vendor/china.js +1 -1
- package/dist/render/vendor/country-aliases.d.ts +207 -0
- package/dist/render/vendor/country-aliases.js +7 -0
- package/dist/render/vendor/de.js +1 -1
- package/dist/render/vendor/eu.js +1 -1
- package/dist/render/vendor/japan.js +1 -1
- package/dist/render/vendor/kr.js +1 -1
- package/dist/render/vendor/world-geo.js +1 -1
- package/dist/render/vendor/world-ne.d.ts +18 -0
- package/dist/render/vendor/world-ne.js +8 -0
- package/dist/render/vendor/world.js +1 -1
- package/dist/render/vexflow.d.ts +10 -0
- package/dist/render/vexflow.js +189 -0
- package/dist/render/wavedrom.d.ts +14 -0
- package/dist/render/wavedrom.js +113 -0
- package/dist/source.d.ts +20 -0
- package/dist/source.js +27 -0
- package/dist/specs/base.js +9 -4
- package/dist/specs/combo.d.ts +1 -0
- package/dist/specs/combo.js +8 -1
- package/dist/specs/gauge.d.ts +1 -0
- package/dist/specs/gauge.js +14 -2
- package/dist/specs/multi.d.ts +3 -0
- package/dist/specs/multi.js +29 -3
- package/dist/specs/quadrant.js +5 -4
- package/dist/specs/scatter.d.ts +1 -0
- package/dist/specs/scatter.js +7 -0
- package/dist/styles/bar.js +3 -0
- package/dist/styles/baseline.d.ts +47 -0
- package/dist/styles/baseline.js +48 -0
- package/dist/styles/hbar.js +3 -0
- package/dist/styles/index.d.ts +1 -1
- package/dist/styles/index.js +16 -4
- package/dist/styles/line.js +9 -0
- package/dist/styles/pie.js +4 -0
- package/dist/styles/sankey.js +4 -0
- package/dist/styles/skins.d.ts +23 -0
- package/dist/styles/skins.js +349 -0
- package/dist/styles/types.d.ts +29 -1
- package/dist/styles/types.js +30 -6
- package/dist/world-data.d.ts +12 -0
- package/dist/world-data.js +192 -0
- package/package.json +38 -5
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
export interface Vec3 {
|
|
2
|
+
x: number;
|
|
3
|
+
y: number;
|
|
4
|
+
z: number;
|
|
5
|
+
}
|
|
6
|
+
/** 相机:绕场景转 */
|
|
7
|
+
export interface Camera {
|
|
8
|
+
/** 水平角(度)—— 0 = 正对着 */
|
|
9
|
+
yaw: number;
|
|
10
|
+
/** 俯仰角(度)—— 负数往下看 */
|
|
11
|
+
pitch: number;
|
|
12
|
+
/** 相机离场景中心的距离 */
|
|
13
|
+
dist: number;
|
|
14
|
+
/** 焦距(像素)—— 越大越平(透视越弱) */
|
|
15
|
+
focal: number;
|
|
16
|
+
}
|
|
17
|
+
/** 默认相机:等轴测那一眼(俯 30°,转 30°) */
|
|
18
|
+
export declare const DEFAULT_CAMERA: Camera;
|
|
19
|
+
export interface SceneNode {
|
|
20
|
+
id: string;
|
|
21
|
+
label: string;
|
|
22
|
+
sub?: string;
|
|
23
|
+
/** 语义色(#rrggbb) */
|
|
24
|
+
color: string;
|
|
25
|
+
/** 图标(data URI)—— 摆在块上面,像参考图里那些浮着的图标 */
|
|
26
|
+
icon?: string;
|
|
27
|
+
/** 板砖中心 */
|
|
28
|
+
p: Vec3;
|
|
29
|
+
/** 板砖尺寸:沿 x / 沿 y / 沿 z */
|
|
30
|
+
w: number;
|
|
31
|
+
d: number;
|
|
32
|
+
h: number;
|
|
33
|
+
/** 层:0=源 1=中 2=汇 */
|
|
34
|
+
tier: number;
|
|
35
|
+
}
|
|
36
|
+
export interface SceneEdge {
|
|
37
|
+
from: string;
|
|
38
|
+
to: string;
|
|
39
|
+
label?: string;
|
|
40
|
+
/** 三维折点 */
|
|
41
|
+
pts: Vec3[];
|
|
42
|
+
}
|
|
43
|
+
export interface SceneGroup {
|
|
44
|
+
label: string;
|
|
45
|
+
ids: string[];
|
|
46
|
+
/** 罩住成员的包围盒 */
|
|
47
|
+
min: Vec3;
|
|
48
|
+
max: Vec3;
|
|
49
|
+
}
|
|
50
|
+
export interface SceneTier {
|
|
51
|
+
/** 0=源 1=中 2=汇 */
|
|
52
|
+
tier: number;
|
|
53
|
+
z: number;
|
|
54
|
+
/** 这一层的板台范围 */
|
|
55
|
+
min: Vec3;
|
|
56
|
+
max: Vec3;
|
|
57
|
+
}
|
|
58
|
+
export interface Scene {
|
|
59
|
+
nodes: SceneNode[];
|
|
60
|
+
edges: SceneEdge[];
|
|
61
|
+
groups: SceneGroup[];
|
|
62
|
+
tiers: SceneTier[];
|
|
63
|
+
/** 地面网格的范围 */
|
|
64
|
+
ground: {
|
|
65
|
+
min: Vec3;
|
|
66
|
+
max: Vec3;
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
export interface SceneInput {
|
|
70
|
+
nodes: {
|
|
71
|
+
id: string;
|
|
72
|
+
label: string;
|
|
73
|
+
sub?: string;
|
|
74
|
+
color: string;
|
|
75
|
+
icon?: string;
|
|
76
|
+
w: number;
|
|
77
|
+
d: number;
|
|
78
|
+
h: number;
|
|
79
|
+
}[];
|
|
80
|
+
edges: {
|
|
81
|
+
from: string;
|
|
82
|
+
to: string;
|
|
83
|
+
label?: string;
|
|
84
|
+
}[];
|
|
85
|
+
groups: {
|
|
86
|
+
label: string;
|
|
87
|
+
ids: string[];
|
|
88
|
+
}[];
|
|
89
|
+
/** 层与层之间的高度 */
|
|
90
|
+
tierGap?: number;
|
|
91
|
+
/** 板砖的厚度 */
|
|
92
|
+
slabH?: number;
|
|
93
|
+
/** 层内的间距 */
|
|
94
|
+
gapX?: number;
|
|
95
|
+
gapY?: number;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* 摆场景:分层 → 层内排 → 落到三维坐标。
|
|
99
|
+
*/
|
|
100
|
+
export declare function buildScene(input: SceneInput): Scene;
|
|
101
|
+
interface Basis {
|
|
102
|
+
cam: Vec3;
|
|
103
|
+
r: Vec3;
|
|
104
|
+
u: Vec3;
|
|
105
|
+
f: Vec3;
|
|
106
|
+
}
|
|
107
|
+
/** 相机的三个基向量:右、上、前(视线方向) */
|
|
108
|
+
export declare function cameraBasis(cam: Camera): Basis;
|
|
109
|
+
/** 世界坐标 → 屏幕坐标(深度 = 离相机多远,用来排前后) */
|
|
110
|
+
export declare function project(p: Vec3, basis: Basis, focal: number): {
|
|
111
|
+
x: number;
|
|
112
|
+
y: number;
|
|
113
|
+
depth: number;
|
|
114
|
+
};
|
|
115
|
+
export interface ProjNode {
|
|
116
|
+
id: string;
|
|
117
|
+
/** 顶面 */
|
|
118
|
+
top: [number, number][];
|
|
119
|
+
/** 图标摆在哪儿(顶面中心往上飘一点) */
|
|
120
|
+
icon: {
|
|
121
|
+
x: number;
|
|
122
|
+
y: number;
|
|
123
|
+
} | null;
|
|
124
|
+
/** 顶面朝不朝相机(从下往上看的时候该藏起来) */
|
|
125
|
+
topVis: boolean;
|
|
126
|
+
/** 底面(从下往上看的时候露出来的那一面) */
|
|
127
|
+
bottom: [number, number][];
|
|
128
|
+
/** 落在地上的影子(块底那个面)—— 有了影子才看得出块是浮着的 */
|
|
129
|
+
shadow: [number, number][];
|
|
130
|
+
/** 四个侧面 + 哪些朝着相机 */
|
|
131
|
+
sides: {
|
|
132
|
+
pts: [number, number][];
|
|
133
|
+
vis: boolean;
|
|
134
|
+
}[];
|
|
135
|
+
/** 标签落点 */
|
|
136
|
+
lx: number;
|
|
137
|
+
ly: number;
|
|
138
|
+
depth: number;
|
|
139
|
+
}
|
|
140
|
+
export interface ProjEdge {
|
|
141
|
+
from: string;
|
|
142
|
+
to: string;
|
|
143
|
+
label?: string;
|
|
144
|
+
pts: [number, number][];
|
|
145
|
+
lx: number;
|
|
146
|
+
ly: number;
|
|
147
|
+
depth: number;
|
|
148
|
+
}
|
|
149
|
+
export interface ProjGroup {
|
|
150
|
+
label: string;
|
|
151
|
+
ids: string[];
|
|
152
|
+
/** 盒子的十二条棱 */
|
|
153
|
+
lines: [number, number][][];
|
|
154
|
+
lx: number;
|
|
155
|
+
ly: number;
|
|
156
|
+
depth: number;
|
|
157
|
+
}
|
|
158
|
+
export interface ProjTier {
|
|
159
|
+
tier: number;
|
|
160
|
+
/** 板台的四个角(上面) */
|
|
161
|
+
pts: [number, number][];
|
|
162
|
+
/** 板台的两个侧面(有厚度才像块板) */
|
|
163
|
+
sides: [number, number][][];
|
|
164
|
+
/** 板台多厚 */
|
|
165
|
+
thick: number;
|
|
166
|
+
/** 层名挂在哪儿(板台最靠前的那个角下面) */
|
|
167
|
+
lx: number;
|
|
168
|
+
ly: number;
|
|
169
|
+
depth: number;
|
|
170
|
+
}
|
|
171
|
+
export interface ProjScene {
|
|
172
|
+
nodes: ProjNode[];
|
|
173
|
+
edges: ProjEdge[];
|
|
174
|
+
groups: ProjGroup[];
|
|
175
|
+
tiers: ProjTier[];
|
|
176
|
+
/** 地面的网格线 */
|
|
177
|
+
grid: [number, number][][];
|
|
178
|
+
/** 画布范围(投影后) */
|
|
179
|
+
bbox: {
|
|
180
|
+
x: number;
|
|
181
|
+
y: number;
|
|
182
|
+
w: number;
|
|
183
|
+
h: number;
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
/** 把整个场景投影到屏幕上 */
|
|
187
|
+
export declare function projectScene(scene: Scene, cam: Camera): ProjScene;
|
|
188
|
+
export {};
|
|
@@ -0,0 +1,433 @@
|
|
|
1
|
+
// 三维场景:结构图的 3D 版本(arch3d)。
|
|
2
|
+
//
|
|
3
|
+
// 服务端(出静态图)与浏览器端(能转)共用这一份 —— 投影公式只有一处,
|
|
4
|
+
// 两边算出来的画面才是一张。
|
|
5
|
+
//
|
|
6
|
+
// ── 分层怎么定义 ──────────────────────────────────────────────────
|
|
7
|
+
// 3D 场景的高度轴只表达**一件事**:流到哪儿了。所以只有三层:
|
|
8
|
+
//
|
|
9
|
+
// 顶层(源) —— 没有入边的节点:入口、用户、请求
|
|
10
|
+
// 中层 —— 两头都有边的节点:平台、服务
|
|
11
|
+
// 底层(汇) —— 没有出边的节点:数据、资源
|
|
12
|
+
//
|
|
13
|
+
// 层的算法:去掉环上的边(回边)后按最长路径分层 —— 源在前,汇在后。
|
|
14
|
+
// 一个连通分量单独算(分量之间不相通,层号不能接起来),
|
|
15
|
+
// 分量内:第一层是顶层,最后一层是底层,中间的都是中层。
|
|
16
|
+
// 整个分量只有一层(孤零零一个节点)→ 算中层(没有流向可言)。
|
|
17
|
+
//
|
|
18
|
+
// 为什么不用「层号」而用「源/中/汇」:层号可以有很多(五层六层),
|
|
19
|
+
// 但 3D 场景里高度轴最多表达三层 —— 再多就分不清谁是谁了。
|
|
20
|
+
//
|
|
21
|
+
// ── 一层里怎么排 ──────────────────────────────────────────────────
|
|
22
|
+
// 一层之内用分层引擎再排一遍(只算层内的边):横向还是「源在左、汇在右」。
|
|
23
|
+
// 于是整张图读下来是:上面一层往下一层流,层内从左往右流。
|
|
24
|
+
//
|
|
25
|
+
// ── 3D 坐标 ──────────────────────────────────────────────────────
|
|
26
|
+
// x 向右、y 向里(纵深)、z 向上。节点是一块板砖(有厚度),浮在自己那层的高度上。
|
|
27
|
+
import { layeredCore } from '../layout/layered.js';
|
|
28
|
+
/** 默认相机:等轴测那一眼(俯 30°,转 30°) */
|
|
29
|
+
export const DEFAULT_CAMERA = { yaw: 32, pitch: -38, dist: 1400, focal: 1500 };
|
|
30
|
+
/** 层与层的高度:底 0、中 tierGap、顶 2*tierGap */
|
|
31
|
+
const TIER_Z = [2, 1, 0];
|
|
32
|
+
/**
|
|
33
|
+
* 摆场景:分层 → 层内排 → 落到三维坐标。
|
|
34
|
+
*/
|
|
35
|
+
export function buildScene(input) {
|
|
36
|
+
const tierGap = input.tierGap ?? 210;
|
|
37
|
+
const slabH = input.slabH ?? 26;
|
|
38
|
+
const gapX = input.gapX ?? 90;
|
|
39
|
+
const gapY = input.gapY ?? 70;
|
|
40
|
+
// 1. 层:每个连通分量单独分层(去环 → 最长路径)
|
|
41
|
+
const byId = new Map(input.nodes.map((n) => [n.id, n]));
|
|
42
|
+
const all = layeredCore({
|
|
43
|
+
nodes: input.nodes.map((n) => ({ id: n.id, w: n.w, h: n.d })),
|
|
44
|
+
edges: input.edges.map((e) => ({ from: e.from, to: e.to })),
|
|
45
|
+
dir: 'LR',
|
|
46
|
+
layerGap: gapX,
|
|
47
|
+
nodeGap: gapY,
|
|
48
|
+
pad: 0,
|
|
49
|
+
});
|
|
50
|
+
/** 节点 → 层(0=源 1=中 2=汇) */
|
|
51
|
+
const tierOf = new Map();
|
|
52
|
+
for (const comp of all.compLayers) {
|
|
53
|
+
const last = comp.length - 1;
|
|
54
|
+
comp.forEach((layer, r) => {
|
|
55
|
+
const tier = comp.length === 1 ? 1 : r === 0 ? 0 : r === last ? 2 : 1;
|
|
56
|
+
for (const id of layer)
|
|
57
|
+
tierOf.set(id, tier);
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
// 2. 层内再排一遍(只算层内的边)—— 层内保持「源在左、汇在右」
|
|
61
|
+
const byTier = new Map();
|
|
62
|
+
for (const n of input.nodes) {
|
|
63
|
+
const t = tierOf.get(n.id) ?? 1;
|
|
64
|
+
byTier.set(t, [...(byTier.get(t) ?? []), n.id]);
|
|
65
|
+
}
|
|
66
|
+
const pos = new Map();
|
|
67
|
+
for (const [tier, ids] of byTier) {
|
|
68
|
+
const inTier = new Set(ids);
|
|
69
|
+
const res = layeredCore({
|
|
70
|
+
nodes: ids.map((id) => ({ id, w: byId.get(id).w, h: byId.get(id).d })),
|
|
71
|
+
edges: input.edges.filter((e) => inTier.has(e.from) && inTier.has(e.to)).map((e) => ({ from: e.from, to: e.to })),
|
|
72
|
+
dir: 'LR',
|
|
73
|
+
layerGap: gapX,
|
|
74
|
+
nodeGap: gapY,
|
|
75
|
+
pad: 0,
|
|
76
|
+
});
|
|
77
|
+
// 每层各自居中 —— 三层叠起来才正
|
|
78
|
+
let minX = Infinity;
|
|
79
|
+
let maxX = -Infinity;
|
|
80
|
+
let minY = Infinity;
|
|
81
|
+
let maxY = -Infinity;
|
|
82
|
+
for (const id of ids) {
|
|
83
|
+
const b = res.boxes.get(id);
|
|
84
|
+
if (!b)
|
|
85
|
+
continue;
|
|
86
|
+
minX = Math.min(minX, b.x);
|
|
87
|
+
maxX = Math.max(maxX, b.x + b.w);
|
|
88
|
+
minY = Math.min(minY, b.y);
|
|
89
|
+
maxY = Math.max(maxY, b.y + b.h);
|
|
90
|
+
}
|
|
91
|
+
const cx = (minX + maxX) / 2;
|
|
92
|
+
const cy = (minY + maxY) / 2;
|
|
93
|
+
for (const id of ids) {
|
|
94
|
+
const b = res.boxes.get(id);
|
|
95
|
+
if (!b)
|
|
96
|
+
continue;
|
|
97
|
+
pos.set(id, { x: b.x + b.w / 2 - cx, y: b.y + b.h / 2 - cy });
|
|
98
|
+
}
|
|
99
|
+
void tier;
|
|
100
|
+
}
|
|
101
|
+
// 3. 三维坐标:层定高度,层内排好的位置定平面
|
|
102
|
+
const nodes = input.nodes.map((n) => {
|
|
103
|
+
const tier = tierOf.get(n.id) ?? 1;
|
|
104
|
+
const p = pos.get(n.id) ?? { x: 0, y: 0 };
|
|
105
|
+
return {
|
|
106
|
+
id: n.id,
|
|
107
|
+
label: n.label,
|
|
108
|
+
sub: n.sub,
|
|
109
|
+
color: n.color,
|
|
110
|
+
icon: n.icon,
|
|
111
|
+
p: { x: p.x, y: p.y, z: TIER_Z[tier] * tierGap + slabH / 2 },
|
|
112
|
+
w: n.w,
|
|
113
|
+
d: n.d,
|
|
114
|
+
h: slabH,
|
|
115
|
+
tier,
|
|
116
|
+
};
|
|
117
|
+
});
|
|
118
|
+
const nodeOf = new Map(nodes.map((n) => [n.id, n]));
|
|
119
|
+
// 4. 边:从板砖边到板砖边(直线,3D 里就是一条空间直线)
|
|
120
|
+
const edges = [];
|
|
121
|
+
for (const e of input.edges) {
|
|
122
|
+
const a = nodeOf.get(e.from);
|
|
123
|
+
const b = nodeOf.get(e.to);
|
|
124
|
+
if (!a || !b)
|
|
125
|
+
continue;
|
|
126
|
+
edges.push({ from: e.from, to: e.to, label: e.label, pts: trim(a, b) });
|
|
127
|
+
}
|
|
128
|
+
// 5. 分组:罩住成员的半透明盒子
|
|
129
|
+
const groups = [];
|
|
130
|
+
for (const g of input.groups) {
|
|
131
|
+
const members = g.ids.map((id) => nodeOf.get(id)).filter(Boolean);
|
|
132
|
+
if (!members.length)
|
|
133
|
+
continue;
|
|
134
|
+
const min = { x: Infinity, y: Infinity, z: Infinity };
|
|
135
|
+
const max = { x: -Infinity, y: -Infinity, z: -Infinity };
|
|
136
|
+
for (const m of members) {
|
|
137
|
+
min.x = Math.min(min.x, m.p.x - m.w / 2);
|
|
138
|
+
max.x = Math.max(max.x, m.p.x + m.w / 2);
|
|
139
|
+
min.y = Math.min(min.y, m.p.y - m.d / 2);
|
|
140
|
+
max.y = Math.max(max.y, m.p.y + m.d / 2);
|
|
141
|
+
min.z = Math.min(min.z, m.p.z - m.h / 2);
|
|
142
|
+
max.z = Math.max(max.z, m.p.z + m.h / 2);
|
|
143
|
+
}
|
|
144
|
+
groups.push({ label: g.label, ids: g.ids, min, max });
|
|
145
|
+
}
|
|
146
|
+
// 6. 每层的板台(那一层的地坪)
|
|
147
|
+
const tiers = [];
|
|
148
|
+
for (const tier of [0, 1, 2]) {
|
|
149
|
+
const members = nodes.filter((n) => n.tier === tier);
|
|
150
|
+
if (!members.length)
|
|
151
|
+
continue;
|
|
152
|
+
const min = { x: Infinity, y: Infinity, z: Infinity };
|
|
153
|
+
const max = { x: -Infinity, y: -Infinity, z: -Infinity };
|
|
154
|
+
for (const m of members) {
|
|
155
|
+
min.x = Math.min(min.x, m.p.x - m.w / 2);
|
|
156
|
+
max.x = Math.max(max.x, m.p.x + m.w / 2);
|
|
157
|
+
min.y = Math.min(min.y, m.p.y - m.d / 2);
|
|
158
|
+
max.y = Math.max(max.y, m.p.y + m.d / 2);
|
|
159
|
+
min.z = Math.min(min.z, m.p.z - m.h / 2);
|
|
160
|
+
max.z = Math.max(max.z, m.p.z + m.h / 2);
|
|
161
|
+
}
|
|
162
|
+
tiers.push({ tier, z: TIER_Z[tier] * tierGap, min, max });
|
|
163
|
+
}
|
|
164
|
+
// 7. 地面:比最底那层大一圈
|
|
165
|
+
const gz = tiers.length ? Math.min(...tiers.map((t) => t.z)) : 0;
|
|
166
|
+
let gMinX = Infinity, gMaxX = -Infinity, gMinY = Infinity, gMaxY = -Infinity;
|
|
167
|
+
for (const t of tiers) {
|
|
168
|
+
gMinX = Math.min(gMinX, t.min.x);
|
|
169
|
+
gMaxX = Math.max(gMaxX, t.max.x);
|
|
170
|
+
gMinY = Math.min(gMinY, t.min.y);
|
|
171
|
+
gMaxY = Math.max(gMaxY, t.max.y);
|
|
172
|
+
}
|
|
173
|
+
if (!Number.isFinite(gMinX)) {
|
|
174
|
+
gMinX = gMaxX = gMinY = gMaxY = 0;
|
|
175
|
+
}
|
|
176
|
+
const pad = 70;
|
|
177
|
+
const ground = {
|
|
178
|
+
min: { x: gMinX - pad, y: gMinY - pad, z: gz },
|
|
179
|
+
max: { x: gMaxX + pad, y: gMaxY + pad, z: gz },
|
|
180
|
+
};
|
|
181
|
+
return { nodes, edges, groups, tiers, ground };
|
|
182
|
+
}
|
|
183
|
+
/** 边的两个端点:从板砖的边出发(不穿进板砖里) */
|
|
184
|
+
function trim(a, b) {
|
|
185
|
+
const dx = b.p.x - a.p.x;
|
|
186
|
+
const dy = b.p.y - a.p.y;
|
|
187
|
+
const dz = b.p.z - a.p.z;
|
|
188
|
+
const len = Math.hypot(dx, dy, dz) || 1;
|
|
189
|
+
const ux = dx / len;
|
|
190
|
+
const uy = dy / len;
|
|
191
|
+
const uz = dz / len;
|
|
192
|
+
const ra = Math.max(a.w, a.d, a.h) / 2;
|
|
193
|
+
const rb = Math.max(b.w, b.d, b.h) / 2;
|
|
194
|
+
return [
|
|
195
|
+
{ x: a.p.x + ux * ra, y: a.p.y + uy * ra, z: a.p.z + uz * ra },
|
|
196
|
+
{ x: b.p.x - ux * rb, y: b.p.y - uy * rb, z: b.p.z - uz * rb },
|
|
197
|
+
];
|
|
198
|
+
}
|
|
199
|
+
/** 相机的三个基向量:右、上、前(视线方向) */
|
|
200
|
+
export function cameraBasis(cam) {
|
|
201
|
+
const yaw = (cam.yaw * Math.PI) / 180;
|
|
202
|
+
const pitch = (cam.pitch * Math.PI) / 180;
|
|
203
|
+
const cp = Math.cos(pitch);
|
|
204
|
+
const c = {
|
|
205
|
+
x: cam.dist * cp * Math.sin(yaw),
|
|
206
|
+
y: -cam.dist * cp * Math.cos(yaw),
|
|
207
|
+
// 俯仰角为负 = 从上往下看(所以这里取负号)
|
|
208
|
+
z: -cam.dist * Math.sin(pitch),
|
|
209
|
+
};
|
|
210
|
+
const len = Math.hypot(c.x, c.y, c.z) || 1;
|
|
211
|
+
const f = { x: -c.x / len, y: -c.y / len, z: -c.z / len };
|
|
212
|
+
// 右 = 前 × 上(世界上方向)
|
|
213
|
+
let r = { x: f.y * 1 - f.z * 0, y: f.z * 0 - f.x * 1, z: 0 };
|
|
214
|
+
const rl = Math.hypot(r.x, r.y) || 1;
|
|
215
|
+
r = { x: r.x / rl, y: r.y / rl, z: 0 };
|
|
216
|
+
// 上 = 右 × 前
|
|
217
|
+
const u = {
|
|
218
|
+
x: r.y * f.z - r.z * f.y,
|
|
219
|
+
y: r.z * f.x - r.x * f.z,
|
|
220
|
+
z: r.x * f.y - r.y * f.x,
|
|
221
|
+
};
|
|
222
|
+
return { cam: c, r, u, f };
|
|
223
|
+
}
|
|
224
|
+
/** 世界坐标 → 屏幕坐标(深度 = 离相机多远,用来排前后) */
|
|
225
|
+
export function project(p, basis, focal) {
|
|
226
|
+
const v = { x: p.x - basis.cam.x, y: p.y - basis.cam.y, z: p.z - basis.cam.z };
|
|
227
|
+
const cx = v.x * basis.r.x + v.y * basis.r.y + v.z * basis.r.z;
|
|
228
|
+
const cy = v.x * basis.u.x + v.y * basis.u.y + v.z * basis.u.z;
|
|
229
|
+
const cz = v.x * basis.f.x + v.y * basis.f.y + v.z * basis.f.z; // 沿视线往前 = 正
|
|
230
|
+
const k = focal / Math.max(1, cz);
|
|
231
|
+
return { x: cx * k, y: -cy * k, depth: cz };
|
|
232
|
+
}
|
|
233
|
+
/** 板砖的八个角 */
|
|
234
|
+
function corners(n) {
|
|
235
|
+
const hw = n.w / 2;
|
|
236
|
+
const hd = n.d / 2;
|
|
237
|
+
const hh = n.h / 2;
|
|
238
|
+
return [
|
|
239
|
+
{ x: n.p.x - hw, y: n.p.y - hd, z: n.p.z - hh },
|
|
240
|
+
{ x: n.p.x + hw, y: n.p.y - hd, z: n.p.z - hh },
|
|
241
|
+
{ x: n.p.x + hw, y: n.p.y + hd, z: n.p.z - hh },
|
|
242
|
+
{ x: n.p.x - hw, y: n.p.y + hd, z: n.p.z - hh },
|
|
243
|
+
{ x: n.p.x - hw, y: n.p.y - hd, z: n.p.z + hh },
|
|
244
|
+
{ x: n.p.x + hw, y: n.p.y - hd, z: n.p.z + hh },
|
|
245
|
+
{ x: n.p.x + hw, y: n.p.y + hd, z: n.p.z + hh },
|
|
246
|
+
{ x: n.p.x - hw, y: n.p.y + hd, z: n.p.z + hh },
|
|
247
|
+
];
|
|
248
|
+
}
|
|
249
|
+
/** 把整个场景投影到屏幕上 */
|
|
250
|
+
export function projectScene(scene, cam) {
|
|
251
|
+
const basis = cameraBasis(cam);
|
|
252
|
+
const focal = cam.focal;
|
|
253
|
+
const nodes = [];
|
|
254
|
+
for (const n of scene.nodes) {
|
|
255
|
+
const c = corners(n);
|
|
256
|
+
const pr = c.map((p) => project(p, basis, focal));
|
|
257
|
+
const top = [pr[4], pr[5], pr[6], pr[7]].map((p) => [p.x, p.y]);
|
|
258
|
+
// 四个侧面:法线朝着相机的才可见
|
|
259
|
+
const sideIdx = [
|
|
260
|
+
[0, 1, 5, 4],
|
|
261
|
+
[1, 2, 6, 5],
|
|
262
|
+
[2, 3, 7, 6],
|
|
263
|
+
[3, 0, 4, 7],
|
|
264
|
+
];
|
|
265
|
+
const sideNormals = [
|
|
266
|
+
{ x: 0, y: -1, z: 0 },
|
|
267
|
+
{ x: 1, y: 0, z: 0 },
|
|
268
|
+
{ x: 0, y: 1, z: 0 },
|
|
269
|
+
{ x: -1, y: 0, z: 0 },
|
|
270
|
+
];
|
|
271
|
+
const sides = [];
|
|
272
|
+
sideIdx.forEach((idx, i) => {
|
|
273
|
+
const nm = sideNormals[i];
|
|
274
|
+
const toCam = {
|
|
275
|
+
x: basis.cam.x - n.p.x,
|
|
276
|
+
y: basis.cam.y - n.p.y,
|
|
277
|
+
z: basis.cam.z - n.p.z,
|
|
278
|
+
};
|
|
279
|
+
const vis = nm.x * toCam.x + nm.y * toCam.y + nm.z * toCam.z > 0;
|
|
280
|
+
sides.push({ pts: idx.map((k) => [pr[k].x, pr[k].y]), vis });
|
|
281
|
+
});
|
|
282
|
+
// 顶面的中心要在**三维**里算 —— 拿投影后的点去平均就歪了
|
|
283
|
+
const topMid = project({ x: n.p.x, y: n.p.y, z: n.p.z + n.h / 2 }, basis, focal);
|
|
284
|
+
const mid = project(n.p, basis, focal);
|
|
285
|
+
// 顶面朝不朝相机:相机在块的上方才看得见顶面
|
|
286
|
+
const topVis = basis.cam.z > n.p.z + n.h / 2;
|
|
287
|
+
nodes.push({
|
|
288
|
+
id: n.id,
|
|
289
|
+
top,
|
|
290
|
+
// 图标:贴在板上,直立着(跟着面歪就认不出是什么)
|
|
291
|
+
icon: n.icon ? { x: topMid.x, y: topMid.y - 20 } : null,
|
|
292
|
+
topVis,
|
|
293
|
+
bottom: [pr[0], pr[1], pr[2], pr[3]].map((p) => [p.x, p.y]),
|
|
294
|
+
shadow: [pr[0], pr[1], pr[2], pr[3]].map((p) => [p.x, p.y]),
|
|
295
|
+
sides,
|
|
296
|
+
lx: mid.x,
|
|
297
|
+
ly: mid.y + 17, // 标签在板下(图标在板上,各占一边)
|
|
298
|
+
depth: topMid.depth,
|
|
299
|
+
});
|
|
300
|
+
}
|
|
301
|
+
const edges = scene.edges.map((e) => {
|
|
302
|
+
const pr = e.pts.map((p) => project(p, basis, focal));
|
|
303
|
+
const mid = pr[Math.floor((pr.length - 1) / 2)];
|
|
304
|
+
return {
|
|
305
|
+
from: e.from,
|
|
306
|
+
to: e.to,
|
|
307
|
+
label: e.label,
|
|
308
|
+
pts: pr.map((p) => [p.x, p.y]),
|
|
309
|
+
lx: mid.x,
|
|
310
|
+
ly: mid.y,
|
|
311
|
+
depth: mid.depth,
|
|
312
|
+
};
|
|
313
|
+
});
|
|
314
|
+
const groups = scene.groups.map((g) => {
|
|
315
|
+
const { min, max } = g;
|
|
316
|
+
const cs = [
|
|
317
|
+
{ x: min.x, y: min.y, z: min.z },
|
|
318
|
+
{ x: max.x, y: min.y, z: min.z },
|
|
319
|
+
{ x: max.x, y: max.y, z: min.z },
|
|
320
|
+
{ x: min.x, y: max.y, z: min.z },
|
|
321
|
+
{ x: min.x, y: min.y, z: max.z },
|
|
322
|
+
{ x: max.x, y: min.y, z: max.z },
|
|
323
|
+
{ x: max.x, y: max.y, z: max.z },
|
|
324
|
+
{ x: min.x, y: max.y, z: max.z },
|
|
325
|
+
];
|
|
326
|
+
const pr = cs.map((p) => project(p, basis, focal));
|
|
327
|
+
const edgesIdx = [
|
|
328
|
+
[0, 1], [1, 2], [2, 3], [3, 0],
|
|
329
|
+
[4, 5], [5, 6], [6, 7], [7, 4],
|
|
330
|
+
[0, 4], [1, 5], [2, 6], [3, 7],
|
|
331
|
+
];
|
|
332
|
+
const lines = edgesIdx.map(([a, b]) => [
|
|
333
|
+
[pr[a].x, pr[a].y],
|
|
334
|
+
[pr[b].x, pr[b].y],
|
|
335
|
+
]);
|
|
336
|
+
const c0 = project({ x: (min.x + max.x) / 2, y: (min.y + max.y) / 2, z: max.z }, basis, focal);
|
|
337
|
+
return { label: g.label, ids: g.ids, lines, lx: c0.x, ly: c0.y, depth: c0.depth };
|
|
338
|
+
});
|
|
339
|
+
const tiers = scene.tiers.map((t) => {
|
|
340
|
+
const { min, max } = t;
|
|
341
|
+
const z = t.z - 1;
|
|
342
|
+
const cs = [
|
|
343
|
+
{ x: min.x, y: min.y, z },
|
|
344
|
+
{ x: max.x, y: min.y, z },
|
|
345
|
+
{ x: max.x, y: max.y, z },
|
|
346
|
+
{ x: min.x, y: max.y, z },
|
|
347
|
+
];
|
|
348
|
+
const pr = cs.map((p) => project(p, basis, focal));
|
|
349
|
+
const c0 = project({ x: (min.x + max.x) / 2, y: (min.y + max.y) / 2, z }, basis, focal);
|
|
350
|
+
const pts = pr.map((p) => [p.x, p.y]);
|
|
351
|
+
// 厚度:往下沉一截,于是有侧面 —— 板台是块板,不是一张纸
|
|
352
|
+
const th = 16;
|
|
353
|
+
const low = cs.map((p) => project({ x: p.x, y: p.y, z: z - th }, basis, focal));
|
|
354
|
+
// 两个侧面:朝向相机的两条边
|
|
355
|
+
const sidePairs = [[0, 1], [1, 2], [2, 3], [3, 0]];
|
|
356
|
+
const sides = [];
|
|
357
|
+
sidePairs.forEach(([a, b], i) => {
|
|
358
|
+
const nm = [{ x: 0, y: -1 }, { x: 1, y: 0 }, { x: 0, y: 1 }, { x: -1, y: 0 }][i];
|
|
359
|
+
const toCam = { x: basis.cam.x - (min.x + max.x) / 2, y: basis.cam.y - (min.y + max.y) / 2 };
|
|
360
|
+
if (nm.x * toCam.x + nm.y * toCam.y > 0) {
|
|
361
|
+
sides.push([
|
|
362
|
+
[pr[a].x, pr[a].y],
|
|
363
|
+
[pr[b].x, pr[b].y],
|
|
364
|
+
[low[b].x, low[b].y],
|
|
365
|
+
[low[a].x, low[a].y],
|
|
366
|
+
]);
|
|
367
|
+
}
|
|
368
|
+
});
|
|
369
|
+
// 最靠前的角(屏幕上最低的那个)—— 层名挂它下面,那里是空的
|
|
370
|
+
let front = pts[0];
|
|
371
|
+
for (const q of pts)
|
|
372
|
+
if (q[1] > front[1])
|
|
373
|
+
front = q;
|
|
374
|
+
return { tier: t.tier, pts, sides, thick: th, lx: front[0], ly: front[1] + 13, depth: c0.depth };
|
|
375
|
+
});
|
|
376
|
+
// 地面网格
|
|
377
|
+
const grid = [];
|
|
378
|
+
{
|
|
379
|
+
const g = scene.ground;
|
|
380
|
+
const step = 120;
|
|
381
|
+
const z = g.min.z;
|
|
382
|
+
for (let x = g.min.x; x <= g.max.x + 1; x += step) {
|
|
383
|
+
const a = project({ x, y: g.min.y, z }, basis, focal);
|
|
384
|
+
const b = project({ x, y: g.max.y, z }, basis, focal);
|
|
385
|
+
grid.push([[a.x, a.y], [b.x, b.y]]);
|
|
386
|
+
}
|
|
387
|
+
for (let y = g.min.y; y <= g.max.y + 1; y += step) {
|
|
388
|
+
const a = project({ x: g.min.x, y, z }, basis, focal);
|
|
389
|
+
const b = project({ x: g.max.x, y, z }, basis, focal);
|
|
390
|
+
grid.push([[a.x, a.y], [b.x, b.y]]);
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
// 画布范围
|
|
394
|
+
let minX = Infinity, minY = Infinity, maxX = -Infinity, maxY = -Infinity;
|
|
395
|
+
const eat = (x, y) => {
|
|
396
|
+
minX = Math.min(minX, x);
|
|
397
|
+
maxX = Math.max(maxX, x);
|
|
398
|
+
minY = Math.min(minY, y);
|
|
399
|
+
maxY = Math.max(maxY, y);
|
|
400
|
+
};
|
|
401
|
+
for (const n of nodes) {
|
|
402
|
+
for (const p of n.top)
|
|
403
|
+
eat(p[0], p[1]);
|
|
404
|
+
for (const s of n.sides)
|
|
405
|
+
for (const p of s.pts)
|
|
406
|
+
eat(p[0], p[1]);
|
|
407
|
+
}
|
|
408
|
+
for (const e of edges)
|
|
409
|
+
for (const p of e.pts)
|
|
410
|
+
eat(p[0], p[1]);
|
|
411
|
+
for (const g of groups)
|
|
412
|
+
for (const l of g.lines)
|
|
413
|
+
for (const p of l)
|
|
414
|
+
eat(p[0], p[1]);
|
|
415
|
+
for (const t of tiers)
|
|
416
|
+
for (const p of t.pts)
|
|
417
|
+
eat(p[0], p[1]);
|
|
418
|
+
for (const l of grid)
|
|
419
|
+
for (const p of l)
|
|
420
|
+
eat(p[0], p[1]);
|
|
421
|
+
if (!Number.isFinite(minX)) {
|
|
422
|
+
minX = minY = 0;
|
|
423
|
+
maxX = maxY = 1;
|
|
424
|
+
}
|
|
425
|
+
return {
|
|
426
|
+
nodes,
|
|
427
|
+
edges,
|
|
428
|
+
groups,
|
|
429
|
+
tiers,
|
|
430
|
+
grid,
|
|
431
|
+
bbox: { x: minX, y: minY, w: Math.max(1, maxX - minX), h: Math.max(1, maxY - minY) },
|
|
432
|
+
};
|
|
433
|
+
}
|
package/dist/render/seq.js
CHANGED
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
// 画法:参与方一行,下面拖出生命线;每条消息在下一行,从发方生命线画一条箭头到收方,
|
|
9
9
|
// 收方在这段时间画一根激活条(细竖条)。回信写 dash → 虚线箭头。
|
|
10
10
|
import { ApiError } from '../specs/index.js';
|
|
11
|
+
import { BASELINE } from '../styles/baseline.js';
|
|
11
12
|
import { packGrid, parseBoundaries, parseNodes } from './archmap.js';
|
|
12
13
|
import { resolveSkin } from '../styles/index.js';
|
|
13
14
|
import { clampInt, schemeParam } from './query.js';
|
|
@@ -16,7 +17,7 @@ const PAD = 40;
|
|
|
16
17
|
const HEADER_H = 56; // 参与方标题盒高
|
|
17
18
|
const MSG_GAP = 78; // 两条消息之间的行距(要给分支框的标签留位置)
|
|
18
19
|
const ARROW = 10; // 箭头长度
|
|
19
|
-
const LABEL_FS =
|
|
20
|
+
const LABEL_FS = BASELINE.pointName;
|
|
20
21
|
const LANE_TOP = 30; // 有 b= 时,给泳道标签留出来的那一行
|
|
21
22
|
/** f=kind;label;start;end —— 分支框罩住第 start..end 条消息(含两端) */
|
|
22
23
|
function parseFrags(raw, msgCount) {
|
|
@@ -165,9 +166,11 @@ export function renderSeqCore(o) {
|
|
|
165
166
|
}
|
|
166
167
|
// 分支框(alt / else / opt / loop / par / break):
|
|
167
168
|
// 一个 alt 后面连续的 else 归成一组,共用一个外框,中间一条虚线分开两支。
|
|
169
|
+
// 框和分隔线压在消息底下,标签(alt [ok])压在最上面 ——
|
|
170
|
+
// 激活条是竖着的白杠,落点正好在框的左边沿,标签先画会被它盖掉半个字。
|
|
168
171
|
const fragSvg = () => {
|
|
169
172
|
if (!o.frags.length)
|
|
170
|
-
return '';
|
|
173
|
+
return { boxes: '', labels: '' };
|
|
171
174
|
const groups = [];
|
|
172
175
|
for (const f of o.frags) {
|
|
173
176
|
const last = groups[groups.length - 1];
|
|
@@ -177,7 +180,8 @@ export function renderSeqCore(o) {
|
|
|
177
180
|
else
|
|
178
181
|
groups.push({ frags: [f] });
|
|
179
182
|
}
|
|
180
|
-
const
|
|
183
|
+
const boxes = [];
|
|
184
|
+
const labels = [];
|
|
181
185
|
for (const g of groups) {
|
|
182
186
|
const first = g.frags[0];
|
|
183
187
|
const lastF = g.frags[g.frags.length - 1];
|
|
@@ -189,7 +193,7 @@ export function renderSeqCore(o) {
|
|
|
189
193
|
const x1 = Math.max(...xs) + 18;
|
|
190
194
|
const y0 = rowY(first.start) - 50;
|
|
191
195
|
const y1 = rowY(lastF.end) + 24;
|
|
192
|
-
|
|
196
|
+
boxes.push(`<rect x="${r2(x0)}" y="${r2(y0)}" width="${r2(x1 - x0)}" height="${r2(y1 - y0)}" rx="8" fill="var(--d-muted)" fill-opacity="0.06" stroke="var(--d-border)" stroke-width="1.2"/>`);
|
|
193
197
|
// 标签:alt [ok] / else [fail] / loop [each]
|
|
194
198
|
g.frags.forEach((f, i) => {
|
|
195
199
|
const text = f.label ? `${f.kind} [${f.label}]` : f.kind;
|
|
@@ -199,19 +203,20 @@ export function renderSeqCore(o) {
|
|
|
199
203
|
const ly = i === 0 ? y0 + 14 : rowY(f.start) - 34 + 4;
|
|
200
204
|
if (i > 0) {
|
|
201
205
|
const dy = rowY(f.start) - 34;
|
|
202
|
-
|
|
206
|
+
boxes.push(`<line x1="${r2(x0)}" y1="${r2(dy)}" x2="${r2(x1)}" y2="${r2(dy)}" stroke="var(--d-border)" stroke-width="1.2" stroke-dasharray="5 4"/>`);
|
|
203
207
|
}
|
|
204
|
-
|
|
208
|
+
labels.push(`<rect x="${r2(lx - 6)}" y="${r2(ly - 11)}" width="${r2(w)}" height="17" rx="5" fill="var(--d-card)" stroke="var(--d-border)" stroke-width="1"/>`, `<text x="${r2(lx)}" y="${r2(ly + 1)}" font-size="10.5" font-weight="600" letter-spacing="0.4" fill="var(--d-muted)">${esc(text)}</text>`);
|
|
205
209
|
});
|
|
206
210
|
}
|
|
207
|
-
return
|
|
211
|
+
return { boxes: boxes.join(''), labels: labels.join('') };
|
|
208
212
|
};
|
|
209
213
|
const titleSvg = o.title
|
|
210
214
|
? `<text x="${PAD}" y="${PAD + 16}" font-size="18" font-weight="600" letter-spacing="-0.02em" fill="var(--d-ink)">${esc(o.title)}</text>`
|
|
211
215
|
: '';
|
|
212
216
|
const headSvg = placed.map((p) => headerBox(p.box.x, p.box.y, p.box.w, p.label, p.sub, p.color, o.interactive, p.id)).join('');
|
|
213
217
|
const spec = { type: 'seq', title: o.title, participants: o.nodes, messages: o.msgs };
|
|
214
|
-
const
|
|
218
|
+
const frags = fragSvg();
|
|
219
|
+
const svg = svgDoc(width, height, 'seq', o.version, o.title ?? `sequence diagram, ${o.msgs.length} messages`, spec, o.skin, titleSvg + headSvg + frags.boxes + parts.join('') + frags.labels, o.tagQuery, 'seq');
|
|
215
220
|
return { svg, version: o.version, cacheControl: o.cacheControl };
|
|
216
221
|
}
|
|
217
222
|
/**
|