@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,277 @@
|
|
|
1
|
+
import { __exportAll } from "../_virtual/_rolldown/runtime.js";
|
|
2
|
+
import { error, warning } from "./support.js";
|
|
3
|
+
import { presentation } from "./presentation.js";
|
|
4
|
+
import { normalizeLabel } from "./label.js";
|
|
5
|
+
import { resolveIconRef } from "../core/icons.js";
|
|
6
|
+
import { createRegistry, layouts } from "../chart/registry.js";
|
|
7
|
+
import { sizeBudget, validate } from "../chart/spec.js";
|
|
8
|
+
import { mindmapPresentation } from "../chart/mindmap.js";
|
|
9
|
+
// src/diagram/mindmap.js
|
|
10
|
+
var mindmap_exports = /* @__PURE__ */ __exportAll({ implementations: () => implementations });
|
|
11
|
+
var MAX_NODES = 2e3;
|
|
12
|
+
var MAX_DEPTH = 100;
|
|
13
|
+
var LAYOUTS = [
|
|
14
|
+
"bilateral",
|
|
15
|
+
"right",
|
|
16
|
+
"left",
|
|
17
|
+
"radial",
|
|
18
|
+
"org",
|
|
19
|
+
"brace",
|
|
20
|
+
"fishbone",
|
|
21
|
+
"timeline"
|
|
22
|
+
];
|
|
23
|
+
var LAYOUT_ALIASES = /* @__PURE__ */ new Set([
|
|
24
|
+
"tidy-tree",
|
|
25
|
+
"dagre",
|
|
26
|
+
"elk",
|
|
27
|
+
"cose-bilkent"
|
|
28
|
+
]);
|
|
29
|
+
var SHAPE_FORMS = [
|
|
30
|
+
[
|
|
31
|
+
"((",
|
|
32
|
+
"))",
|
|
33
|
+
"circle"
|
|
34
|
+
],
|
|
35
|
+
[
|
|
36
|
+
"))",
|
|
37
|
+
"((",
|
|
38
|
+
"bang"
|
|
39
|
+
],
|
|
40
|
+
[
|
|
41
|
+
"{{",
|
|
42
|
+
"}}",
|
|
43
|
+
"hexagon"
|
|
44
|
+
],
|
|
45
|
+
[
|
|
46
|
+
"-)",
|
|
47
|
+
"(-",
|
|
48
|
+
"cloud"
|
|
49
|
+
],
|
|
50
|
+
[
|
|
51
|
+
"(-",
|
|
52
|
+
"-)",
|
|
53
|
+
"cloud"
|
|
54
|
+
],
|
|
55
|
+
[
|
|
56
|
+
"[",
|
|
57
|
+
"]",
|
|
58
|
+
"rect"
|
|
59
|
+
],
|
|
60
|
+
[
|
|
61
|
+
"(",
|
|
62
|
+
")",
|
|
63
|
+
"rounded"
|
|
64
|
+
],
|
|
65
|
+
[
|
|
66
|
+
")",
|
|
67
|
+
"(",
|
|
68
|
+
"cloud"
|
|
69
|
+
]
|
|
70
|
+
];
|
|
71
|
+
var BRACKETS = /[()[\]{}]|-\)|\(-/;
|
|
72
|
+
var unquote = (value) => value.length > 1 && value.startsWith("\"") && value.endsWith("\"") ? value.slice(1, -1) : value;
|
|
73
|
+
function parseNodeText(raw) {
|
|
74
|
+
const value = raw.trim();
|
|
75
|
+
const start = value.search(BRACKETS);
|
|
76
|
+
if (start < 0) return {
|
|
77
|
+
label: unquote(value).trim(),
|
|
78
|
+
shape: "none"
|
|
79
|
+
};
|
|
80
|
+
for (const [open, close, shape] of SHAPE_FORMS) {
|
|
81
|
+
if (!value.startsWith(open, start) || !value.endsWith(close) || value.length < start + open.length + close.length) continue;
|
|
82
|
+
return {
|
|
83
|
+
label: unquote(value.slice(start + open.length, value.length - close.length).trim()).trim(),
|
|
84
|
+
shape
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
return {
|
|
88
|
+
label: value,
|
|
89
|
+
shape: ""
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
function readRecords(lines, firstLine, lang, errors) {
|
|
93
|
+
const records = [];
|
|
94
|
+
for (let [index, raw] of lines.entries()) {
|
|
95
|
+
if (!raw.trim() || raw.trimStart().startsWith("%%")) continue;
|
|
96
|
+
const line = firstLine + index;
|
|
97
|
+
if (/^[ \t]*\t/.test(raw)) {
|
|
98
|
+
errors.push(error(lang, line, "缩进不能使用 Tab", "Tabs are not allowed in indentation", "把 Tab 换成空格", "Replace tabs with spaces"));
|
|
99
|
+
continue;
|
|
100
|
+
}
|
|
101
|
+
const indent = raw.match(/^ */)[0].length;
|
|
102
|
+
records.push({
|
|
103
|
+
text: raw.slice(indent).trimEnd(),
|
|
104
|
+
line,
|
|
105
|
+
indent
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
return records;
|
|
109
|
+
}
|
|
110
|
+
function parse(body, info = {}) {
|
|
111
|
+
const lang = info.lang || "zh";
|
|
112
|
+
const firstLine = Number.isInteger(info.firstLine) ? info.firstLine : 2;
|
|
113
|
+
const headerLine = info.headerLine || firstLine - 1;
|
|
114
|
+
const errors = [];
|
|
115
|
+
const addError = (line, zh, en, fixZh = "修正脑图语法后重试", fixEn = "Correct the mindmap syntax and try again", column = 1) => {
|
|
116
|
+
errors.push(error(lang, line, zh, en, fixZh, fixEn, column));
|
|
117
|
+
};
|
|
118
|
+
const lines = String(body ?? "").split("\n");
|
|
119
|
+
const look = presentation({ lang }), assets = /* @__PURE__ */ new Set(), identifiers = /* @__PURE__ */ new Map();
|
|
120
|
+
const addAsset = (diagnostic) => {
|
|
121
|
+
if (!assets.has(diagnostic.message)) {
|
|
122
|
+
assets.add(diagnostic.message);
|
|
123
|
+
errors.push(diagnostic);
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
const decorationByLine = /* @__PURE__ */ new Map();
|
|
127
|
+
let previousNodeLine = -1;
|
|
128
|
+
for (let i = 0; i < lines.length; i += 1) {
|
|
129
|
+
const trimmed = lines[i].trim();
|
|
130
|
+
if (!trimmed || trimmed.startsWith("%%")) continue;
|
|
131
|
+
if (look.accept(trimmed, firstLine + i)) {
|
|
132
|
+
lines[i] = "";
|
|
133
|
+
continue;
|
|
134
|
+
}
|
|
135
|
+
if (/^(?::::|::icon\b)/i.test(trimmed)) {
|
|
136
|
+
lines[i] = "";
|
|
137
|
+
const classes = /^:::\s*([\w-]+(?:\s+[\w-]+)*)$/.exec(trimmed)?.[1];
|
|
138
|
+
const ref = /^::icon\(\s*([^()]+?)\s*\)$/i.exec(trimmed)?.[1];
|
|
139
|
+
if (previousNodeLine < 0 || !classes && !ref) addError(firstLine + i, "脑图装饰无效或前面缺少节点", "Malformed mindmap decoration or missing preceding node");
|
|
140
|
+
else {
|
|
141
|
+
const decoration = decorationByLine.get(previousNodeLine) || { classes: [] };
|
|
142
|
+
if (classes) decoration.classes.push(...classes.split(/\s+/));
|
|
143
|
+
if (ref) {
|
|
144
|
+
decoration.icon = resolveIconRef(ref);
|
|
145
|
+
if (!decoration.icon) addAsset(warning("IGNORED_ASSET", lang, firstLine + i, `未知图标 ${ref}`, `Unknown icon ${ref}`, "改用内置图标", "Use a supported icon"));
|
|
146
|
+
}
|
|
147
|
+
decorationByLine.set(previousNodeLine, decoration);
|
|
148
|
+
}
|
|
149
|
+
continue;
|
|
150
|
+
}
|
|
151
|
+
previousNodeLine = i;
|
|
152
|
+
}
|
|
153
|
+
const records = readRecords(lines, firstLine, lang, errors);
|
|
154
|
+
const roots = [], stack = [], linesByPath = /* @__PURE__ */ new Map();
|
|
155
|
+
let nodeCount = 0, maxDepth = 0;
|
|
156
|
+
for (const record of records) {
|
|
157
|
+
while (stack.length && record.indent <= stack.at(-1).indent) stack.pop();
|
|
158
|
+
const parent = stack.at(-1)?.node ?? null;
|
|
159
|
+
const depth = stack.length;
|
|
160
|
+
maxDepth = Math.max(maxDepth, depth + 1);
|
|
161
|
+
const { label: rawLabel, shape } = parseNodeText(record.text);
|
|
162
|
+
const id = (shape !== "none" ? record.text.split(BRACKETS, 1)[0].trim() : "") || rawLabel;
|
|
163
|
+
const normalized = normalizeLabel(rawLabel, {
|
|
164
|
+
lang,
|
|
165
|
+
line: record.line
|
|
166
|
+
});
|
|
167
|
+
normalized.diagnostics.forEach(addAsset);
|
|
168
|
+
const label = normalized.text || (normalized.icon ? id || " " : "");
|
|
169
|
+
nodeCount += 1;
|
|
170
|
+
if (nodeCount === 2001) addError(record.line, `脑图超过安全上限 ${MAX_NODES} 个节点`, `Mindmap exceeds the safety cap of ${MAX_NODES} nodes`, "拆分脑图后重试", "Split the mindmap and try again");
|
|
171
|
+
if (depth >= MAX_DEPTH) addError(record.line, `脑图超过安全深度上限 ${MAX_DEPTH} 层`, `Mindmap exceeds the safety depth cap of ${MAX_DEPTH}`, "拆分脑图或降低层级", "Split the mindmap or reduce its depth");
|
|
172
|
+
if (/:::(?:[\w-]+)?|::icon\(/i.test(record.text)) addError(record.line, "不支持行内节点装饰", "Inline node decorations are unsupported", "在节点下一行使用受控 :::状态 标记", "Use a supported :::status marker on the next line");
|
|
173
|
+
if (!label) addError(record.line, "节点名称不能为空", "Node label cannot be empty");
|
|
174
|
+
const node = {
|
|
175
|
+
label,
|
|
176
|
+
children: []
|
|
177
|
+
};
|
|
178
|
+
if (shape) node.shape = shape;
|
|
179
|
+
const decoration = decorationByLine.get(record.line - firstLine);
|
|
180
|
+
if (decoration?.classes.length) look.addClasses(id, decoration.classes, record.line);
|
|
181
|
+
identifiers.set(node, {
|
|
182
|
+
id,
|
|
183
|
+
icon: decoration?.icon || normalized.icon
|
|
184
|
+
});
|
|
185
|
+
const sibling = parent ? parent.children.length : roots.length;
|
|
186
|
+
linesByPath.set(parent ? `${stack.at(-1).path}/children/${sibling}` : `/roots/${sibling}`, record.line);
|
|
187
|
+
const path = parent ? `${stack.at(-1).path}/children/${sibling}` : `/roots/${sibling}`;
|
|
188
|
+
if (parent) parent.children.push(node);
|
|
189
|
+
else if (roots.length) {
|
|
190
|
+
addError(record.line, `mindmap 只能有一个根节点:「${label}」没有父节点`, `A mindmap can have only one root: "${label}" has no parent`, "把该节点缩进到更浅一级的节点下面", "Indent this node under a shallower node");
|
|
191
|
+
roots[0].children.push(node);
|
|
192
|
+
} else roots.push(node);
|
|
193
|
+
stack.push({
|
|
194
|
+
indent: record.indent,
|
|
195
|
+
node,
|
|
196
|
+
path
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
if (!roots.length) addError(firstLine, "脑图中没有节点", "Mindmap is empty", "保留一个根节点并将其他节点缩进到它下面", "Keep one root node and indent all other nodes beneath it");
|
|
200
|
+
const layoutValue = info.config?.layout ?? info.config?.mindmap?.layoutAlgorithm ?? (typeof info.layout === "string" ? info.layout : info.layout?.config?.layout ?? info.layout?.layout);
|
|
201
|
+
let layout = "bilateral";
|
|
202
|
+
if (layoutValue != null && layoutValue !== "") {
|
|
203
|
+
const candidate = String(layoutValue).toLowerCase();
|
|
204
|
+
if (LAYOUT_ALIASES.has(candidate)) layout = "bilateral";
|
|
205
|
+
else if (LAYOUTS.includes(candidate)) layout = candidate;
|
|
206
|
+
else errors.push(warning("IGNORED_CONFIG", lang, headerLine, `脑图布局「${layoutValue}」不生效;按 bilateral 排版`, `Mindmap layout "${layoutValue}" is not honored; laid out as bilateral`, "改用 bilateral、right、left、radial、org、brace、fishbone 或 timeline", "Use bilateral, right, left, radial, org, brace, fishbone, or timeline"));
|
|
207
|
+
}
|
|
208
|
+
for (const key of Object.keys(info.options || {})) addError(headerLine, `脑图头行不支持选项「${key}」`, `Mindmap header option is unsupported: ${key}`, "移除头行选项,使用 config.layout 指定布局", "Remove the header option; use config.layout to choose a layout");
|
|
209
|
+
const data = roots[0] || { label: "" };
|
|
210
|
+
if (linesByPath.has("/roots/0")) linesByPath.set("/data", linesByPath.get("/roots/0"));
|
|
211
|
+
errors.push(...look.diagnostics());
|
|
212
|
+
for (const [node, { id, icon }] of identifiers) {
|
|
213
|
+
const status = look.statusOf(id);
|
|
214
|
+
if (status) node.status = status;
|
|
215
|
+
node[mindmapPresentation] = {
|
|
216
|
+
icon,
|
|
217
|
+
link: look.linkOf(id)
|
|
218
|
+
};
|
|
219
|
+
}
|
|
220
|
+
const spec = {
|
|
221
|
+
chart: "mindmap",
|
|
222
|
+
data,
|
|
223
|
+
layout,
|
|
224
|
+
[mindmapPresentation]: true,
|
|
225
|
+
[sizeBudget]: {
|
|
226
|
+
nodes: 2001,
|
|
227
|
+
depth: 101
|
|
228
|
+
}
|
|
229
|
+
};
|
|
230
|
+
Object.defineProperties(spec, {
|
|
231
|
+
nodeCount: { value: nodeCount },
|
|
232
|
+
maxDepth: { value: maxDepth }
|
|
233
|
+
});
|
|
234
|
+
if (info.title) spec.title = info.title;
|
|
235
|
+
const checked = validate(spec);
|
|
236
|
+
for (const issue of checked.errors) {
|
|
237
|
+
let path = "", line = firstLine;
|
|
238
|
+
for (const part of issue.path.split("/").slice(1)) {
|
|
239
|
+
path += `/${part}`;
|
|
240
|
+
if (linesByPath.has(path)) line = linesByPath.get(path);
|
|
241
|
+
}
|
|
242
|
+
errors.push({
|
|
243
|
+
...error(lang, line, issue.message, issue.message, issue.fix, issue.fix),
|
|
244
|
+
code: issue.code,
|
|
245
|
+
path: issue.path
|
|
246
|
+
});
|
|
247
|
+
}
|
|
248
|
+
return {
|
|
249
|
+
model: spec,
|
|
250
|
+
errors
|
|
251
|
+
};
|
|
252
|
+
}
|
|
253
|
+
var mindmapRegistry = createRegistry(validate);
|
|
254
|
+
mindmapRegistry.register("mindmap", layouts.get("mindmap"));
|
|
255
|
+
function layout(model, options = {}, info = {}) {
|
|
256
|
+
const radial = model.nodeCount > 80 && model.layout !== "radial";
|
|
257
|
+
const scene = mindmapRegistry.layout(radial ? {
|
|
258
|
+
...model,
|
|
259
|
+
layout: "radial"
|
|
260
|
+
} : model, options.renderOptions || options);
|
|
261
|
+
const requested = options.width || 800;
|
|
262
|
+
const errors = model.nodeCount > 60 || model.maxDepth > 5 || scene.width > requested * 2 ? [warning("LARGE_DIAGRAM", info.lang || options.lang || "zh", info.firstLine || 1, radial ? "大型脑图使用径向布局以避免重叠" : "脑图较大,可在图内滚动查看", radial ? "Large mindmap uses radial layout to avoid overlaps" : "Large mindmap; scroll within the figure", "拆分脑图以便阅读", "Split the mindmap for readability")] : [];
|
|
263
|
+
return {
|
|
264
|
+
width: scene.width,
|
|
265
|
+
height: scene.height,
|
|
266
|
+
scene,
|
|
267
|
+
errors
|
|
268
|
+
};
|
|
269
|
+
}
|
|
270
|
+
var implementations = { mindmap: {
|
|
271
|
+
acceptsPresentation: true,
|
|
272
|
+
honoredConfig: ["layout", "mindmap.layoutAlgorithm"],
|
|
273
|
+
parse,
|
|
274
|
+
layout,
|
|
275
|
+
scene: (geometry) => geometry.scene
|
|
276
|
+
} };
|
|
277
|
+
export { implementations, mindmap_exports };
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { __exportAll } from "../_virtual/_rolldown/runtime.js";
|
|
2
|
+
import { parsePie, parseTreemap } from "./numeric-parse.js";
|
|
3
|
+
import { diagnostics, renderWith, validateWith } from "./numeric-model.js";
|
|
4
|
+
import { compositionPresentation } from "../chart/composition.js";
|
|
5
|
+
import { createRegistry, layouts } from "../chart/registry.js";
|
|
6
|
+
import { sizeBudget, validate } from "../chart/spec.js";
|
|
7
|
+
import { warning } from "./support.js";
|
|
8
|
+
// src/diagram/numeric-composition.js
|
|
9
|
+
var numeric_composition_exports = /* @__PURE__ */ __exportAll({ implementations: () => implementations });
|
|
10
|
+
function bind(parse, toSpec, lineFor, options) {
|
|
11
|
+
return {
|
|
12
|
+
...options,
|
|
13
|
+
parse,
|
|
14
|
+
validate: (model, info) => validateWith(toSpec(model, info), info, (detail) => lineFor(model, detail.path)),
|
|
15
|
+
layout: (model, options, info) => renderWith(toSpec(model, info), options, info, (detail) => lineFor(model, detail.path))
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
var pie = bind(parsePie, (model) => ({
|
|
19
|
+
chart: "pie",
|
|
20
|
+
title: model.title || void 0,
|
|
21
|
+
sliceLabels: true,
|
|
22
|
+
data: model.rows.map(({ category, value }) => ({
|
|
23
|
+
category,
|
|
24
|
+
value
|
|
25
|
+
})),
|
|
26
|
+
encode: {
|
|
27
|
+
category: "category",
|
|
28
|
+
value: "value"
|
|
29
|
+
},
|
|
30
|
+
[compositionPresentation]: { labelRadius: model.labelRadius }
|
|
31
|
+
}), (model, path) => path === "/title" ? model.titleLine : model.rows[Number(path?.split("/")[2])]?.line || model.rows[0]?.line, {
|
|
32
|
+
optionMode: "raw",
|
|
33
|
+
honoredConfig: ["pie.textPosition"]
|
|
34
|
+
});
|
|
35
|
+
var treemapSpec = (model, info) => ({
|
|
36
|
+
chart: "treemap",
|
|
37
|
+
title: model.title || void 0,
|
|
38
|
+
data: model.data,
|
|
39
|
+
fields: model.valueField ? { value: model.valueField } : void 0,
|
|
40
|
+
[compositionPresentation]: {
|
|
41
|
+
showValues: info.config?.treemap?.showValues !== false,
|
|
42
|
+
prefix: model.prefix,
|
|
43
|
+
namedRoot: model.namedRoot
|
|
44
|
+
},
|
|
45
|
+
[sizeBudget]: {
|
|
46
|
+
nodes: 202,
|
|
47
|
+
depth: 101
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
var treemapLine = (model, path) => {
|
|
51
|
+
if (path === "/title") return model.titleLine;
|
|
52
|
+
for (let key = path; key; key = key.slice(0, key.lastIndexOf("/"))) {
|
|
53
|
+
if (model.treeLines[key]) return model.treeLines[key];
|
|
54
|
+
if (!key.includes("/")) break;
|
|
55
|
+
}
|
|
56
|
+
return null;
|
|
57
|
+
};
|
|
58
|
+
var treemapRegistry = createRegistry(validate);
|
|
59
|
+
treemapRegistry.register("treemap", layouts.get("treemap"));
|
|
60
|
+
var implementations = {
|
|
61
|
+
pie,
|
|
62
|
+
treemap: {
|
|
63
|
+
parse: parseTreemap,
|
|
64
|
+
acceptsPresentation: true,
|
|
65
|
+
honoredConfig: ["treemap.showValues", "treemap.valueFormat"],
|
|
66
|
+
validate(model, info) {
|
|
67
|
+
const spec = treemapSpec(model, info);
|
|
68
|
+
return diagnostics(validate(spec).errors, info, (detail) => treemapLine(model, detail.path));
|
|
69
|
+
},
|
|
70
|
+
layout(model, options, info) {
|
|
71
|
+
const spec = treemapSpec(model, info), lineFor = (detail) => treemapLine(model, detail.path);
|
|
72
|
+
const result = renderWith(spec, options, info, lineFor, treemapRegistry.layout);
|
|
73
|
+
if (result.scene && (model.nodeCount > 60 || model.depth > 5 || result.width > options.width * 2)) result.errors.push(warning("LARGE_DIAGRAM", info.lang, info.headerLine, "矩形树图较大,可滚动查看", "Large treemap; scroll to view it", "考虑拆分图表", "Consider splitting the chart"));
|
|
74
|
+
return result;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
export { implementations, numeric_composition_exports };
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { __exportAll } from "../_virtual/_rolldown/runtime.js";
|
|
2
|
+
import { error, warning } from "./support.js";
|
|
3
|
+
import { normalizeLabel } from "./label.js";
|
|
4
|
+
import { validate } from "../chart/spec.js";
|
|
5
|
+
import { layout } from "../chart/registry.js";
|
|
6
|
+
import { ExpectedDiagnostic } from "../core/diagnostics.js";
|
|
7
|
+
// src/diagram/numeric-model.js
|
|
8
|
+
var numeric_model_exports = /* @__PURE__ */ __exportAll({
|
|
9
|
+
diagnostics: () => diagnostics,
|
|
10
|
+
numericLabel: () => numericLabel,
|
|
11
|
+
renderWith: () => renderWith,
|
|
12
|
+
validateWith: () => validateWith
|
|
13
|
+
});
|
|
14
|
+
function diagnostics(errors, info, lineFor) {
|
|
15
|
+
return errors.map((detail) => error(info.lang, lineFor(detail) || info.firstLine, detail.message || "KChart 声明无效", detail.message || "Invalid KChart declaration", detail.fix || "修正图表声明", detail.fix || "Correct the chart declaration"));
|
|
16
|
+
}
|
|
17
|
+
function validateWith(spec, info, lineFor) {
|
|
18
|
+
return diagnostics(validate(spec).errors, info, lineFor);
|
|
19
|
+
}
|
|
20
|
+
function addVisibleHeader(scene, options) {
|
|
21
|
+
if (options.renderOptions?.frame) return scene;
|
|
22
|
+
const { ctx } = options;
|
|
23
|
+
const heading = scene.heading || "";
|
|
24
|
+
const subtitle = scene.subtitle || "";
|
|
25
|
+
if (!heading && !subtitle) return scene;
|
|
26
|
+
const available = Math.max(24, scene.width - 32), children = [];
|
|
27
|
+
let top = 16, requiredWidth = scene.width;
|
|
28
|
+
const paragraph = (text, size, weight) => {
|
|
29
|
+
if (!text) return;
|
|
30
|
+
const lines = ctx.wrap(text, available, size, weight), step = size + 6;
|
|
31
|
+
requiredWidth = Math.max(requiredWidth, 32 + Math.max(0, ...lines.map((line) => ctx.measure(line, size, weight))));
|
|
32
|
+
children.push(ctx.textLines(16, top + size, lines, {
|
|
33
|
+
leading: step,
|
|
34
|
+
size,
|
|
35
|
+
weight,
|
|
36
|
+
fill: ctx.color(weight > 400 ? "fg" : "muted")
|
|
37
|
+
}));
|
|
38
|
+
top += lines.length * step + 6;
|
|
39
|
+
};
|
|
40
|
+
paragraph(heading, 16, 650);
|
|
41
|
+
paragraph(subtitle, 12, 400);
|
|
42
|
+
top += 8;
|
|
43
|
+
return {
|
|
44
|
+
...scene,
|
|
45
|
+
width: requiredWidth,
|
|
46
|
+
height: scene.height + top,
|
|
47
|
+
children: [...children, ctx.el("g", { transform: `translate(0 ${top})` }, scene.children)]
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
function renderWith(spec, options, info, lineFor, layoutSpec = layout) {
|
|
51
|
+
const layoutOptions = {
|
|
52
|
+
...options.renderOptions,
|
|
53
|
+
width: options.width,
|
|
54
|
+
lang: info.lang,
|
|
55
|
+
...!options.renderOptions?.measure && options.measure ? { measure: (text, size = 12, weight = 400) => options.measure(text, {
|
|
56
|
+
size,
|
|
57
|
+
weight
|
|
58
|
+
}) } : {}
|
|
59
|
+
};
|
|
60
|
+
try {
|
|
61
|
+
const scene = addVisibleHeader(layoutSpec(spec, layoutOptions), options);
|
|
62
|
+
return {
|
|
63
|
+
width: scene.width,
|
|
64
|
+
height: scene.height,
|
|
65
|
+
scene,
|
|
66
|
+
errors: []
|
|
67
|
+
};
|
|
68
|
+
} catch (error) {
|
|
69
|
+
if (!(error instanceof ExpectedDiagnostic)) throw error;
|
|
70
|
+
return {
|
|
71
|
+
width: options.width,
|
|
72
|
+
height: 0,
|
|
73
|
+
errors: diagnostics(error.errors || [], info, lineFor)
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
function numericLabel(value, info, line, errors) {
|
|
78
|
+
const { text, icon, diagnostics } = normalizeLabel(value, {
|
|
79
|
+
lang: info.lang,
|
|
80
|
+
line
|
|
81
|
+
});
|
|
82
|
+
if (icon) diagnostics.push(warning("IGNORED_ASSET", info.lang, line, "数值图标签仅绘制文字,不绘制图标", "Numeric chart labels show text only; icons are omitted", "改用纯文本标签", "Use a text label"));
|
|
83
|
+
for (const diagnostic of diagnostics) if (!errors.some((e) => e.message === diagnostic.message)) errors.push(diagnostic);
|
|
84
|
+
return text.trim() || String(value);
|
|
85
|
+
}
|
|
86
|
+
export { diagnostics, numericLabel, numeric_model_exports, renderWith, validateWith };
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
import { __exportAll } from "../_virtual/_rolldown/runtime.js";
|
|
2
|
+
import { error, warning } from "./support.js";
|
|
3
|
+
import { presentation } from "./presentation.js";
|
|
4
|
+
import { numericLabel } from "./numeric-model.js";
|
|
5
|
+
import { compositionPresentation } from "../chart/composition.js";
|
|
6
|
+
// src/diagram/numeric-parse.js
|
|
7
|
+
var numeric_parse_exports = /* @__PURE__ */ __exportAll({
|
|
8
|
+
TREEMAP_MAX_DEPTH: () => 100,
|
|
9
|
+
TREEMAP_MAX_NODES: () => 201,
|
|
10
|
+
parsePie: () => parsePie,
|
|
11
|
+
parseTreemap: () => parseTreemap
|
|
12
|
+
});
|
|
13
|
+
var issue = (info, line, text, en) => error(info.lang, line, text, en, "修正图表语法", "Correct the chart syntax");
|
|
14
|
+
var unquote = (text) => text.replace(/^(["'])(.*)\1$/, "$2");
|
|
15
|
+
var numeric = (value) => /^[-+]?(?:\d+(?:\.\d*)?|\.\d+)(?:e[-+]?\d+)?$/i.test(value) && Number.isFinite(Number(value));
|
|
16
|
+
var TREEMAP_MAX_NODES = 201;
|
|
17
|
+
var TREEMAP_MAX_DEPTH = 100;
|
|
18
|
+
var linesOf = (source, firstLine) => source.split("\n").map((raw, i) => ({
|
|
19
|
+
raw,
|
|
20
|
+
text: raw.trim(),
|
|
21
|
+
line: firstLine + i
|
|
22
|
+
})).filter((x) => x.text && !x.text.startsWith("%%"));
|
|
23
|
+
function parsePie(source, info) {
|
|
24
|
+
const errors = [], rows = [], labels = /* @__PURE__ */ new Set(), duplicates = [];
|
|
25
|
+
const header = info.headerLine || info.firstLine - 1;
|
|
26
|
+
const params = (info.params || "").trim();
|
|
27
|
+
const showData = /^showData\b/i.test(params) || info.options?.showData === true;
|
|
28
|
+
const rest = params.replace(/^showData\b\s*/i, "");
|
|
29
|
+
let title = null, titleLine = null;
|
|
30
|
+
const setTitle = (text, line) => {
|
|
31
|
+
if (title !== null) errors.push(issue(info, line, "pie 只能有一个 title", "Pie accepts only one title"));
|
|
32
|
+
else {
|
|
33
|
+
title = numericLabel(unquote(text), info, line, errors);
|
|
34
|
+
titleLine = line;
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
if (/^title\s+\S/i.test(rest)) setTitle(rest.replace(/^title\s+/i, ""), header);
|
|
38
|
+
else if (rest) errors.push(issue(info, header, "pie 只支持 showData 和 title", "Pie only supports showData and title"));
|
|
39
|
+
for (const { text, line } of linesOf(source, info.firstLine)) {
|
|
40
|
+
if (/^title\s+/i.test(text)) {
|
|
41
|
+
setTitle(text.replace(/^title\s+/i, ""), line);
|
|
42
|
+
continue;
|
|
43
|
+
}
|
|
44
|
+
const m = /^(.+?)\s*:\s*(\S+)$/.exec(text);
|
|
45
|
+
const label = m && numericLabel(unquote(m[1]), info, line, errors);
|
|
46
|
+
if (!label || !numeric(m[2]) || +m[2] < 0) errors.push(issue(info, line, "pie 数据必须是非负有限数值及非空标签", "Pie sections require a label and a finite nonnegative value"));
|
|
47
|
+
else if (labels.has(label)) duplicates.push({
|
|
48
|
+
label,
|
|
49
|
+
line
|
|
50
|
+
});
|
|
51
|
+
else {
|
|
52
|
+
labels.add(label);
|
|
53
|
+
rows.push({
|
|
54
|
+
category: label,
|
|
55
|
+
value: +m[2],
|
|
56
|
+
line
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
if (!rows.length) errors.push(issue(info, info.firstLine, "pie 至少需要一条数据", "Pie requires at least one section"));
|
|
61
|
+
if (duplicates.length) {
|
|
62
|
+
const names = [...new Set(duplicates.map((x) => x.label))].join(", ");
|
|
63
|
+
errors.push(warning("DIAGRAM_HINT", info.lang, duplicates[0].line, `pie 重复标签仅保留首次值:${names}`, `Pie keeps the first value for duplicate labels: ${names}`, "删除重复条目", "Remove duplicate sections"));
|
|
64
|
+
}
|
|
65
|
+
if (rows.length > 60) errors.push(warning("LARGE_DIAGRAM", info.lang, rows[60].line, "饼图条目较多,建议拆分图表", "Large pie chart; consider splitting it", "请拆分图表", "Split the chart"));
|
|
66
|
+
if (rows.length > 6) {
|
|
67
|
+
const overflow = rows.splice(5), value = overflow.reduce((sum, row) => sum + row.value, 0);
|
|
68
|
+
const names = overflow.map((row) => row.category).join(", ");
|
|
69
|
+
let category = `${/^en/i.test(info.lang) ? "Other" : "其他"} (${names})`;
|
|
70
|
+
while (labels.has(category)) category += "*";
|
|
71
|
+
if (!(value > 0)) errors.push(issue(info, overflow[0].line, "pie 合并项的总值必须大于零", "The combined pie section must have a positive total"));
|
|
72
|
+
rows.push({
|
|
73
|
+
category,
|
|
74
|
+
value,
|
|
75
|
+
line: overflow[0].line
|
|
76
|
+
});
|
|
77
|
+
errors.push(warning("DIAGRAM_HINT", info.lang, overflow[0].line, `pie 已将其余条目合并为其他:${names}`, `Pie combines remaining sections as Other: ${names}`, "如需分别展示,请拆分图表", "Split the chart to show these sections separately"));
|
|
78
|
+
}
|
|
79
|
+
const position = info.config?.pie?.textPosition;
|
|
80
|
+
const labelRadius = Number.isFinite(position) ? Math.max(.5, Math.min(.95, position)) : .72;
|
|
81
|
+
if (position !== void 0 && position !== labelRadius) errors.push(warning("IGNORED_CONFIG", info.lang, info.configLines?.["pie.textposition"] || header, `pie.textPosition 调整为 ${labelRadius}`, `pie.textPosition adjusted to ${labelRadius}`, "使用 0.5 至 0.95", "Use a value from 0.5 to 0.95"));
|
|
82
|
+
return {
|
|
83
|
+
model: {
|
|
84
|
+
chart: "pie",
|
|
85
|
+
title,
|
|
86
|
+
titleLine,
|
|
87
|
+
showData,
|
|
88
|
+
rows,
|
|
89
|
+
labelRadius
|
|
90
|
+
},
|
|
91
|
+
errors
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
function parseTreemap(source, info) {
|
|
95
|
+
const errors = [], roots = [], stack = [], levels = [], names = /* @__PURE__ */ new Map();
|
|
96
|
+
let nodeCount = 0;
|
|
97
|
+
const look = presentation({ lang: info.lang });
|
|
98
|
+
let title = null, titleLine = null;
|
|
99
|
+
for (const key of Object.keys(info.options || {})) errors.push(issue(info, info.headerLine, `treemap 不支持选项 ${key}`, `Unsupported treemap option ${key}`));
|
|
100
|
+
for (const { raw, text, line } of linesOf(source, info.firstLine)) {
|
|
101
|
+
if (look.accept(text, line)) continue;
|
|
102
|
+
if (/^title\s+/i.test(text)) {
|
|
103
|
+
if (title !== null) errors.push(issue(info, line, "treemap 只能有一个 title", "Treemap accepts only one title"));
|
|
104
|
+
else {
|
|
105
|
+
title = numericLabel(unquote(text.replace(/^title\s+/i, "")), info, line, errors);
|
|
106
|
+
titleLine = line;
|
|
107
|
+
}
|
|
108
|
+
continue;
|
|
109
|
+
}
|
|
110
|
+
const leading = raw.match(/^[ \t]*/)[0];
|
|
111
|
+
if (leading.includes(" ")) {
|
|
112
|
+
errors.push(error(info.lang, line, "treemap 缩进不能使用 Tab", "Treemap indentation cannot use tabs", "用空格缩进", "Indent with spaces", leading.indexOf(" ") + 1));
|
|
113
|
+
continue;
|
|
114
|
+
}
|
|
115
|
+
const suffix = /:::\s*([\w-]+)\s*$/.exec(text);
|
|
116
|
+
const statement = suffix ? text.slice(0, suffix.index).trimEnd() : text;
|
|
117
|
+
const match = /^("(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*'|[^:,]+?)(?:\s*[:,]\s*(.+))?$/.exec(statement);
|
|
118
|
+
const name = match && unquote(match[1].trim());
|
|
119
|
+
if (!name || /:::|[{}]/.test(name)) {
|
|
120
|
+
errors.push(issue(info, line, "treemap 节点名称无效", "Invalid treemap node name"));
|
|
121
|
+
continue;
|
|
122
|
+
}
|
|
123
|
+
nodeCount += 1;
|
|
124
|
+
if (nodeCount === 202) errors.push(issue(info, line, `treemap 超过安全上限 201 个节点`, `Treemap exceeds the safety cap of 201 nodes; split the diagram`));
|
|
125
|
+
const node = {
|
|
126
|
+
label: numericLabel(name, info, line, errors),
|
|
127
|
+
children: [],
|
|
128
|
+
line
|
|
129
|
+
};
|
|
130
|
+
if (suffix) look.addClasses(name, [suffix[1]], line);
|
|
131
|
+
names.set(node, name);
|
|
132
|
+
if (match[2] !== void 0) {
|
|
133
|
+
const value = match[2].replace(/[_,]/g, "");
|
|
134
|
+
if (!numeric(value) || Number(value) < 0 || match[2].includes(":::")) errors.push(issue(info, line, "treemap 权重必须是非负有限数", "Treemap weights must be finite and nonnegative"));
|
|
135
|
+
else node.value = Number(value);
|
|
136
|
+
}
|
|
137
|
+
const indent = leading.length;
|
|
138
|
+
while (stack.length && indent <= stack.at(-1).indent) stack.pop();
|
|
139
|
+
const depth = stack.length;
|
|
140
|
+
if (depth && levels[depth] !== void 0 && levels[depth] !== indent) errors.push(issue(info, line, "treemap 同级缩进不一致", "Treemap sibling indentation must match"));
|
|
141
|
+
levels[depth] ??= indent;
|
|
142
|
+
(depth ? stack.at(-1).node.children : roots).push(node);
|
|
143
|
+
stack.push({
|
|
144
|
+
indent,
|
|
145
|
+
node
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
if (!roots.length) errors.push(issue(info, info.firstLine, "treemap 需要至少一个根节点", "Treemap requires at least one root"));
|
|
149
|
+
const data = roots.length === 1 ? roots[0] : {
|
|
150
|
+
label: "Treemap",
|
|
151
|
+
children: roots,
|
|
152
|
+
line: info.firstLine
|
|
153
|
+
};
|
|
154
|
+
const treeLines = {};
|
|
155
|
+
let maxDepth = 0;
|
|
156
|
+
const clean = (node, path, depth) => {
|
|
157
|
+
maxDepth = Math.max(maxDepth, depth);
|
|
158
|
+
treeLines[path] = node.line;
|
|
159
|
+
if (depth > 100) {
|
|
160
|
+
errors.push(issue(info, node.line, `treemap 超过安全深度上限 100 层`, `Treemap exceeds the safety depth cap of 100; split the diagram`));
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
node.children.forEach((child, i) => clean(child, `${path}/children/${i}`, depth + 1));
|
|
164
|
+
if (node.children.length && node.value !== void 0) errors.push(issue(info, node.line, "有子项的 treemap 节点不能同时指定权重", "Treemap sections with children cannot have weights"));
|
|
165
|
+
if (!node.children.length && node.value === void 0) errors.push(issue(info, node.line, "treemap 叶节点必须指定权重", "Treemap leaves require a weight"));
|
|
166
|
+
delete node.line;
|
|
167
|
+
};
|
|
168
|
+
if (roots.length) clean(data, "/data", 1);
|
|
169
|
+
for (const [node, name] of names) node[compositionPresentation] = {
|
|
170
|
+
status: look.statusOf(name),
|
|
171
|
+
link: look.linkOf(name)
|
|
172
|
+
};
|
|
173
|
+
errors.push(...look.diagnostics());
|
|
174
|
+
const pattern = info.config?.treemap?.valueFormat;
|
|
175
|
+
let valueField;
|
|
176
|
+
if (pattern !== void 0 && pattern !== ",") {
|
|
177
|
+
const match = /^(\$)?(?:,)?(?:\.([0-6]))?(%|f)?$/.exec(typeof pattern === "string" ? pattern : "");
|
|
178
|
+
if (pattern === "$0,0") valueField = {
|
|
179
|
+
unit: "$",
|
|
180
|
+
decimals: 0
|
|
181
|
+
};
|
|
182
|
+
else if (match && pattern) valueField = {
|
|
183
|
+
...match[1] && match[3] !== "%" ? { unit: "$" } : {},
|
|
184
|
+
...match[2] ? { decimals: +match[2] } : {},
|
|
185
|
+
...match[3] === "%" ? { format: "percent" } : {}
|
|
186
|
+
};
|
|
187
|
+
else errors.push(warning("IGNORED_CONFIG", info.lang, info.configLines?.["treemap.valueformat"] || info.firstLine, `未识别 treemap.valueFormat ${pattern}`, `Unsupported treemap.valueFormat ${pattern}`, "使用默认数字格式", "Use the default number format"));
|
|
188
|
+
}
|
|
189
|
+
return {
|
|
190
|
+
model: {
|
|
191
|
+
chart: "treemap",
|
|
192
|
+
title,
|
|
193
|
+
titleLine,
|
|
194
|
+
treeLines,
|
|
195
|
+
data,
|
|
196
|
+
nodeCount,
|
|
197
|
+
depth: maxDepth,
|
|
198
|
+
namedRoot: roots.length === 1 && data.children.length > 0,
|
|
199
|
+
valueField,
|
|
200
|
+
prefix: valueField?.format === "percent" && pattern.startsWith("$") ? "$" : ""
|
|
201
|
+
},
|
|
202
|
+
errors
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
export { TREEMAP_MAX_DEPTH, TREEMAP_MAX_NODES, numeric_parse_exports, parsePie, parseTreemap };
|