@fengwk/kchart 0.1.1 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +35 -0
- package/README.md +31 -2
- package/README.zh-CN.md +31 -2
- package/dist/esm/_virtual/_kchart-families.js +2 -1
- package/dist/esm/chart/composition.js +7 -5
- package/dist/esm/chart/maps.js +9 -7
- package/dist/esm/chart/mindmap.js +19 -5
- package/dist/esm/chart/multivariate.js +49 -14
- package/dist/esm/chart/relations.js +15 -7
- package/dist/esm/chart/spec.js +5 -2
- package/dist/esm/core/context.js +29 -10
- package/dist/esm/core/scene.js +238 -21
- package/dist/esm/core/text.js +1 -1
- package/dist/esm/diagram/block.js +287 -295
- package/dist/esm/diagram/blocks.js +541 -605
- package/dist/esm/diagram/board-paint.js +594 -0
- package/dist/esm/diagram/board-route.js +60 -0
- package/dist/esm/diagram/c4.js +75 -35
- package/dist/esm/diagram/class.js +3 -2
- package/dist/esm/diagram/cynefin.js +55 -9
- package/dist/esm/diagram/eventmodeling.js +4 -2
- package/dist/esm/diagram/gantt.js +37 -15
- package/dist/esm/diagram/gitgraph.js +26 -5
- package/dist/esm/diagram/graph-layout.js +39 -2
- package/dist/esm/diagram/graph-route.js +296 -38
- package/dist/esm/diagram/info.js +32 -0
- package/dist/esm/diagram/journey.js +5 -5
- package/dist/esm/diagram/kanban.js +3 -3
- package/dist/esm/diagram/layers.js +9 -7
- package/dist/esm/diagram/mindmap.js +5 -1
- package/dist/esm/diagram/numeric-composition.js +24 -4
- package/dist/esm/diagram/numeric-model.js +1 -1
- package/dist/esm/diagram/numeric-radar.js +25 -7
- package/dist/esm/diagram/numeric-sankey.js +4 -3
- package/dist/esm/diagram/numeric-xy.js +12 -2
- package/dist/esm/diagram/packet.js +4 -4
- package/dist/esm/diagram/quadrant.js +12 -5
- package/dist/esm/diagram/railroad-parse.js +20 -10
- package/dist/esm/diagram/railroad.js +1 -1
- package/dist/esm/diagram/registry.js +46 -8
- package/dist/esm/diagram/sequence.js +43 -6
- package/dist/esm/diagram/swimlane.js +2 -2
- package/dist/esm/diagram/time.js +3 -3
- package/dist/esm/diagram/timeline.js +5 -5
- package/dist/esm/diagram/treeview.js +5 -3
- package/dist/esm/diagram/venn.js +35 -15
- package/dist/esm/diagram/wardley.js +61 -26
- package/dist/esm/diagram/zenuml.js +338 -0
- package/dist/esm/index.d.ts +3 -1
- package/dist/esm/mermaid.d.ts +1 -1
- package/dist/esm/mermaid.js +2 -1
- package/dist/esm/node.js +8 -2
- package/dist/esm/src/families.js +6 -1
- package/dist/units/chart/composition.js +1 -1
- package/dist/units/chart/maps.js +1 -1
- package/dist/units/chart/mindmap.js +1 -1
- package/dist/units/chart/multivariate.js +1 -1
- package/dist/units/chart/relations.js +1 -1
- package/dist/units/chart/spec.js +1 -1
- package/dist/units/core/context.js +1 -1
- package/dist/units/core/scene.js +1 -1
- package/dist/units/core/text.js +1 -1
- package/dist/units/diagram/block.js +2 -2
- package/dist/units/diagram/blocks.js +2 -2
- package/dist/units/diagram/board-paint.js +1 -0
- package/dist/units/diagram/board-route.js +1 -0
- package/dist/units/diagram/c4.js +1 -1
- package/dist/units/diagram/class.js +2 -2
- package/dist/units/diagram/cynefin.js +2 -2
- package/dist/units/diagram/eventmodeling.js +1 -1
- package/dist/units/diagram/gantt.js +3 -3
- package/dist/units/diagram/gitgraph.js +2 -1
- package/dist/units/diagram/graph-layout.js +1 -1
- package/dist/units/diagram/graph-route.js +1 -1
- package/dist/units/diagram/info.js +2 -0
- package/dist/units/diagram/journey.js +3 -3
- package/dist/units/diagram/kanban.js +1 -1
- package/dist/units/diagram/layers.js +1 -1
- package/dist/units/diagram/mindmap.js +1 -1
- package/dist/units/diagram/numeric-composition.js +1 -1
- package/dist/units/diagram/numeric-model.js +1 -1
- package/dist/units/diagram/numeric-radar.js +2 -2
- package/dist/units/diagram/numeric-sankey.js +1 -1
- package/dist/units/diagram/numeric-xy.js +1 -1
- package/dist/units/diagram/packet.js +1 -1
- package/dist/units/diagram/quadrant.js +1 -1
- package/dist/units/diagram/railroad-parse.js +2 -2
- package/dist/units/diagram/railroad.js +1 -1
- package/dist/units/diagram/registry.js +2 -2
- package/dist/units/diagram/sequence.js +1 -1
- package/dist/units/diagram/swimlane.js +2 -2
- package/dist/units/diagram/time.js +1 -1
- package/dist/units/diagram/timeline.js +1 -1
- package/dist/units/diagram/treeview.js +1 -1
- package/dist/units/diagram/venn.js +1 -1
- package/dist/units/diagram/wardley.js +4 -4
- package/dist/units/diagram/zenuml.js +2 -0
- package/dist/units.json +79 -51
- package/package.json +1 -1
- package/dist/esm/diagram/relations.js +0 -966
- package/dist/units/diagram/relations.js +0 -3
|
@@ -0,0 +1,338 @@
|
|
|
1
|
+
import { __exportAll } from "../_virtual/_rolldown/runtime.js";
|
|
2
|
+
import { error, warning } from "./support.js";
|
|
3
|
+
import { stripEmphasis } from "./emphasis.js";
|
|
4
|
+
import { LIMITS, implementations as implementations$1 } from "./sequence.js";
|
|
5
|
+
// src/diagram/zenuml.js
|
|
6
|
+
var zenuml_exports = /* @__PURE__ */ __exportAll({ implementations: () => implementations });
|
|
7
|
+
var ID = "[\\p{L}\\p{N}_$][\\p{L}\\p{N}_$-]*";
|
|
8
|
+
var participant = new RegExp(`^(?:@(\\w+)\\s+)?(${ID})(?:\\s+as\\s+(.+))?$`, "u");
|
|
9
|
+
var annotationCall = new RegExp(`^@(\\w+)\\s*\\(\\s*(${ID})\\s*\\)$`, "u");
|
|
10
|
+
var asyncMessage = new RegExp(`^(${ID}?)\\s*(-->>|-->|->>|->|<<--|<--|<-|==>|=>|\\.\\.>)\\s*(${ID})\\s*:\\s*(.*)$`, "u");
|
|
11
|
+
var call = new RegExp(`^(?:(?:[\\w.$<>\\[\\]]+\\s+)?(${ID})\\s*=\\s*)?(?:(${ID}?)\\s*->\\s*)?(${ID})\\.(${ID})(?:\\s*\\((.*)\\))?$`, "u");
|
|
12
|
+
var creation = new RegExp(`^new\\s+(${ID})(?:\\s*\\((.*)\\))?$`, "u");
|
|
13
|
+
var fragments = /^(while|for|foreach|loop|if|opt|par|try|else\s+if|else|catch|finally)\s*(?:\((.*)\))?$/iu;
|
|
14
|
+
var kinds = /* @__PURE__ */ new Set([
|
|
15
|
+
"actor",
|
|
16
|
+
"boundary",
|
|
17
|
+
"control",
|
|
18
|
+
"entity",
|
|
19
|
+
"database",
|
|
20
|
+
"collections",
|
|
21
|
+
"queue",
|
|
22
|
+
"participant"
|
|
23
|
+
]);
|
|
24
|
+
var STARTER = ":starter";
|
|
25
|
+
var MAX_LINES = 240;
|
|
26
|
+
var MAX_PARTICIPANTS = 40;
|
|
27
|
+
function tokenize(lines, firstLine) {
|
|
28
|
+
const tokens = [];
|
|
29
|
+
for (const [index, raw] of lines.entries()) {
|
|
30
|
+
const line = firstLine + index, text = raw.trim();
|
|
31
|
+
let start = 0, quote = "", depth = 0;
|
|
32
|
+
const push = (value) => {
|
|
33
|
+
if (value.trim()) tokens.push({
|
|
34
|
+
text: value.trim(),
|
|
35
|
+
line
|
|
36
|
+
});
|
|
37
|
+
};
|
|
38
|
+
if (/^title\s/i.test(text)) {
|
|
39
|
+
push(text);
|
|
40
|
+
continue;
|
|
41
|
+
}
|
|
42
|
+
for (let i = 0; i < text.length; i++) {
|
|
43
|
+
const ch = text[i];
|
|
44
|
+
if (quote) {
|
|
45
|
+
if (ch === "\\") i++;
|
|
46
|
+
else if (ch === quote) quote = "";
|
|
47
|
+
} else if (ch === "\"" || ch === "'" && depth) quote = ch;
|
|
48
|
+
else if (ch === "(") depth++;
|
|
49
|
+
else if (ch === ")") depth = Math.max(0, depth - 1);
|
|
50
|
+
else if (!depth) {
|
|
51
|
+
if (ch === ":") break;
|
|
52
|
+
if (ch === "/" && text[i + 1] === "/") {
|
|
53
|
+
push(text.slice(start, i));
|
|
54
|
+
push(text.slice(i));
|
|
55
|
+
start = text.length;
|
|
56
|
+
break;
|
|
57
|
+
}
|
|
58
|
+
if ("{};".includes(ch)) {
|
|
59
|
+
push(text.slice(start, i));
|
|
60
|
+
if (ch !== ";") push(ch);
|
|
61
|
+
start = i + 1;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
push(text.slice(start));
|
|
66
|
+
}
|
|
67
|
+
return tokens;
|
|
68
|
+
}
|
|
69
|
+
function parse(source, info) {
|
|
70
|
+
const { lang = "zh", firstLine = 2 } = info;
|
|
71
|
+
const actors = /* @__PURE__ */ new Map(), statements = [], errors = [], stack = [], ignored = /* @__PURE__ */ new Set();
|
|
72
|
+
let title = info.title || "", comments = [], replyLine, ignoredLine, messages = 0;
|
|
73
|
+
const bad = (line, zh, en, fixZh, fixEn) => errors.push(error(lang, line, zh, en, fixZh, fixEn));
|
|
74
|
+
const unrecognized = (line, text) => bad(line, `无法识别 ZenUML 语句:「${text}」`, `Unrecognized ZenUML statement: "${text}"`, "例如:@Actor Client、Client->API: 请求 或 API.call()", "For example: @Actor Client, Client->API: request, or API.call()");
|
|
75
|
+
const touch = (id, line) => {
|
|
76
|
+
if (!actors.has(id)) actors.set(id, {
|
|
77
|
+
id,
|
|
78
|
+
name: id === STARTER ? "" : id,
|
|
79
|
+
kind: id === STARTER ? "actor" : "participant",
|
|
80
|
+
line
|
|
81
|
+
});
|
|
82
|
+
return actors.get(id);
|
|
83
|
+
};
|
|
84
|
+
const caller = () => stack.findLast((item) => item.call);
|
|
85
|
+
const beginUnit = (line) => {
|
|
86
|
+
const parent = stack.at(-1);
|
|
87
|
+
if (parent?.keyword === "par" && parent.units++) {
|
|
88
|
+
const section = {
|
|
89
|
+
type: "section",
|
|
90
|
+
keyword: "",
|
|
91
|
+
line
|
|
92
|
+
};
|
|
93
|
+
parent.event.sections.push(section);
|
|
94
|
+
statements.push(section);
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
const addComment = (from, to, line) => {
|
|
98
|
+
const text = stripEmphasis(comments.join("\n"));
|
|
99
|
+
if (text) statements.push({
|
|
100
|
+
type: "note",
|
|
101
|
+
place: "over",
|
|
102
|
+
ids: from === to ? [from] : [from, to],
|
|
103
|
+
text,
|
|
104
|
+
line
|
|
105
|
+
});
|
|
106
|
+
comments = [];
|
|
107
|
+
};
|
|
108
|
+
const send = (from, to, text, line, extra = {}) => {
|
|
109
|
+
touch(from, line).used = true;
|
|
110
|
+
touch(to, line).used = true;
|
|
111
|
+
messages++;
|
|
112
|
+
statements.push({
|
|
113
|
+
type: "message",
|
|
114
|
+
from,
|
|
115
|
+
to,
|
|
116
|
+
text,
|
|
117
|
+
line,
|
|
118
|
+
arrow: {
|
|
119
|
+
head: "open",
|
|
120
|
+
dashed: false
|
|
121
|
+
},
|
|
122
|
+
...extra
|
|
123
|
+
});
|
|
124
|
+
};
|
|
125
|
+
const reply = (from, to, text, line) => send(from, to, text, line, { arrow: {
|
|
126
|
+
head: "open",
|
|
127
|
+
dashed: true
|
|
128
|
+
} });
|
|
129
|
+
const finishCall = (entry, line) => {
|
|
130
|
+
if (entry.assignment) reply(entry.to, entry.from, entry.assignment, line);
|
|
131
|
+
statements.push({
|
|
132
|
+
type: "deactivate",
|
|
133
|
+
id: entry.to,
|
|
134
|
+
line
|
|
135
|
+
});
|
|
136
|
+
};
|
|
137
|
+
const missingBlock = (line) => bad(line, "ZenUML 语句缺少花括号块", "ZenUML statement is missing a brace block", "在语句后添加 { … }", "Add { … } after the statement");
|
|
138
|
+
const missingReply = (line) => bad(line, "回复注解后缺少消息", "Expected a message after the reply annotation", "写成 @return A->B: 结果", "Write @return A->B: result");
|
|
139
|
+
for (const key of Object.keys(info.options || {})) bad(firstLine - 1, `ZenUML 头行不接受选项「${key}」`, `The ZenUML header does not accept option "${key}"`, "头行只保留 zenuml", "Use only zenuml on the header line");
|
|
140
|
+
const lines = String(source).split(/\r\n?|\n/u);
|
|
141
|
+
if (lines.length > MAX_LINES) bad(firstLine + MAX_LINES, `ZenUML 正文超过 ${MAX_LINES} 行`, `ZenUML body exceeds ${MAX_LINES} lines`, "拆分为多张图", "Split into several diagrams");
|
|
142
|
+
const tokens = tokenize(lines.slice(0, MAX_LINES), firstLine);
|
|
143
|
+
for (let i = 0; i < tokens.length; i++) {
|
|
144
|
+
const { text, line } = tokens[i];
|
|
145
|
+
if (text.startsWith("//")) {
|
|
146
|
+
comments.push(text.slice(2).trim());
|
|
147
|
+
continue;
|
|
148
|
+
}
|
|
149
|
+
let syntax = text;
|
|
150
|
+
const annotation = /^@(?:return|reply)(?:\s+(.*))?$/iu.exec(text);
|
|
151
|
+
if (annotation) {
|
|
152
|
+
if (replyLine) missingReply(replyLine);
|
|
153
|
+
replyLine = line;
|
|
154
|
+
if (!annotation[1]) continue;
|
|
155
|
+
syntax = annotation[1];
|
|
156
|
+
}
|
|
157
|
+
let match = asyncMessage.exec(syntax);
|
|
158
|
+
const isReply = Boolean(replyLine);
|
|
159
|
+
if (replyLine && !match) missingReply(replyLine);
|
|
160
|
+
replyLine = void 0;
|
|
161
|
+
if (match) {
|
|
162
|
+
const [, from, operator, to, label] = match;
|
|
163
|
+
if (operator !== "->") {
|
|
164
|
+
const example = `${from}->${to}: ${label}`;
|
|
165
|
+
bad(line, `ZenUML 消息箭头写法无效:「${operator}」`, `Invalid ZenUML message arrow "${operator}"`, `异步消息用 ${example};回复用 @return ${example} 或调用块内的 return`, `For an async message use ${example}; for a reply use @return ${example} or return inside a call block`);
|
|
166
|
+
} else {
|
|
167
|
+
beginUnit(line);
|
|
168
|
+
addComment(from, to, line);
|
|
169
|
+
if (isReply) reply(from, to, label, line);
|
|
170
|
+
else send(from, to, label, line);
|
|
171
|
+
}
|
|
172
|
+
} else if (syntax === "}") {
|
|
173
|
+
const entry = stack.at(-1);
|
|
174
|
+
if (!entry) bad(line, "ZenUML 多余的 }", "Unexpected } in ZenUML", "删除多余的 }", "Remove the unmatched }");
|
|
175
|
+
else if (entry.call) {
|
|
176
|
+
stack.pop();
|
|
177
|
+
finishCall(entry, line);
|
|
178
|
+
} else {
|
|
179
|
+
const next = tokens.slice(i + 1).find((token) => !token.text.startsWith("//"));
|
|
180
|
+
const branch = next && fragments.exec(next.text)?.[1].toLowerCase().replace(/\s+/g, " ");
|
|
181
|
+
if (entry.keyword === "if" && entry.branch !== "else" && (branch === "else" || branch === "else if") || entry.keyword === "try" && entry.branch !== "finally" && (branch === "catch" || branch === "finally")) entry.awaitingBranch = true;
|
|
182
|
+
else {
|
|
183
|
+
stack.pop();
|
|
184
|
+
statements.push({
|
|
185
|
+
type: "end",
|
|
186
|
+
line
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
} else if (match = fragments.exec(syntax)) {
|
|
191
|
+
const keyword = match[1].toLowerCase().replace(/\s+/g, " "), label = match[2]?.trim() || "";
|
|
192
|
+
const parent = stack.at(-1);
|
|
193
|
+
const branch = /^(else|catch|finally)/u.test(keyword);
|
|
194
|
+
if (tokens[i + 1]?.text !== "{") missingBlock(line);
|
|
195
|
+
else if (branch && !parent?.awaitingBranch) unrecognized(line, syntax);
|
|
196
|
+
else if (stack.length >= LIMITS.fragmentDepth && !branch) bad(line, "ZenUML 块嵌套过深", "ZenUML blocks are nested too deeply", "减少块的嵌套层数", "Reduce block nesting");
|
|
197
|
+
else {
|
|
198
|
+
i++;
|
|
199
|
+
if (branch) {
|
|
200
|
+
const section = {
|
|
201
|
+
type: "section",
|
|
202
|
+
keyword,
|
|
203
|
+
text: label,
|
|
204
|
+
line
|
|
205
|
+
};
|
|
206
|
+
parent.event.sections.push(section);
|
|
207
|
+
statements.push(section);
|
|
208
|
+
Object.assign(parent, {
|
|
209
|
+
branch: keyword,
|
|
210
|
+
awaitingBranch: false
|
|
211
|
+
});
|
|
212
|
+
} else {
|
|
213
|
+
beginUnit(line);
|
|
214
|
+
const event = {
|
|
215
|
+
type: "fragment",
|
|
216
|
+
keyword: keyword === "if" ? "alt" : /^(while|for|foreach)$/u.test(keyword) ? "loop" : keyword,
|
|
217
|
+
text: label,
|
|
218
|
+
sections: [],
|
|
219
|
+
line
|
|
220
|
+
};
|
|
221
|
+
statements.push(event);
|
|
222
|
+
stack.push({
|
|
223
|
+
event,
|
|
224
|
+
keyword,
|
|
225
|
+
line,
|
|
226
|
+
units: 0
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
} else if (match = /^return(?:\s+(.*))?$/u.exec(syntax)) {
|
|
231
|
+
const entry = caller();
|
|
232
|
+
if (!entry) bad(line, "return 应放在 ZenUML 同步调用块内", "Put return inside a ZenUML synchronous call block", "在调用的 { … } 内使用 return,或用 @return A->B: 结果", "Use return inside the call’s { … }, or use @return A->B: result");
|
|
233
|
+
else {
|
|
234
|
+
beginUnit(line);
|
|
235
|
+
addComment(entry.to, entry.from, line);
|
|
236
|
+
reply(entry.to, entry.from, match[1] || "", line);
|
|
237
|
+
}
|
|
238
|
+
} else if (match = creation.exec(syntax)) {
|
|
239
|
+
const [, to, args] = match, from = caller()?.to || STARTER;
|
|
240
|
+
if (touch(to, line).used || from === to) bad(line, `应在首次使用「${to}」前创建它`, `Create "${to}" before its first message`, "将 new 移到该参与者的其他消息前", "Move new before other messages involving this participant");
|
|
241
|
+
else {
|
|
242
|
+
beginUnit(line);
|
|
243
|
+
addComment(from, to, line);
|
|
244
|
+
send(from, to, args?.trim() ? `«${args.trim()}»` : "«create»", line, {
|
|
245
|
+
create: to,
|
|
246
|
+
activateOn: to,
|
|
247
|
+
arrow: {
|
|
248
|
+
head: "open",
|
|
249
|
+
dashed: true
|
|
250
|
+
}
|
|
251
|
+
});
|
|
252
|
+
finishCall({ to }, line);
|
|
253
|
+
}
|
|
254
|
+
} else if (match = call.exec(syntax)) {
|
|
255
|
+
const [, assignment, explicit, to, method, args] = match, from = explicit || caller()?.to || STARTER;
|
|
256
|
+
beginUnit(line);
|
|
257
|
+
addComment(from, to, line);
|
|
258
|
+
send(from, to, args === void 0 ? method : `${method}(${args})`, line, {
|
|
259
|
+
activateOn: to,
|
|
260
|
+
arrow: {
|
|
261
|
+
head: "arrow",
|
|
262
|
+
dashed: false
|
|
263
|
+
}
|
|
264
|
+
});
|
|
265
|
+
const entry = {
|
|
266
|
+
call: true,
|
|
267
|
+
from,
|
|
268
|
+
to,
|
|
269
|
+
assignment,
|
|
270
|
+
line
|
|
271
|
+
};
|
|
272
|
+
if (tokens[i + 1]?.text !== "{") finishCall(entry, line);
|
|
273
|
+
else if (stack.length >= LIMITS.fragmentDepth) bad(line, "ZenUML 块嵌套过深", "ZenUML blocks are nested too deeply", "减少块的嵌套层数", "Reduce block nesting");
|
|
274
|
+
else {
|
|
275
|
+
i++;
|
|
276
|
+
stack.push(entry);
|
|
277
|
+
}
|
|
278
|
+
} else if (match = /^title\s+(.+)$/iu.exec(syntax)) {
|
|
279
|
+
if (title) bad(line, "ZenUML 标题重复", "Duplicate ZenUML title", "只保留一个 title 或前置元数据标题", "Keep one title statement or front-matter title");
|
|
280
|
+
else title = match[1];
|
|
281
|
+
} else if (/^@(?:startuml|enduml)$/iu.test(syntax)) {} else if (match = annotationCall.exec(syntax)) {
|
|
282
|
+
const form = `@${match[1]} ${match[2]}`;
|
|
283
|
+
bad(line, `ZenUML 参与者注解写法无效:「${syntax}」`, `Invalid ZenUML participant annotation "${syntax}"`, `去掉括号,写成 ${form}`, `Remove the parentheses: ${form}`);
|
|
284
|
+
} else if (match = participant.exec(syntax)) {
|
|
285
|
+
const [, type, id, name] = match, actor = touch(id, line);
|
|
286
|
+
const kind = type?.toLowerCase() || "participant";
|
|
287
|
+
if (actor.declared) bad(line, `ZenUML 参与者「${id}」重复声明`, `Duplicate ZenUML participant "${id}"`, "删除重复声明", "Remove the duplicate declaration");
|
|
288
|
+
else Object.assign(actor, {
|
|
289
|
+
declared: true,
|
|
290
|
+
name: name?.replace(/^(["'])(.*)\1$/u, "$2") || id,
|
|
291
|
+
kind: kinds.has(kind) ? kind : "participant",
|
|
292
|
+
line
|
|
293
|
+
});
|
|
294
|
+
if (!kinds.has(kind)) {
|
|
295
|
+
ignored.add(`@${type}`);
|
|
296
|
+
ignoredLine ??= line;
|
|
297
|
+
}
|
|
298
|
+
} else unrecognized(line, syntax);
|
|
299
|
+
comments = [];
|
|
300
|
+
}
|
|
301
|
+
if (replyLine) missingReply(replyLine);
|
|
302
|
+
for (const entry of stack) bad(entry.line, "ZenUML 块缺少 }", "ZenUML block is missing }", "添加匹配的 }", "Add a matching }");
|
|
303
|
+
if (!actors.size && !errors.length) bad(firstLine, "ZenUML 缺少参与者", "ZenUML needs at least one participant", "添加参与者 Client 或消息 Client->API: 请求", "Add a participant Client or a message Client->API: request");
|
|
304
|
+
const participants = [...actors.values()];
|
|
305
|
+
if (participants.length > MAX_PARTICIPANTS) bad(participants[MAX_PARTICIPANTS].line, `ZenUML 参与者超过 ${MAX_PARTICIPANTS} 个`, `ZenUML has more than ${MAX_PARTICIPANTS} participants`, "拆分为多张图", "Split into several diagrams");
|
|
306
|
+
if (ignored.size) {
|
|
307
|
+
const names = [...ignored].join(", ");
|
|
308
|
+
errors.push(warning("DIAGRAM_HINT", lang, ignoredLine, `以下注解使用普通参与者外观:${names}`, `Using standard participants for these annotations: ${names}`, "如需图标,使用受支持的参与者类型", "Use a supported participant type if an icon is needed"));
|
|
309
|
+
}
|
|
310
|
+
if (actors.has(STARTER)) participants.unshift(participants.splice(participants.indexOf(actors.get(STARTER)), 1)[0]);
|
|
311
|
+
participants.forEach((actor, index) => {
|
|
312
|
+
actor.index = index;
|
|
313
|
+
});
|
|
314
|
+
return {
|
|
315
|
+
model: {
|
|
316
|
+
type: "sequence",
|
|
317
|
+
title,
|
|
318
|
+
participants,
|
|
319
|
+
statements,
|
|
320
|
+
messages,
|
|
321
|
+
zenuml: true
|
|
322
|
+
},
|
|
323
|
+
errors
|
|
324
|
+
};
|
|
325
|
+
}
|
|
326
|
+
var shared = implementations$1.sequenceDiagram;
|
|
327
|
+
var implementations = { zenuml: {
|
|
328
|
+
parse,
|
|
329
|
+
layout: (model, options, info) => shared.layout(model, {
|
|
330
|
+
...options,
|
|
331
|
+
compact: true
|
|
332
|
+
}, {
|
|
333
|
+
...info,
|
|
334
|
+
config: { sequence: { mirrorActors: false } }
|
|
335
|
+
}),
|
|
336
|
+
scene: shared.scene
|
|
337
|
+
} };
|
|
338
|
+
export { implementations, zenuml_exports };
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -48,6 +48,7 @@ export interface RenderOptions {
|
|
|
48
48
|
lang?: string;
|
|
49
49
|
theme?: string | Theme;
|
|
50
50
|
media?: Media;
|
|
51
|
+
/** Draw the outer frame and its title (default true). With false the host shows the title; see Scene.heading. */
|
|
51
52
|
frame?: boolean;
|
|
52
53
|
prefix?: string;
|
|
53
54
|
measure?: (text: string, size: number, weight: number, fontFamily: string) => number;
|
|
@@ -55,7 +56,7 @@ export interface RenderOptions {
|
|
|
55
56
|
}
|
|
56
57
|
|
|
57
58
|
export interface CheckOptions { syntax?: Syntax; lang?: string }
|
|
58
|
-
export interface DiagramOptions extends RenderOptions { syntax?: Syntax }
|
|
59
|
+
export interface DiagramOptions extends RenderOptions { syntax?: Syntax; compact?: boolean }
|
|
59
60
|
export interface ChartDiagnostic {
|
|
60
61
|
code: string;
|
|
61
62
|
message: string;
|
|
@@ -87,6 +88,7 @@ export interface Scene {
|
|
|
87
88
|
height: number;
|
|
88
89
|
children: SceneNode[];
|
|
89
90
|
title?: string;
|
|
91
|
+
/** Visible diagram title. With frame: false (and no compact) the drawing leaves it out for the host to show. */
|
|
90
92
|
heading?: string;
|
|
91
93
|
subtitle?: string;
|
|
92
94
|
source?: string;
|
package/dist/esm/mermaid.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ import type { DiagramDiagnostic, RenderOptions } from './index.js';
|
|
|
6
6
|
* `startOnLoad` pass silently, and the rest, such as `themeVariables` or the theme name `dark`, produce one
|
|
7
7
|
* `IGNORED_CONFIG` warning.
|
|
8
8
|
*/
|
|
9
|
-
export type MermaidOptions = Omit<RenderOptions, 'assets'> & { [setting: string]: unknown };
|
|
9
|
+
export type MermaidOptions = Omit<RenderOptions, 'assets'> & { compact?: boolean; [setting: string]: unknown };
|
|
10
10
|
export interface MermaidError extends Error { diagnostics: DiagramDiagnostic[] }
|
|
11
11
|
/** `diagnostics` holds only warnings: any error rejects instead. */
|
|
12
12
|
export interface MermaidParseResult { diagramType: string; diagnostics: DiagramDiagnostic[] }
|
package/dist/esm/mermaid.js
CHANGED
package/dist/esm/node.js
CHANGED
|
@@ -31,6 +31,8 @@ import { agentflow_exports } from "./diagram/agentflow.js";
|
|
|
31
31
|
import { architecture_exports } from "./diagram/architecture.js";
|
|
32
32
|
import { block_exports } from "./diagram/block.js";
|
|
33
33
|
import { blocks_exports } from "./diagram/blocks.js";
|
|
34
|
+
import { board_paint_exports } from "./diagram/board-paint.js";
|
|
35
|
+
import { board_route_exports } from "./diagram/board-route.js";
|
|
34
36
|
import { c4_exports } from "./diagram/c4.js";
|
|
35
37
|
import { class_exports } from "./diagram/class.js";
|
|
36
38
|
import { cynefin_exports } from "./diagram/cynefin.js";
|
|
@@ -44,6 +46,7 @@ import { graph_layout_exports } from "./diagram/graph-layout.js";
|
|
|
44
46
|
import { graph_parse_exports } from "./diagram/graph-parse.js";
|
|
45
47
|
import { graph_route_exports } from "./diagram/graph-route.js";
|
|
46
48
|
import { graph_exports } from "./diagram/graph.js";
|
|
49
|
+
import { info_exports } from "./diagram/info.js";
|
|
47
50
|
import { ishikawa_exports } from "./diagram/ishikawa.js";
|
|
48
51
|
import { journey_exports } from "./diagram/journey.js";
|
|
49
52
|
import { kanban_exports } from "./diagram/kanban.js";
|
|
@@ -63,7 +66,6 @@ import { quadrant_exports } from "./diagram/quadrant.js";
|
|
|
63
66
|
import { railroad_parse_exports } from "./diagram/railroad-parse.js";
|
|
64
67
|
import { railroad_exports } from "./diagram/railroad.js";
|
|
65
68
|
import { registry_exports as registry_exports$1 } from "./diagram/registry.js";
|
|
66
|
-
import { relations_exports as relations_exports$1 } from "./diagram/relations.js";
|
|
67
69
|
import { requirement_exports } from "./diagram/requirement.js";
|
|
68
70
|
import { sequence_exports } from "./diagram/sequence.js";
|
|
69
71
|
import { shapes_exports } from "./diagram/shapes.js";
|
|
@@ -78,6 +80,7 @@ import { treeview_exports } from "./diagram/treeview.js";
|
|
|
78
80
|
import { usecase_exports } from "./diagram/usecase.js";
|
|
79
81
|
import { venn_exports } from "./diagram/venn.js";
|
|
80
82
|
import { wardley_exports } from "./diagram/wardley.js";
|
|
83
|
+
import { zenuml_exports } from "./diagram/zenuml.js";
|
|
81
84
|
import { interaction_exports } from "./interaction.js";
|
|
82
85
|
import { createPageApi } from "./page-api.js";
|
|
83
86
|
import families_default from "./src/families.js";
|
|
@@ -117,6 +120,8 @@ var modulesByPath = /* #__PURE__ */ Object.assign({
|
|
|
117
120
|
"./src/diagram/architecture.js": architecture_exports,
|
|
118
121
|
"./src/diagram/block.js": block_exports,
|
|
119
122
|
"./src/diagram/blocks.js": blocks_exports,
|
|
123
|
+
"./src/diagram/board-paint.js": board_paint_exports,
|
|
124
|
+
"./src/diagram/board-route.js": board_route_exports,
|
|
120
125
|
"./src/diagram/c4.js": c4_exports,
|
|
121
126
|
"./src/diagram/class.js": class_exports,
|
|
122
127
|
"./src/diagram/cynefin.js": cynefin_exports,
|
|
@@ -130,6 +135,7 @@ var modulesByPath = /* #__PURE__ */ Object.assign({
|
|
|
130
135
|
"./src/diagram/graph-parse.js": graph_parse_exports,
|
|
131
136
|
"./src/diagram/graph-route.js": graph_route_exports,
|
|
132
137
|
"./src/diagram/graph.js": graph_exports,
|
|
138
|
+
"./src/diagram/info.js": info_exports,
|
|
133
139
|
"./src/diagram/ishikawa.js": ishikawa_exports,
|
|
134
140
|
"./src/diagram/journey.js": journey_exports,
|
|
135
141
|
"./src/diagram/kanban.js": kanban_exports,
|
|
@@ -149,7 +155,6 @@ var modulesByPath = /* #__PURE__ */ Object.assign({
|
|
|
149
155
|
"./src/diagram/railroad-parse.js": railroad_parse_exports,
|
|
150
156
|
"./src/diagram/railroad.js": railroad_exports,
|
|
151
157
|
"./src/diagram/registry.js": registry_exports$1,
|
|
152
|
-
"./src/diagram/relations.js": relations_exports$1,
|
|
153
158
|
"./src/diagram/requirement.js": requirement_exports,
|
|
154
159
|
"./src/diagram/sequence.js": sequence_exports,
|
|
155
160
|
"./src/diagram/shapes.js": shapes_exports,
|
|
@@ -164,6 +169,7 @@ var modulesByPath = /* #__PURE__ */ Object.assign({
|
|
|
164
169
|
"./src/diagram/usecase.js": usecase_exports,
|
|
165
170
|
"./src/diagram/venn.js": venn_exports,
|
|
166
171
|
"./src/diagram/wardley.js": wardley_exports,
|
|
172
|
+
"./src/diagram/zenuml.js": zenuml_exports,
|
|
167
173
|
"./src/interaction.js": interaction_exports
|
|
168
174
|
});
|
|
169
175
|
var dist = new URL(
|
package/dist/esm/src/families.js
CHANGED
|
@@ -99,6 +99,11 @@ var families_default = {
|
|
|
99
99
|
"topic": "architecture",
|
|
100
100
|
"aliases": []
|
|
101
101
|
} } },
|
|
102
|
+
"diagram/info": { "diagrams": { "info": {
|
|
103
|
+
"syntax": "mermaid",
|
|
104
|
+
"topic": "mermaid",
|
|
105
|
+
"aliases": []
|
|
106
|
+
} } },
|
|
102
107
|
"diagram/eventmodeling": { "diagrams": { "eventmodeling": {
|
|
103
108
|
"syntax": "mermaid",
|
|
104
109
|
"topic": "flow",
|
|
@@ -166,7 +171,7 @@ var families_default = {
|
|
|
166
171
|
"topic": "data-model",
|
|
167
172
|
"aliases": ["requirement"]
|
|
168
173
|
} } },
|
|
169
|
-
"diagram/
|
|
174
|
+
"diagram/zenuml": { "diagrams": { "zenuml": { "topic": "sequence" } } },
|
|
170
175
|
"diagram/architecture": { "diagrams": { "architecture-beta": {
|
|
171
176
|
"aliases": ["architecture"],
|
|
172
177
|
"topic": "architecture"
|
|
@@ -1 +1 @@
|
|
|
1
|
-
KChartUnits["chart/composition"]=(function(e,t){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var n=Math.PI*2,r=(e,t,n,r)=>[e+Math.cos(r)*n,t+Math.sin(r)*n],i=(e,t,n)=>/^en(?:-|$)/i.test(String(e.lang||``))?n:t;function a(e,t,i,a,o){let s=o-a,c=r(e,t,i,a);if(s<=1e-12)return{start:c,curve:``};if(s>=n-1e-9)return{start:c,curve:` A${i},${i} 0 1 1 ${r(e,t,i,a+s/2)} A${i},${i} 0 1 1 ${c}`,full:!0};let l=+(s>Math.PI);return{start:c,curve:` A${i},${i} 0 ${l} 1 ${r(e,t,i,o)}`,large:l}}var o=(e,t,{start:n,curve:r,full:i})=>r?i?`M${n}${r} Z`:`M${e},${t} L${n}${r} Z`:`M${n}`;function s(e,t,n,i,s,c){let l=a(e,t,i,s,c),u=`M${l.start}${l.curve}`;if(!l.curve)return u;if(n<=0)return o(e,t,l);let d=r(e,t,n,s);return l.full?`${u} Z M${d} A${n},${n} 0 1 0 ${r(e,t,n,s+(c-s)/2)} A${n},${n} 0 1 0 ${d} Z`:`${u} L${r(e,t,n,c)} A${n},${n} 0 ${l.large} 0 ${d} Z`}function c(e,t,n,i){let s=[],c=[],l=i.map(({r:e,a0:r,a1:i})=>e>0?a(t,n,e,r,i):null);for(let[a,{r:u,a0:d,fill:f,meta:p}]of i.entries()){let m=l[a];if(m&&s.push(e.path(o(t,n,m),{fill:f,meta:p})),m?.curve&&c.push(`M${m.start}${m.curve}${m.full?` Z`:``}`),i.length<2)continue;let h=(a+i.length-1)%i.length,g=Math.max(m?.curve?u:0,l[h]?.curve?i[h].r:0);g>0&&c.push(`M${t},${n} L${r(t,n,g,d)}`)}return c.length&&s.push(e.path(c.join(` `),{fill:`none`,stroke:e.color(`bg`),"stroke-width":2,"stroke-linecap":`round`,"pointer-events":`none`})),s}var l=(e,t,n,r)=>({id:e.id==null?void 0:String(e.id),kind:r,record:e,value:n,label:t}),u=(e,t,n)=>{if(t.length<2)return n;let r=t.map(t=>16+e.measure(t.label,12,400)),i=Math.max(...r);return i<=n?i:n},d=(e,t)=>{let n=t.table(e),r=n.valueFields[0],i=n.categories.map(e=>n.rows.find(t=>t[n.categoryField]===e)).filter(Boolean),a=i.map(e=>e[r]),o=a.reduce((e,t)=>e+t,0);return o>0||t.fit(`构成图总值必须大于0`,`为至少一个类别提供正值`),{table:n,field:r,rows:i,values:a,total:o}},f=Symbol(`composition presentation`);function p(e,t,a=!1){let{table:o,field:p,rows:m,values:h,total:g}=d(e,t),_=t.width,v=m.map((n,r)=>({label:`${n[o.categoryField]} ${t.format(h[r],p)} (${t.percent(h[r]/g)})`,color:t.color(`tone${r%6+1}`),meta:l(n,String(n[o.categoryField]),h[r],e.chart)})),y=_>560,b=y?Math.min(320,Math.max(180,_*.34)):Math.min(_-32,270),x=y?Math.min(_-b-36,460):_,S=y?x+28+b:_,C=y?(_-S)/2:0,w=y?C+x/2:_/2,T=_<=360?Math.min(112,_*.275):Math.min(y?168:112,Math.max(60,x*.32)),E=T+36,D=a?T*.58:0,O=T*(e[f]?.labelRadius??.72),k=[],A=[],j=[],M=a&&e.variant===`ticks`,N=-Math.PI/2;if(m.forEach((i,c)=>{let u=N+n*h[c]/g;if(!M&&h[c]>0){let n=t.color(`tone${c%6+1}`),d=l(i,String(i[o.categoryField]),h[c],e.chart);if(a?k.push(t.path(s(w,E,D,T,N,u),{fill:n,stroke:t.color(`bg`),"stroke-width":2,meta:d})):A.push({r:T,a0:N,a1:u,fill:n,meta:d}),e.sliceLabels&&u-N>=14*Math.PI/180&&2*O*Math.sin(Math.min(Math.PI,u-N)/2)>=t.measure(`100%`,12,600)+8){let[e,i]=r(w,E,O,(N+u)/2);j.push(t.text(e,i+4,`${Math.round(100*h[c]/g)}%`,{anchor:`middle`,size:12,weight:600,fill:t.textOn(n)}))}}N=u}),a||k.push(...c(t,w,E,A),...j),M){let e=Math.min(240,Math.max(96,Math.floor(n*(T-8.5)/2.5)));for(let i=0;i<e;i+=1){let a=(i+.5)/e,s=0,c=h.length-1;for(let e=0;e<h.length;e+=1)if(s+=h[e]/g,a<=s){c=e;break}let l=-Math.PI/2+n*a,u=r(w,E,T-17,l),d=r(w,E,T,l);k.push(t.line(...u,...d,{stroke:t.color(`tone${c%6+1}`),"stroke-width":2,"stroke-linecap":`round`,meta:{kind:`donut-tick`,category:String(m[c][o.categoryField]),fraction:a}}))}}if(a){let n=e.fields?.[p]?.label||i(t,`合计`,`Total`),r=M?T-17:D,a=e=>2*Math.sqrt(Math.max(0,r*r-e*e))-16,o=t.format(g,p),s=String(t.field(p).unit||``).trim();t.measure(o,20,650)<=a(20)||!s?k.push(t.text(w,E-12,n,{anchor:`middle`,size:12,fill:t.color(`muted`)}),t.text(w,E+14,o,{anchor:`middle`,size:20,weight:650,fill:t.color(`fg`)})):k.push(t.text(w,E-20,n,{anchor:`middle`,size:12,fill:t.color(`muted`)}),t.text(w,E+6,t.format(g,p,!1),{anchor:`middle`,size:20,weight:650,fill:t.color(`fg`)}),t.text(w,E+24,s,{anchor:`middle`,size:12,fill:t.color(`muted`)}))}let P=y||!(_<=360)?b:u(t,v,b),F=t.legend(v,P);if(y){let n=C+x+28,r=Math.max(16,E-F.height/2);return k.push(t.el(`g`,{transform:`translate(${n}, ${r})`},F.children)),t.scene(Math.max(E+T+24,r+F.height+8),k,e.title)}return k.push(t.el(`g`,{transform:`translate(${(_-P)/2}, ${E+T+24})`},F.children)),t.scene(E+T+30+F.height,k,e.title)}function m(e,t){let r=t.table(e),a=r.valueFields[0],o=e.encode.intensity,c=r.categories.map(e=>r.rows.find(t=>t[r.categoryField]===e)).filter(Boolean),d=c.reduce((e,t)=>e+t[a],0),[,f]=t.field(o).domain||t.extent(c.map(e=>e[o])),p=t.width>560,m=p?Math.min(360,Math.max(200,t.width*.38)):Math.min(360,t.width-32),h=p?Math.min(t.width-m-36,460):t.width,g=p?(t.width-h-28-m)/2:0,_=p?g+h/2:t.width/2,v=t.width<=360?Math.min(112,t.width*.275):Math.min(p?168:112,h*.32),y=v+42,b=[],x=-Math.PI/2;c.forEach((e,i)=>{let c=e[a]/d,u=x+n*c,p=e[o],m=f>0?Math.max(0,Math.min(1,p/f)):0,h=Math.sqrt(1936+(v*v-1936)*m);c>0&&b.push(t.path(s(_,y,44,h,x,u),{fill:t.color(`tone${i%6+1}`),stroke:t.color(`bg`),"stroke-width":2,meta:{...l(e,String(e[r.categoryField]),e[a],`radial-share`),intensity:p}})),b.push(t.path(s(_,y,v+6,v+9,x,u),{fill:t.color(`tone${i%6+1}`),meta:{kind:`share-label-ring`,label:String(e[r.categoryField]),value:e[a]}})),x=u});let S=[i(t,`角度=份额`,`Angle = share`),i(t,`半径=强度`,`Radius = intensity`)],C=e=>2*Math.sqrt(Math.max(0,1936-e*e))-12,w=t.measure(S[0],12)<=C(16)&&t.measure(S[1],12)<=C(17);w&&b.push(t.text(_,y-4,S[0],{anchor:`middle`,size:12,fill:t.color(`fg`)}),t.text(_,y+14,S[1],{anchor:`middle`,size:12,fill:t.color(`muted`)}));let T=(e,n,r)=>{if(w)return 0;let a=t.wrap(i(t,`角度表示份额,半径表示强度。`,`Angle shows share; radius shows intensity.`),r,12);return b.push(t.textLines(e,n+12,a,{fill:t.color(`muted`),meta:{kind:`radial-share-key`}})),a.length*16+8},E=c.map((e,n)=>({label:`${e[r.categoryField]} · ${t.format(e[a],a)} (${t.percent(e[a]/d)}) · ${i(t,`强度`,`intensity`)} ${t.format(e[o],o)}`,color:t.color(`tone${n%6+1}`),meta:{kind:`share-label`,label:String(e[r.categoryField]),value:e[a],intensity:e[o]}})),D=p||t.width>360?m:u(t,E,m),O=t.legend(E,D);if(p){let n=g+h+28,r=Math.max(16,y-O.height/2);b.push(t.el(`g`,{transform:`translate(${n}, ${r})`},O.children));let i=T(n,r+O.height+10,m);return t.scene(Math.max(y+v+24,r+O.height+8+i),b,e.title)}let k=y+v+22,A=(t.width-D)/2;b.push(t.el(`g`,{transform:`translate(${A}, ${k})`},O.children));let j=T(A,k+O.height+10,D);return t.scene(k+O.height+8+j,b,e.title)}function h(e,t){let{table:r,field:a,rows:o,values:s,total:f}=d(e,t),p=t.width>560,m=p?Math.min(320,Math.max(180,t.width*.34)):Math.min(360,t.width-32),h=p?Math.min(t.width-m-36,460):t.width,g=p?(t.width-h-28-m)/2:0,_=p?g+h/2:t.width/2,v=t.width<=360?Math.min(116,t.width*.275):Math.min(p?168:116,h*.32),y=v+32,b=Math.max(...s),x=-Math.PI/2,S=c(t,_,y,o.map((e,i)=>{let a=x+n/o.length,c={a0:x,a1:a,r:v*Math.sqrt(s[i]/b),fill:t.color(`tone${i%6+1}`),meta:l(e,String(e[r.categoryField]),s[i],`rose`)};return x=a,c})),C=o.map((e,n)=>({label:`${e[r.categoryField]} · ${t.format(s[n],a)}`,color:t.color(`tone${n%6+1}`),meta:{kind:`rose-label`,label:String(e[r.categoryField]),value:s[n]}})),w=p||t.width>360?m:u(t,C,m),T=t.legend(C,w),E=e.fields?.[a]?.label||i(t,`合计`,`Total`);if(p){let n=g+h+28,r=Math.max(16,y-T.height/2);return S.push(t.text(_,y+v+22,`${E} ${t.format(f,a)}`,{anchor:`middle`,size:12,fill:t.color(`muted`)})),S.push(t.el(`g`,{transform:`translate(${n}, ${r})`},T.children)),t.scene(Math.max(y+v+40,r+T.height+8),S,e.title)}let D=y+v+18,O=D+20;return S.push(t.text(_,D,`${E} ${t.format(f,a)}`,{anchor:`middle`,size:12,fill:t.color(`muted`)})),S.push(t.el(`g`,{transform:`translate(${(t.width-w)/2}, ${O})`},T.children)),t.scene(O+T.height+8,S,e.title)}function g(e,t){let n=e.data[0],a=e.encode.value,o=n[a],c=e.encode.target?n[e.encode.target]:null,[l,u]=e.range,d=(o-l)/(u-l),f=Math.min(t.width-128,560),p=[],m=e=>t.format(e,a),h=i(t,`目标`,`Target`),g=Math.min(200,t.width*.38),_=t.ticks([l,u],a,{count:2}),v=e=>{let t=_.ticks.findIndex(t=>Math.abs(t-e)<1e-9);return t>=0?_.labels[t]:m(e)},y=`${m(o)}${c==null?``:` · ${h} ${m(c)}`}`,b=t.measure(y,16,600),x=b<=f?64:64+f/2,S=b<=f?`start`:`middle`;if((e.variant||`bar`)===`bar`){if(p.push(t.rect(64,56,f,18,{rx:9,fill:t.color(`grid`)}),t.rect(64,56,f*d,18,{rx:9,fill:t.color(`accent`),meta:{kind:`gauge-value`,value:o}})),c!=null){let e=64+f*(c-l)/(u-l);p.push(t.line(e,47,e,83,{stroke:t.color(`ink`),"stroke-width":2,meta:{kind:`gauge-target`,value:c}}))}p.push(t.text(64,100,v(l),{size:12}),t.text(64+f,100,v(u),{anchor:`end`,size:12}))}else{let n=t.width/2,i=g,a=i+26,f=Math.PI,_=Math.PI+Math.PI*d;for(let e=0;e<=20;e++){let o=Math.PI+Math.PI*e/20,s=r(n,a,i+4,o),c=r(n,a,i+(e%5==0?15:10),o);p.push(t.line(...s,...c,{stroke:t.color(e/20<=d?`accent`:`axis`),"stroke-width":e%5==0?2:1,meta:{kind:`gauge-tick`,major:e%5==0,fraction:e/20}}))}if((e.variant||`bar`)===`arc`)p.push(t.path(s(n,a,i-7,i,f,2*Math.PI),{fill:t.color(`grid`),meta:{kind:`gauge-track`}})),p.push(t.path(s(n,a,i-7,i,f,_),{fill:t.color(`accent`),meta:{kind:`gauge-arc`,value:o}}));else{let[e,s]=r(n,a,8,f),[c,l]=r(n,a,i,_);p.push(t.line(e,s,c,l,{stroke:t.color(`accent`),"stroke-width":3,"stroke-linecap":`round`,meta:{kind:`gauge-needle`,value:o}}),t.circle(n,a,6,{fill:t.color(`ink`)}))}let y=v(l),b=v(u),x=t.measure(y,12,400),S=t.measure(b,12,400),C=Math.max(x/2,n-i),w=Math.min(t.width-S/2,n+i);if(p.push(t.text(n,a+54,m(o),{anchor:`middle`,size:20,weight:600,fill:t.color(`fg`),meta:{kind:`gauge-reading`,value:o}}),t.text(C,a+24,y,{anchor:`middle`,size:12,meta:{kind:`gauge-min`,value:l}}),t.text(w,a+24,b,{anchor:`middle`,size:12,meta:{kind:`gauge-max`,value:u}})),c!=null){let e=(c-l)/(u-l),o=Math.PI+Math.PI*e,s=`${h} ${m(c)}`,d=t.measure(s,12,400),f=e<=.2?`start`:e>=.8?`end`:`middle`,g=f===`end`?-d/2:f===`start`?d/2:0,[_,v]=r(n,a,i+20,o),y=Math.max(12,v);p.push(t.text(_+g,y,s,{anchor:f,size:12,fill:t.color(`ink`),meta:{kind:`gauge-target`,value:c}}))}}(e.variant||`bar`)===`bar`&&p.push(t.text(x,34,y,{anchor:S,size:16,weight:600,fill:t.color(`fg`),meta:{kind:`gauge-reading`,value:o,target:c}}));let C=t.scene((e.variant||`bar`)===`bar`?122:g+26+92,p,e.title);if((e.variant||`bar`)===`bar`){let e=S===`middle`?x+b/2:x+b;C.width=Math.max(t.width,e+16,64+f+16)}return C}var _=e=>{let t=(e,n,r,i)=>{let a={node:e,parent:n,depth:r,path:i,children:[],value:0},o=Array.isArray(e.children)?e.children.filter(Boolean):[];return a.children=o.map((e,n)=>t(e,a,r+1,`${i}.${n+1}`)),a.value=o.length?a.children.reduce((e,t)=>e+t.value,0):Number(e.value||0),a},n=t(e,null,0,`1`),r=[],i=e=>{r.push(e),e.children.forEach(i)};return i(n),r};function v(e,t,n,r,i,a,o,s=e=>a.format(e,`value`)){for(let c of t){let t=a.wrap(`${c.index==null?``:`${c.index}. `}${c.label} · ${s(c.value)}`,Math.max(1,i-28),12);e.push(a.rect(n,r-10,12,12,{fill:c.color}),a.textLines(n+18,r,t,{size:12,fill:a.color(`fg`)}));let l=e[e.length-1];l.children&&(l.children[0].meta={kind:o,path:c.path,label:c.label,value:c.value,index:c.index}),r+=t.length*16+2}return r}function y(e,t){let n=e.data,r=_(n),i=r.filter(e=>!e.children.length),a=e[f],o=Math.min(t.width-48,752),s=242,c=!1,l=!1,u=new Map(i.map((e,t)=>[e,`tone${t%6+1}`])),d=[],p=[],m=e=>t.design[e.node[f]?.status],h=e=>m(e)||t.color(u.get(e)),g=a?.showValues!==!1,y=e=>`${a?.prefix||``}${t.format(e,`value`)}`,b=(e,n)=>{let r=e.node[f]?.link;r&&d.push(t.link(r.href,d.splice(n),r))},x=(e,n,r,o,s,f,_=[])=>{let v=d.length;if(f>0&&o>0&&s>0&&d.push(t.rect(n,r,o,s,{fill:e.children.length&&m(e)?t.tint(t.palette.bg,m(e),.14):f===1?t.color(`bg`):`none`,stroke:m(e)||t.color(`axis`),"stroke-width":1,meta:{kind:a?`frame`:`treemap-node`,...a?{id:e.path}:{},label:String(e.node.label),value:e.value,path:e.path}})),!e.children.length){if(a&&e.value>0){let a=i.indexOf(e)+1,f=String(e.node.label),v=y(e.value),b=o-4,x=s-4,S=e=>t.measure(e,12,600)+8<=b;if(x<16||!S(String(a))){l||=x<16,c||=!S(String(a));return}let C=[..._,f].join(` / `),w=S(C)?C:f,T=`${w} · ${v}`,E=g&&S(T)?[T]:S(w)?g&&x>=34&&S(v)?[w,v]:[w]:[String(a)],D=E[0]===String(a)&&!S(w),O=h(e),k=t.textOn(m(e)||u.get(e));d.push(t.rect(n+2,r+2,b,x,{fill:O,meta:{kind:`node`,id:e.path,path:e.path,label:f,value:v}})),E.forEach((i,o)=>d.push(t.text(n+6,r+2+(x<22?x/2+4:15)+o*15,i,{size:12,weight:600,fill:k,meta:{kind:D?`treemap-tile-index`:`treemap-tile-label`,path:e.path,label:f,...D?{index:a}:{}}}))),(D||w!==C)&&p.push({index:D?a:null,label:C,value:e.value,path:e.path,color:O})}else if(!a&&e.value>0&&o>0&&s>0){let c=i.indexOf(e),l=String(e.node.label),f=y(e.value),v=[..._,l].join(` / `),b=Math.max(0,o-4),x=Math.max(0,s-4),S=t.textOn(m(e)||u.get(e));d.push(t.rect(n+2,r+2,b,x,{fill:h(e),meta:{kind:a?`node`:`treemap-leaf`,...a?{id:e.path}:{},label:l,value:e.value,path:e.path}}));let C=g?`${l} · ${f}`:l,w=t.measure(C,12,600),T=c+1;!_.length&&b>=w+12&&x>=34?d.push(t.text(n+7,r+18,C,{size:12,weight:600,fill:S,meta:{kind:`treemap-tile-label`,label:l,value:e.value,path:e.path,mode:`name-value`}})):(p.push({index:T,label:v,value:e.value,path:e.path,color:h(e)}),b>=t.measure(String(T),12,600)+12&&x>=22&&d.push(t.text(n+7,r+16,String(T),{size:12,weight:600,fill:S,meta:{kind:`treemap-tile-index`,label:l,value:e.value,path:e.path,index:T}})))}else if(!e.children.length){let t=i.indexOf(e);p.push({index:a?null:t+1,label:[..._,String(e.node.label)].join(` / `),value:e.value,path:e.path,color:h(e)})}b(e,v);return}let S=f>0&&s>=32&&t.measure(String(e.node.label),12,600)+14<=o?20:0;f>0&&S&&d.push(t.text(n+7,r+15,String(e.node.label),{size:12,weight:600,fill:t.color(`fg`),meta:{kind:`treemap-group-label`,label:String(e.node.label),path:e.path}})),b(e,v);let C=f>0&&!S?[..._,String(e.node.label)]:_,w=r+S,T=Math.max(0,s-S),E=f%2==0,D=E?o:T,O=0;e.children.forEach(t=>{let r=e.value>0&&t.value>0?D*t.value/e.value:0;E?x(t,n+O,w,r,T,f+1,C):x(t,n,w+O,o,r,f+1,C),O+=r})},S=a?.namedRoot?`${n.label} · ${e.fields?.value?.unit===`$`&&e.fields.value.decimals===0?`$${new Intl.NumberFormat(`en-US`,{maximumFractionDigits:0}).format(r[0].value)}`:y(r[0].value)}`:``,C;for(let e=0;;e+=1){let n=S?t.wrap(S,o,13,650):[];if(C=44+n.length*18,n.length&&d.push(t.textLines(24,39,n,{size:13,weight:650,leading:18,fill:t.color(`fg`)})),x(r[0],24,C,o,s,0),!c&&!l)break;e===6&&t.fit(`矩形树图的最小分块无法容纳编号`,`拆分图表或缩小权重差距`),c&&(o*=1.5),l&&(s*=1.5),c=l=!1,d.length=p.length=0}let w=v(d,p,24,C+s+24,Math.min(o,360),t,`treemap-name`,y),T=p.length?w+8:C+s+8,E=t.scene(T,d,e.title);return a&&(E.width=Math.max(E.width,o+48)),E}function b(e,t){let n=_(e.data),i=n[0],a=n.filter(e=>e.depth>0),o=[],c=new Map(a.map((e,t)=>[e,t+1])),l=Math.max(1,...n.map(e=>e.depth)),u=Math.max(8,Math.min(t.width/2-20,220)),d=String(i.node.label),f=t.measure(d,12,600),p=Math.min(Math.max(36,f+16),Math.max(36,u*.42)),m=Math.min(p,Math.max(36,u/(l+1))),h=(u-m)/l,g=t.width/2,y=u+24,b=[],x=e=>{let t=e;for(;t.parent&&t.parent!==i;)t=t.parent;return t},S=new Map(i.children.map((e,n)=>[e,t.palette[`tone${n%6+1}`]])),C=e=>S.get(x(e))||t.palette.tone1,w=e=>t.mix(C(e),t.palette.bg,Math.min(.72,.35+Math.max(0,e.depth-1)*.12)),T=(e,n,i)=>{let a=e.depth;if(a>0&&e.value>0&&i>n){let l=w(e),u=m+(a-1)*h,d=m+a*h,f=c.get(e);b.push(t.path(s(g,y,u,d,n,i),{fill:l,stroke:t.color(`bg`),"stroke-width":2,meta:{kind:`sunburst-node`,label:String(e.node.label),value:e.value,path:e.path,depth:a}}));let p=(u+d)/2,_=(n+i)/2,v=2*p*Math.sin(Math.min(Math.PI,i-n)/2),x=2*Math.max(0,p-u-5),S=String(e.node.label),C=`${S} · ${t.format(e.value,`value`)}`,T=t.measure(C,12,600),E=t.textOn(l);if(h>=16&&v>=T+8&&x>=T+8){let[n,i]=r(g,y,p,_);b.push(t.text(n,i+4,C,{anchor:`middle`,size:12,weight:600,fill:E,meta:{kind:`sunburst-ring-label`,label:S,value:e.value,path:e.path,depth:a}}))}else{o.push({index:f,label:S,value:e.value,path:e.path,color:l});let n=t.measure(String(f),12,600);if(h>=16&&v>=n+8&&x>=n+8){let[n,i]=r(g,y,p,_);b.push(t.text(n,i+4,String(f),{anchor:`middle`,size:12,weight:600,fill:E,meta:{kind:`sunburst-ring-index`,label:S,value:e.value,path:e.path,depth:a,index:f}}))}}}else a>0&&e.value===0&&o.push({index:c.get(e),label:String(e.node.label),value:0,path:e.path,color:w(e)});let l=n;e.children.forEach(t=>{let r=e.value>0?l+(i-n)*t.value/e.value:l;T(t,l,r),l=r})};T(i,-Math.PI/2,Math.PI*1.5),b.push(t.circle(g,y,Math.max(1,m-2),{fill:t.color(`bg`)}));let E=Math.max(1,2*(m-8)),D=Math.max(1,Math.floor(2*(m-6)/16)),O=t.wrap(d,E,12,600),k=!1;(O.length>D||O.some(e=>t.measure(e,12,600)>E))&&(k=!0,O=t.wrap(d,Math.max(80,t.width-36),12,600));let A=k?y+u+22:y-(O.length-1)*8+4;b.push(t.textLines(g,A,O,{anchor:`middle`,size:12,weight:600,fill:t.color(`fg`),meta:{kind:`sunburst-centre`,label:d}}));let j=v(b,o,18,k?A+O.length*16+12:y+u+28,t.width-36,t,`sunburst-name`),M=k?A+O.length*16+8:y+u+20;return t.scene(o.length?j+8:M,b,e.title)}function x({register:e}){e(`pie`,(e,t)=>p(e,t,!1)),e(`donut`,(e,t)=>p(e,t,!0)),e(`radial-share`,m),e(`rose`,h),e(`gauge`,g),e(`treemap`,y),e(`sunburst`,b)}return x({register:t.register}),e.compositionPresentation=f,e.install=x,e})({},KChartUnits[`chart/registry`]);
|
|
1
|
+
KChartUnits["chart/composition"]=(function(e,t){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var n=Math.PI*2,r=(e,t,n,r)=>[e+Math.cos(r)*n,t+Math.sin(r)*n],i=(e,t,n)=>/^en(?:-|$)/i.test(String(e.lang||``))?n:t;function a(e,t,i,a,o){let s=o-a,c=r(e,t,i,a);if(s<=1e-12)return{start:c,curve:``};if(s>=n-1e-9)return{start:c,curve:` A${i},${i} 0 1 1 ${r(e,t,i,a+s/2)} A${i},${i} 0 1 1 ${c}`,full:!0};let l=+(s>Math.PI);return{start:c,curve:` A${i},${i} 0 ${l} 1 ${r(e,t,i,o)}`,large:l}}var o=(e,t,{start:n,curve:r,full:i})=>r?i?`M${n}${r} Z`:`M${e},${t} L${n}${r} Z`:`M${n}`;function s(e,t,n,i,s,c){let l=a(e,t,i,s,c),u=`M${l.start}${l.curve}`;if(!l.curve)return u;if(n<=0)return o(e,t,l);let d=r(e,t,n,s);return l.full?`${u} Z M${d} A${n},${n} 0 1 0 ${r(e,t,n,s+(c-s)/2)} A${n},${n} 0 1 0 ${d} Z`:`${u} L${r(e,t,n,c)} A${n},${n} 0 ${l.large} 0 ${d} Z`}function c(e,t,n,i){let s=[],c=[],l=i.map(({r:e,a0:r,a1:i})=>e>0?a(t,n,e,r,i):null);for(let[a,{r:u,a0:d,fill:f,meta:p}]of i.entries()){let m=l[a];if(m&&s.push(e.path(o(t,n,m),{fill:f,meta:p})),m?.curve&&c.push(`M${m.start}${m.curve}${m.full?` Z`:``}`),i.length<2)continue;let h=(a+i.length-1)%i.length,g=Math.max(m?.curve?u:0,l[h]?.curve?i[h].r:0);g>0&&c.push(`M${t},${n} L${r(t,n,g,d)}`)}return c.length&&s.push(e.path(c.join(` `),{fill:`none`,stroke:e.color(`bg`),"stroke-width":2,"stroke-linecap":`round`,"pointer-events":`none`})),s}var l=(e,t,n,r)=>({id:e.id==null?void 0:String(e.id),kind:r,record:e,value:n,label:t}),u=(e,t,n)=>{if(t.length<2)return n;let r=t.map(t=>16+e.measure(t.label,12,400)),i=Math.max(...r);return i<=n?i:n},d=(e,t)=>{let n=t.table(e),r=n.valueFields[0],i=n.categories.map(e=>n.rows.find(t=>t[n.categoryField]===e)).filter(Boolean),a=i.map(e=>e[r]),o=a.reduce((e,t)=>e+t,0);return o>0||t.fit(`构成图总值必须大于0`,`为至少一个类别提供正值`),{table:n,field:r,rows:i,values:a,total:o}},f=Symbol(`composition presentation`);function p(e,t,a=!1){let{table:o,field:p,rows:m,values:h,total:g}=d(e,t),_=t.width,v=m.map((n,r)=>({label:`${n[o.categoryField]} ${t.format(h[r],p)} (${t.percent(h[r]/g)})`,color:t.color(`tone${r%6+1}`),meta:l(n,String(n[o.categoryField]),h[r],e.chart)})),y=e[f]?.compact===!0,b=_>560||y&&m.length>=4,x=b?y?Math.max(154,_*.42):Math.min(320,Math.max(180,_*.34)):Math.min(_-32,270),S=b?Math.min(_-x-36,460):_,C=b?S+28+x:_,w=b?(_-C)/2:0,T=b?w+S/2:_/2,E=y?Math.min(92,Math.max(60,S*(b?.44:.26))):_<=360?Math.min(112,_*.275):Math.min(b?168:112,Math.max(60,S*.32)),D=E+36,O=a?E*.58:0,k=E*(e[f]?.labelRadius??.72),A=[],j=[],M=[],N=a&&e.variant===`ticks`,P=-Math.PI/2;if(m.forEach((i,c)=>{let u=P+n*h[c]/g;if(!N&&h[c]>0){let n=t.color(`tone${c%6+1}`),d=l(i,String(i[o.categoryField]),h[c],e.chart);if(a?A.push(t.path(s(T,D,O,E,P,u),{fill:n,stroke:t.color(`bg`),"stroke-width":2,meta:d})):j.push({r:E,a0:P,a1:u,fill:n,meta:d}),e.sliceLabels&&u-P>=14*Math.PI/180&&2*k*Math.sin(Math.min(Math.PI,u-P)/2)>=t.measure(`100%`,12,600)+8){let[e,i]=r(T,D,k,(P+u)/2);M.push(t.text(e,i+4,`${Math.round(100*h[c]/g)}%`,{anchor:`middle`,size:12,weight:600,fill:t.textOn(n)}))}}P=u}),a||A.push(...c(t,T,D,j),...M),N){let e=Math.min(240,Math.max(96,Math.floor(n*(E-8.5)/2.5)));for(let i=0;i<e;i+=1){let a=(i+.5)/e,s=0,c=h.length-1;for(let e=0;e<h.length;e+=1)if(s+=h[e]/g,a<=s){c=e;break}let l=-Math.PI/2+n*a,u=r(T,D,E-17,l),d=r(T,D,E,l);A.push(t.line(...u,...d,{stroke:t.color(`tone${c%6+1}`),"stroke-width":2,"stroke-linecap":`round`,meta:{kind:`donut-tick`,category:String(m[c][o.categoryField]),fraction:a}}))}}if(a){let n=e.fields?.[p]?.label||i(t,`合计`,`Total`),r=N?E-17:O,a=e=>2*Math.sqrt(Math.max(0,r*r-e*e))-16,o=t.format(g,p),s=String(t.field(p).unit||``).trim();t.measure(o,20,650)<=a(20)||!s?A.push(t.text(T,D-12,n,{anchor:`middle`,size:12,fill:t.color(`muted`)}),t.text(T,D+14,o,{anchor:`middle`,size:20,weight:650,fill:t.color(`fg`)})):A.push(t.text(T,D-20,n,{anchor:`middle`,size:12,fill:t.color(`muted`)}),t.text(T,D+6,t.format(g,p,!1),{anchor:`middle`,size:20,weight:650,fill:t.color(`fg`)}),t.text(T,D+24,s,{anchor:`middle`,size:12,fill:t.color(`muted`)}))}let F=b||!(_<=360)?x:u(t,v,x),I=t.legend(v,F);if(b){let n=w+S+28,r=Math.max(16,D-I.height/2);return A.push(t.el(`g`,{transform:`translate(${n}, ${r})`},I.children)),t.scene(Math.max(D+E+24,r+I.height+8),A,e.title)}return A.push(t.el(`g`,{transform:`translate(${(_-F)/2}, ${D+E+24})`},I.children)),t.scene(D+E+30+I.height,A,e.title)}function m(e,t){let r=t.table(e),a=r.valueFields[0],o=e.encode.intensity,c=r.categories.map(e=>r.rows.find(t=>t[r.categoryField]===e)).filter(Boolean),d=c.reduce((e,t)=>e+t[a],0),[,f]=t.field(o).domain||t.extent(c.map(e=>e[o])),p=t.width>560,m=p?Math.min(360,Math.max(200,t.width*.38)):Math.min(360,t.width-32),h=p?Math.min(t.width-m-36,460):t.width,g=p?(t.width-h-28-m)/2:0,_=p?g+h/2:t.width/2,v=t.width<=360?Math.min(112,t.width*.275):Math.min(p?168:112,h*.32),y=v+42,b=[],x=-Math.PI/2;c.forEach((e,i)=>{let c=e[a]/d,u=x+n*c,p=e[o],m=f>0?Math.max(0,Math.min(1,p/f)):0,h=Math.sqrt(1936+(v*v-1936)*m);c>0&&b.push(t.path(s(_,y,44,h,x,u),{fill:t.color(`tone${i%6+1}`),stroke:t.color(`bg`),"stroke-width":2,meta:{...l(e,String(e[r.categoryField]),e[a],`radial-share`),intensity:p}})),b.push(t.path(s(_,y,v+6,v+9,x,u),{fill:t.color(`tone${i%6+1}`),meta:{kind:`share-label-ring`,label:String(e[r.categoryField]),value:e[a]}})),x=u});let S=[i(t,`角度=份额`,`Angle = share`),i(t,`半径=强度`,`Radius = intensity`)],C=e=>2*Math.sqrt(Math.max(0,1936-e*e))-12,w=t.measure(S[0],12)<=C(16)&&t.measure(S[1],12)<=C(17);w&&b.push(t.text(_,y-4,S[0],{anchor:`middle`,size:12,fill:t.color(`fg`)}),t.text(_,y+14,S[1],{anchor:`middle`,size:12,fill:t.color(`muted`)}));let T=(e,n,r)=>{if(w)return 0;let a=t.wrap(i(t,`角度表示份额,半径表示强度。`,`Angle shows share; radius shows intensity.`),r,12);return b.push(t.textLines(e,n+12,a,{fill:t.color(`muted`),meta:{kind:`radial-share-key`}})),a.length*16+8},E=c.map((e,n)=>({label:`${e[r.categoryField]} · ${t.format(e[a],a)} (${t.percent(e[a]/d)}) · ${i(t,`强度`,`intensity`)} ${t.format(e[o],o)}`,color:t.color(`tone${n%6+1}`),meta:{kind:`share-label`,label:String(e[r.categoryField]),value:e[a],intensity:e[o]}})),D=p||t.width>360?m:u(t,E,m),O=t.legend(E,D);if(p){let n=g+h+28,r=Math.max(16,y-O.height/2);b.push(t.el(`g`,{transform:`translate(${n}, ${r})`},O.children));let i=T(n,r+O.height+10,m);return t.scene(Math.max(y+v+24,r+O.height+8+i),b,e.title)}let k=y+v+22,A=(t.width-D)/2;b.push(t.el(`g`,{transform:`translate(${A}, ${k})`},O.children));let j=T(A,k+O.height+10,D);return t.scene(k+O.height+8+j,b,e.title)}function h(e,t){let{table:r,field:a,rows:o,values:s,total:f}=d(e,t),p=t.width>560,m=p?Math.min(320,Math.max(180,t.width*.34)):Math.min(360,t.width-32),h=p?Math.min(t.width-m-36,460):t.width,g=p?(t.width-h-28-m)/2:0,_=p?g+h/2:t.width/2,v=t.width<=360?Math.min(116,t.width*.275):Math.min(p?168:116,h*.32),y=v+32,b=Math.max(...s),x=-Math.PI/2,S=c(t,_,y,o.map((e,i)=>{let a=x+n/o.length,c={a0:x,a1:a,r:v*Math.sqrt(s[i]/b),fill:t.color(`tone${i%6+1}`),meta:l(e,String(e[r.categoryField]),s[i],`rose`)};return x=a,c})),C=o.map((e,n)=>({label:`${e[r.categoryField]} · ${t.format(s[n],a)}`,color:t.color(`tone${n%6+1}`),meta:{kind:`rose-label`,label:String(e[r.categoryField]),value:s[n]}})),w=p||t.width>360?m:u(t,C,m),T=t.legend(C,w),E=e.fields?.[a]?.label||i(t,`合计`,`Total`);if(p){let n=g+h+28,r=Math.max(16,y-T.height/2);return S.push(t.text(_,y+v+22,`${E} ${t.format(f,a)}`,{anchor:`middle`,size:12,fill:t.color(`muted`)})),S.push(t.el(`g`,{transform:`translate(${n}, ${r})`},T.children)),t.scene(Math.max(y+v+40,r+T.height+8),S,e.title)}let D=y+v+18,O=D+20;return S.push(t.text(_,D,`${E} ${t.format(f,a)}`,{anchor:`middle`,size:12,fill:t.color(`muted`)})),S.push(t.el(`g`,{transform:`translate(${(t.width-w)/2}, ${O})`},T.children)),t.scene(O+T.height+8,S,e.title)}function g(e,t){let n=e.data[0],a=e.encode.value,o=n[a],c=e.encode.target?n[e.encode.target]:null,[l,u]=e.range,d=(o-l)/(u-l),f=Math.min(t.width-128,560),p=[],m=e=>t.format(e,a),h=i(t,`目标`,`Target`),g=Math.min(200,t.width*.38),_=t.ticks([l,u],a,{count:2}),v=e=>{let t=_.ticks.findIndex(t=>Math.abs(t-e)<1e-9);return t>=0?_.labels[t]:m(e)},y=`${m(o)}${c==null?``:` · ${h} ${m(c)}`}`,b=t.measure(y,16,600),x=b<=f?64:64+f/2,S=b<=f?`start`:`middle`;if((e.variant||`bar`)===`bar`){if(p.push(t.rect(64,56,f,18,{rx:9,fill:t.color(`grid`)}),t.rect(64,56,f*d,18,{rx:9,fill:t.color(`accent`),meta:{kind:`gauge-value`,value:o}})),c!=null){let e=64+f*(c-l)/(u-l);p.push(t.line(e,47,e,83,{stroke:t.color(`ink`),"stroke-width":2,meta:{kind:`gauge-target`,value:c}}))}p.push(t.text(64,100,v(l),{size:12}),t.text(64+f,100,v(u),{anchor:`end`,size:12}))}else{let n=t.width/2,i=g,a=i+26,f=Math.PI,_=Math.PI+Math.PI*d;for(let e=0;e<=20;e++){let o=Math.PI+Math.PI*e/20,s=r(n,a,i+4,o),c=r(n,a,i+(e%5==0?15:10),o);p.push(t.line(...s,...c,{stroke:t.color(e/20<=d?`accent`:`axis`),"stroke-width":e%5==0?2:1,meta:{kind:`gauge-tick`,major:e%5==0,fraction:e/20}}))}if((e.variant||`bar`)===`arc`)p.push(t.path(s(n,a,i-7,i,f,2*Math.PI),{fill:t.color(`grid`),meta:{kind:`gauge-track`}})),p.push(t.path(s(n,a,i-7,i,f,_),{fill:t.color(`accent`),meta:{kind:`gauge-arc`,value:o}}));else{let[e,s]=r(n,a,8,f),[c,l]=r(n,a,i,_);p.push(t.line(e,s,c,l,{stroke:t.color(`accent`),"stroke-width":3,"stroke-linecap":`round`,meta:{kind:`gauge-needle`,value:o}}),t.circle(n,a,6,{fill:t.color(`ink`)}))}let y=v(l),b=v(u),x=t.measure(y,12,400),S=t.measure(b,12,400),C=Math.max(x/2,n-i),w=Math.min(t.width-S/2,n+i);if(p.push(t.text(n,a+54,m(o),{anchor:`middle`,size:20,weight:600,fill:t.color(`fg`),meta:{kind:`gauge-reading`,value:o}}),t.text(C,a+24,y,{anchor:`middle`,size:12,meta:{kind:`gauge-min`,value:l}}),t.text(w,a+24,b,{anchor:`middle`,size:12,meta:{kind:`gauge-max`,value:u}})),c!=null){let e=(c-l)/(u-l),o=Math.PI+Math.PI*e,s=`${h} ${m(c)}`,d=t.measure(s,12,400),f=e<=.2?`start`:e>=.8?`end`:`middle`,g=f===`end`?-d/2:f===`start`?d/2:0,[_,v]=r(n,a,i+20,o),y=Math.max(12,v);p.push(t.text(_+g,y,s,{anchor:f,size:12,fill:t.color(`ink`),meta:{kind:`gauge-target`,value:c}}))}}(e.variant||`bar`)===`bar`&&p.push(t.text(x,34,y,{anchor:S,size:16,weight:600,fill:t.color(`fg`),meta:{kind:`gauge-reading`,value:o,target:c}}));let C=t.scene((e.variant||`bar`)===`bar`?122:g+26+92,p,e.title);if((e.variant||`bar`)===`bar`){let e=S===`middle`?x+b/2:x+b;C.width=Math.max(t.width,e+16,64+f+16)}return C}var _=e=>{let t=(e,n,r,i)=>{let a={node:e,parent:n,depth:r,path:i,children:[],value:0},o=Array.isArray(e.children)?e.children.filter(Boolean):[];return a.children=o.map((e,n)=>t(e,a,r+1,`${i}.${n+1}`)),a.value=o.length?a.children.reduce((e,t)=>e+t.value,0):Number(e.value||0),a},n=t(e,null,0,`1`),r=[],i=e=>{r.push(e),e.children.forEach(i)};return i(n),r};function v(e,t,n,r,i,a,o,s=e=>a.format(e,`value`)){for(let c of t){let t=a.wrap(`${c.index==null?``:`${c.index}. `}${c.label} · ${s(c.value)}`,Math.max(1,i-28),12);e.push(a.rect(n,r-10,12,12,{fill:c.color}),a.textLines(n+18,r,t,{size:12,fill:a.color(`fg`)}));let l=e[e.length-1];l.children&&(l.children[0].meta={kind:o,path:c.path,label:c.label,value:c.value,index:c.index}),r+=t.length*16+2}return r}function y(e,t){let n=e.data,r=_(n),i=r.filter(e=>!e.children.length),a=e[f],o=Math.min(t.width-48,752),s=a?.compact?i.length===1?120:Math.min(280,190+i.length*8):242,c=!1,l=!1,u=new Map(i.map((e,t)=>[e,`tone${t%6+1}`])),d=[],p=[],m=e=>t.design[e.node[f]?.status],h=e=>m(e)||t.color(u.get(e)),g=a?.showValues!==!1,y=e=>`${a?.prefix||``}${t.format(e,`value`)}`,b=(e,n)=>{let r=e.node[f]?.link;r&&d.push(t.link(r.href,d.splice(n),r))},x=(e,n,r,o,s,f,_=[])=>{let v=d.length;if(f>0&&o>0&&s>0&&d.push(t.rect(n,r,o,s,{fill:e.children.length&&m(e)?t.tint(t.palette.bg,m(e),.14):f===1?t.color(`bg`):`none`,stroke:m(e)||t.color(`axis`),"stroke-width":1,meta:{kind:a?`frame`:`treemap-node`,...a?{id:e.path}:{},label:String(e.node.label),value:e.value,path:e.path}})),!e.children.length){if(a&&e.value>0){let a=i.indexOf(e)+1,f=String(e.node.label),v=y(e.value),b=o-4,x=s-4,S=e=>t.measure(e,12,600)+8<=b;if(x<16||!S(String(a))){l||=x<16,c||=!S(String(a));return}let C=[..._,f].join(` / `),w=S(C)?C:f,T=`${w} · ${v}`,E=g&&S(T)?[T]:S(w)?g&&x>=34&&S(v)?[w,v]:[w]:[String(a)],D=E[0]===String(a)&&!S(w),O=h(e),k=t.textOn(m(e)||u.get(e));d.push(t.rect(n+2,r+2,b,x,{fill:O,meta:{kind:`node`,id:e.path,path:e.path,label:f,value:v}})),E.forEach((i,o)=>d.push(t.text(n+6,r+2+(x<22?x/2+4:15)+o*15,i,{size:12,weight:600,fill:k,meta:{kind:D?`treemap-tile-index`:`treemap-tile-label`,path:e.path,label:f,...D?{index:a}:{}}}))),(D||w!==C)&&p.push({index:D?a:null,label:C,value:e.value,path:e.path,color:O})}else if(!a&&e.value>0&&o>0&&s>0){let c=i.indexOf(e),l=String(e.node.label),f=y(e.value),v=[..._,l].join(` / `),b=Math.max(0,o-4),x=Math.max(0,s-4),S=t.textOn(m(e)||u.get(e));d.push(t.rect(n+2,r+2,b,x,{fill:h(e),meta:{kind:a?`node`:`treemap-leaf`,...a?{id:e.path}:{},label:l,value:e.value,path:e.path}}));let C=g?`${l} · ${f}`:l,w=t.measure(C,12,600),T=c+1;!_.length&&b>=w+12&&x>=34?d.push(t.text(n+7,r+18,C,{size:12,weight:600,fill:S,meta:{kind:`treemap-tile-label`,label:l,value:e.value,path:e.path,mode:`name-value`}})):(p.push({index:T,label:v,value:e.value,path:e.path,color:h(e)}),b>=t.measure(String(T),12,600)+12&&x>=22&&d.push(t.text(n+7,r+16,String(T),{size:12,weight:600,fill:S,meta:{kind:`treemap-tile-index`,label:l,value:e.value,path:e.path,index:T}})))}else if(!e.children.length){let t=i.indexOf(e);p.push({index:a?null:t+1,label:[..._,String(e.node.label)].join(` / `),value:e.value,path:e.path,color:h(e)})}b(e,v);return}let S=f>0&&s>=32&&t.measure(String(e.node.label),12,600)+14<=o?20:0;f>0&&S&&d.push(t.text(n+7,r+15,String(e.node.label),{size:12,weight:600,fill:t.color(`fg`),meta:{kind:`treemap-group-label`,label:String(e.node.label),path:e.path}})),b(e,v);let C=f>0&&!S?[..._,String(e.node.label)]:_,w=r+S,T=Math.max(0,s-S),E=f%2==0,D=E?o:T,O=0;e.children.forEach(t=>{let r=e.value>0&&t.value>0?D*t.value/e.value:0;E?x(t,n+O,w,r,T,f+1,C):x(t,n,w+O,o,r,f+1,C),O+=r})},S=a?.namedRoot?`${n.label} · ${e.fields?.value?.unit===`$`&&e.fields.value.decimals===0?`$${new Intl.NumberFormat(`en-US`,{maximumFractionDigits:0}).format(r[0].value)}`:y(r[0].value)}`:``,C;for(let e=0;;e+=1){let n=S?t.wrap(S,o,13,650):[];C=44+n.length*18,n.length&&d.push(t.textLines(24,39,n,{size:13,weight:650,leading:18,fill:t.color(`fg`)}));let u=a?.compact&&i.length===1?.02:0;if(x(r[0],24+o*u,C+s*u,o*(1-u*2),s*(1-u*2),0),!c&&!l)break;e===6&&t.fit(`矩形树图的最小分块无法容纳编号`,`拆分图表或缩小权重差距`),c&&(o*=1.5),l&&(s*=1.5),c=l=!1,d.length=p.length=0}let w=v(d,p,24,C+s+24,Math.min(o,360),t,`treemap-name`,y),T=p.length?w+8:C+s+8,E=t.scene(T,d,e.title);return a&&(E.width=Math.max(E.width,o+48)),E}function b(e,t){let n=_(e.data),i=n[0],a=n.filter(e=>e.depth>0),o=[],c=new Map(a.map((e,t)=>[e,t+1])),l=Math.max(1,...n.map(e=>e.depth)),u=Math.max(8,Math.min(t.width/2-20,220)),d=String(i.node.label),f=t.measure(d,12,600),p=Math.min(Math.max(36,f+16),Math.max(36,u*.42)),m=Math.min(p,Math.max(36,u/(l+1))),h=(u-m)/l,g=t.width/2,y=u+24,b=[],x=e=>{let t=e;for(;t.parent&&t.parent!==i;)t=t.parent;return t},S=new Map(i.children.map((e,n)=>[e,t.palette[`tone${n%6+1}`]])),C=e=>S.get(x(e))||t.palette.tone1,w=e=>t.mix(C(e),t.palette.bg,Math.min(.72,.35+Math.max(0,e.depth-1)*.12)),T=(e,n,i)=>{let a=e.depth;if(a>0&&e.value>0&&i>n){let l=w(e),u=m+(a-1)*h,d=m+a*h,f=c.get(e);b.push(t.path(s(g,y,u,d,n,i),{fill:l,stroke:t.color(`bg`),"stroke-width":2,meta:{kind:`sunburst-node`,label:String(e.node.label),value:e.value,path:e.path,depth:a}}));let p=(u+d)/2,_=(n+i)/2,v=2*p*Math.sin(Math.min(Math.PI,i-n)/2),x=2*Math.max(0,p-u-5),S=String(e.node.label),C=`${S} · ${t.format(e.value,`value`)}`,T=t.measure(C,12,600),E=t.textOn(l);if(h>=16&&v>=T+8&&x>=T+8){let[n,i]=r(g,y,p,_);b.push(t.text(n,i+4,C,{anchor:`middle`,size:12,weight:600,fill:E,meta:{kind:`sunburst-ring-label`,label:S,value:e.value,path:e.path,depth:a}}))}else{o.push({index:f,label:S,value:e.value,path:e.path,color:l});let n=t.measure(String(f),12,600);if(h>=16&&v>=n+8&&x>=n+8){let[n,i]=r(g,y,p,_);b.push(t.text(n,i+4,String(f),{anchor:`middle`,size:12,weight:600,fill:E,meta:{kind:`sunburst-ring-index`,label:S,value:e.value,path:e.path,depth:a,index:f}}))}}}else a>0&&e.value===0&&o.push({index:c.get(e),label:String(e.node.label),value:0,path:e.path,color:w(e)});let l=n;e.children.forEach(t=>{let r=e.value>0?l+(i-n)*t.value/e.value:l;T(t,l,r),l=r})};T(i,-Math.PI/2,Math.PI*1.5),b.push(t.circle(g,y,Math.max(1,m-2),{fill:t.color(`bg`)}));let E=Math.max(1,2*(m-8)),D=Math.max(1,Math.floor(2*(m-6)/16)),O=t.wrap(d,E,12,600),k=!1;(O.length>D||O.some(e=>t.measure(e,12,600)>E))&&(k=!0,O=t.wrap(d,Math.max(80,t.width-36),12,600));let A=k?y+u+22:y-(O.length-1)*8+4;b.push(t.textLines(g,A,O,{anchor:`middle`,size:12,weight:600,fill:t.color(`fg`),meta:{kind:`sunburst-centre`,label:d}}));let j=v(b,o,18,k?A+O.length*16+12:y+u+28,t.width-36,t,`sunburst-name`),M=k?A+O.length*16+8:y+u+20;return t.scene(o.length?j+8:M,b,e.title)}function x({register:e}){e(`pie`,(e,t)=>p(e,t,!1)),e(`donut`,(e,t)=>p(e,t,!0)),e(`radial-share`,m),e(`rose`,h),e(`gauge`,g),e(`treemap`,y),e(`sunburst`,b)}return x({register:t.register}),e.compositionPresentation=f,e.install=x,e})({},KChartUnits[`chart/registry`]);
|
package/dist/units/chart/maps.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
KChartUnits["chart/maps"]=(function(e,t){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var n=Math.PI/180,r=(e,t,r=`equirectangular`)=>{let i=Number(e),a=Number(t);if(!Number.isFinite(i)||!Number.isFinite(a)||i<-180||i>180||a<-90||a>90)return null;if(r===`mercator`){let e=Math.max(-85.05112878,Math.min(85.05112878,a));return[i*n,Math.log(Math.tan(Math.PI/4+e*n/2))]}if(r!==`equirectangular`)throw TypeError(`Unknown map projection: ${r}`);return[i*n,a*n]},i=e=>typeof e==`object`&&!!e&&!Array.isArray(e);function a(e,t){let n=t,r=e.data.map,a,o;r.geojson?(a=r.geojson,o=r.idProperty):(a=t.assets?.[r.asset],a||n.fit(`缺少注入的地图资产 ${r.asset}`,`由宿主通过 ctx.assets 注入对应 FeatureCollection`),o=`id`),a&&a.type===`FeatureCollection`&&Array.isArray(a.features)||n.fit(`地图资产不是 FeatureCollection`,`传入合法 GeoJSON FeatureCollection`);for(let[e,t]of a.features.entries()){i(t)&&t.type===`Feature`&&i(t.properties)&&i(t.geometry)&&[`Polygon`,`MultiPolygon`].includes(t.geometry.type)||n.fit(`地图要素 ${e} 缺少合法 Polygon/MultiPolygon geometry`,`修正 GeoJSON geometry.type 与 coordinates`);let r=t.geometry.type===`Polygon`?[t.geometry.coordinates]:t.geometry.coordinates;Array.isArray(r)&&r.length&&!r.some(e=>!Array.isArray(e)||!e.length||e.some(e=>!Array.isArray(e)||e.length<4||e.some(e=>!Array.isArray(e)||e.length<2||!Number.isFinite(e[0])||!Number.isFinite(e[1])||e[0]<-180||e[0]>180||e[1]<-90||e[1]>90)||e[0][0]!==e.at(-1)[0]||e[0][1]!==e.at(-1)[1]))||n.fit(`地图要素 ${e} 含空或非法坐标环`,`每个 ring 须至少含4个合法经纬度位置且首尾闭合`)}return{features:a.features,idProperty:o}}function o(e){let t=[];for(let[n,r]of e){let e=n;if(t.length){let n=t.at(-1)[0];for(;e-n>180;)e-=360;for(;e-n<-180;)e+=360}t.push([e,r])}let n=Math.floor((Math.min(...t.map(e=>e[0]))+180)/360),r=Math.floor((Math.max(...t.map(e=>e[0]))+180)/360),i=(e,t,n)=>{let r=[];for(let i=0;i<e.length;i+=1){let a=e[i],o=e[(i+1)%e.length],s=n?a[0]>=t:a[0]<=t,c=n?o[0]>=t:o[0]<=t;if(s&&r.push(a),s!==c){let e=(t-a[0])/(o[0]-a[0]);r.push([t,a[1]+(o[1]-a[1])*e])}}return r},a=[];for(let e=n;e<=r;e+=1){let n=-180+e*360,r=180+e*360,o=i(i(t,n,!0),r,!1);if(o.length<3)continue;let s=o.map(([t,n])=>[t-e*360,n]);s.push([...s[0]]),a.push(s)}return a}function s(e,t){return o(e).map(e=>{let n=e.map(([e,n])=>t(e,n)).filter(Boolean);return n.length<4?``:`${n.map(([e,t],n)=>`${n?`L`:`M`}${e.toFixed(2)},${t.toFixed(2)}`).join(` `)} Z`}).filter(Boolean).join(` `)}function c(e){return e.type===`Polygon`?e.coordinates:e.coordinates.flat()}function l(e,t,n,r,i){if(r)return{west:-126,east:-66,south:23,north:50};let a=[];for(let t of e)for(let e of c(t.geometry))for(let t of e)a.push(t);if(!a.length)for(let e of t||[])Number.isFinite(e[n?.longitude])&&Number.isFinite(e[n?.latitude])&&a.push([e[n.longitude],e[n.latitude]]);if(!a.length)return{west:-180,east:180,south:-90,north:90};let o=Math.min(...a.map(e=>e[0])),s=Math.max(...a.map(e=>e[0])),l=Math.min(...a.map(e=>e[1])),u=Math.max(...a.map(e=>e[1]));return o===s&&(--o,s+=1),l===u&&(--l,u+=1),i===`mercator`&&(l=Math.max(l,-85.05112878),u=Math.min(u,85.05112878)),{west:o,east:s,south:l,north:u}}var u=98,d=16,f=24;function p(e,t,n,i=[]){let a=t.width,o=e.data.map.asset===`us-states`,s=t.assets?.projection||`equirectangular`,c=l(n,i,e.encode,o,s),u=r(c.west,c.south,s),p=r(c.east,c.north,s),m=a<=360?12:32,h=Math.min(i.length,f),g=h?126+Math.ceil(h/(a<420?1:2))*d:112,_=a-m*2,v=Math.max(180,Math.round(a*.64)-(h?120:80)),y=Math.min(_/Math.max(1e-9,p[0]-u[0]),v/Math.max(1e-9,p[1]-u[1])),b={x:m+(_-(p[0]-u[0])*y)/2,y:20,w:(p[0]-u[0])*y,h:(p[1]-u[1])*y},x=Math.ceil(b.y+b.h+4+g),S=(e,t)=>{let n=r(e,t,s);return o&&e>c.east?null:n&&[b.x+(n[0]-u[0])*y,b.y+(p[1]-n[1])*y]},C=[],w=t.palette.grid;t.palette.muted;let T=o?10:Math.max(10,Math.round((c.east-c.west)/6/10)*10),E=o?5:Math.max(10,Math.round((c.north-c.south)/5/10)*10);for(let e=Math.ceil(c.west/T)*T;e<=c.east;e+=T){let n=S(e,c.south),r=S(e,c.north);n&&r&&C.push(t.line(n[0],n[1],r[0],r[1],{stroke:w,"stroke-width":.6,"stroke-dasharray":`2 4`}))}for(let e=Math.ceil(c.south/E)*E;e<=c.north;e+=E){let n=S(c.west,e),r=S(c.east,e);n&&r&&C.push(t.line(n[0],n[1],r[0],r[1],{stroke:w,"stroke-width":.6,"stroke-dasharray":`2 4`}))}return{width:a,height:x,plot:b,children:C,projectPoint:S,inset:o,projection:s,bounds:c,bottom:g}}function m(e,t,n,r){let i=t===`US-AK`,a=i?-188:-161,o=i?-129:-154,s=i?51:18,c=i?72:23,l=i?{x:e.plot.x,y:e.plot.y+e.plot.h-62,w:102,h:48}:{x:e.plot.x+112,y:e.plot.y+e.plot.h-28,w:36,h:22},u=i&&n>0?n-360:n;return!i&&u<a-1?null:[l.x+(u-a)/(o-a)*l.w,l.y+(c-r)/(c-s)*l.h]}function h(e,t,n,r){let i=r.data.map.geojson?t.lang.startsWith(`en`)?`Source: supplied GeoJSON`:`地图来源:注入的 GeoJSON`:t.lang.startsWith(`en`)?`Source: Natural Earth`:`地图来源:Natural Earth`,a=t.lang.startsWith(`en`)?`${i} · Boundaries are illustrative, not an endorsement.`:`${i} · 边界仅作示意,不代表立场或认可。`,o=t.wrap(a,Math.max(120,n.width-24),12,400);e.push(t.textLines(n.width/2,n.height-6,o,{anchor:`middle`,size:12,fill:g(t).muted,meta:{kind:`map-source`}})),n.height+=(o.length-1)*16}function g(e){let{accent:t,bg:n,muted:r}=e.palette;return{low:e.mix(n,t,.3),high:t,missing:n,border:e.mix(n,r,.5),ink:e.palette.fg,muted:r,grid:e.palette.grid}}function _(e,t,n){let r=e.field(n),i=e.format(t,n);return r.unit&&i!==`—`&&!i.includes(r.unit)?`${i} ${r.unit}`:i}function v(e,t,n,r,i,a,o=!1){let s=g(t),c=n.height-n.bottom+16,l=n.width/2,u=e=>{e+24>n.width&&(n.width=Math.ceil(e+24),l=n.width/2)},d=a?t.field(a):{},f=d.label&&d.label!==a?d.label:d.unit||``;if(o){let n=_(t,r,a),o=_(t,i,a),d=t.lang.startsWith(`en`)?`area ∝ value`:`面积 ∝ 数值`;if(r===i){let r=t.measure(n,12,400),i=t.measure(d,12,400),a=40+r+i;u(a);let o=l-a/2;e.push(t.circle(o+5,c+26,5,{fill:s.high,stroke:s.ink,"stroke-width":.7,meta:{kind:`geo-scatter-size-legend`}})),e.push(t.text(o+14,c+30,n,{size:12,fill:s.ink})),e.push(t.text(o+22+r+18,c+30,d,{size:12,fill:s.muted}))}else{let r=[n,o,d].map(e=>t.measure(e,12,400)),i=74+r[0]+r[1]+r[2];u(i);let a=l-i/2;e.push(t.circle(a+5,c+26,5,{fill:s.high,stroke:s.ink,"stroke-width":.7,meta:{kind:`geo-scatter-size-legend`}})),a+=16,e.push(t.text(a,c+30,n,{size:12,fill:s.ink})),a+=r[0]+18,e.push(t.circle(a+9,c+26,9,{fill:s.high,stroke:s.ink,"stroke-width":.7,meta:{kind:`geo-scatter-size-legend`}})),a+=24,e.push(t.text(a,c+30,o,{size:12,fill:s.ink})),a+=r[1]+16,e.push(t.text(a,c+30,d,{size:12,fill:s.muted}))}e.push(t.text(l,c,f,{anchor:`middle`,size:12,fill:s.ink}))}else e.push(t.text(l,c,f,{anchor:`middle`,size:12,fill:s.ink})),e.push(t.rect(l-100,c+8,200,12,{fill:`url(#map-legend)`})),e.push(t.text(l-100,c+38,_(t,r,a),{size:12,fill:s.ink})),e.push(t.text(l+100,c+38,_(t,i,a),{anchor:`end`,size:12,fill:s.ink})),e.push(t.rect(l-100,c+46,12,12,{fill:s.missing,stroke:s.border,"stroke-width":1})),e.push(t.text(l-82,c+57,t.lang.startsWith(`en`)?`No data`:`无数据`,{size:12,fill:s.ink})),e.push(t.el(`defs`,{},[t.el(`linearGradient`,{id:`map-legend`,x1:`0%`,x2:`100%`,y1:`0%`,y2:`0%`},[t.el(`stop`,{offset:`0%`,"stop-color":s.low}),t.el(`stop`,{offset:`100%`,"stop-color":s.high})])]))}function y(e,t,n){let r=new Set;for(let i of e){let e=i.properties[t];(typeof e!=`string`||!e||r.has(e))&&n.fit(`地图地区键 ${String(e)} 缺失或重复`,`修正 idProperty 并确保每个地区键唯一`),r.add(e)}return r}function b(e,t){let{features:n,idProperty:r}=a(e,t),i=y(n,r,t),[o,l]=[e.encode.region,e.encode.value],u=new Map;for(let[n,r]of e.data.rows.entries()){let e=r?.[o];typeof e==`string`&&i.has(e)||t.fit(`数据行 ${n} 的地区键 ${String(e)} 不存在于地图资产`,`使地区键与 GeoJSON id 完全一致;禁止按名称模糊匹配`),u.has(e)&&t.fit(`地区键 ${e} 在数据中重复`,`每个地区只能提供一行数据`);let a=r[l];a===null||typeof a==`number`&&Number.isFinite(a)||t.fit(`地区 ${e} 的数值非法`,`value 必须是有限数值或 null`),u.set(e,a)}let d=t.field(l),f=Array.isArray(d.domain)&&d.domain.length===2&&d.domain.every(Number.isFinite)?d.domain:null,_=[...u.values()].filter(Number.isFinite),b=f?.[0]??(_.length?Math.min(..._):0),x=f?.[1]??(_.length?Math.max(..._):0),S=p(e,t,n),C=g(t),{children:w,projectPoint:T}=S;for(let e of n){let n=e.properties[r],i=u.has(n)&&Number.isFinite(u.get(n)),a=i?u.get(n):null;if(S.inset&&[`US-AK`,`US-HI`].includes(n))continue;let o=i?x===b?.5:Math.max(0,Math.min(1,(a-b)/(x-b))):0,l=i?t.mix(C.low,C.high,o):C.missing,d=c(e.geometry).map(e=>s(e,T)).filter(Boolean).join(` `);d&&w.push(t.path(d,{fill:l,"fill-rule":`evenodd`,stroke:C.border,"stroke-width":.7,"vector-effect":`non-scaling-stroke`,meta:{kind:`choropleth`,region:n,label:e.properties.name||n,value:i?a:null}}))}if(S.inset)for(let e of n){let n=e.properties[r];if(![`US-AK`,`US-HI`].includes(n))continue;let i=(e,t)=>m(S,n,e,t),a=c(e.geometry).map(e=>s(e,i)).filter(Boolean).join(` `),o=u.get(n),l=u.has(n)&&Number.isFinite(o);a&&w.push(t.path(a,{fill:l?t.mix(C.low,C.high,x===b?.5:Math.max(0,Math.min(1,(o-b)/(x-b)))):C.missing,"fill-rule":`evenodd`,stroke:C.border,"stroke-width":.7,meta:{kind:`choropleth`,region:n,label:e.properties.name||n,value:l?o:null,inset:!0}}))}return v(w,t,S,b,x,l),h(w,t,S,e),{width:S.width,height:S.height,title:e.title||`Choropleth map`,children:w}}function x(e,t){let{features:n}=a(e,t),r=e.data.rows,i=e.encode,o=p(e,t,n,r),l=g(t),{children:y,projectPoint:b}=o;for(let e of n){let n=e.properties.id||null,r=o.inset&&[`US-AK`,`US-HI`].includes(n)?(e,t)=>m(o,n,e,t):b;for(let i of c(e.geometry)){let e=s(i,r);e&&y.push(t.path(e,{fill:`none`,stroke:l.border,"stroke-width":.7,meta:{kind:`geo-boundary`,region:n,...o.inset&&[`US-AK`,`US-HI`].includes(n)?{inset:!0}:{}}}))}}let x=i.value,S=x?r.map(e=>e[x]).filter(e=>typeof e==`number`&&Number.isFinite(e)):[];S.some(e=>e<0)&&t.fit(`geo-scatter value 不可为负数`,`协议规定非负数值按面积映射;修正 value`);let C=x?t.field(x).domain:null,w=C?.length===2&&C.every(Number.isFinite)?C[0]:S.length?Math.min(...S):0,T=C?.length===2&&C.every(Number.isFinite)?C[1]:S.length?Math.max(...S):0,E=[],D=[];r.forEach((e,n)=>{let r=e[i.longitude],a=e[i.latitude],s=i.id?e[i.id]:null,c=i.label?e[i.label]:null,u=o.inset&&(a>50&&r<=-129?`US-AK`:a>=18&&a<=23&&r>=-161&&r<=-154?`US-HI`:null),d=u?m(o,u,r,a):b(r,a),f=!!x&&typeof e[x]==`number`&&Number.isFinite(e[x]),p=!u&&(r<o.bounds.west||r>o.bounds.east||a<o.bounds.south||a>o.bounds.north);if(!d||p||d[0]<0||d[0]>o.width||d[1]<0||d[1]>o.height-o.bottom){D.push(c||s||`#${n+1}`);return}if(f&&e[x]===0){E.push({index:n,label:c,id:s,value:0,zero:!0});return}let h=f?e[x]:null,g=f&&T>0?Math.sqrt(h/T)*9:4.5;y.push(t.circle(d[0],d[1],g,{fill:l.high,"fill-opacity":.85,stroke:l.ink,"stroke-width":1,meta:{kind:`geo-scatter`,...s==null?{}:{id:s},...c==null?{}:{label:c},value:h}})),E.push({index:n,label:c,id:s,value:h,zero:!1})}),x&&v(y,t,o,w,T,x,!0);let O=o.height-o.bottom+u,k=t.lang.startsWith(`en`);y.push(t.text(24,O,k?`Locations`:`地点索引`,{size:12,weight:600,fill:l.ink}));let A=o.width<420?1:2,j=E.slice(0,f),M=E.length-j.length,N=Math.max(96,(o.width-48)/A-12),P=O+8,F=Array.from({length:A},()=>O+20);if(j.forEach((e,n)=>{let r=n%A,i=24+r*((o.width-48)/A),a=F[r],s=e.label||e.id||`#${e.index+1}`,c=e.zero?k?`${_(t,0,x)} (no marker)`:`${_(t,0,x)}(无点)`:e.value==null?k?`no value`:`无数值`:_(t,e.value,x),u=t.wrap(`${s} · ${c}`,N,12,400);u.forEach((n,r)=>y.push(t.text(i,a+r*d,n,{size:12,fill:l.ink,meta:r===0?{kind:`geo-scatter-index`,id:e.id,label:s,value:e.value}:void 0}))),F[r]=a+u.length*d,P=Math.max(P,F[r])}),M>0){let e=k?`and ${M} more`:`另有 ${M} 处`;y.push(t.text(24,P+4,e,{size:12,fill:l.muted,meta:{kind:`geo-scatter-more`,omitted:M}})),P+=20}let I=o.bottom-u,L=P-O+16;if(L>I&&(o.height+=L-I),D.length){let e=P+8,n=t.wrap(`${k?`Outside map bounds`:`不在地图范围`}: ${D.join(`, `)}`,Math.max(120,o.width-48),12,400);n.forEach((n,r)=>y.push(t.text(24,e+r*d,n,{size:12,fill:l.muted,meta:r===0?{kind:`geo-scatter-outside`,ids:D}:void 0}))),o.height+=n.length*d+8}return h(y,t,o,e),{width:o.width,height:o.height,title:e.title||`Geographic scatter`,children:y}}function S({register:e}){e(`choropleth`,b),e(`geo-scatter`,x)}S({register:t.register});var C=Object.freeze({project:r,featuresFor:a});return e.install=S,e.maps=C,e})({},KChartUnits[`chart/registry`]);
|
|
1
|
+
KChartUnits["chart/maps"]=(function(e,t){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var n=Math.PI/180,r=(e,t,r=`equirectangular`)=>{let i=Number(e),a=Number(t);if(!Number.isFinite(i)||!Number.isFinite(a)||i<-180||i>180||a<-90||a>90)return null;if(r===`mercator`){let e=Math.max(-85.05112878,Math.min(85.05112878,a));return[i*n,Math.log(Math.tan(Math.PI/4+e*n/2))]}if(r!==`equirectangular`)throw TypeError(`Unknown map projection: ${r}`);return[i*n,a*n]},i=e=>typeof e==`object`&&!!e&&!Array.isArray(e);function a(e,t){let n=t,r=e.data.map,a,o;r.geojson?(a=r.geojson,o=r.idProperty):(a=t.assets?.[r.asset],a||n.fit(`缺少注入的地图资产 ${r.asset}`,`由宿主通过 ctx.assets 注入对应 FeatureCollection`),o=`id`),a&&a.type===`FeatureCollection`&&Array.isArray(a.features)||n.fit(`地图资产不是 FeatureCollection`,`传入合法 GeoJSON FeatureCollection`);for(let[e,t]of a.features.entries()){i(t)&&t.type===`Feature`&&i(t.properties)&&i(t.geometry)&&[`Polygon`,`MultiPolygon`].includes(t.geometry.type)||n.fit(`地图要素 ${e} 缺少合法 Polygon/MultiPolygon geometry`,`修正 GeoJSON geometry.type 与 coordinates`);let r=t.geometry.type===`Polygon`?[t.geometry.coordinates]:t.geometry.coordinates;Array.isArray(r)&&r.length&&!r.some(e=>!Array.isArray(e)||!e.length||e.some(e=>!Array.isArray(e)||e.length<4||e.some(e=>!Array.isArray(e)||e.length<2||!Number.isFinite(e[0])||!Number.isFinite(e[1])||e[0]<-180||e[0]>180||e[1]<-90||e[1]>90)||e[0][0]!==e.at(-1)[0]||e[0][1]!==e.at(-1)[1]))||n.fit(`地图要素 ${e} 含空或非法坐标环`,`每个 ring 须至少含4个合法经纬度位置且首尾闭合`)}return{features:a.features,idProperty:o}}function o(e){let t=[];for(let[n,r]of e){let e=n;if(t.length){let n=t.at(-1)[0];for(;e-n>180;)e-=360;for(;e-n<-180;)e+=360}t.push([e,r])}let n=Math.floor((Math.min(...t.map(e=>e[0]))+180)/360),r=Math.floor((Math.max(...t.map(e=>e[0]))+180)/360),i=(e,t,n)=>{let r=[];for(let i=0;i<e.length;i+=1){let a=e[i],o=e[(i+1)%e.length],s=n?a[0]>=t:a[0]<=t,c=n?o[0]>=t:o[0]<=t;if(s&&r.push(a),s!==c){let e=(t-a[0])/(o[0]-a[0]);r.push([t,a[1]+(o[1]-a[1])*e])}}return r},a=[];for(let e=n;e<=r;e+=1){let n=-180+e*360,r=180+e*360,o=i(i(t,n,!0),r,!1);if(o.length<3)continue;let s=o.map(([t,n])=>[t-e*360,n]);s.push([...s[0]]),a.push(s)}return a}function s(e,t){return o(e).map(e=>{let n=e.map(([e,n])=>t(e,n)).filter(Boolean);return n.length<4?``:`${n.map(([e,t],n)=>`${n?`L`:`M`}${e.toFixed(2)},${t.toFixed(2)}`).join(` `)} Z`}).filter(Boolean).join(` `)}function c(e){return e.type===`Polygon`?e.coordinates:e.coordinates.flat()}function l(e,t,n,r,i){if(r)return{west:-126,east:-66,south:23,north:50};let a=[];for(let t of e)for(let e of c(t.geometry))for(let t of e)a.push(t);if(!a.length)for(let e of t||[])Number.isFinite(e[n?.longitude])&&Number.isFinite(e[n?.latitude])&&a.push([e[n.longitude],e[n.latitude]]);if(!a.length)return{west:-180,east:180,south:-90,north:90};let o=Math.min(...a.map(e=>e[0])),s=Math.max(...a.map(e=>e[0])),l=Math.min(...a.map(e=>e[1])),u=Math.max(...a.map(e=>e[1]));return o===s&&(--o,s+=1),l===u&&(--l,u+=1),i===`mercator`&&(l=Math.max(l,-85.05112878),u=Math.min(u,85.05112878)),{west:o,east:s,south:l,north:u}}var u=98,d=28,f=16,p=24;function m(e,t,n,i=[],a=u){let o=t.width,s=e.data.map.asset===`us-states`,c=t.assets?.projection||`equirectangular`,d=l(n,i,e.encode,s,c),m=r(d.west,d.south,c),h=r(d.east,d.north,c),g=o<=360?12:32,_=Math.min(i.length,p),v=_?a+28+Math.ceil(_/(o<420?1:2))*f:112,y=o-g*2,b=Math.max(180,Math.round(o*.64)-(_?120:80)),x=Math.min(y/Math.max(1e-9,h[0]-m[0]),b/Math.max(1e-9,h[1]-m[1])),S={x:g+(y-(h[0]-m[0])*x)/2,y:20,w:(h[0]-m[0])*x,h:(h[1]-m[1])*x},C=Math.ceil(S.y+S.h+4+v),w=(e,t)=>{let n=r(e,t,c);return s&&e>d.east?null:n&&[S.x+(n[0]-m[0])*x,S.y+(h[1]-n[1])*x]},T=[],E=t.palette.grid;t.palette.muted;let D=s?10:Math.max(10,Math.round((d.east-d.west)/6/10)*10),O=s?5:Math.max(10,Math.round((d.north-d.south)/5/10)*10);for(let e=Math.ceil(d.west/D)*D;e<=d.east;e+=D){let n=w(e,d.south),r=w(e,d.north);n&&r&&T.push(t.line(n[0],n[1],r[0],r[1],{stroke:E,"stroke-width":.6,"stroke-dasharray":`2 4`}))}for(let e=Math.ceil(d.south/O)*O;e<=d.north;e+=O){let n=w(d.west,e),r=w(d.east,e);n&&r&&T.push(t.line(n[0],n[1],r[0],r[1],{stroke:E,"stroke-width":.6,"stroke-dasharray":`2 4`}))}return{width:o,height:C,plot:S,children:T,projectPoint:w,inset:s,projection:c,bounds:d,bottom:v}}function h(e,t,n,r){let i=t===`US-AK`,a=i?-188:-161,o=i?-129:-154,s=i?51:18,c=i?72:23,l=i?{x:e.plot.x,y:e.plot.y+e.plot.h-62,w:102,h:48}:{x:e.plot.x+112,y:e.plot.y+e.plot.h-28,w:36,h:22},u=i&&n>0?n-360:n;return!i&&u<a-1?null:[l.x+(u-a)/(o-a)*l.w,l.y+(c-r)/(c-s)*l.h]}function g(e,t,n,r){let i=r.data.map.geojson?t.lang.startsWith(`en`)?`Source: supplied GeoJSON`:`地图来源:注入的 GeoJSON`:t.lang.startsWith(`en`)?`Source: Natural Earth`:`地图来源:Natural Earth`,a=t.lang.startsWith(`en`)?`${i} · Boundaries are illustrative, not an endorsement.`:`${i} · 边界仅作示意,不代表立场或认可。`,o=t.wrap(a,Math.max(120,n.width-24),12,400);e.push(t.textLines(n.width/2,n.height-6,o,{anchor:`middle`,size:12,fill:_(t).muted,meta:{kind:`map-source`}})),n.height+=(o.length-1)*16}function _(e){let{accent:t,bg:n,muted:r}=e.palette;return{low:e.mix(n,t,.3),high:t,missing:n,border:e.mix(n,r,.5),ink:e.palette.fg,muted:r,grid:e.palette.grid}}function v(e,t,n){let r=e.field(n),i=e.format(t,n);return r.unit&&i!==`—`&&!i.includes(r.unit)?`${i} ${r.unit}`:i}function y(e,t,n,r,i,a,o=!1){let s=_(t),c=n.height-n.bottom+16,l=n.width/2,u=e=>{e+24>n.width&&(n.width=Math.ceil(e+24),l=n.width/2)},d=a?t.field(a):{},f=d.label&&d.label!==a?d.label:d.unit||``;if(o){let n=v(t,r,a),o=v(t,i,a),d=t.lang.startsWith(`en`)?`area ∝ value`:`面积 ∝ 数值`;if(r===i){let r=t.measure(n,12,400),i=t.measure(d,12,400),a=40+r+i;u(a);let o=l-a/2;e.push(t.circle(o+5,c+26,5,{fill:s.high,stroke:s.ink,"stroke-width":.7,meta:{kind:`geo-scatter-size-legend`}})),e.push(t.text(o+14,c+30,n,{size:12,fill:s.ink})),e.push(t.text(o+22+r+18,c+30,d,{size:12,fill:s.muted}))}else{let r=[n,o,d].map(e=>t.measure(e,12,400)),i=74+r[0]+r[1]+r[2];u(i);let a=l-i/2;e.push(t.circle(a+5,c+26,5,{fill:s.high,stroke:s.ink,"stroke-width":.7,meta:{kind:`geo-scatter-size-legend`}})),a+=16,e.push(t.text(a,c+30,n,{size:12,fill:s.ink})),a+=r[0]+18,e.push(t.circle(a+9,c+26,9,{fill:s.high,stroke:s.ink,"stroke-width":.7,meta:{kind:`geo-scatter-size-legend`}})),a+=24,e.push(t.text(a,c+30,o,{size:12,fill:s.ink})),a+=r[1]+16,e.push(t.text(a,c+30,d,{size:12,fill:s.muted}))}e.push(t.text(l,c,f,{anchor:`middle`,size:12,fill:s.ink}))}else e.push(t.text(l,c,f,{anchor:`middle`,size:12,fill:s.ink})),e.push(t.rect(l-100,c+8,200,12,{fill:`url(#map-legend)`})),e.push(t.text(l-100,c+38,v(t,r,a),{size:12,fill:s.ink})),e.push(t.text(l+100,c+38,v(t,i,a),{anchor:`end`,size:12,fill:s.ink})),e.push(t.rect(l-100,c+46,12,12,{fill:s.missing,stroke:s.border,"stroke-width":1})),e.push(t.text(l-82,c+57,t.lang.startsWith(`en`)?`No data`:`无数据`,{size:12,fill:s.ink})),e.push(t.el(`defs`,{},[t.el(`linearGradient`,{id:`map-legend`,x1:`0%`,x2:`100%`,y1:`0%`,y2:`0%`},[t.el(`stop`,{offset:`0%`,"stop-color":s.low}),t.el(`stop`,{offset:`100%`,"stop-color":s.high})])]))}function b(e,t,n){let r=new Set;for(let i of e){let e=i.properties[t];(typeof e!=`string`||!e||r.has(e))&&n.fit(`地图地区键 ${String(e)} 缺失或重复`,`修正 idProperty 并确保每个地区键唯一`),r.add(e)}return r}function x(e,t){let{features:n,idProperty:r}=a(e,t),i=b(n,r,t),[o,l]=[e.encode.region,e.encode.value],u=new Map;for(let[n,r]of e.data.rows.entries()){let e=r?.[o];typeof e==`string`&&i.has(e)||t.fit(`数据行 ${n} 的地区键 ${String(e)} 不存在于地图资产`,`使地区键与 GeoJSON id 完全一致;禁止按名称模糊匹配`),u.has(e)&&t.fit(`地区键 ${e} 在数据中重复`,`每个地区只能提供一行数据`);let a=r[l];a===null||typeof a==`number`&&Number.isFinite(a)||t.fit(`地区 ${e} 的数值非法`,`value 必须是有限数值或 null`),u.set(e,a)}let d=t.field(l),f=Array.isArray(d.domain)&&d.domain.length===2&&d.domain.every(Number.isFinite)?d.domain:null,p=[...u.values()].filter(Number.isFinite),v=f?.[0]??(p.length?Math.min(...p):0),x=f?.[1]??(p.length?Math.max(...p):0),S=m(e,t,n),C=_(t),{children:w,projectPoint:T}=S;for(let e of n){let n=e.properties[r],i=u.has(n)&&Number.isFinite(u.get(n)),a=i?u.get(n):null;if(S.inset&&[`US-AK`,`US-HI`].includes(n))continue;let o=i?x===v?.5:Math.max(0,Math.min(1,(a-v)/(x-v))):0,l=i?t.mix(C.low,C.high,o):C.missing,d=c(e.geometry).map(e=>s(e,T)).filter(Boolean).join(` `);d&&w.push(t.path(d,{fill:l,"fill-rule":`evenodd`,stroke:C.border,"stroke-width":.7,"vector-effect":`non-scaling-stroke`,meta:{kind:`choropleth`,region:n,label:e.properties.name||n,value:i?a:null}}))}if(S.inset)for(let e of n){let n=e.properties[r];if(![`US-AK`,`US-HI`].includes(n))continue;let i=(e,t)=>h(S,n,e,t),a=c(e.geometry).map(e=>s(e,i)).filter(Boolean).join(` `),o=u.get(n),l=u.has(n)&&Number.isFinite(o);a&&w.push(t.path(a,{fill:l?t.mix(C.low,C.high,x===v?.5:Math.max(0,Math.min(1,(o-v)/(x-v)))):C.missing,"fill-rule":`evenodd`,stroke:C.border,"stroke-width":.7,meta:{kind:`choropleth`,region:n,label:e.properties.name||n,value:l?o:null,inset:!0}}))}return y(w,t,S,v,x,l),g(w,t,S,e),{width:S.width,height:S.height,title:e.title||`Choropleth map`,children:w}}function S(e,t){let{features:n}=a(e,t),r=e.data.rows,i=e.encode,o=i.value?u:d,l=m(e,t,n,r,o),b=_(t),{children:x,projectPoint:S}=l;for(let e of n){let n=e.properties.id||null,r=l.inset&&[`US-AK`,`US-HI`].includes(n)?(e,t)=>h(l,n,e,t):S;for(let i of c(e.geometry)){let e=s(i,r);e&&x.push(t.path(e,{fill:`none`,stroke:b.border,"stroke-width":.7,meta:{kind:`geo-boundary`,region:n,...l.inset&&[`US-AK`,`US-HI`].includes(n)?{inset:!0}:{}}}))}}let C=i.value,w=C?r.map(e=>e[C]).filter(e=>typeof e==`number`&&Number.isFinite(e)):[];w.some(e=>e<0)&&t.fit(`geo-scatter value 不可为负数`,`协议规定非负数值按面积映射;修正 value`);let T=C?t.field(C).domain:null,E=T?.length===2&&T.every(Number.isFinite)?T[0]:w.length?Math.min(...w):0,D=T?.length===2&&T.every(Number.isFinite)?T[1]:w.length?Math.max(...w):0,O=[],k=[];r.forEach((e,n)=>{let r=e[i.longitude],a=e[i.latitude],o=i.id?e[i.id]:null,s=i.label?e[i.label]:null,c=l.inset&&(a>50&&r<=-129?`US-AK`:a>=18&&a<=23&&r>=-161&&r<=-154?`US-HI`:null),u=c?h(l,c,r,a):S(r,a),d=!!C&&typeof e[C]==`number`&&Number.isFinite(e[C]),f=!c&&(r<l.bounds.west||r>l.bounds.east||a<l.bounds.south||a>l.bounds.north);if(!u||f||u[0]<0||u[0]>l.width||u[1]<0||u[1]>l.height-l.bottom){k.push(s||o||`#${n+1}`);return}if(d&&e[C]===0){O.push({index:n,label:s,id:o,value:0,zero:!0});return}let p=d?e[C]:null,m=d&&D>0?Math.sqrt(p/D)*9:4.5;x.push(t.circle(u[0],u[1],m,{fill:b.high,"fill-opacity":.85,stroke:b.ink,"stroke-width":1,meta:{kind:`geo-scatter`,...o==null?{}:{id:o},...s==null?{}:{label:s},value:p}})),O.push({index:n,label:s,id:o,value:p,zero:!1})}),C&&y(x,t,l,E,D,C,!0);let A=l.height-l.bottom+o,j=t.lang.startsWith(`en`);x.push(t.text(24,A,j?`Locations`:`地点索引`,{size:12,weight:600,fill:b.ink}));let M=l.width<420?1:2,N=O.slice(0,p),P=O.length-N.length,F=Math.max(96,(l.width-48)/M-12),I=A+8,L=Array.from({length:M},()=>A+20);if(N.forEach((e,n)=>{let r=n%M,i=24+r*((l.width-48)/M),a=L[r],o=e.label||e.id||`#${e.index+1}`,s=C?e.zero?j?`${v(t,0,C)} (no marker)`:`${v(t,0,C)}(无点)`:e.value==null?j?`no value`:`无数值`:v(t,e.value,C):``,c=t.wrap(s?`${o} · ${s}`:o,F,12,400);c.forEach((n,r)=>x.push(t.text(i,a+r*f,n,{size:12,fill:b.ink,meta:r===0?{kind:`geo-scatter-index`,id:e.id,label:o,value:e.value}:void 0}))),L[r]=a+c.length*f,I=Math.max(I,L[r])}),P>0){let e=j?`and ${P} more`:`另有 ${P} 处`;x.push(t.text(24,I+4,e,{size:12,fill:b.muted,meta:{kind:`geo-scatter-more`,omitted:P}})),I+=20}let R=l.bottom-o,z=I-A+16;if(z>R&&(l.height+=z-R),k.length){let e=I+8,n=t.wrap(`${j?`Outside map bounds`:`不在地图范围`}: ${k.join(`, `)}`,Math.max(120,l.width-48),12,400);n.forEach((n,r)=>x.push(t.text(24,e+r*f,n,{size:12,fill:b.muted,meta:r===0?{kind:`geo-scatter-outside`,ids:k}:void 0}))),l.height+=n.length*f+8}return g(x,t,l,e),{width:l.width,height:l.height,title:e.title||`Geographic scatter`,children:x}}function C({register:e}){e(`choropleth`,x),e(`geo-scatter`,S)}C({register:t.register});var w=Object.freeze({project:r,featuresFor:a});return e.install=C,e.maps=w,e})({},KChartUnits[`chart/registry`]);
|