@fengwk/kchart 0.0.0-stage → 0.1.1
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/CHANGELOG.md +17 -0
- package/LICENSE +21 -0
- package/NOTICE.md +11 -0
- package/README.md +68 -2
- package/README.zh-CN.md +69 -0
- package/dist/LICENSE +21 -0
- package/dist/NOTICE.md +11 -0
- package/dist/assets/ICONS-LICENSE.txt +53 -0
- package/dist/assets/maps/LICENSE.md +75 -0
- package/dist/assets/maps/METADATA.md +9 -0
- package/dist/assets/maps/REGIONS.md +28 -0
- package/dist/assets/maps/us-states.geojson +1 -0
- package/dist/assets/maps/world.geojson +1 -0
- package/dist/esm/_virtual/_kchart-families.js +48 -0
- package/dist/esm/_virtual/_rolldown/runtime.js +12 -0
- package/dist/esm/assets/icons.js +11 -0
- package/dist/esm/assets/maps/us-states.js +3 -0
- package/dist/esm/assets/maps/world.js +3 -0
- package/dist/esm/assets/themes/claude.js +69 -0
- package/dist/esm/assets/themes/cloudmusic.js +62 -0
- package/dist/esm/assets/themes/kanagawa.js +67 -0
- package/dist/esm/assets/themes/obsidian.js +67 -0
- package/dist/esm/assets/themes/paper.js +61 -0
- package/dist/esm/assets/themes/terminal.js +60 -0
- package/dist/esm/assets/themes/tokyo.js +62 -0
- package/dist/esm/chart/basic.js +1313 -0
- package/dist/esm/chart/catalog.js +476 -0
- package/dist/esm/chart/composition.js +844 -0
- package/dist/esm/chart/context.js +189 -0
- package/dist/esm/chart/distribution.js +442 -0
- package/dist/esm/chart/fields.js +67 -0
- package/dist/esm/chart/maps.js +563 -0
- package/dist/esm/chart/mindmap.js +629 -0
- package/dist/esm/chart/multivariate.js +1229 -0
- package/dist/esm/chart/registry.js +108 -0
- package/dist/esm/chart/relations.js +949 -0
- package/dist/esm/chart/spec.js +1415 -0
- package/dist/esm/chart/stat-compare.js +302 -0
- package/dist/esm/chart/stat-trend.js +181 -0
- package/dist/esm/chart/statistics.js +1007 -0
- package/dist/esm/chart/unit-variants.js +645 -0
- package/dist/esm/chart/variants.js +552 -0
- package/dist/esm/core/color.js +197 -0
- package/dist/esm/core/context.js +256 -0
- package/dist/esm/core/diagnostics.js +23 -0
- package/dist/esm/core/format.js +167 -0
- package/dist/esm/core/geometry.js +130 -0
- package/dist/esm/core/icon-data.js +5 -0
- package/dist/esm/core/icons.js +173 -0
- package/dist/esm/core/scale.js +112 -0
- package/dist/esm/core/scene.js +234 -0
- package/dist/esm/core/svg.js +89 -0
- package/dist/esm/core/text.js +184 -0
- package/dist/esm/core/theme.js +318 -0
- package/dist/esm/diagram/agentflow.js +596 -0
- package/dist/esm/diagram/architecture.js +729 -0
- package/dist/esm/diagram/block.js +988 -0
- package/dist/esm/diagram/blocks.js +687 -0
- package/dist/esm/diagram/c4.js +1002 -0
- package/dist/esm/diagram/class.js +1158 -0
- package/dist/esm/diagram/cynefin.js +749 -0
- package/dist/esm/diagram/emphasis.js +7 -0
- package/dist/esm/diagram/er.js +657 -0
- package/dist/esm/diagram/eventmodeling.js +948 -0
- package/dist/esm/diagram/gantt-date.js +323 -0
- package/dist/esm/diagram/gantt.js +661 -0
- package/dist/esm/diagram/gitgraph.js +472 -0
- package/dist/esm/diagram/graph-layout.js +4046 -0
- package/dist/esm/diagram/graph-parse.js +1366 -0
- package/dist/esm/diagram/graph-route.js +490 -0
- package/dist/esm/diagram/graph.js +553 -0
- package/dist/esm/diagram/ishikawa.js +496 -0
- package/dist/esm/diagram/journey.js +512 -0
- package/dist/esm/diagram/kanban.js +280 -0
- package/dist/esm/diagram/label.js +56 -0
- package/dist/esm/diagram/layers.js +385 -0
- package/dist/esm/diagram/map-label.js +44 -0
- package/dist/esm/diagram/mindmap.js +277 -0
- package/dist/esm/diagram/numeric-composition.js +78 -0
- package/dist/esm/diagram/numeric-model.js +86 -0
- package/dist/esm/diagram/numeric-parse.js +205 -0
- package/dist/esm/diagram/numeric-radar.js +355 -0
- package/dist/esm/diagram/numeric-sankey.js +201 -0
- package/dist/esm/diagram/numeric-xy.js +422 -0
- package/dist/esm/diagram/packet.js +175 -0
- package/dist/esm/diagram/presentation.js +252 -0
- package/dist/esm/diagram/quadrant.js +297 -0
- package/dist/esm/diagram/railroad-parse.js +465 -0
- package/dist/esm/diagram/railroad.js +294 -0
- package/dist/esm/diagram/registry.js +296 -0
- package/dist/esm/diagram/relations.js +966 -0
- package/dist/esm/diagram/requirement.js +341 -0
- package/dist/esm/diagram/sequence.js +1228 -0
- package/dist/esm/diagram/shapes.js +366 -0
- package/dist/esm/diagram/source.js +538 -0
- package/dist/esm/diagram/support.js +153 -0
- package/dist/esm/diagram/swimlane-mermaid.js +140 -0
- package/dist/esm/diagram/swimlane.js +1186 -0
- package/dist/esm/diagram/time.js +748 -0
- package/dist/esm/diagram/timeline.js +376 -0
- package/dist/esm/diagram/tree-family-icon.js +22 -0
- package/dist/esm/diagram/treeview.js +293 -0
- package/dist/esm/diagram/usecase.js +852 -0
- package/dist/esm/diagram/venn.js +1038 -0
- package/dist/esm/diagram/wardley.js +838 -0
- package/dist/esm/index.d.ts +133 -0
- package/dist/esm/index.js +92 -0
- package/dist/esm/interaction.js +561 -0
- package/dist/esm/mermaid.d.ts +28 -0
- package/dist/esm/mermaid.js +70 -0
- package/dist/esm/node.d.ts +68 -0
- package/dist/esm/node.js +373 -0
- package/dist/esm/package.json +1 -0
- package/dist/esm/page-api.js +65 -0
- package/dist/esm/runtime.js +352 -0
- package/dist/esm/src/families.js +209 -0
- package/dist/page-api.js +1 -0
- package/dist/units/chart/basic.js +1 -0
- package/dist/units/chart/catalog.js +1 -0
- package/dist/units/chart/composition.js +1 -0
- package/dist/units/chart/context.js +1 -0
- package/dist/units/chart/distribution.js +1 -0
- package/dist/units/chart/fields.js +1 -0
- package/dist/units/chart/maps.js +1 -0
- package/dist/units/chart/mindmap.js +1 -0
- package/dist/units/chart/multivariate.js +1 -0
- package/dist/units/chart/registry.js +1 -0
- package/dist/units/chart/relations.js +1 -0
- package/dist/units/chart/spec.js +3 -0
- package/dist/units/chart/stat-compare.js +1 -0
- package/dist/units/chart/stat-trend.js +1 -0
- package/dist/units/chart/statistics.js +1 -0
- package/dist/units/chart/unit-variants.js +1 -0
- package/dist/units/chart/variants.js +1 -0
- package/dist/units/core/color.js +1 -0
- package/dist/units/core/context.js +1 -0
- package/dist/units/core/diagnostics.js +1 -0
- package/dist/units/core/format.js +1 -0
- package/dist/units/core/geometry.js +1 -0
- package/dist/units/core/icon-data.js +1 -0
- package/dist/units/core/icons.js +1 -0
- package/dist/units/core/scale.js +1 -0
- package/dist/units/core/scene.js +1 -0
- package/dist/units/core/svg.js +1 -0
- package/dist/units/core/text.js +2 -0
- package/dist/units/core/theme.js +1 -0
- package/dist/units/diagram/agentflow.js +12 -0
- package/dist/units/diagram/architecture.js +4 -0
- package/dist/units/diagram/block.js +2 -0
- package/dist/units/diagram/blocks.js +2 -0
- package/dist/units/diagram/c4.js +6 -0
- package/dist/units/diagram/class.js +5 -0
- package/dist/units/diagram/cynefin.js +4 -0
- package/dist/units/diagram/emphasis.js +1 -0
- package/dist/units/diagram/er.js +9 -0
- package/dist/units/diagram/eventmodeling.js +5 -0
- package/dist/units/diagram/gantt-date.js +1 -0
- package/dist/units/diagram/gantt.js +3 -0
- package/dist/units/diagram/gitgraph.js +2 -0
- package/dist/units/diagram/graph-layout.js +4 -0
- package/dist/units/diagram/graph-parse.js +9 -0
- package/dist/units/diagram/graph-route.js +1 -0
- package/dist/units/diagram/graph.js +1 -0
- package/dist/units/diagram/ishikawa.js +2 -0
- package/dist/units/diagram/journey.js +5 -0
- package/dist/units/diagram/kanban.js +2 -0
- package/dist/units/diagram/label.js +4 -0
- package/dist/units/diagram/layers.js +1 -0
- package/dist/units/diagram/map-label.js +1 -0
- package/dist/units/diagram/mindmap.js +2 -0
- package/dist/units/diagram/numeric-composition.js +1 -0
- package/dist/units/diagram/numeric-model.js +1 -0
- package/dist/units/diagram/numeric-parse.js +2 -0
- package/dist/units/diagram/numeric-radar.js +3 -0
- package/dist/units/diagram/numeric-sankey.js +2 -0
- package/dist/units/diagram/numeric-xy.js +2 -0
- package/dist/units/diagram/packet.js +2 -0
- package/dist/units/diagram/presentation.js +2 -0
- package/dist/units/diagram/quadrant.js +2 -0
- package/dist/units/diagram/railroad-parse.js +4 -0
- package/dist/units/diagram/railroad.js +1 -0
- package/dist/units/diagram/registry.js +2 -0
- package/dist/units/diagram/relations.js +3 -0
- package/dist/units/diagram/requirement.js +3 -0
- package/dist/units/diagram/sequence.js +2 -0
- package/dist/units/diagram/shapes.js +60 -0
- package/dist/units/diagram/source.js +20 -0
- package/dist/units/diagram/support.js +3 -0
- package/dist/units/diagram/swimlane-mermaid.js +3 -0
- package/dist/units/diagram/swimlane.js +2 -0
- package/dist/units/diagram/time.js +3 -0
- package/dist/units/diagram/timeline.js +2 -0
- package/dist/units/diagram/tree-family-icon.js +1 -0
- package/dist/units/diagram/treeview.js +2 -0
- package/dist/units/diagram/usecase.js +3 -0
- package/dist/units/diagram/venn.js +2 -0
- package/dist/units/diagram/wardley.js +4 -0
- package/dist/units/interaction.js +1 -0
- package/dist/units/runtime.js +1 -0
- package/dist/units.json +712 -0
- package/package.json +30 -4
|
@@ -0,0 +1,838 @@
|
|
|
1
|
+
import { __exportAll } from "../_virtual/_rolldown/runtime.js";
|
|
2
|
+
import { FONT, appearance, error, isEn, message, textBlock, warning } from "./support.js";
|
|
3
|
+
import { mapConfig, mapIcon, mapLabels } from "./map-label.js";
|
|
4
|
+
// src/diagram/wardley.js
|
|
5
|
+
var wardley_exports = /* @__PURE__ */ __exportAll({ implementations: () => implementations });
|
|
6
|
+
var DEC = String.raw`\d+\.\d+`;
|
|
7
|
+
var NUM = String.raw`\d+(?:\.\d+)?`;
|
|
8
|
+
var QUOTED = String.raw`"(?:\\.|[^"\\])*"`;
|
|
9
|
+
var NAME = String.raw`(?:${QUOTED}|[A-Za-z_](?:[\w()&]|-(?![-.>]))*(?:[ \t]+[A-Za-z(](?:[\w()&]|-(?![-.>]))*)*)`;
|
|
10
|
+
var pair = (number) => String.raw`\[\s*(${number})\s*,\s*(${number})\s*\]`;
|
|
11
|
+
var offset = String.raw`(?:\s+label\s*${pair("-?\\d+")})?`;
|
|
12
|
+
var sizePattern = new RegExp(String.raw`^size\s*${pair("\\d+")}$`);
|
|
13
|
+
var nodePattern = new RegExp(String.raw`^(component|anchor|note|accelerator|deaccelerator)\s+(${NAME})\s*${pair(DEC)}${offset}(?:\s+\((build|buy|outsource|market)\))?(?:\s+(inertia|\(inertia\)))?$`);
|
|
14
|
+
var childPattern = new RegExp(String.raw`^component\s+(${NAME})\s*\[\s*(${DEC})\s*\]${offset}$`);
|
|
15
|
+
var stagePattern = new RegExp(String.raw`^(${NAME})(?:\s*@\s*(${DEC}))?(?:\s*/\s*(${NAME}))?$`);
|
|
16
|
+
var pipelinePattern = new RegExp(String.raw`^pipeline\s+(${NAME})\s*\{$`);
|
|
17
|
+
var evolvePattern = new RegExp(String.raw`^evolve\s+(${NAME})\s+(${DEC})$`);
|
|
18
|
+
var pinPattern = new RegExp(String.raw`^annotation\s+(\d+)\s*,\s*${pair(NUM)}\s+(${QUOTED})$`);
|
|
19
|
+
var boxPattern = new RegExp(String.raw`^annotations\s*${pair(NUM)}$`);
|
|
20
|
+
var linkPattern = new RegExp(String.raw`^(${NAME})\s*(\+<>|\+>|\+<)?\s*(-->|-\.->|->|>|\+'([^']*)'(<>|<|>))?\s*(${NAME})\s*(\+<>|\+>|\+<)?\s*(?:;\s*(.+))?$`);
|
|
21
|
+
var defaults = [
|
|
22
|
+
["起源", "Genesis"],
|
|
23
|
+
["定制", "Custom Built"],
|
|
24
|
+
["产品", "Product"],
|
|
25
|
+
["商品", "Commodity"]
|
|
26
|
+
];
|
|
27
|
+
var words = {
|
|
28
|
+
visibility: ["可见度", "Visibility"],
|
|
29
|
+
evolution: ["演化", "Evolution"],
|
|
30
|
+
annotations: ["注释", "Annotations"],
|
|
31
|
+
build: ["自建", "build"],
|
|
32
|
+
buy: ["采购", "buy"],
|
|
33
|
+
outsource: ["外包", "outsource"],
|
|
34
|
+
market: ["市场", "market"]
|
|
35
|
+
};
|
|
36
|
+
var word = (lang, key) => message(lang, ...words[key]);
|
|
37
|
+
var strategyGlyphs = {
|
|
38
|
+
build: "B",
|
|
39
|
+
buy: "Y",
|
|
40
|
+
outsource: "O",
|
|
41
|
+
market: "M"
|
|
42
|
+
};
|
|
43
|
+
var strategyTones = {
|
|
44
|
+
build: "tone1",
|
|
45
|
+
buy: "tone2",
|
|
46
|
+
outsource: "tone3",
|
|
47
|
+
market: "tone4"
|
|
48
|
+
};
|
|
49
|
+
var readName = (name) => name.startsWith("\"") ? name.slice(1, -1).replace(/\\(["\\])/g, "$1") : name;
|
|
50
|
+
function parse(body, { lang, firstLine = 2, title = "", headerLine = 1 } = {}) {
|
|
51
|
+
const model = {
|
|
52
|
+
type: "wardley",
|
|
53
|
+
title,
|
|
54
|
+
size: null,
|
|
55
|
+
stages: defaults.map((names) => ({
|
|
56
|
+
name: names[isEn(lang) ? 1 : 0],
|
|
57
|
+
secondName: null,
|
|
58
|
+
boundary: null
|
|
59
|
+
})),
|
|
60
|
+
nodes: [],
|
|
61
|
+
pipelines: [],
|
|
62
|
+
links: [],
|
|
63
|
+
trends: [],
|
|
64
|
+
notes: [],
|
|
65
|
+
annotations: [],
|
|
66
|
+
annotationBox: null,
|
|
67
|
+
forces: []
|
|
68
|
+
};
|
|
69
|
+
const errors = [], hints = /* @__PURE__ */ new Set(), nodes = /* @__PURE__ */ new Map();
|
|
70
|
+
const normalize = mapLabels(lang, (item) => errors.push(item));
|
|
71
|
+
const readLabel = (value, line) => normalize(readName(value), line);
|
|
72
|
+
if (title) ({text: model.title, icon: model.titleIcon} = normalize(title, headerLine));
|
|
73
|
+
const bad = (line, zh, en) => errors.push(error(lang, line, zh, en, "检查 Wardley 地图语法", "Check Wardley map syntax"));
|
|
74
|
+
const hint = (key, line, zh, en) => {
|
|
75
|
+
if (hints.has(key)) return;
|
|
76
|
+
hints.add(key);
|
|
77
|
+
errors.push(warning("DIAGRAM_HINT", lang, line, zh, en));
|
|
78
|
+
};
|
|
79
|
+
const percent = (raw, line) => {
|
|
80
|
+
const value = Number(raw);
|
|
81
|
+
if (value > 100) bad(line, "坐标超出 0–100 范围", "Coordinate is outside 0–100");
|
|
82
|
+
return value <= 1 ? value * 100 : value;
|
|
83
|
+
};
|
|
84
|
+
const coords = (v, e, line) => ({
|
|
85
|
+
visibility: percent(v, line),
|
|
86
|
+
evolution: percent(e, line)
|
|
87
|
+
});
|
|
88
|
+
const labelOffset = (dx, dy) => dx == null ? null : {
|
|
89
|
+
dx: +dx,
|
|
90
|
+
dy: +dy
|
|
91
|
+
};
|
|
92
|
+
const add = (node) => {
|
|
93
|
+
const previous = nodes.get(node.id);
|
|
94
|
+
if (previous) {
|
|
95
|
+
if (previous.visibility !== node.visibility || previous.evolution !== node.evolution) bad(node.line, `「${node.id}」有不同的坐标`, `Conflicting coordinates for "${node.id}"`);
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
nodes.set(node.id, node);
|
|
99
|
+
model.nodes.push(node);
|
|
100
|
+
};
|
|
101
|
+
if (body.length > 2e5) {
|
|
102
|
+
bad(firstLine, "地图源文本过长", "Map source exceeds 200,000 characters");
|
|
103
|
+
return {
|
|
104
|
+
model,
|
|
105
|
+
errors
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
const bareLinks = [];
|
|
109
|
+
let pipeline = null, accessibility = false;
|
|
110
|
+
for (const [index, raw] of body.split("\n").entries()) {
|
|
111
|
+
const text = raw.match(/^(?:"(?:\\.|[^"\\])*"|\+'[^']*'|%(?!%)|[^"%])*/)[0].trim();
|
|
112
|
+
const line = firstLine + index;
|
|
113
|
+
if (!text) continue;
|
|
114
|
+
let m;
|
|
115
|
+
if (pipeline) {
|
|
116
|
+
if (text === "}") {
|
|
117
|
+
if (!pipeline.children.length) bad(line, "演进管道没有组件", "Pipeline needs at least one component");
|
|
118
|
+
pipeline = null;
|
|
119
|
+
} else if (m = childPattern.exec(text)) {
|
|
120
|
+
const [, name, evo, dx, dy] = m, { text: label, icon } = readLabel(name, line);
|
|
121
|
+
pipeline.children.push({
|
|
122
|
+
id: `${pipeline.parent}_${readName(name)}`,
|
|
123
|
+
name: readName(name),
|
|
124
|
+
label,
|
|
125
|
+
icon,
|
|
126
|
+
evolution: percent(evo, line),
|
|
127
|
+
labelOffset: labelOffset(dx, dy),
|
|
128
|
+
kind: "pipeline",
|
|
129
|
+
parent: pipeline.parent,
|
|
130
|
+
line
|
|
131
|
+
});
|
|
132
|
+
} else bad(line, "无效的演进管道组件", "Invalid pipeline component");
|
|
133
|
+
continue;
|
|
134
|
+
}
|
|
135
|
+
if (accessibility) {
|
|
136
|
+
if (text.includes("}")) accessibility = false;
|
|
137
|
+
continue;
|
|
138
|
+
}
|
|
139
|
+
if (m = /^title\s*:?[ \t]+(.+)$/.exec(text)) {
|
|
140
|
+
if (!title) ({text: model.title, icon: model.titleIcon} = readLabel(m[1], line));
|
|
141
|
+
} else if (/^acc(?:Title|Descr)\s*:/.test(text)) continue;
|
|
142
|
+
else if (/^accDescr\s*\{/.test(text)) accessibility = !text.includes("}");
|
|
143
|
+
else if (m = sizePattern.exec(text)) {
|
|
144
|
+
model.size = {
|
|
145
|
+
width: Number(m[1]),
|
|
146
|
+
height: Number(m[2])
|
|
147
|
+
};
|
|
148
|
+
if (Object.values(model.size).some((n) => n > 16e3)) bad(line, "地图尺寸超过 16000 像素", "Map size exceeds 16,000 pixels");
|
|
149
|
+
} else if (text.startsWith("evolution ")) {
|
|
150
|
+
const parts = text.slice(10).match(/"(?:\\.|[^"\\])*"|->|[^"-]+|-/g) || [];
|
|
151
|
+
const stages = [""];
|
|
152
|
+
for (const part of parts) part === "->" ? stages.push("") : stages[stages.length - 1] += part;
|
|
153
|
+
const matches = stages.map((stage) => stagePattern.exec(stage.trim()));
|
|
154
|
+
if (matches.length < 2 || matches.some((match) => !match)) bad(line, "无效的演进阶段", "Invalid evolution stages");
|
|
155
|
+
else {
|
|
156
|
+
model.stages = matches.map(([, name, end, second]) => {
|
|
157
|
+
const primary = readLabel(name, line), secondary = second ? readLabel(second, line) : null;
|
|
158
|
+
return {
|
|
159
|
+
name: primary.text,
|
|
160
|
+
icon: primary.icon,
|
|
161
|
+
secondName: secondary?.text ?? null,
|
|
162
|
+
secondIcon: secondary?.icon,
|
|
163
|
+
boundary: end == null ? null : percent(end, line)
|
|
164
|
+
};
|
|
165
|
+
});
|
|
166
|
+
const ends = model.stages.map((stage) => stage.boundary);
|
|
167
|
+
if (ends.some((end) => end !== null) && (ends.some((end, i) => end === null || end <= (ends[i - 1] ?? 0)) || ends.at(-1) !== 100)) {
|
|
168
|
+
hint("stages", line, "阶段边界不完整或未递增至 100;使用等宽阶段", "Incomplete or unordered stage boundaries; using equal bands");
|
|
169
|
+
for (const stage of model.stages) stage.boundary = null;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
} else if (m = nodePattern.exec(text)) {
|
|
173
|
+
const [, kind, name, vis, evo, dx, dy, strategy, inertia] = m;
|
|
174
|
+
const { text: label, icon } = readLabel(name, line), point = coords(vis, evo, line);
|
|
175
|
+
if (kind !== "component" && (dx != null || strategy || inertia) || kind === "note" && !name.startsWith("\"")) bad(line, "无效的装饰或备注", "Invalid decorator or note");
|
|
176
|
+
else if (kind === "note") model.notes.push({
|
|
177
|
+
text: label,
|
|
178
|
+
icon,
|
|
179
|
+
...point,
|
|
180
|
+
line
|
|
181
|
+
});
|
|
182
|
+
else if (kind.endsWith("accelerator")) model.forces.push({
|
|
183
|
+
kind,
|
|
184
|
+
name: label,
|
|
185
|
+
icon,
|
|
186
|
+
...point,
|
|
187
|
+
line
|
|
188
|
+
});
|
|
189
|
+
else add({
|
|
190
|
+
id: readName(name),
|
|
191
|
+
label,
|
|
192
|
+
icon,
|
|
193
|
+
kind,
|
|
194
|
+
...point,
|
|
195
|
+
labelOffset: labelOffset(dx, dy),
|
|
196
|
+
strategy: strategy ?? null,
|
|
197
|
+
inertia: !!inertia,
|
|
198
|
+
line
|
|
199
|
+
});
|
|
200
|
+
} else if (m = pipelinePattern.exec(text)) {
|
|
201
|
+
pipeline = {
|
|
202
|
+
parent: readName(m[1]),
|
|
203
|
+
children: [],
|
|
204
|
+
line
|
|
205
|
+
};
|
|
206
|
+
model.pipelines.push(pipeline);
|
|
207
|
+
} else if (m = evolvePattern.exec(text)) model.trends.push({
|
|
208
|
+
nodeId: readName(m[1]),
|
|
209
|
+
targetEvolution: percent(m[2], line),
|
|
210
|
+
line
|
|
211
|
+
});
|
|
212
|
+
else if (m = pinPattern.exec(text)) model.annotations.push({
|
|
213
|
+
number: m[1],
|
|
214
|
+
...coords(m[2], m[3], line),
|
|
215
|
+
...readLabel(m[4], line),
|
|
216
|
+
line
|
|
217
|
+
});
|
|
218
|
+
else if (m = boxPattern.exec(text)) {
|
|
219
|
+
if (model.annotationBox) hint("box", line, "只使用第一个注释框", "Only the first annotation box is used");
|
|
220
|
+
else model.annotationBox = coords(m[1], m[2], line);
|
|
221
|
+
} else if ((m = linkPattern.exec(text)) && (m[2] || m[3] || m[7] || m[8] || m[1].startsWith("\"") || m[6].startsWith("\""))) {
|
|
222
|
+
const [, from, sourcePort, arrow, flowLabel, arrowPort, to, targetPort, label] = m;
|
|
223
|
+
const port = sourcePort || targetPort || arrowPort && `+${arrowPort}`;
|
|
224
|
+
const { text: caption, icon } = readLabel(flowLabel ?? label ?? "", line);
|
|
225
|
+
model.links.push({
|
|
226
|
+
from: readName(from),
|
|
227
|
+
to: readName(to),
|
|
228
|
+
dashed: arrow === "-.->",
|
|
229
|
+
flow: {
|
|
230
|
+
"+>": "forward",
|
|
231
|
+
"+<": "backward",
|
|
232
|
+
"+<>": "bidirectional"
|
|
233
|
+
}[port] || "none",
|
|
234
|
+
label: caption,
|
|
235
|
+
icon,
|
|
236
|
+
line
|
|
237
|
+
});
|
|
238
|
+
} else bareLinks.push({
|
|
239
|
+
text,
|
|
240
|
+
line
|
|
241
|
+
});
|
|
242
|
+
}
|
|
243
|
+
if (pipeline) bad(pipeline.line, "演进管道缺少结束括号", "Unclosed pipeline");
|
|
244
|
+
for (const group of model.pipelines) {
|
|
245
|
+
const parent = nodes.get(group.parent);
|
|
246
|
+
if (parent?.kind !== "component") bad(group.line, `管道父级「${group.parent}」不是组件`, `Pipeline parent "${group.parent}" is not a component`);
|
|
247
|
+
else for (const child of group.children) add({
|
|
248
|
+
...child,
|
|
249
|
+
visibility: parent.visibility
|
|
250
|
+
});
|
|
251
|
+
}
|
|
252
|
+
const childNames = /* @__PURE__ */ new Map();
|
|
253
|
+
for (const node of model.nodes) if (node.parent && !childNames.has(node.name)) childNames.set(node.name, node.id);
|
|
254
|
+
const resolve = (id) => nodes.has(id) ? id : childNames.get(id) ?? id;
|
|
255
|
+
for (const { text, line } of bareLinks) {
|
|
256
|
+
let split;
|
|
257
|
+
for (const { index, 0: gap } of text.matchAll(/\s+/g)) {
|
|
258
|
+
const a = text.slice(0, index), b = text.slice(index + gap.length);
|
|
259
|
+
if (nodes.has(resolve(a)) && nodes.has(resolve(b))) {
|
|
260
|
+
split = [a, b];
|
|
261
|
+
break;
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
if (split) model.links.push({
|
|
265
|
+
from: split[0],
|
|
266
|
+
to: split[1],
|
|
267
|
+
dashed: false,
|
|
268
|
+
flow: "none",
|
|
269
|
+
label: "",
|
|
270
|
+
line
|
|
271
|
+
});
|
|
272
|
+
else bad(line, "无法识别 Wardley 地图语句", "Unrecognized Wardley map statement");
|
|
273
|
+
}
|
|
274
|
+
model.links.sort((a, b) => a.line - b.line);
|
|
275
|
+
for (const link of model.links) {
|
|
276
|
+
link.from = resolve(link.from);
|
|
277
|
+
link.to = resolve(link.to);
|
|
278
|
+
if (!nodes.has(link.from) || !nodes.has(link.to)) bad(link.line, "依赖引用未定义的节点", "Dependency references an undefined node");
|
|
279
|
+
}
|
|
280
|
+
for (const trend of model.trends) {
|
|
281
|
+
trend.nodeId = resolve(trend.nodeId);
|
|
282
|
+
if (!nodes.has(trend.nodeId)) hint("trend", trend.line, "演进引用未定义的组件", "Evolution references an undefined component");
|
|
283
|
+
}
|
|
284
|
+
if (model.nodes.length > 300 || model.links.length + model.trends.length > 600) bad(firstLine, "地图超过 300 个节点或 600 条连线,请拆分", "Split maps exceeding 300 nodes or 600 connections");
|
|
285
|
+
return {
|
|
286
|
+
model,
|
|
287
|
+
errors
|
|
288
|
+
};
|
|
289
|
+
}
|
|
290
|
+
var box = (x, y, w, h) => ({
|
|
291
|
+
x,
|
|
292
|
+
y,
|
|
293
|
+
w,
|
|
294
|
+
h
|
|
295
|
+
});
|
|
296
|
+
var centerBox = (x, y, w, h) => box(x - w / 2, y - h / 2, w, h);
|
|
297
|
+
var collides = (a, b) => a.x < b.x + b.w && b.x < a.x + a.w && a.y < b.y + b.h && b.y < a.y + a.h;
|
|
298
|
+
var grow = (b, n) => box(b.x - n, b.y - n, b.w + n * 2, b.h + n * 2);
|
|
299
|
+
var length = (a, b) => Math.hypot(b.x - a.x, b.y - a.y);
|
|
300
|
+
function boxSpan(a, b, r) {
|
|
301
|
+
let lo = 0, hi = 1;
|
|
302
|
+
for (const [k, d] of [["x", "w"], ["y", "h"]]) {
|
|
303
|
+
const delta = b[k] - a[k];
|
|
304
|
+
if (!delta) {
|
|
305
|
+
if (a[k] < r[k] || a[k] > r[k] + r[d]) return false;
|
|
306
|
+
continue;
|
|
307
|
+
}
|
|
308
|
+
const p = (r[k] - a[k]) / delta, q = (r[k] + r[d] - a[k]) / delta;
|
|
309
|
+
lo = Math.max(lo, Math.min(p, q));
|
|
310
|
+
hi = Math.min(hi, Math.max(p, q));
|
|
311
|
+
if (lo > hi) return false;
|
|
312
|
+
}
|
|
313
|
+
return [lo, hi];
|
|
314
|
+
}
|
|
315
|
+
var crosses = (a, b, r) => Boolean(boxSpan(a, b, r));
|
|
316
|
+
function visibleSpans(a, b, blockers, painted) {
|
|
317
|
+
const dx = b.x - a.x, dy = b.y - a.y, span = dx * dx + dy * dy;
|
|
318
|
+
if (!span) return [];
|
|
319
|
+
const hidden = blockers.map((rect) => boxSpan(a, b, rect)).filter(Boolean);
|
|
320
|
+
for (const pair of painted) {
|
|
321
|
+
if (!pair.every((p) => Math.abs(dx * (p.y - a.y) - dy * (p.x - a.x)) < 1e-5)) continue;
|
|
322
|
+
const [lo, hi] = pair.map((p) => (dx * (p.x - a.x) + dy * (p.y - a.y)) / span).sort((x, y) => x - y);
|
|
323
|
+
if (lo < 1 && hi > 0) hidden.push([Math.max(0, lo), Math.min(1, hi)]);
|
|
324
|
+
}
|
|
325
|
+
let cursor = 0;
|
|
326
|
+
const visible = [];
|
|
327
|
+
for (const [lo, hi] of [...hidden.sort((x, y) => x[0] - y[0]), [1, 1]]) {
|
|
328
|
+
if (lo - cursor > 1e-7) visible.push([cursor, lo]);
|
|
329
|
+
cursor = Math.max(cursor, hi);
|
|
330
|
+
}
|
|
331
|
+
return visible.map((pair) => pair.map((t) => ({
|
|
332
|
+
x: a.x + t * dx,
|
|
333
|
+
y: a.y + t * dy
|
|
334
|
+
})));
|
|
335
|
+
}
|
|
336
|
+
var move = (a, b, distance) => {
|
|
337
|
+
const t = distance / (length(a, b) || 1);
|
|
338
|
+
return {
|
|
339
|
+
x: a.x + (b.x - a.x) * t,
|
|
340
|
+
y: a.y + (b.y - a.y) * t
|
|
341
|
+
};
|
|
342
|
+
};
|
|
343
|
+
var arrowhead = (ctx, a, b, fill) => {
|
|
344
|
+
const p = move(b, a, 7), dx = p.y - b.y, dy = b.x - p.x;
|
|
345
|
+
return ctx.path(`M${b.x} ${b.y} L${p.x + dx * .48} ${p.y + dy * .48} L${p.x - dx * .48} ${p.y - dy * .48} Z`, { fill });
|
|
346
|
+
};
|
|
347
|
+
function layout(model, { width, lang, ctx }, info = {}) {
|
|
348
|
+
const t = appearance(ctx), edge = ctx.color("muted"), grid = ctx.color("grid"), axis = t.fg4;
|
|
349
|
+
const config = mapConfig(info.config, "wardley");
|
|
350
|
+
const pad = 48;
|
|
351
|
+
const stageParts = model.stages.map((stage) => [{
|
|
352
|
+
text: stage.name + (stage.secondName !== null ? " /" : ""),
|
|
353
|
+
icons: [stage.icon].filter(Boolean)
|
|
354
|
+
}, ...stage.secondName !== null ? [{
|
|
355
|
+
text: stage.secondName,
|
|
356
|
+
icons: [stage.secondIcon].filter(Boolean)
|
|
357
|
+
}] : []].flatMap(({ text, icons }) => text.split("\n").map((row, i) => ({
|
|
358
|
+
text: row,
|
|
359
|
+
icons: i === 0 ? icons : []
|
|
360
|
+
}))));
|
|
361
|
+
const iconGap = (icon) => icon ? 20 : 0;
|
|
362
|
+
const stageInkWidth = ({ text, icons }) => ctx.measure(text, FONT.label.size, 400) + icons.length * 20;
|
|
363
|
+
const fractions = model.stages.map((stage, i) => (stage.boundary ?? 100 * (i + 1) / stageParts.length) / 100);
|
|
364
|
+
const bandFraction = (i) => fractions[i] - (fractions[i - 1] || 0);
|
|
365
|
+
const stageWidth = Math.max(...stageParts.map((rows, i) => (Math.max(...rows.map(stageInkWidth)) + 22) / bandFraction(i)));
|
|
366
|
+
const dimension = (value, fallback) => typeof value === "number" && Number.isFinite(value) ? Math.max(0, Math.min(16e3, value)) : fallback;
|
|
367
|
+
const W = Math.max(96 + stageWidth, 420, dimension(model.size?.width ?? mapConfig(config, "width"), 900));
|
|
368
|
+
const right = W - pad, plotW = right - pad;
|
|
369
|
+
const stages = stageParts.map((parts, i) => {
|
|
370
|
+
if (parts.length !== 2 || model.stages[i].secondName === null || [model.stages[i].name, model.stages[i].secondName].some((text) => text.includes("\n"))) return parts;
|
|
371
|
+
const together = {
|
|
372
|
+
text: parts.map((part) => part.text).join(" "),
|
|
373
|
+
icons: parts.flatMap((part) => part.icons)
|
|
374
|
+
};
|
|
375
|
+
return stageInkWidth(together) + 22 <= plotW * bandFraction(i) ? [together] : parts;
|
|
376
|
+
});
|
|
377
|
+
const titleRows = model.title || model.titleIcon ? ctx.wrap(model.title, plotW - iconGap(model.titleIcon), FONT.title.size, FONT.title.weight) : [];
|
|
378
|
+
const top = 48 + Math.max(0, titleRows.length - 1) * 16;
|
|
379
|
+
const stagesExtra = Math.max(0, ...stages.map((rows) => rows.length - 2)) * 16;
|
|
380
|
+
const H = Math.max(top + 212 + stagesExtra, dimension(model.size?.height ?? mapConfig(config, "height"), 600));
|
|
381
|
+
const bottom = H - 86 - stagesExtra, plotH = bottom - top;
|
|
382
|
+
const project = ({ evolution, visibility }) => ({
|
|
383
|
+
x: pad + plotW * evolution / 100,
|
|
384
|
+
y: bottom - plotH * visibility / 100
|
|
385
|
+
});
|
|
386
|
+
const nodes = new Map(model.nodes.map((node) => [node.id, {
|
|
387
|
+
...node,
|
|
388
|
+
...project(node),
|
|
389
|
+
r: node.strategy ? 10 : 5
|
|
390
|
+
}]));
|
|
391
|
+
const guides = [], frames = [], lines = [], marks = [], labels = [], leaders = [];
|
|
392
|
+
const obstacles = [], occupied = [], wires = [], annotations = model.annotations.slice().sort((a, b) => Number(a.number) - Number(b.number));
|
|
393
|
+
const stroke = (color, extra = {}) => ({
|
|
394
|
+
stroke: color,
|
|
395
|
+
"stroke-width": 1,
|
|
396
|
+
...extra
|
|
397
|
+
});
|
|
398
|
+
const line = (a, b, color, extra) => ctx.line(a.x, a.y, b.x, b.y, stroke(color, extra));
|
|
399
|
+
const addLeader = (a, b) => {
|
|
400
|
+
leaders.push(line(a, b, t.fg4, {
|
|
401
|
+
"stroke-dasharray": "2 3",
|
|
402
|
+
meta: { kind: "leader" }
|
|
403
|
+
}));
|
|
404
|
+
wires.push([a, b]);
|
|
405
|
+
};
|
|
406
|
+
const label = (x, y, rows, font = FONT.label, fill = t.fg1, anchor = "middle", meta) => textBlock(ctx, {
|
|
407
|
+
x,
|
|
408
|
+
y,
|
|
409
|
+
lines: rows,
|
|
410
|
+
font,
|
|
411
|
+
fill,
|
|
412
|
+
anchor,
|
|
413
|
+
lineHeight: 16,
|
|
414
|
+
meta
|
|
415
|
+
});
|
|
416
|
+
const caption = (x, y, rows, icon, font, fill = t.fg1, anchor = "middle") => {
|
|
417
|
+
if (!icon) return label(x, y, rows, font, fill, anchor);
|
|
418
|
+
const textW = Math.max(0, ...rows.map((row) => ctx.measure(row, font.size, font.weight)));
|
|
419
|
+
const shift = iconGap(icon);
|
|
420
|
+
return ctx.el("g", {}, [label(x + shift * (anchor === "middle" ? .5 : 1), y, rows, font, fill, anchor), mapIcon(ctx, icon, x - (anchor === "middle" ? (textW + shift) / 2 : 0) + 7, y, fill)]);
|
|
421
|
+
};
|
|
422
|
+
const bold = {
|
|
423
|
+
...FONT.label,
|
|
424
|
+
weight: 650
|
|
425
|
+
};
|
|
426
|
+
const pipelineEdges = [], pipelineRows = [];
|
|
427
|
+
for (const pipeline of model.pipelines) {
|
|
428
|
+
const parent = nodes.get(pipeline.parent);
|
|
429
|
+
const children = pipeline.children.map((child) => nodes.get(child.id)).filter(Boolean).sort((a, b) => a.x - b.x);
|
|
430
|
+
if (!parent || !children.length) continue;
|
|
431
|
+
const x = children[0].x - 16, w = children.at(-1).x - x + 16;
|
|
432
|
+
parent.x = x + w / 2;
|
|
433
|
+
parent.y -= 25;
|
|
434
|
+
parent.square = true;
|
|
435
|
+
frames.push(ctx.rect(x, children[0].y - 15, w, 30, {
|
|
436
|
+
rx: t.smallRadius,
|
|
437
|
+
fill: ctx.tint(t.bg, ctx.frameTone(ctx.color("tone1")), .07),
|
|
438
|
+
stroke: ctx.tint(t.bg, ctx.frameTone(ctx.color("tone1")), .45),
|
|
439
|
+
meta: {
|
|
440
|
+
kind: "frame",
|
|
441
|
+
id: pipeline.parent
|
|
442
|
+
}
|
|
443
|
+
}));
|
|
444
|
+
pipelineRows.push({
|
|
445
|
+
children,
|
|
446
|
+
bottom: children[0].y + 15
|
|
447
|
+
});
|
|
448
|
+
for (let i = 1; i < children.length; i++) pipelineEdges.push({
|
|
449
|
+
from: children[i - 1].id,
|
|
450
|
+
to: children[i].id,
|
|
451
|
+
dashed: true
|
|
452
|
+
});
|
|
453
|
+
}
|
|
454
|
+
for (const node of nodes.values()) {
|
|
455
|
+
obstacles.push(centerBox(node.x, node.y, node.r * 2, node.r * 2));
|
|
456
|
+
if (node.inertia) obstacles.push(centerBox(node.x + node.r + 6, node.y, 3, 20));
|
|
457
|
+
}
|
|
458
|
+
const placeMarker = (item, radius) => {
|
|
459
|
+
const p = project(item);
|
|
460
|
+
const candidates = [p];
|
|
461
|
+
for (const distance of [
|
|
462
|
+
radius + 5,
|
|
463
|
+
22,
|
|
464
|
+
32,
|
|
465
|
+
46,
|
|
466
|
+
64
|
|
467
|
+
]) for (const [dx, dy] of [
|
|
468
|
+
[0, -1],
|
|
469
|
+
[1, 0],
|
|
470
|
+
[-1, 0],
|
|
471
|
+
[0, 1],
|
|
472
|
+
[1, -1],
|
|
473
|
+
[-1, -1],
|
|
474
|
+
[1, 1],
|
|
475
|
+
[-1, 1]
|
|
476
|
+
]) candidates.push({
|
|
477
|
+
x: p.x + dx * distance,
|
|
478
|
+
y: p.y + dy * distance
|
|
479
|
+
});
|
|
480
|
+
const blockers = [...obstacles, ...occupied];
|
|
481
|
+
const { x, y } = candidates.find((q) => {
|
|
482
|
+
const b = grow(centerBox(q.x, q.y, radius * 2, radius * 2), 3);
|
|
483
|
+
return !blockers.some((o) => collides(b, o)) && !wires.some(([a, z]) => crosses(a, z, b)) && (q === p || !occupied.some((o) => crosses(p, q, grow(o, 2))));
|
|
484
|
+
}) || p;
|
|
485
|
+
obstacles.push(centerBox(x, y, radius * 2, radius * 2));
|
|
486
|
+
if (x !== p.x || y !== p.y) addLeader(p, move({
|
|
487
|
+
x,
|
|
488
|
+
y
|
|
489
|
+
}, p, radius));
|
|
490
|
+
return {
|
|
491
|
+
...item,
|
|
492
|
+
x,
|
|
493
|
+
y,
|
|
494
|
+
radius
|
|
495
|
+
};
|
|
496
|
+
};
|
|
497
|
+
const forces = model.forces.map((item) => {
|
|
498
|
+
const p = project(item);
|
|
499
|
+
obstacles.push(centerBox(p.x, p.y, 40, 20));
|
|
500
|
+
return {
|
|
501
|
+
...item,
|
|
502
|
+
...p
|
|
503
|
+
};
|
|
504
|
+
});
|
|
505
|
+
let footerY = H;
|
|
506
|
+
function place(text, p, options = {}) {
|
|
507
|
+
const { font = FONT.label, fill = t.fg1, radius = 6, preferred, fixed, plate, meta, icon, clearance = 2 } = options;
|
|
508
|
+
const rows = ctx.wrap(text, Math.min(260, plotW / 2) - iconGap(icon), font.size, font.weight);
|
|
509
|
+
const w = Math.max(...rows.map((row) => ctx.measure(row, font.size, font.weight))) + iconGap(icon) + (plate ? 14 : 4);
|
|
510
|
+
const h = rows.length * 16 + (plate ? 6 : 2);
|
|
511
|
+
const stepX = radius + w / 2 + 6, stepY = radius + h / 2 + 6;
|
|
512
|
+
const candidates = preferred ? [preferred] : [];
|
|
513
|
+
for (const gap of [
|
|
514
|
+
0,
|
|
515
|
+
12,
|
|
516
|
+
26,
|
|
517
|
+
44,
|
|
518
|
+
68,
|
|
519
|
+
98,
|
|
520
|
+
136
|
|
521
|
+
]) {
|
|
522
|
+
const sides = [
|
|
523
|
+
[stepX + gap, -gap / 4],
|
|
524
|
+
[stepX + gap, -stepY - gap / 2],
|
|
525
|
+
[-stepX - gap, 0],
|
|
526
|
+
[0, stepY + gap],
|
|
527
|
+
[0, -stepY - gap],
|
|
528
|
+
[-stepX - gap, -stepY - gap / 2],
|
|
529
|
+
[stepX + gap, stepY + gap / 2],
|
|
530
|
+
[-stepX - gap, stepY + gap / 2]
|
|
531
|
+
];
|
|
532
|
+
if (options.above) sides.unshift(sides.splice(4, 1)[0]);
|
|
533
|
+
for (const [dx, dy] of sides) candidates.push({
|
|
534
|
+
x: p.x + dx,
|
|
535
|
+
y: p.y + dy
|
|
536
|
+
});
|
|
537
|
+
}
|
|
538
|
+
const leaderFor = (q) => {
|
|
539
|
+
if (length(p, q) <= Math.hypot(stepX, stepY) + 10) return null;
|
|
540
|
+
const scale = Math.min((w / 2 + 1) / Math.abs(q.x - p.x), (h / 2 + 1) / Math.abs(q.y - p.y));
|
|
541
|
+
return [move(p, q, radius + 3), move(q, p, length(p, q) * scale)];
|
|
542
|
+
};
|
|
543
|
+
const fits = (q) => {
|
|
544
|
+
const { x, y } = q;
|
|
545
|
+
const leader = leaderFor(q);
|
|
546
|
+
if (leader && [...obstacles, ...occupied].some((o) => crosses(...leader, grow(o, 2)))) return false;
|
|
547
|
+
const b = grow(centerBox(x, y, w, h), clearance);
|
|
548
|
+
return b.x > 31 && b.x + b.w < W - 8 && b.y > top - 20 && b.y + b.h < bottom + 9 && !obstacles.some((o) => collides(b, o)) && !occupied.some((o) => collides(b, o)) && !wires.some(([a, z]) => crosses(a, z, b));
|
|
549
|
+
};
|
|
550
|
+
let chosen = fixed || candidates.find(fits);
|
|
551
|
+
const leader = !fixed && chosen && leaderFor(chosen);
|
|
552
|
+
if (leader) addLeader(...leader);
|
|
553
|
+
if (!chosen) {
|
|
554
|
+
chosen = {
|
|
555
|
+
x: pad + w / 2,
|
|
556
|
+
y: footerY + h / 2 + 4
|
|
557
|
+
};
|
|
558
|
+
footerY += h + 8;
|
|
559
|
+
}
|
|
560
|
+
const { x, y } = chosen, b = centerBox(x, y, w, h);
|
|
561
|
+
occupied.push(b);
|
|
562
|
+
const textNode = caption(x, y, rows, icon, font, fill);
|
|
563
|
+
if (fixed && wires.some(([a, z]) => crosses(a, z, b))) labels.push(ctx.rect(b.x, b.y, b.w, b.h, {
|
|
564
|
+
fill: t.bg,
|
|
565
|
+
rx: t.smallRadius
|
|
566
|
+
}));
|
|
567
|
+
labels.push(plate ? {
|
|
568
|
+
...ctx.el("g", {}, [ctx.rect(b.x, b.y, b.w, b.h, {
|
|
569
|
+
fill: t.bg,
|
|
570
|
+
stroke: grid,
|
|
571
|
+
rx: t.smallRadius
|
|
572
|
+
}), textNode]),
|
|
573
|
+
...meta ? { meta } : {}
|
|
574
|
+
} : textNode);
|
|
575
|
+
}
|
|
576
|
+
const pendingLabels = [], painted = [];
|
|
577
|
+
const nodeBoxes = [...nodes.values()].map((node) => ({
|
|
578
|
+
id: node.id,
|
|
579
|
+
...grow(centerBox(node.x, node.y, node.r * 2, node.r * 2), 2)
|
|
580
|
+
}));
|
|
581
|
+
function connect(a, b, link, trend = false) {
|
|
582
|
+
const color = trend ? t.danger : edge;
|
|
583
|
+
const distance = length(a, b);
|
|
584
|
+
const inset = (p, q) => p.r ? Math.min(distance / 2, (p.square || p.kind === "anchor" ? p.r * distance / Math.max(Math.abs(p.x - q.x), Math.abs(p.y - q.y), 1e-9) : p.r) + 1) : 0;
|
|
585
|
+
const start = move(a, b, inset(a, b)), end = move(b, a, inset(b, a));
|
|
586
|
+
const visible = visibleSpans(start, end, nodeBoxes.filter((box) => box.id !== a.id && box.id !== b.id), painted);
|
|
587
|
+
painted.push(...visible);
|
|
588
|
+
wires.push(...visible);
|
|
589
|
+
const path = visible.map(([p, q]) => `M${p.x} ${p.y} L${q.x} ${q.y}`).join(" ");
|
|
590
|
+
if (path) {
|
|
591
|
+
const edgePath = ctx.path(path, {
|
|
592
|
+
fill: "none",
|
|
593
|
+
...stroke(color, {
|
|
594
|
+
"stroke-width": trend ? 1.5 : 1.2,
|
|
595
|
+
...link.dashed || trend ? { "stroke-dasharray": trend ? "5 4" : "3 4" } : {},
|
|
596
|
+
meta: {
|
|
597
|
+
kind: "edge",
|
|
598
|
+
from: a.id,
|
|
599
|
+
to: b.id ?? `trend:${a.id}`
|
|
600
|
+
}
|
|
601
|
+
})
|
|
602
|
+
});
|
|
603
|
+
const clipped = visible.length !== 1 || length(visible[0][0], start) > 1e-5 || length(visible[0][1], end) > 1e-5;
|
|
604
|
+
lines.push(!trend && clipped ? ctx.titled(edgePath, `${a.label} → ${b.label}`) : edgePath);
|
|
605
|
+
}
|
|
606
|
+
if (trend || link.flow === "forward" || link.flow === "bidirectional") lines.push(arrowhead(ctx, start, end, color));
|
|
607
|
+
if (link.flow === "backward" || link.flow === "bidirectional") lines.push(arrowhead(ctx, end, start, color));
|
|
608
|
+
if (link.label || link.icon) pendingLabels.push({
|
|
609
|
+
link,
|
|
610
|
+
point: move(start, end, length(start, end) / 2)
|
|
611
|
+
});
|
|
612
|
+
}
|
|
613
|
+
const dependencies = [...pipelineEdges, ...model.links].map((link) => ({
|
|
614
|
+
link,
|
|
615
|
+
a: nodes.get(link.from),
|
|
616
|
+
b: nodes.get(link.to)
|
|
617
|
+
})).filter(({ a, b }) => a && b && a.parent !== b.id && b.parent !== a.id);
|
|
618
|
+
dependencies.sort((p, q) => length(p.a, p.b) - length(q.a, q.b));
|
|
619
|
+
for (const { a, b, link } of dependencies) connect(a, b, link);
|
|
620
|
+
for (const { nodeId, targetEvolution } of model.trends) {
|
|
621
|
+
const a = nodes.get(nodeId);
|
|
622
|
+
if (!a) continue;
|
|
623
|
+
connect(a, {
|
|
624
|
+
x: project({
|
|
625
|
+
evolution: targetEvolution,
|
|
626
|
+
visibility: a.visibility
|
|
627
|
+
}).x,
|
|
628
|
+
y: a.y
|
|
629
|
+
}, {}, true);
|
|
630
|
+
}
|
|
631
|
+
if (titleRows.length) guides.push(caption(W / 2, 23 + (titleRows.length - 1) * 8, titleRows, model.titleIcon, FONT.title));
|
|
632
|
+
guides.push(ctx.line(pad, top, pad, bottom, stroke(axis)), ctx.line(pad, bottom, right, bottom, stroke(axis)));
|
|
633
|
+
const axisMiddle = (top + bottom) / 2;
|
|
634
|
+
guides.push(ctx.el("g", { transform: `rotate(-90 18 ${axisMiddle})` }, [label(18, axisMiddle, [word(lang, "visibility")], bold, t.fg2)]));
|
|
635
|
+
guides.push(label((pad + right) / 2, bottom + 64 + stagesExtra, [word(lang, "evolution")], bold, t.fg2));
|
|
636
|
+
stages.forEach((rows, i) => {
|
|
637
|
+
const x = pad + plotW * (fractions[i - 1] || 0), end = pad + plotW * fractions[i];
|
|
638
|
+
if (i) guides.push(ctx.line(x, top, x, bottom, stroke(grid)));
|
|
639
|
+
const mid = (x + end) / 2;
|
|
640
|
+
rows.forEach(({ text, icons }, j) => {
|
|
641
|
+
const y = bottom + 25 + j * 16;
|
|
642
|
+
guides.push(label(mid + icons.length * 10, y, [text], FONT.label, t.fg2));
|
|
643
|
+
icons.forEach((icon, k) => guides.push(mapIcon(ctx, icon, mid - stageInkWidth({
|
|
644
|
+
text,
|
|
645
|
+
icons
|
|
646
|
+
}) / 2 + k * 20 + 7, y, t.fg2)));
|
|
647
|
+
});
|
|
648
|
+
});
|
|
649
|
+
const placeComponent = (node) => {
|
|
650
|
+
const fixed = node.labelOffset && {
|
|
651
|
+
x: node.x + node.labelOffset.dx,
|
|
652
|
+
y: node.y + node.labelOffset.dy
|
|
653
|
+
};
|
|
654
|
+
const above = node.kind === "anchor" || node.square;
|
|
655
|
+
place(node.label, node, {
|
|
656
|
+
radius: node.r,
|
|
657
|
+
fixed,
|
|
658
|
+
icon: node.icon,
|
|
659
|
+
above,
|
|
660
|
+
font: above ? bold : FONT.label
|
|
661
|
+
});
|
|
662
|
+
};
|
|
663
|
+
for (const node of nodes.values()) if (node.labelOffset) placeComponent(node);
|
|
664
|
+
const grouped = /* @__PURE__ */ new Set();
|
|
665
|
+
for (const row of pipelineRows) {
|
|
666
|
+
const captions = row.children.filter((node) => !node.labelOffset).map((node) => {
|
|
667
|
+
const maxWidth = Math.min(260, plotW / 2) - iconGap(node.icon);
|
|
668
|
+
const rows = ctx.wrap(node.label, maxWidth, 12);
|
|
669
|
+
return {
|
|
670
|
+
node,
|
|
671
|
+
rows,
|
|
672
|
+
w: Math.max(...rows.map((text) => ctx.measure(text, 12, 400))) + iconGap(node.icon) + 8
|
|
673
|
+
};
|
|
674
|
+
});
|
|
675
|
+
if (!captions.length) continue;
|
|
676
|
+
const height = Math.max(...captions.map((item) => item.rows.length)) * 16;
|
|
677
|
+
const total = captions.reduce((sum, item) => sum + item.w, 0);
|
|
678
|
+
let next = pad, remaining = total;
|
|
679
|
+
const xs = captions.map(({ node, w }) => {
|
|
680
|
+
const left = Math.max(next, Math.min(node.x - w / 2, right - remaining));
|
|
681
|
+
remaining -= w;
|
|
682
|
+
next = left + w;
|
|
683
|
+
return left + w / 2;
|
|
684
|
+
});
|
|
685
|
+
const firstY = row.bottom + 8 + height / 2;
|
|
686
|
+
const boxes = (y) => captions.map(({ w }, i) => centerBox(xs[i], y, w, height));
|
|
687
|
+
let y = firstY;
|
|
688
|
+
while (y + height / 2 < bottom && boxes(y).some((b) => [...obstacles, ...occupied].some((o) => collides(b, o)) || wires.some(([a, z]) => crosses(a, z, b)))) y += 12;
|
|
689
|
+
if (y + height / 2 >= bottom || total > plotW) {
|
|
690
|
+
y = footerY + height / 2 + 4;
|
|
691
|
+
footerY += height + 8;
|
|
692
|
+
}
|
|
693
|
+
occupied.push(...boxes(y));
|
|
694
|
+
captions.forEach(({ node, rows }, i) => {
|
|
695
|
+
grouped.add(node.id);
|
|
696
|
+
labels.push(caption(xs[i], y - (height - rows.length * 16) / 2, rows, node.icon, FONT.label));
|
|
697
|
+
});
|
|
698
|
+
}
|
|
699
|
+
const pins = annotations.map((item) => placeMarker(item, Math.max(9, ctx.measure(item.number, 12, 650) / 2 + 4)));
|
|
700
|
+
const notes = model.notes.map((item) => placeMarker(item, 2));
|
|
701
|
+
for (const { link, point } of pendingLabels) place(link.label, point, {
|
|
702
|
+
plate: true,
|
|
703
|
+
above: true,
|
|
704
|
+
radius: 0,
|
|
705
|
+
icon: link.icon,
|
|
706
|
+
meta: {
|
|
707
|
+
kind: "edge-label-group",
|
|
708
|
+
from: link.from,
|
|
709
|
+
to: link.to
|
|
710
|
+
}
|
|
711
|
+
});
|
|
712
|
+
for (const node of nodes.values()) {
|
|
713
|
+
const { x, y, r, id, strategy, inertia, square } = node, anchor = node.kind === "anchor";
|
|
714
|
+
const meta = {
|
|
715
|
+
kind: "node",
|
|
716
|
+
id
|
|
717
|
+
};
|
|
718
|
+
const tone = ctx.frameTone(ctx.color(strategyTones[strategy] || "tone1"));
|
|
719
|
+
const shape = {
|
|
720
|
+
fill: anchor ? t.fg1 : strategy ? ctx.tint(t.bg, tone, .16) : t.node,
|
|
721
|
+
stroke: ctx.frameTone(edge),
|
|
722
|
+
"stroke-width": 1.4,
|
|
723
|
+
meta
|
|
724
|
+
};
|
|
725
|
+
if (square) marks.push(ctx.rect(x - r, y - r, 2 * r, 2 * r, {
|
|
726
|
+
...shape,
|
|
727
|
+
rx: 2
|
|
728
|
+
}));
|
|
729
|
+
else if (anchor) marks.push(ctx.rect(x - r, y - r, 2 * r, 2 * r, {
|
|
730
|
+
...shape,
|
|
731
|
+
rx: 3
|
|
732
|
+
}));
|
|
733
|
+
else marks.push(ctx.circle(x, y, r, shape));
|
|
734
|
+
if (strategy) marks.push(ctx.titled(label(x, y, [strategyGlyphs[strategy]], bold, ctx.textOn(shape.fill)), strategy));
|
|
735
|
+
if (inertia) marks.push(ctx.rect(x + r + 4.5, y - 10, 3, 20, {
|
|
736
|
+
rx: 1,
|
|
737
|
+
fill: edge
|
|
738
|
+
}));
|
|
739
|
+
if (!node.labelOffset && !grouped.has(id)) placeComponent(node);
|
|
740
|
+
}
|
|
741
|
+
for (const note of notes) {
|
|
742
|
+
marks.push(ctx.circle(note.x, note.y, 2, { fill: edge }));
|
|
743
|
+
place(note.text, note, {
|
|
744
|
+
plate: true,
|
|
745
|
+
radius: 2,
|
|
746
|
+
clearance: 12,
|
|
747
|
+
fill: t.fg2,
|
|
748
|
+
icon: note.icon
|
|
749
|
+
});
|
|
750
|
+
}
|
|
751
|
+
for (const f of forces) {
|
|
752
|
+
const d = f.kind === "accelerator" ? 1 : -1;
|
|
753
|
+
const points = [
|
|
754
|
+
[-20, -5],
|
|
755
|
+
[6, -5],
|
|
756
|
+
[6, -10],
|
|
757
|
+
[20, 0],
|
|
758
|
+
[6, 10],
|
|
759
|
+
[6, 5],
|
|
760
|
+
[-20, 5]
|
|
761
|
+
].map(([x, y]) => `${f.x + x * d},${f.y + y}`);
|
|
762
|
+
marks.push(ctx.shape("polygon", {
|
|
763
|
+
points: points.join(" "),
|
|
764
|
+
fill: t.node,
|
|
765
|
+
stroke: edge,
|
|
766
|
+
"stroke-width": 1.3
|
|
767
|
+
}));
|
|
768
|
+
place(f.name, f, {
|
|
769
|
+
preferred: {
|
|
770
|
+
x: f.x,
|
|
771
|
+
y: f.y + 24
|
|
772
|
+
},
|
|
773
|
+
radius: 20,
|
|
774
|
+
icon: f.icon
|
|
775
|
+
});
|
|
776
|
+
}
|
|
777
|
+
for (const pin of pins) {
|
|
778
|
+
marks.push(ctx.circle(pin.x, pin.y, pin.radius, {
|
|
779
|
+
fill: t.bg,
|
|
780
|
+
stroke: edge,
|
|
781
|
+
"stroke-width": 1.4
|
|
782
|
+
}));
|
|
783
|
+
marks.push(label(pin.x, pin.y, [pin.number], bold));
|
|
784
|
+
}
|
|
785
|
+
if (annotations.length) {
|
|
786
|
+
const rows = annotations.flatMap(({ number, text, icon }) => ctx.wrap(`${number}. ${text}`, Math.min(270, plotW / 2) - iconGap(icon), 12).map((row, i) => ({
|
|
787
|
+
row,
|
|
788
|
+
icon: i === 0 ? icon : null
|
|
789
|
+
})));
|
|
790
|
+
const w = Math.max(...rows.map(({ row, icon }) => ctx.measure(row, 12, 400) + iconGap(icon))) + 28, h = rows.length * 16 + 35;
|
|
791
|
+
const p = model.annotationBox ? project(model.annotationBox) : {
|
|
792
|
+
x: right,
|
|
793
|
+
y: bottom
|
|
794
|
+
};
|
|
795
|
+
const desired = box(Math.max(34, Math.min(W - w - 10, p.x)), Math.min(bottom - h - 5, p.y), w, h);
|
|
796
|
+
const floating = width >= 480 && desired.y >= top && ![...obstacles, ...occupied].some((o) => collides(grow(desired, 4), o)) && !wires.some(([a, b]) => crosses(a, b, grow(desired, 3)));
|
|
797
|
+
const r = floating ? desired : box(pad, footerY, w, h);
|
|
798
|
+
if (!floating) footerY += h + 8;
|
|
799
|
+
labels.push(ctx.rect(r.x, r.y, r.w, r.h, {
|
|
800
|
+
rx: t.radius,
|
|
801
|
+
fill: t.node,
|
|
802
|
+
stroke: grid,
|
|
803
|
+
meta: {
|
|
804
|
+
kind: "frame",
|
|
805
|
+
id: "annotations"
|
|
806
|
+
}
|
|
807
|
+
}), label(r.x + 14, r.y + 14, [word(lang, "annotations")], bold, t.fg1, "start"), ...rows.map(({ row, icon }, i) => caption(r.x + 14, r.y + 35 + i * 16, [row], icon, FONT.label, t.fg2, "start")));
|
|
808
|
+
}
|
|
809
|
+
const strategies = Object.keys(strategyGlyphs).filter((strategy) => model.nodes.some((node) => node.strategy === strategy));
|
|
810
|
+
if (strategies.length) {
|
|
811
|
+
const rows = ctx.wrap(strategies.map((strategy) => `${strategyGlyphs[strategy]} · ${word(lang, strategy)}`).join(" / "), plotW, 12);
|
|
812
|
+
labels.push(label(pad, footerY + rows.length * 8, rows, FONT.label, t.fg2, "start"));
|
|
813
|
+
footerY += rows.length * 16 + 8;
|
|
814
|
+
}
|
|
815
|
+
const errors = W > width * 2 || nodes.size > 60 ? [warning("LARGE_DIAGRAM", lang, info.headerLine || 1, "地图较大,可拆成多张地图", "Large map; consider splitting it into smaller maps")] : [];
|
|
816
|
+
return {
|
|
817
|
+
scene: {
|
|
818
|
+
width: W,
|
|
819
|
+
height: footerY + 8,
|
|
820
|
+
title: model.title || void 0,
|
|
821
|
+
children: [
|
|
822
|
+
...guides,
|
|
823
|
+
...frames,
|
|
824
|
+
...lines,
|
|
825
|
+
...leaders,
|
|
826
|
+
...marks,
|
|
827
|
+
...labels
|
|
828
|
+
]
|
|
829
|
+
},
|
|
830
|
+
errors
|
|
831
|
+
};
|
|
832
|
+
}
|
|
833
|
+
var implementations = { "wardley-beta": {
|
|
834
|
+
parse,
|
|
835
|
+
layout,
|
|
836
|
+
honoredConfig: ["wardley.width", "wardley.height"]
|
|
837
|
+
} };
|
|
838
|
+
export { implementations, wardley_exports };
|