@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,252 @@
|
|
|
1
|
+
import { __exportAll } from "../_virtual/_rolldown/runtime.js";
|
|
2
|
+
import { linkTargets, safeHref } from "../core/scene.js";
|
|
3
|
+
import { statusMarks } from "../core/theme.js";
|
|
4
|
+
import { error, warning } from "./support.js";
|
|
5
|
+
// src/diagram/presentation.js
|
|
6
|
+
var presentation_exports = /* @__PURE__ */ __exportAll({
|
|
7
|
+
parseProps: () => parseProps,
|
|
8
|
+
presentation: () => presentation,
|
|
9
|
+
roleOfColor: () => roleOfColor,
|
|
10
|
+
safeHref: () => safeHref
|
|
11
|
+
});
|
|
12
|
+
var named = new Map(`aliceblue:f0f8ff antiquewhite:faebd7 aqua:00ffff aquamarine:7fffd4 azure:f0ffff beige:f5f5dc bisque:ffe4c4 black:000000 blanchedalmond:ffebcd blue:0000ff blueviolet:8a2be2 brown:a52a2a burlywood:deb887 cadetblue:5f9ea0 chartreuse:7fff00 chocolate:d2691e coral:ff7f50 cornflowerblue:6495ed cornsilk:fff8dc crimson:dc143c cyan:00ffff darkblue:00008b darkcyan:008b8b darkgoldenrod:b8860b darkgray:a9a9a9 darkgreen:006400 darkgrey:a9a9a9 darkkhaki:bdb76b darkmagenta:8b008b darkolivegreen:556b2f darkorange:ff8c00 darkorchid:9932cc darkred:8b0000 darksalmon:e9967a darkseagreen:8fbc8f darkslateblue:483d8b darkslategray:2f4f4f darkslategrey:2f4f4f darkturquoise:00ced1 darkviolet:9400d3 deeppink:ff1493 deepskyblue:00bfff dimgray:696969 dimgrey:696969 dodgerblue:1e90ff firebrick:b22222 floralwhite:fffaf0 forestgreen:228b22 fuchsia:ff00ff gainsboro:dcdcdc ghostwhite:f8f8ff gold:ffd700 goldenrod:daa520 gray:808080 green:008000 greenyellow:adff2f grey:808080 honeydew:f0fff0 hotpink:ff69b4 indianred:cd5c5c indigo:4b0082 ivory:fffff0 khaki:f0e68c lavender:e6e6fa lavenderblush:fff0f5 lawngreen:7cfc00 lemonchiffon:fffacd
|
|
13
|
+
lightblue:add8e6 lightcoral:f08080 lightcyan:e0ffff lightgoldenrodyellow:fafad2 lightgray:d3d3d3 lightgreen:90ee90 lightgrey:d3d3d3 lightpink:ffb6c1 lightsalmon:ffa07a lightseagreen:20b2aa lightskyblue:87cefa lightslategray:778899 lightslategrey:778899 lightsteelblue:b0c4de lightyellow:ffffe0 lime:00ff00 limegreen:32cd32 linen:faf0e6 magenta:ff00ff maroon:800000 mediumaquamarine:66cdaa mediumblue:0000cd mediumorchid:ba55d3 mediumpurple:9370db mediumseagreen:3cb371 mediumslateblue:7b68ee mediumspringgreen:00fa9a mediumturquoise:48d1cc mediumvioletred:c71585 midnightblue:191970 mintcream:f5fffa mistyrose:ffe4e1 moccasin:ffe4b5 navajowhite:ffdead navy:000080 oldlace:fdf5e6 olive:808000 olivedrab:6b8e23 orange:ffa500 orangered:ff4500 orchid:da70d6 palegoldenrod:eee8aa palegreen:98fb98 paleturquoise:afeeee palevioletred:db7093 papayawhip:ffefd5 peachpuff:ffdab9 peru:cd853f pink:ffc0cb plum:dda0dd powderblue:b0e0e6 purple:800080 rebeccapurple:663399 red:ff0000 rosybrown:bc8f8f royalblue:4169e1 saddlebrown:8b4513 salmon:fa8072 sandybrown:f4a460 seagreen:2e8b57 seashell:fff5ee sienna:a0522d silver:c0c0c0 skyblue:87ceeb slateblue:6a5acd slategray:708090 slategrey:708090 snow:fffafa springgreen:00ff7f steelblue:4682b4 tan:d2b48c teal:008080 thistle:d8bfd8 tomato:ff6347 turquoise:40e0d0 violet:ee82ee wheat:f5deb3 white:ffffff whitesmoke:f5f5f5 yellow:ffff00 yellowgreen:9acd32`.split(/\s+/).map((pair) => pair.split(":")));
|
|
14
|
+
var clamp = (n) => Math.max(0, Math.min(1, n));
|
|
15
|
+
var number = /^([+-]?(?:\d*\.\d+|\d+)(?:e[+-]?\d+)?)(%|deg|rad|grad|turn)?$/;
|
|
16
|
+
var hue = (n) => (n % 360 + 360) % 360;
|
|
17
|
+
function rgba(css) {
|
|
18
|
+
if (typeof css !== "string") return null;
|
|
19
|
+
css = css.trim().toLowerCase();
|
|
20
|
+
let hex = named.get(css) ?? /^#([\da-f]{3,4}|[\da-f]{6}|[\da-f]{8})$/.exec(css)?.[1];
|
|
21
|
+
if (hex) {
|
|
22
|
+
if (hex.length <= 4) hex = [...hex].map((c) => c + c).join("");
|
|
23
|
+
return hex.match(/../g).map((c) => parseInt(c, 16) / 255);
|
|
24
|
+
}
|
|
25
|
+
const match = /^(rgb|hsl)a?\(([^()]*)\)$/.exec(css);
|
|
26
|
+
if (!match) return null;
|
|
27
|
+
const body = match[2].trim();
|
|
28
|
+
const legacy = body.includes(",");
|
|
29
|
+
const [channels, alpha, extra] = body.split(/\s*\/\s*/);
|
|
30
|
+
const values = legacy ? body.split(/\s*,\s*/) : channels.split(/\s+/);
|
|
31
|
+
if (legacy ? values.length < 3 || values.length > 4 : values.length !== 3 || extra !== void 0) return null;
|
|
32
|
+
if (!legacy && alpha !== void 0) values.push(alpha);
|
|
33
|
+
const tokens = values.map((v) => number.exec(v));
|
|
34
|
+
if (tokens.some((t) => !t || !Number.isFinite(Number(t[1])))) return null;
|
|
35
|
+
const [[, x, u], [, y, v], [, z, w], [, a = 1, au] = []] = tokens;
|
|
36
|
+
if (au && au !== "%") return null;
|
|
37
|
+
const opacity = clamp(Number(a) / (au ? 100 : 1));
|
|
38
|
+
if (match[1] === "rgb") {
|
|
39
|
+
if ([
|
|
40
|
+
u,
|
|
41
|
+
v,
|
|
42
|
+
w
|
|
43
|
+
].some((unit) => unit && unit !== "%") || legacy && (u !== v || v !== w)) return null;
|
|
44
|
+
return [
|
|
45
|
+
clamp(x / (u ? 100 : 255)),
|
|
46
|
+
clamp(y / (v ? 100 : 255)),
|
|
47
|
+
clamp(z / (w ? 100 : 255)),
|
|
48
|
+
opacity
|
|
49
|
+
];
|
|
50
|
+
}
|
|
51
|
+
if (u === "%" || v !== "%" || w !== "%") return null;
|
|
52
|
+
const h = hue(x * ({
|
|
53
|
+
turn: 360,
|
|
54
|
+
rad: 180 / Math.PI,
|
|
55
|
+
grad: .9,
|
|
56
|
+
deg: 1
|
|
57
|
+
}[u] ?? 1)) / 30;
|
|
58
|
+
const s = clamp(y / 100), l = clamp(z / 100), c = s * Math.min(l, 1 - l);
|
|
59
|
+
return [...[
|
|
60
|
+
0,
|
|
61
|
+
8,
|
|
62
|
+
4
|
|
63
|
+
].map((n) => {
|
|
64
|
+
const k = (n + h) % 12;
|
|
65
|
+
return l - c * Math.max(-1, Math.min(k - 3, 9 - k, 1));
|
|
66
|
+
}), opacity];
|
|
67
|
+
}
|
|
68
|
+
function roleOfColor(css) {
|
|
69
|
+
const channels = rgba(css);
|
|
70
|
+
if (!channels || (channels[3] ?? 1) < .2) return null;
|
|
71
|
+
const [r, g, b] = channels.slice(0, 3).map((c) => c <= .04045 ? c / 12.92 : ((c + .055) / 1.055) ** 2.4);
|
|
72
|
+
const l = Math.cbrt(.4122214708 * r + .5363325363 * g + .0514459929 * b);
|
|
73
|
+
const m = Math.cbrt(.2119034982 * r + .6806995451 * g + .1073969566 * b);
|
|
74
|
+
const s = Math.cbrt(.0883024619 * r + .2817188376 * g + .6299787005 * b);
|
|
75
|
+
const a = 1.9779984951 * l - 2.428592205 * m + .4505937099 * s;
|
|
76
|
+
const bb = .0259040371 * l + .7827717662 * m - .808675766 * s;
|
|
77
|
+
if (!Number.isFinite(a + bb) || Math.hypot(a, bb) < .035) return null;
|
|
78
|
+
const h = hue(Math.atan2(bb, a) * 180 / Math.PI);
|
|
79
|
+
return h < 45 || h >= 345 ? "danger" : h < 115 ? "warn" : h < 200 ? "ok" : h < 290 ? "info" : "new";
|
|
80
|
+
}
|
|
81
|
+
function declarations(source) {
|
|
82
|
+
const entries = [];
|
|
83
|
+
let quote = "", depth = 0, start = 0, malformed = false;
|
|
84
|
+
const add = (end) => {
|
|
85
|
+
const part = source.slice(start, end).trim();
|
|
86
|
+
start = end + 1;
|
|
87
|
+
if (!part) return;
|
|
88
|
+
const pair = /^([\w-]+)\s*:\s*(\S[\s\S]*)$/.exec(part);
|
|
89
|
+
if (!pair) malformed = true;
|
|
90
|
+
else entries.push([pair[1].toLowerCase(), pair[2].replace(/\\([,;])/g, "$1")]);
|
|
91
|
+
};
|
|
92
|
+
for (let i = 0; i < source.length; i++) {
|
|
93
|
+
const c = source[i];
|
|
94
|
+
if (c === "\\") i++;
|
|
95
|
+
else if (quote) {
|
|
96
|
+
if (c === quote) quote = "";
|
|
97
|
+
} else if (c === "\"" || c === "'") quote = c;
|
|
98
|
+
else if (c === "(") depth++;
|
|
99
|
+
else if (c === ")") {
|
|
100
|
+
if (depth) depth--;
|
|
101
|
+
else malformed = true;
|
|
102
|
+
} else if (!depth && (c === "," || c === ";")) {
|
|
103
|
+
if (c === "," && /^\s*stroke-dasharray\s*:/i.test(source.slice(start, i)) && /^\s*[+-]?(?:\d|\.\d)/.test(source.slice(i + 1))) continue;
|
|
104
|
+
add(i);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
add(source.length);
|
|
108
|
+
return {
|
|
109
|
+
props: Object.fromEntries(entries),
|
|
110
|
+
entries,
|
|
111
|
+
malformed: malformed || !!quote || !!depth || !entries.length
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
function parseProps(source) {
|
|
115
|
+
return declarations(source).props;
|
|
116
|
+
}
|
|
117
|
+
var nodeColors = [
|
|
118
|
+
"fill",
|
|
119
|
+
"background",
|
|
120
|
+
"stroke",
|
|
121
|
+
"border-color"
|
|
122
|
+
];
|
|
123
|
+
var edgeColors = [
|
|
124
|
+
"stroke",
|
|
125
|
+
"fill",
|
|
126
|
+
"background",
|
|
127
|
+
"border-color"
|
|
128
|
+
];
|
|
129
|
+
var statuses = new Set(Object.keys(statusMarks));
|
|
130
|
+
var words = /"(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*'|[^\s"']+/gy;
|
|
131
|
+
var quoted = /^(?:"|')/;
|
|
132
|
+
var unquote = (word) => quoted.test(word) ? word.slice(1, -1).replace(/\\(["'])/g, "$1") : word;
|
|
133
|
+
var list = (value) => value.split(",").map((s) => s.trim());
|
|
134
|
+
var listHead = /^("[^"\n]+"|'[^'\n]+'|[^\s,"']+(?:\s*,\s*[^\s,"']+)*)\s+(.+)$/s;
|
|
135
|
+
function tokenize(source) {
|
|
136
|
+
const tokens = [];
|
|
137
|
+
for (let start = 0; start < source.length;) {
|
|
138
|
+
words.lastIndex = start;
|
|
139
|
+
const word = words.exec(source)?.[0];
|
|
140
|
+
if (!word) return null;
|
|
141
|
+
tokens.push(word);
|
|
142
|
+
start += word.length;
|
|
143
|
+
if (start < source.length && !/\s/.test(source[start])) return null;
|
|
144
|
+
while (start < source.length && /\s/.test(source[start])) start++;
|
|
145
|
+
}
|
|
146
|
+
return tokens;
|
|
147
|
+
}
|
|
148
|
+
function presentation({ lang, classKeyword = "class" } = {}) {
|
|
149
|
+
const defs = /* @__PURE__ */ new Map(), classes = /* @__PURE__ */ new Map(), styles = /* @__PURE__ */ new Map(), edges = /* @__PURE__ */ new Map(), links = /* @__PURE__ */ new Map();
|
|
150
|
+
const issues = [], ignoredStyles = /* @__PURE__ */ new Map(), interactions = /* @__PURE__ */ new Set();
|
|
151
|
+
const addClasses = (id, names, _line) => {
|
|
152
|
+
if (!classes.has(id)) classes.set(id, []);
|
|
153
|
+
classes.get(id).push(...names);
|
|
154
|
+
};
|
|
155
|
+
function accept(text, line) {
|
|
156
|
+
const source = text.trim().replace(/;$/, "").trimEnd();
|
|
157
|
+
const [, keyword, body = ""] = /^(\S+)(?:\s+(.*))?$/s.exec(source) ?? [];
|
|
158
|
+
const kind = keyword?.toLowerCase();
|
|
159
|
+
if (![
|
|
160
|
+
classKeyword.toLowerCase(),
|
|
161
|
+
"classdef",
|
|
162
|
+
"style",
|
|
163
|
+
"linkstyle",
|
|
164
|
+
"click",
|
|
165
|
+
"href",
|
|
166
|
+
"link",
|
|
167
|
+
"callback"
|
|
168
|
+
].includes(kind)) return false;
|
|
169
|
+
const malformed = () => issues.push({
|
|
170
|
+
...error(lang, line, `无效的 ${keyword} 语句`, `Malformed ${keyword} statement`, "检查标识符和参数", "Check identifiers and arguments"),
|
|
171
|
+
severity: "error"
|
|
172
|
+
});
|
|
173
|
+
const ignoreInteraction = (subject, zh, en) => {
|
|
174
|
+
if (interactions.has(subject)) return;
|
|
175
|
+
interactions.add(subject);
|
|
176
|
+
issues.push(warning("IGNORED_INTERACTION", lang, line, zh, en, "改用安全链接,不使用回调", "Use a safe URL instead of a callback or unsupported link"));
|
|
177
|
+
};
|
|
178
|
+
const head = listHead.exec(body);
|
|
179
|
+
const ids = head ? list(unquote(head[1])) : [];
|
|
180
|
+
if (kind === classKeyword.toLowerCase()) {
|
|
181
|
+
const names = head ? list(unquote(head[2])) : [];
|
|
182
|
+
if (!ids.length || ids.some((id) => !id) || names.some((name) => !/^[^\s,"']+$/.test(name))) malformed();
|
|
183
|
+
else for (const id of ids) addClasses(id, names, line);
|
|
184
|
+
} else if (kind === "style" || kind === "classdef" || kind === "linkstyle") {
|
|
185
|
+
if (!ids.length || ids.some((id) => !id) || kind === "style" && ids.length !== 1 || kind === "linkstyle" && !(ids.length === 1 && ids[0] === "default") && !ids.every((id) => /^\d+$/.test(id) && Number.isSafeInteger(Number(id)))) malformed();
|
|
186
|
+
else {
|
|
187
|
+
const { props, entries, malformed: invalid } = declarations(head[2]);
|
|
188
|
+
if (invalid) malformed();
|
|
189
|
+
else {
|
|
190
|
+
const colors = kind === "linkstyle" ? edgeColors : nodeColors;
|
|
191
|
+
for (const [key, value] of entries) if (!colors.includes(key) || !roleOfColor(value)) {
|
|
192
|
+
const subject = colors.includes(key) ? `${key}: ${value}` : key;
|
|
193
|
+
if (!ignoredStyles.has(subject)) ignoredStyles.set(subject, line);
|
|
194
|
+
}
|
|
195
|
+
const role = colors.map((key) => roleOfColor(props[key])).find(Boolean) ?? null;
|
|
196
|
+
const store = kind === "classdef" ? defs : kind === "style" ? styles : edges;
|
|
197
|
+
for (const id of ids) store.set(kind === "linkstyle" && id !== "default" ? Number(id) : id, role);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
} else {
|
|
201
|
+
const call = kind === "click" && /^(?:"[^"]+"|'[^']+'|\S+)\s+call\s+([\w.$]+)\s*\([\s\S]*\)(?:\s+"(?:\\.|[^"\\])*")?$/.exec(body);
|
|
202
|
+
if (call) ignoreInteraction(`callback:${call[1]}`, `已忽略回调 ${call[1]}`, `Ignored callback ${call[1]}`);
|
|
203
|
+
else {
|
|
204
|
+
const [id, arg, ...tail] = tokenize(body) ?? [];
|
|
205
|
+
const explicit = kind === "click" && arg === "href";
|
|
206
|
+
const url = explicit ? tail.shift() : arg;
|
|
207
|
+
const tooltip = quoted.test(tail[0] ?? "") ? unquote(tail.shift()) : void 0;
|
|
208
|
+
const target = tail.shift();
|
|
209
|
+
if (!id || !unquote(id) || !url || kind === "click" && arg === "call" || tail.length) malformed();
|
|
210
|
+
else if (kind === "callback" || kind === "click" && !explicit && /^[\w$]+(?:\.[\w$]+)*$/.test(url)) {
|
|
211
|
+
if (target !== void 0) malformed();
|
|
212
|
+
else ignoreInteraction(`callback:${unquote(url)}`, `已忽略回调 ${unquote(url)}`, `Ignored callback ${unquote(url)}`);
|
|
213
|
+
} else {
|
|
214
|
+
const href = safeHref(unquote(url));
|
|
215
|
+
if (!href || target !== void 0 && !linkTargets.has(target)) ignoreInteraction(`link:${!href ? unquote(url) : target}`, "已忽略不安全的链接或不支持的目标", "Ignored unsafe URL or unsupported target");
|
|
216
|
+
else links.set(unquote(id), {
|
|
217
|
+
href,
|
|
218
|
+
...tooltip === void 0 ? {} : { tooltip },
|
|
219
|
+
...target === void 0 ? {} : { target }
|
|
220
|
+
});
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
return true;
|
|
225
|
+
}
|
|
226
|
+
function statusOf(id) {
|
|
227
|
+
if (styles.get(id)) return styles.get(id);
|
|
228
|
+
const applied = classes.get(id) ?? [];
|
|
229
|
+
for (let i = applied.length - 1; i >= 0; i--) {
|
|
230
|
+
const name = applied[i], status = statuses.has(name) ? name : defs.get(name);
|
|
231
|
+
if (status) return status;
|
|
232
|
+
}
|
|
233
|
+
return defs.get("default") ?? null;
|
|
234
|
+
}
|
|
235
|
+
function diagnostics() {
|
|
236
|
+
const result = [...issues];
|
|
237
|
+
if (ignoredStyles.size) {
|
|
238
|
+
const subjects = [...ignoredStyles.keys()].join(", ");
|
|
239
|
+
result.push(warning("IGNORED_STYLE", lang, ignoredStyles.values().next().value, `已忽略部分样式:${subjects}`, `Ignored styles: ${subjects}`, "用状态类或有彩度的颜色", "Use status classes or chromatic colors"));
|
|
240
|
+
}
|
|
241
|
+
return result.sort((a, b) => a.line - b.line);
|
|
242
|
+
}
|
|
243
|
+
return {
|
|
244
|
+
accept,
|
|
245
|
+
addClasses,
|
|
246
|
+
statusOf,
|
|
247
|
+
edgeStatusOf: (index) => edges.get(index) ?? edges.get("default") ?? null,
|
|
248
|
+
linkOf: (id) => links.get(id) ?? null,
|
|
249
|
+
diagnostics
|
|
250
|
+
};
|
|
251
|
+
}
|
|
252
|
+
export { parseProps, presentation, presentation_exports, roleOfColor, safeHref };
|
|
@@ -0,0 +1,297 @@
|
|
|
1
|
+
import { __exportAll } from "../_virtual/_rolldown/runtime.js";
|
|
2
|
+
import { normalizeLabel } from "./label.js";
|
|
3
|
+
import { presentation, roleOfColor } from "./presentation.js";
|
|
4
|
+
import { FONT, appearance, error, warning } from "./support.js";
|
|
5
|
+
// src/diagram/quadrant.js
|
|
6
|
+
var quadrant_exports = /* @__PURE__ */ __exportAll({ implementations: () => implementations });
|
|
7
|
+
var honoredConfig = [
|
|
8
|
+
"chartWidth",
|
|
9
|
+
"chartHeight",
|
|
10
|
+
"pointRadius",
|
|
11
|
+
"pointLabelFontSize",
|
|
12
|
+
"xAxisPosition",
|
|
13
|
+
"yAxisPosition",
|
|
14
|
+
"quadrantPadding",
|
|
15
|
+
"xAxisLabelPadding",
|
|
16
|
+
"yAxisLabelPadding",
|
|
17
|
+
"quadrantTextTopPadding",
|
|
18
|
+
"pointTextPadding"
|
|
19
|
+
].map((key) => `quadrantChart.${key}`);
|
|
20
|
+
function parse(body, { lang, title = "", firstLine = 2, config, options = {} }) {
|
|
21
|
+
const points = [], captions = [], axes = {}, errors = [], ignored = /* @__PURE__ */ new Set(), classes = /* @__PURE__ */ new Map(), assets = /* @__PURE__ */ new Set();
|
|
22
|
+
const look = presentation({ lang });
|
|
23
|
+
const clean = (s, line) => {
|
|
24
|
+
const { text, icon, diagnostics } = normalizeLabel(s.trim().replace(/^"(.*)"$/, "$1"), {
|
|
25
|
+
lang,
|
|
26
|
+
line
|
|
27
|
+
});
|
|
28
|
+
if (icon) diagnostics.push(warning("IGNORED_ASSET", lang, line, "象限图标签仅显示文本", "Quadrant labels display text only"));
|
|
29
|
+
for (const d of diagnostics) if (!assets.has(d.message)) {
|
|
30
|
+
assets.add(d.message);
|
|
31
|
+
errors.push(d);
|
|
32
|
+
}
|
|
33
|
+
return text.replace(/\n/g, " ");
|
|
34
|
+
};
|
|
35
|
+
const fail = (line, zh, en) => errors.push(error(lang, line, zh, en, "修正坐标或图表声明", "Fix the coordinates or chart declaration"));
|
|
36
|
+
if (Object.keys(options).length) fail(firstLine - 1, "象限图不接受标题行选项", "Unexpected quadrantChart header option");
|
|
37
|
+
let ignoredLine, bareLine;
|
|
38
|
+
const pointStyle = (source, line) => {
|
|
39
|
+
const style = {};
|
|
40
|
+
for (const part of source ? source.split(/,(?![^()]*\))/) : []) {
|
|
41
|
+
const m = /^(radius|color|stroke-color|stroke-width)\s*:\s*(.+)$/i.exec(part.trim());
|
|
42
|
+
if (!m) {
|
|
43
|
+
fail(line, "无效的点样式", "Invalid point style");
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
46
|
+
const key = m[1].toLowerCase(), val = m[2];
|
|
47
|
+
if (key.endsWith("color")) {
|
|
48
|
+
const role = roleOfColor(val);
|
|
49
|
+
if (role) style[key] = role;
|
|
50
|
+
else {
|
|
51
|
+
ignoredLine ??= line;
|
|
52
|
+
ignored.add(`${key}: ${val}`);
|
|
53
|
+
}
|
|
54
|
+
} else {
|
|
55
|
+
const n = Number(val.replace(/px$/i, ""));
|
|
56
|
+
if (!Number.isFinite(n)) {
|
|
57
|
+
fail(line, "点样式需要数值", "Expected a numeric point style");
|
|
58
|
+
continue;
|
|
59
|
+
}
|
|
60
|
+
style[key] = key === "radius" ? Math.min(12, Math.max(3, n)) : Math.min(3, Math.max(0, n));
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return style;
|
|
64
|
+
};
|
|
65
|
+
for (const [i, raw] of body.split("\n").entries()) {
|
|
66
|
+
const line = firstLine + i, s = raw.trim();
|
|
67
|
+
if (!s || s.startsWith("%%")) continue;
|
|
68
|
+
const definition = /^classDef\s+(\w+)\s+((?:radius|color|stroke-color|stroke-width)\s*:.*)$/i.exec(s);
|
|
69
|
+
if (definition) {
|
|
70
|
+
classes.set(definition[1], pointStyle(definition[2], line));
|
|
71
|
+
continue;
|
|
72
|
+
}
|
|
73
|
+
if (look.accept(s, line)) continue;
|
|
74
|
+
const heading = /^title(?:\s*:\s*|\s+)(.+)/i.exec(s);
|
|
75
|
+
if (heading) {
|
|
76
|
+
title = clean(heading[1], line);
|
|
77
|
+
continue;
|
|
78
|
+
}
|
|
79
|
+
const axis = /^([xy])-axis\s+(.+)/i.exec(s);
|
|
80
|
+
if (axis) {
|
|
81
|
+
const arrow = [...axis[2].matchAll(/"[^"]*"|--+>/g)].find(([part]) => part.startsWith("-"));
|
|
82
|
+
const pieces = arrow ? [axis[2].slice(0, arrow.index), axis[2].slice(arrow.index + arrow[0].length)] : [axis[2]];
|
|
83
|
+
axes[axis[1].toLowerCase()] = pieces.map((piece) => clean(piece, line));
|
|
84
|
+
if (pieces.length === 1) axes[axis[1].toLowerCase()][0] += " ⟶";
|
|
85
|
+
continue;
|
|
86
|
+
}
|
|
87
|
+
const caption = /^quadrant-([1-4])\s+(.+)/i.exec(s);
|
|
88
|
+
if (caption) {
|
|
89
|
+
captions[Number(caption[1]) - 1] = clean(caption[2], line);
|
|
90
|
+
continue;
|
|
91
|
+
}
|
|
92
|
+
const point = /^("[^"]*"|[^:]+?)(?:::\:(\w+))?\s*:\s*(\[)?\s*(\d*\.?\d+)\s*,\s*(\d*\.?\d+)\s*(\])?\s*(.*)$/.exec(s);
|
|
93
|
+
if (!point || Boolean(point[3]) !== Boolean(point[6]) || !point[3] && point[7] || Number(point[4]) > 1 || Number(point[5]) > 1) {
|
|
94
|
+
fail(line, "坐标必须在 0 到 1 之间", "Expected a point with coordinates in [0, 1]");
|
|
95
|
+
continue;
|
|
96
|
+
}
|
|
97
|
+
if (points.length === 2e3) {
|
|
98
|
+
fail(line, "点超过 2000 个,请拆分图表", "More than 2000 points; split the diagram");
|
|
99
|
+
break;
|
|
100
|
+
}
|
|
101
|
+
if (!point[3]) bareLine ??= line;
|
|
102
|
+
const id = point[1].trim().replace(/^"(.*)"$/, "$1"), className = point[2];
|
|
103
|
+
if (className) look.addClasses(id, [className], line);
|
|
104
|
+
points.push({
|
|
105
|
+
id,
|
|
106
|
+
className,
|
|
107
|
+
text: clean(point[1], line),
|
|
108
|
+
x: Number(point[4]),
|
|
109
|
+
y: Number(point[5]),
|
|
110
|
+
style: pointStyle(point[7], line)
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
for (const point of points) {
|
|
114
|
+
point.style = {
|
|
115
|
+
color: look.statusOf(point.id),
|
|
116
|
+
...classes.get(point.className),
|
|
117
|
+
...point.style
|
|
118
|
+
};
|
|
119
|
+
point.link = look.linkOf(point.id);
|
|
120
|
+
}
|
|
121
|
+
errors.push(...look.diagnostics());
|
|
122
|
+
if (bareLine) errors.push(warning("DIAGRAM_HINT", lang, bareLine, "点坐标缺少方括号,Mermaid 不接受这种旧写法", "Mermaid rejects point coordinates without brackets", "写成「名称: [x, y]」", "Write the point as Name: [x, y]"));
|
|
123
|
+
if (ignored.size) {
|
|
124
|
+
const styles = [...ignored].join(", ");
|
|
125
|
+
errors.push(warning("IGNORED_STYLE", lang, ignoredLine, `已忽略无法匹配主题的点颜色:${styles}`, `Ignored unmappable point colors: ${styles}`, "使用可映射为主题状态的颜色", "Use colors that map to theme statuses"));
|
|
126
|
+
}
|
|
127
|
+
return {
|
|
128
|
+
model: {
|
|
129
|
+
type: "quadrantChart",
|
|
130
|
+
title,
|
|
131
|
+
axes,
|
|
132
|
+
captions,
|
|
133
|
+
points,
|
|
134
|
+
config: config?.quadrantChart || {}
|
|
135
|
+
},
|
|
136
|
+
errors
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
function layout(model, { ctx, width, renderOptions }, info = {}) {
|
|
140
|
+
const { title, captions, axes, points, config } = model, t = appearance(ctx);
|
|
141
|
+
const dimension = (key, fallback, min, max) => Number.isFinite(config[key]) ? Math.min(max, Math.max(min, config[key])) : fallback;
|
|
142
|
+
const size = dimension("pointLabelFontSize", 12, 12, 24);
|
|
143
|
+
const r = dimension("pointRadius", 5, 3, 12);
|
|
144
|
+
const titleInline = title && !renderOptions?.frame;
|
|
145
|
+
const xTop = config.xAxisPosition ? config.xAxisPosition === "top" : !points.length;
|
|
146
|
+
const yRight = config.yAxisPosition === "right";
|
|
147
|
+
const centered = {
|
|
148
|
+
anchor: "middle",
|
|
149
|
+
"dominant-baseline": "central"
|
|
150
|
+
};
|
|
151
|
+
const W = (s, font = FONT.label) => ctx.measure(s || "", font.size, font.weight);
|
|
152
|
+
const spanOf = (values) => (values || []).reduce((sum, text) => sum + W(text), 36);
|
|
153
|
+
const pad = 18 + dimension("quadrantPadding", 5, 0, 48);
|
|
154
|
+
const dotClearance = Math.max(5, ...points.map((p) => (p.style.radius ?? r) + (p.style["stroke-width"] ?? 1) / 2));
|
|
155
|
+
const xGap = dotClearance + 6 + dimension("xAxisLabelPadding", 5, 5, 48);
|
|
156
|
+
const yGap = dotClearance + 6 + dimension("yAxisLabelPadding", 5, 5, 48);
|
|
157
|
+
const xRoom = xGap + 10, yRoom = yGap + 10;
|
|
158
|
+
const top = pad + (titleInline ? 32 : 0) + (xTop && axes.x ? xRoom : 0);
|
|
159
|
+
const left = pad + (!yRight && axes.y ? yRoom : 0);
|
|
160
|
+
const right = pad + (yRight && axes.y ? yRoom : 0);
|
|
161
|
+
const span = Math.max(Math.min(520, width - left - right), 360, dimension("chartWidth", 0, 0, 4e3), spanOf(axes.x), ...captions.map((s) => 2 * W(s, FONT.title) + 44).filter(Number.isFinite));
|
|
162
|
+
const h = Math.max(340, spanOf(axes.y), dimension("chartHeight", 0, 0, 4e3));
|
|
163
|
+
const w = left + span + right, bottom = top + h;
|
|
164
|
+
const children = [], occupied = [];
|
|
165
|
+
const pushText = (x, y, value, font = FONT.label, fill = t.fg1, attrs = {}) => {
|
|
166
|
+
if (value) children.push(ctx.text(x, y, value, {
|
|
167
|
+
...font,
|
|
168
|
+
...centered,
|
|
169
|
+
fill,
|
|
170
|
+
...attrs
|
|
171
|
+
}));
|
|
172
|
+
};
|
|
173
|
+
if (titleInline) pushText(w / 2, 26, title, FONT.title);
|
|
174
|
+
children.push(ctx.rect(left, top, span, h, {
|
|
175
|
+
stroke: t.line,
|
|
176
|
+
fill: t.bg,
|
|
177
|
+
meta: {
|
|
178
|
+
kind: "frame",
|
|
179
|
+
id: "quadrants"
|
|
180
|
+
}
|
|
181
|
+
}));
|
|
182
|
+
for (let i = 0; i < 4; i++) {
|
|
183
|
+
const dx = i === 0 || i === 3 ? span / 2 : 0, dy = i >= 2 ? h / 2 : 0;
|
|
184
|
+
const x = left + dx, y = top + dy;
|
|
185
|
+
children.push(ctx.rect(x, y, span / 2, h / 2, {
|
|
186
|
+
fill: ctx.tint(t.bg, ctx.color(`tone${i + 1}`), .08),
|
|
187
|
+
stroke: t.line
|
|
188
|
+
}));
|
|
189
|
+
}
|
|
190
|
+
const dots = points.map((p) => ({
|
|
191
|
+
...p,
|
|
192
|
+
cx: left + p.x * span,
|
|
193
|
+
cy: bottom - p.y * h,
|
|
194
|
+
r: p.style.radius ?? r
|
|
195
|
+
}));
|
|
196
|
+
const box = (x, y, hw, hh) => ({
|
|
197
|
+
x0: x - hw,
|
|
198
|
+
x1: x + hw,
|
|
199
|
+
y0: y - hh,
|
|
200
|
+
y1: y + hh
|
|
201
|
+
});
|
|
202
|
+
const free = (b) => occupied.every((a) => a.x1 + 3 <= b.x0 || a.x0 - 3 >= b.x1 || a.y1 + 3 <= b.y0 || a.y0 - 3 >= b.y1);
|
|
203
|
+
dots.forEach((p) => occupied.push(box(p.cx, p.cy, p.r + 2, p.r + 2)));
|
|
204
|
+
captions.forEach((s, i) => {
|
|
205
|
+
const x = left + (i === 0 || i === 3 ? .75 : .25) * span;
|
|
206
|
+
const start = top + (i >= 2 ? h / 2 : 0), hw = W(s, FONT.title) / 2;
|
|
207
|
+
let y = start + (dots.length ? 15 + dimension("quadrantTextTopPadding", 5, 3, 50) : h / 4);
|
|
208
|
+
while (!free(box(x, y, hw, 7))) y += 18;
|
|
209
|
+
pushText(x, y, s, FONT.title, t.fg2);
|
|
210
|
+
occupied.push(box(x, y, hw, 7));
|
|
211
|
+
});
|
|
212
|
+
if (axes.x) {
|
|
213
|
+
const y = xTop ? top - xGap : bottom + xGap;
|
|
214
|
+
pushText(left, y, axes.x[0], FONT.label, t.fg2, { anchor: "start" });
|
|
215
|
+
pushText(left + span, y, axes.x[1], FONT.label, t.fg2, { anchor: "end" });
|
|
216
|
+
}
|
|
217
|
+
if (axes.y) {
|
|
218
|
+
const x = yRight ? left + span + yGap : left - yGap;
|
|
219
|
+
[[
|
|
220
|
+
axes.y[0],
|
|
221
|
+
bottom,
|
|
222
|
+
"start"
|
|
223
|
+
], [
|
|
224
|
+
axes.y[1],
|
|
225
|
+
top,
|
|
226
|
+
"end"
|
|
227
|
+
]].forEach(([text, y, anchor]) => {
|
|
228
|
+
pushText(x, y, text, FONT.label, t.fg2, {
|
|
229
|
+
anchor,
|
|
230
|
+
transform: `rotate(-90 ${x} ${y})`
|
|
231
|
+
});
|
|
232
|
+
});
|
|
233
|
+
}
|
|
234
|
+
const overflow = [];
|
|
235
|
+
dots.forEach((p, i) => {
|
|
236
|
+
const dot = ctx.circle(p.cx, p.cy, p.r, {
|
|
237
|
+
fill: t[p.style.color] || t.accent,
|
|
238
|
+
stroke: t[p.style["stroke-color"]] || t.bg,
|
|
239
|
+
"stroke-width": p.style["stroke-width"] ?? 1,
|
|
240
|
+
meta: {
|
|
241
|
+
kind: "node",
|
|
242
|
+
id: i
|
|
243
|
+
}
|
|
244
|
+
});
|
|
245
|
+
children.push(p.link ? ctx.link(p.link.href, [dot], p.link) : dot);
|
|
246
|
+
const font = {
|
|
247
|
+
...FONT.label,
|
|
248
|
+
size
|
|
249
|
+
}, hw = W(p.text, font) / 2;
|
|
250
|
+
const cx = Math.min(left + span - hw, Math.max(left + hw, p.cx)), offset = p.r + size / 2 + dimension("pointTextPadding", 5, 5, 40);
|
|
251
|
+
const placement = [
|
|
252
|
+
[cx, p.cy + offset],
|
|
253
|
+
[cx, p.cy - offset],
|
|
254
|
+
[p.cx + offset + hw, p.cy],
|
|
255
|
+
[p.cx - offset - hw, p.cy]
|
|
256
|
+
].find(([x, y]) => x - hw >= left && x + hw <= left + span && y - size / 2 >= top && y + size / 2 <= bottom && free(box(x, y, hw, size / 2)));
|
|
257
|
+
if (placement) {
|
|
258
|
+
pushText(...placement, p.text, font, t.fg1, { meta: { kind: "edge-label" } });
|
|
259
|
+
occupied.push(box(...placement, hw, size / 2));
|
|
260
|
+
} else overflow.push({
|
|
261
|
+
text: `${p.text} (${p.x}, ${p.y})`,
|
|
262
|
+
x: p.cx
|
|
263
|
+
});
|
|
264
|
+
});
|
|
265
|
+
const lanes = ctx.labelLanes(ctx, overflow, {
|
|
266
|
+
left,
|
|
267
|
+
right: left + span,
|
|
268
|
+
maxWidth: 180
|
|
269
|
+
});
|
|
270
|
+
const start = bottom + (!xTop && axes.x ? xRoom : 0) + pad;
|
|
271
|
+
for (const item of lanes.items) children.push(ctx.textLines(item.cx, start + 10 + item.offset, item.lines, {
|
|
272
|
+
...FONT.label,
|
|
273
|
+
...centered,
|
|
274
|
+
fill: t.fg1
|
|
275
|
+
}));
|
|
276
|
+
const height = start + lanes.height;
|
|
277
|
+
const errors = w > width * 2 || points.length > 60 ? [warning("LARGE_DIAGRAM", ctx.lang, info.headerLine || 1, "象限图较大", "Large quadrant chart", "考虑拆分图表", "Consider splitting the diagram")] : [];
|
|
278
|
+
return {
|
|
279
|
+
width: w,
|
|
280
|
+
height,
|
|
281
|
+
scene: {
|
|
282
|
+
width: w,
|
|
283
|
+
height,
|
|
284
|
+
children,
|
|
285
|
+
title,
|
|
286
|
+
heading: title
|
|
287
|
+
},
|
|
288
|
+
errors
|
|
289
|
+
};
|
|
290
|
+
}
|
|
291
|
+
var implementations = { quadrantChart: {
|
|
292
|
+
parse,
|
|
293
|
+
layout,
|
|
294
|
+
honoredConfig,
|
|
295
|
+
acceptsPresentation: true
|
|
296
|
+
} };
|
|
297
|
+
export { implementations, quadrant_exports };
|