@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,553 @@
|
|
|
1
|
+
import { __exportAll } from "../_virtual/_rolldown/runtime.js";
|
|
2
|
+
import { FONT, appearance } from "./support.js";
|
|
3
|
+
import { parseGraph } from "./graph-parse.js";
|
|
4
|
+
import { layoutGraph } from "./graph-layout.js";
|
|
5
|
+
import { cubicPath } from "../core/geometry.js";
|
|
6
|
+
import { flowOutlineName, shapeGlyphBox, shapeOutline } from "./shapes.js";
|
|
7
|
+
// src/diagram/graph.js
|
|
8
|
+
var graph_exports = /* @__PURE__ */ __exportAll({ implementations: () => implementations });
|
|
9
|
+
var path = (ctx, d, attrs = {}, meta) => ({
|
|
10
|
+
...ctx.path(d, attrs),
|
|
11
|
+
...meta ? { meta } : {}
|
|
12
|
+
});
|
|
13
|
+
var text = (ctx, x, y, value, opts, meta) => ctx.text(x, y, value, {
|
|
14
|
+
"dominant-baseline": "central",
|
|
15
|
+
...opts,
|
|
16
|
+
meta
|
|
17
|
+
});
|
|
18
|
+
var group = (ctx, children, meta, attrs = {}) => ({
|
|
19
|
+
...ctx.el("g", attrs, children),
|
|
20
|
+
...meta ? { meta } : {}
|
|
21
|
+
});
|
|
22
|
+
var titleNode = (ctx, value) => value ? {
|
|
23
|
+
...ctx.el("title"),
|
|
24
|
+
text: String(value)
|
|
25
|
+
} : null;
|
|
26
|
+
var points = (coords) => coords.map(([x, y]) => `${x},${y}`).join(" ");
|
|
27
|
+
function defs(ctx, a) {
|
|
28
|
+
const arrow = (id, color, d = "M0 0 L8 4 L0 8 Z") => ({
|
|
29
|
+
tag: "marker",
|
|
30
|
+
attrs: {
|
|
31
|
+
id,
|
|
32
|
+
viewBox: "0 0 8 8",
|
|
33
|
+
refX: 8,
|
|
34
|
+
refY: 4,
|
|
35
|
+
markerWidth: 8,
|
|
36
|
+
markerHeight: 8,
|
|
37
|
+
markerUnits: "userSpaceOnUse",
|
|
38
|
+
orient: "auto-start-reverse"
|
|
39
|
+
},
|
|
40
|
+
children: [ctx.path(d, { fill: color })]
|
|
41
|
+
});
|
|
42
|
+
const zero = [
|
|
43
|
+
"circle",
|
|
44
|
+
4,
|
|
45
|
+
8,
|
|
46
|
+
3
|
|
47
|
+
], minOne = ["line", "M4 2 V14"];
|
|
48
|
+
const maxOne = ["line", "M12 2 V14"], many = ["line", "M15 2 L9 8 L15 14 M9 8 H15"];
|
|
49
|
+
const cards = Object.entries({
|
|
50
|
+
"zero-one": [zero, maxOne],
|
|
51
|
+
"exactly-one": [minOne, maxOne],
|
|
52
|
+
"zero-many": [zero, many],
|
|
53
|
+
"one-many": [minOne, many]
|
|
54
|
+
}).map(([name, shapes]) => ({
|
|
55
|
+
tag: "marker",
|
|
56
|
+
attrs: {
|
|
57
|
+
id: `graph-card-${name}`,
|
|
58
|
+
viewBox: "0 0 16 16",
|
|
59
|
+
refX: 16,
|
|
60
|
+
refY: 8,
|
|
61
|
+
markerWidth: 16,
|
|
62
|
+
markerHeight: 16,
|
|
63
|
+
markerUnits: "userSpaceOnUse",
|
|
64
|
+
orient: "auto-start-reverse"
|
|
65
|
+
},
|
|
66
|
+
children: shapes.map(([kind, ...args]) => kind === "circle" ? ctx.circle(...args, {
|
|
67
|
+
fill: a.surface,
|
|
68
|
+
stroke: a.fg4,
|
|
69
|
+
"stroke-width": 1.4
|
|
70
|
+
}) : ctx.path(args[0], {
|
|
71
|
+
fill: "none",
|
|
72
|
+
stroke: a.fg4,
|
|
73
|
+
"stroke-width": 1.4
|
|
74
|
+
}))
|
|
75
|
+
}));
|
|
76
|
+
return ctx.el("defs", {}, [
|
|
77
|
+
arrow("graph-arrow", a.fg4),
|
|
78
|
+
arrow("graph-arrow-bold", a.fg3),
|
|
79
|
+
arrow("graph-barb", a.fg4, "M0 0 L8 4 L0 8 L2 4 Z"),
|
|
80
|
+
...cards,
|
|
81
|
+
...["circle", "cross"].map((mark) => ({
|
|
82
|
+
tag: "marker",
|
|
83
|
+
attrs: {
|
|
84
|
+
id: `graph-${mark}`,
|
|
85
|
+
viewBox: "0 0 10 10",
|
|
86
|
+
refX: 9,
|
|
87
|
+
refY: 5,
|
|
88
|
+
markerWidth: 10,
|
|
89
|
+
markerHeight: 10,
|
|
90
|
+
markerUnits: "userSpaceOnUse",
|
|
91
|
+
orient: "auto-start-reverse"
|
|
92
|
+
},
|
|
93
|
+
children: [mark === "circle" ? ctx.circle(5, 5, 3.375, {
|
|
94
|
+
fill: a.surface,
|
|
95
|
+
stroke: a.fg4,
|
|
96
|
+
"stroke-width": 1.25
|
|
97
|
+
}) : ctx.path("M2 2 L8.5 8 M2 8 L8.5 2", {
|
|
98
|
+
fill: "none",
|
|
99
|
+
stroke: a.fg4,
|
|
100
|
+
"stroke-width": 1.25
|
|
101
|
+
})]
|
|
102
|
+
}))
|
|
103
|
+
]);
|
|
104
|
+
}
|
|
105
|
+
function cardKey(card) {
|
|
106
|
+
return card === "|o" || card === "o|" ? "zero-one" : card === "||" ? "exactly-one" : card === "}o" || card === "o{" ? "zero-many" : card === "}|" || card === "|{" ? "one-many" : null;
|
|
107
|
+
}
|
|
108
|
+
function edgePath(edge, modelNodes, ctx, a) {
|
|
109
|
+
if (!edge.segments?.length || edge.style === "invisible") return null;
|
|
110
|
+
const d = cubicPath(edge.segments);
|
|
111
|
+
const isEr = modelNodes.get(edge.from)?.kind === "er" || modelNodes.get(edge.to)?.kind === "er";
|
|
112
|
+
const bold = edge.style === "bold";
|
|
113
|
+
const attrs = {
|
|
114
|
+
fill: "none",
|
|
115
|
+
stroke: a[edge.status] ?? (bold ? a.fg3 : a.fg4),
|
|
116
|
+
"stroke-width": bold ? 2 : 1.25,
|
|
117
|
+
...edge.style === "dashed" || edge.animated ? { "stroke-dasharray": "5 4" } : {}
|
|
118
|
+
};
|
|
119
|
+
if (isEr) {
|
|
120
|
+
const start = edge.startCard && cardKey(edge.startCard), end = edge.endCard && cardKey(edge.endCard);
|
|
121
|
+
if (start) attrs["marker-start"] = `url(#graph-card-${start})`;
|
|
122
|
+
if (end) attrs["marker-end"] = `url(#graph-card-${end})`;
|
|
123
|
+
} else for (const side of ["start", "end"]) {
|
|
124
|
+
const mark = edge[`${side}Mark`] ?? (edge[`${side}Arrow`] ? "point" : "none");
|
|
125
|
+
if (mark !== "none") attrs[`marker-${side}`] = `url(#graph-${mark === "point" ? `arrow${bold ? "-bold" : ""}` : mark})`;
|
|
126
|
+
}
|
|
127
|
+
return group(ctx, [titleNode(ctx, `${edge.from} → ${edge.to}${edge.label ? `:${edge.label}` : ""}`), path(ctx, d, attrs, {
|
|
128
|
+
kind: "edge",
|
|
129
|
+
from: edge.from,
|
|
130
|
+
to: edge.to,
|
|
131
|
+
...edge.status ? { status: edge.status } : {}
|
|
132
|
+
})], { kind: "edge-group" });
|
|
133
|
+
}
|
|
134
|
+
function drawFlowShape(ctx, name, { x, y, w, h, direction }, common, a) {
|
|
135
|
+
const glyph = shapeGlyphBox(name, w, h, direction);
|
|
136
|
+
const fill = [
|
|
137
|
+
"fork",
|
|
138
|
+
"f-circ",
|
|
139
|
+
"anchor"
|
|
140
|
+
].includes(name) ? a.fg3 : common.fill;
|
|
141
|
+
const stroke = glyph && common.stroke === a.line2 ? a.fg4 : common.stroke;
|
|
142
|
+
const outlineAttrs = name === "text" || name === "icon" || [
|
|
143
|
+
"brace",
|
|
144
|
+
"brace-r",
|
|
145
|
+
"braces"
|
|
146
|
+
].includes(name) ? {
|
|
147
|
+
fill: "none",
|
|
148
|
+
stroke: "none"
|
|
149
|
+
} : {
|
|
150
|
+
...common,
|
|
151
|
+
fill,
|
|
152
|
+
stroke,
|
|
153
|
+
...name === "datastore" ? { "stroke-dasharray": `${w} ${h}` } : {}
|
|
154
|
+
};
|
|
155
|
+
const children = [ctx.shape("polygon", {
|
|
156
|
+
points: points(shapeOutline(name, w, h, direction).map(([px, py]) => [x + px, y + py])),
|
|
157
|
+
...outlineAttrs
|
|
158
|
+
})];
|
|
159
|
+
if (glyph) {
|
|
160
|
+
x += glyph.x;
|
|
161
|
+
y += glyph.y;
|
|
162
|
+
({w, h} = glyph);
|
|
163
|
+
}
|
|
164
|
+
const at = (u, v) => `${x + w * u} ${y + h * v}`;
|
|
165
|
+
const detail = (d) => children.push(path(ctx, d, {
|
|
166
|
+
fill: "none",
|
|
167
|
+
stroke,
|
|
168
|
+
"stroke-width": 1.25
|
|
169
|
+
}));
|
|
170
|
+
const line = (u, v, s, t) => `M${at(u, v)} L${at(s, t)}`;
|
|
171
|
+
if (name === "fr-rect") detail(line(.1, 0, .1, 1) + line(.9, 0, .9, 1));
|
|
172
|
+
if ([
|
|
173
|
+
"win-pane",
|
|
174
|
+
"lin-rect",
|
|
175
|
+
"lin-doc"
|
|
176
|
+
].includes(name)) detail(line(.11, 0, .11, name === "lin-doc" ? .95 : 1));
|
|
177
|
+
if ([
|
|
178
|
+
"win-pane",
|
|
179
|
+
"div-rect",
|
|
180
|
+
"browser",
|
|
181
|
+
"console"
|
|
182
|
+
].includes(name)) detail(line(0, .22, 1, .22));
|
|
183
|
+
if (name === "browser") for (const dx of [
|
|
184
|
+
10,
|
|
185
|
+
16,
|
|
186
|
+
22
|
|
187
|
+
]) children.push(ctx.circle(x + dx, y + h * .11, 1.4, { fill: common.stroke }));
|
|
188
|
+
if (name === "console") detail(`M${at(.08, .06)} L${at(.13, .11)} L${at(.08, .16)} ${line(.15, .16, .21, .16)}`);
|
|
189
|
+
if ([
|
|
190
|
+
"cyl",
|
|
191
|
+
"lin-cyl",
|
|
192
|
+
"bucket"
|
|
193
|
+
].includes(name)) {
|
|
194
|
+
detail(`M${at(0, .12)} A${w / 2} ${h * .12} 0 0 0 ${at(1, .12)}`);
|
|
195
|
+
if (name === "lin-cyl") detail(`M${at(0, .19)} A${w / 2} ${h * .12} 0 0 0 ${at(1, .19)}`);
|
|
196
|
+
}
|
|
197
|
+
if (name === "h-cyl") detail(`M${at(.12, 0)} A${w * .12} ${h / 2} 0 0 1 ${at(.12, 1)}`);
|
|
198
|
+
if (name === "tag-rect" || name === "tag-doc") {
|
|
199
|
+
const d = Math.min(14, h * .24), base = name === "tag-doc" ? .9 : 1;
|
|
200
|
+
const start = 1 - d / w;
|
|
201
|
+
detail(line(start, name === "tag-doc" ? base + .09 * Math.sin(start * 2 * Math.PI) : base, 1, base - d / h));
|
|
202
|
+
}
|
|
203
|
+
if (name === "note") {
|
|
204
|
+
const fold = Math.min(12, w / 3, h / 3);
|
|
205
|
+
detail(`M${x + w - fold} ${y} v${fold} h${fold}`);
|
|
206
|
+
}
|
|
207
|
+
if (name === "docs" || name === "st-rect") {
|
|
208
|
+
const bottom = (name === "docs" ? .9 : 1) * (h - 10);
|
|
209
|
+
for (const i of [1, 2]) {
|
|
210
|
+
const d = i * 5, right = x + w - d;
|
|
211
|
+
detail(`M${x + 10 - d} ${y + d} H${right} V${y + d + bottom}`);
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
if (name === "dbl-circ" || name === "fr-circ") children.push(ctx.circle(x + w / 2, y + h / 2, w / 2 - 5, {
|
|
215
|
+
fill: name === "fr-circ" ? a.fg4 : "none",
|
|
216
|
+
stroke: common.stroke
|
|
217
|
+
}));
|
|
218
|
+
if (name === "cross-circ") detail(line(.16, .16, .84, .84) + line(.84, .16, .16, .84));
|
|
219
|
+
const brace = (side) => {
|
|
220
|
+
const b = side ? .94 : .06, c = side ? .06 : -.06;
|
|
221
|
+
detail(`M${at(b - c, .04)} Q${at(b, .04)} ${at(b, .25)} Q${at(b, .5)} ${at(b + c, .5)} Q${at(b, .5)} ${at(b, .75)} Q${at(b, .96)} ${at(b - c, .96)}`);
|
|
222
|
+
};
|
|
223
|
+
if (name === "brace" || name === "braces") brace(false);
|
|
224
|
+
if (name === "brace-r" || name === "braces") brace(true);
|
|
225
|
+
return children;
|
|
226
|
+
}
|
|
227
|
+
function drawShape(ctx, item, n, a) {
|
|
228
|
+
const { x, y, w, h } = n;
|
|
229
|
+
const node = item.node;
|
|
230
|
+
const stroke = node.class === "ext" ? a.line2 : node.class && a[node.class] ? a[node.class] : a.line2;
|
|
231
|
+
const common = {
|
|
232
|
+
fill: node.class === "ext" ? "none" : node.class && a[node.class] ? ctx.mix(a.node, a[node.class], a.soft) : a.node,
|
|
233
|
+
stroke,
|
|
234
|
+
"stroke-width": 1.25,
|
|
235
|
+
...node.class === "ext" ? { "stroke-dasharray": "4 3" } : {}
|
|
236
|
+
};
|
|
237
|
+
const flowShape = item.flowchart && flowOutlineName(node.shape);
|
|
238
|
+
if (flowShape) return drawFlowShape(ctx, flowShape, n, common, a);
|
|
239
|
+
if (node.kind === "note") return drawFlowShape(ctx, "note", n, {
|
|
240
|
+
...common,
|
|
241
|
+
fill: ctx.mix(a.node, a.warn, a.soft)
|
|
242
|
+
}, a);
|
|
243
|
+
if (node.kind === "start") return [ctx.circle(x + w / 2, y + h / 2, Math.min(w, h) / 2, {
|
|
244
|
+
fill: a.fg2,
|
|
245
|
+
stroke: "none"
|
|
246
|
+
})];
|
|
247
|
+
if (node.kind === "end") return [ctx.circle(x + w / 2, y + h / 2, Math.min(w, h) / 2, {
|
|
248
|
+
fill: a.node,
|
|
249
|
+
stroke: a.fg2,
|
|
250
|
+
"stroke-width": 1.5
|
|
251
|
+
}), ctx.circle(x + w / 2, y + h / 2, Math.min(w, h) / 2 - 4, {
|
|
252
|
+
fill: a.fg2,
|
|
253
|
+
stroke: "none"
|
|
254
|
+
})];
|
|
255
|
+
if (node.kind === "choice" || node.shape === "diamond") return [ctx.shape("polygon", {
|
|
256
|
+
points: points([
|
|
257
|
+
[x + w / 2, y],
|
|
258
|
+
[x + w, y + h / 2],
|
|
259
|
+
[x + w / 2, y + h],
|
|
260
|
+
[x, y + h / 2]
|
|
261
|
+
]),
|
|
262
|
+
...common
|
|
263
|
+
})];
|
|
264
|
+
if (node.kind === "fork" || node.kind === "join") return [ctx.rect(x, y, w, h, {
|
|
265
|
+
...common,
|
|
266
|
+
fill: a.fg3,
|
|
267
|
+
rx: 2
|
|
268
|
+
})];
|
|
269
|
+
if (node.shape === "circle") return [ctx.shape("ellipse", {
|
|
270
|
+
cx: x + w / 2,
|
|
271
|
+
cy: y + h / 2,
|
|
272
|
+
rx: w / 2,
|
|
273
|
+
ry: h / 2,
|
|
274
|
+
...common
|
|
275
|
+
})];
|
|
276
|
+
if (node.shape === "hexagon") {
|
|
277
|
+
const cut = 16;
|
|
278
|
+
return [ctx.shape("polygon", {
|
|
279
|
+
points: points([
|
|
280
|
+
[x + cut, y],
|
|
281
|
+
[x + w - cut, y],
|
|
282
|
+
[x + w, y + h / 2],
|
|
283
|
+
[x + w - cut, y + h],
|
|
284
|
+
[x + cut, y + h],
|
|
285
|
+
[x, y + h / 2]
|
|
286
|
+
]),
|
|
287
|
+
...common
|
|
288
|
+
})];
|
|
289
|
+
}
|
|
290
|
+
if (node.shape === "stadium") return [ctx.rect(x, y, w, h, {
|
|
291
|
+
...common,
|
|
292
|
+
rx: h / 2
|
|
293
|
+
})];
|
|
294
|
+
if (node.shape === "cylinder") {
|
|
295
|
+
const ry = 6;
|
|
296
|
+
return [path(ctx, `M${x} ${y + ry} C${x} ${y - ry * .2} ${x + w} ${y - ry * .2} ${x + w} ${y + ry} V${y + h - ry} C${x + w} ${y + h + ry * .2} ${x} ${y + h + ry * .2} ${x} ${y + h - ry} Z`, common), path(ctx, `M${x} ${y + ry} C${x} ${y + 12} ${x + w} ${y + 12} ${x + w} ${y + ry}`, common)];
|
|
297
|
+
}
|
|
298
|
+
const rx = node.kind === "state" ? 8 : node.shape === "round" ? 11 : 3;
|
|
299
|
+
const shape = ctx.rect(x, y, w, h, {
|
|
300
|
+
...common,
|
|
301
|
+
rx
|
|
302
|
+
});
|
|
303
|
+
if (node.shape !== "subroutine") return [shape];
|
|
304
|
+
return [shape, path(ctx, `M${x + 9} ${y + 4} V${y + h - 4} M${x + w - 9} ${y + 4} V${y + h - 4}`, {
|
|
305
|
+
fill: "none",
|
|
306
|
+
stroke,
|
|
307
|
+
"stroke-width": 1.25
|
|
308
|
+
})];
|
|
309
|
+
}
|
|
310
|
+
function drawIcon(ctx, icon, x, y, color, size = 16) {
|
|
311
|
+
const [left, top, w, h] = icon.viewBox.split(/\s+/).map(Number), scale = size / Math.max(w, h);
|
|
312
|
+
return ctx.el("g", { transform: `translate(${x - (left + w / 2) * scale} ${y - (top + h / 2) * scale}) scale(${scale})` }, icon.elements.map(({ tag, attrs }) => ctx.shape(tag, {
|
|
313
|
+
...attrs,
|
|
314
|
+
...icon.set === "simple" ? { fill: color } : {
|
|
315
|
+
fill: "none",
|
|
316
|
+
stroke: color,
|
|
317
|
+
"stroke-width": 1.6,
|
|
318
|
+
"stroke-linecap": "round",
|
|
319
|
+
"stroke-linejoin": "round"
|
|
320
|
+
}
|
|
321
|
+
})));
|
|
322
|
+
}
|
|
323
|
+
var linked = (ctx, item, drawing) => item?.link ? ctx.link(item.link.href, [drawing], item.link) : drawing;
|
|
324
|
+
function drawNode(ctx, item, n, a) {
|
|
325
|
+
const node = item.node, children = [titleNode(ctx, node.label || node.id), ...drawShape(ctx, item, n, a)];
|
|
326
|
+
const nodeMeta = {
|
|
327
|
+
kind: node.kind === "collapsed" ? "frame" : "node",
|
|
328
|
+
id: node.id,
|
|
329
|
+
...node.class ? { status: node.class } : {}
|
|
330
|
+
};
|
|
331
|
+
if (node.kind === "start" || node.kind === "end" || node.kind === "choice" || node.kind === "fork" || node.kind === "join") return group(ctx, children, nodeMeta);
|
|
332
|
+
if (node.kind === "er" && n.er) {
|
|
333
|
+
const er = n.er, pad = er.pad, ruleY = n.y + er.headerH;
|
|
334
|
+
for (const [i, line] of er.headLines.entries()) children.push(text(ctx, n.x + n.w / 2, n.y + 7 + (i + .5) * 19, line, {
|
|
335
|
+
anchor: "middle",
|
|
336
|
+
size: 14,
|
|
337
|
+
weight: 600,
|
|
338
|
+
fill: a.fg1
|
|
339
|
+
}, {
|
|
340
|
+
kind: "node-label",
|
|
341
|
+
id: node.id
|
|
342
|
+
}));
|
|
343
|
+
children.push(path(ctx, `M${n.x + 1} ${ruleY} H${n.x + n.w - 1}`, {
|
|
344
|
+
stroke: a.line2,
|
|
345
|
+
"stroke-width": 1
|
|
346
|
+
}));
|
|
347
|
+
let rowY = ruleY + 2;
|
|
348
|
+
for (const row of er.rows) {
|
|
349
|
+
const rowChildren = [];
|
|
350
|
+
if (row.comment) rowChildren.push(titleNode(ctx, `${row.name}${row.keys.length ? ` · ${row.keys.join(" ")}` : ""}:${row.comment}`));
|
|
351
|
+
const cy = rowY + row.rowH / 2;
|
|
352
|
+
row.typeLines.forEach((line, i) => rowChildren.push(text(ctx, n.x + pad, cy + (i - (row.typeLines.length - 1) / 2) * 17, line, {
|
|
353
|
+
anchor: "start",
|
|
354
|
+
size: 13,
|
|
355
|
+
fill: a.fg3
|
|
356
|
+
}, {
|
|
357
|
+
kind: "attribute-type",
|
|
358
|
+
entity: node.id,
|
|
359
|
+
attribute: row.name
|
|
360
|
+
})));
|
|
361
|
+
row.nameLines.forEach((line, i) => rowChildren.push(text(ctx, n.x + pad + er.typeW + 12, cy + (i - (row.nameLines.length - 1) / 2) * 17, line, {
|
|
362
|
+
anchor: "start",
|
|
363
|
+
size: 13,
|
|
364
|
+
fill: a.fg2
|
|
365
|
+
}, {
|
|
366
|
+
kind: "attribute",
|
|
367
|
+
entity: node.id,
|
|
368
|
+
attribute: row.name
|
|
369
|
+
})));
|
|
370
|
+
if (row.keyText) rowChildren.push(text(ctx, n.x + n.w - pad, cy, row.keyText, {
|
|
371
|
+
anchor: "end",
|
|
372
|
+
size: 12,
|
|
373
|
+
fill: a.fg3
|
|
374
|
+
}, {
|
|
375
|
+
kind: "attribute-key",
|
|
376
|
+
entity: node.id,
|
|
377
|
+
attribute: row.name
|
|
378
|
+
}));
|
|
379
|
+
children.push(group(ctx, rowChildren, {
|
|
380
|
+
kind: "attribute-row",
|
|
381
|
+
entity: node.id,
|
|
382
|
+
attribute: row.name
|
|
383
|
+
}));
|
|
384
|
+
rowY += row.rowH;
|
|
385
|
+
}
|
|
386
|
+
return group(ctx, children, nodeMeta);
|
|
387
|
+
}
|
|
388
|
+
const lines = item.titleLines || [], desc = item.descLines || [];
|
|
389
|
+
const titleH = lines.length * 19, descH = desc.length * 17, gap = desc.length ? 7 : 0;
|
|
390
|
+
const collapsed = node.kind === "collapsed";
|
|
391
|
+
const flowShape = item.flowchart && flowOutlineName(node.shape);
|
|
392
|
+
const glyph = flowShape && shapeGlyphBox(flowShape, n.w, n.h, n.direction);
|
|
393
|
+
const iconSize = node.iconHeight ?? 16;
|
|
394
|
+
const iconH = node.icon ? iconSize + 8 : 0;
|
|
395
|
+
const aboveIcon = node.iconPosition === "t" && titleH > 0;
|
|
396
|
+
const top = glyph ? n.y + (n.h - titleH) / 2 : n.y + Math.max(10, (n.h - titleH - gap - descH - (collapsed ? 20 : 0) - iconH) / 2) + (aboveIcon ? 0 : iconH);
|
|
397
|
+
if (node.icon) {
|
|
398
|
+
const cx = n.x + n.w / 2, cy = aboveIcon ? top + titleH + iconH / 2 : top - iconH / 2;
|
|
399
|
+
const tile = {
|
|
400
|
+
fill: a.surface,
|
|
401
|
+
stroke: a[node.class] ?? a.line2,
|
|
402
|
+
"stroke-width": 1
|
|
403
|
+
};
|
|
404
|
+
if (node.iconForm === "circle") children.push(ctx.circle(cx, cy, iconH / 2, tile));
|
|
405
|
+
else if (["square", "rounded"].includes(node.iconForm)) children.push(ctx.rect(cx - iconH / 2, cy - iconH / 2, iconH, iconH, {
|
|
406
|
+
...tile,
|
|
407
|
+
rx: node.iconForm === "rounded" ? 8 : 0
|
|
408
|
+
}));
|
|
409
|
+
children.push(drawIcon(ctx, node.icon, cx, cy, a.fg3, iconSize));
|
|
410
|
+
}
|
|
411
|
+
const textX = glyph ? n.x + glyph.x + (n.glyphLabelLeft ? -8 : glyph.w + 8) : n.x + n.w / 2;
|
|
412
|
+
if (collapsed) {
|
|
413
|
+
const y = n.y + n.h - 20;
|
|
414
|
+
children.push(path(ctx, `M${n.x} ${y} H${n.x + n.w}`, {
|
|
415
|
+
fill: "none",
|
|
416
|
+
stroke: a.line2,
|
|
417
|
+
"stroke-dasharray": "4 3"
|
|
418
|
+
}));
|
|
419
|
+
for (const dx of [
|
|
420
|
+
-5,
|
|
421
|
+
0,
|
|
422
|
+
5
|
|
423
|
+
]) children.push(ctx.circle(n.x + n.w / 2 + dx, y + 10, 1.25, { fill: a.fg4 }));
|
|
424
|
+
}
|
|
425
|
+
lines.forEach((line, i) => children.push(text(ctx, textX, top + i * 19 + 9.5, line, {
|
|
426
|
+
anchor: glyph ? n.glyphLabelLeft ? "end" : "start" : "middle",
|
|
427
|
+
size: FONT.title.size,
|
|
428
|
+
weight: node.kind === "note" ? FONT.body.weight : FONT.title.weight,
|
|
429
|
+
fill: a.fg1
|
|
430
|
+
}, {
|
|
431
|
+
kind: "node-label",
|
|
432
|
+
id: node.id
|
|
433
|
+
})));
|
|
434
|
+
desc.forEach((line, i) => children.push(text(ctx, n.x + n.w / 2, top + titleH + gap + i * 17 + 8.5, line, {
|
|
435
|
+
anchor: "middle",
|
|
436
|
+
size: FONT.body.size,
|
|
437
|
+
fill: a.fg3
|
|
438
|
+
}, {
|
|
439
|
+
kind: "node-description",
|
|
440
|
+
id: node.id
|
|
441
|
+
})));
|
|
442
|
+
return group(ctx, children, nodeMeta);
|
|
443
|
+
}
|
|
444
|
+
function scene(geometry, ctx, info = {}) {
|
|
445
|
+
const a = appearance(ctx), model = geometry.model || {}, modelNodes = new Map((model.nodes || []).map((node) => [node.id, node]));
|
|
446
|
+
const modelEdges = new Map((model.edges || []).map((edge) => [edge.seq, edge]));
|
|
447
|
+
const modelFrames = new Map((model.subgraphs || []).map((frame) => [frame.id, frame]));
|
|
448
|
+
const framesLayer = [], edgeLayer = [], nodeLayer = [], edgeLabelLayer = [], titleLayer = [];
|
|
449
|
+
for (const frame of geometry.frames || []) {
|
|
450
|
+
const attrs = {
|
|
451
|
+
fill: frame.kind === "divider" ? a.node : a.surface,
|
|
452
|
+
stroke: frame.class && a[frame.class] ? a[frame.class] : a.line2,
|
|
453
|
+
"stroke-width": 1,
|
|
454
|
+
"stroke-dasharray": "5 4"
|
|
455
|
+
};
|
|
456
|
+
const frameChildren = [ctx.rect(frame.x, frame.y, frame.w, frame.h, {
|
|
457
|
+
...attrs,
|
|
458
|
+
rx: 6
|
|
459
|
+
})];
|
|
460
|
+
const presentation = modelFrames.get(frame.id);
|
|
461
|
+
framesLayer.push(linked(ctx, presentation, group(ctx, frameChildren, {
|
|
462
|
+
kind: "frame",
|
|
463
|
+
id: frame.id,
|
|
464
|
+
...frame.class ? { status: frame.class } : {}
|
|
465
|
+
})));
|
|
466
|
+
if (frame.lines?.length) {
|
|
467
|
+
const rect = frame.titleRect;
|
|
468
|
+
const titleChildren = [ctx.rect(rect.x - 3, rect.y - 3, rect.w + 6, rect.h + 6, {
|
|
469
|
+
fill: a.surface,
|
|
470
|
+
rx: 2
|
|
471
|
+
})];
|
|
472
|
+
if (presentation?.icon) titleChildren.push(drawIcon(ctx, presentation.icon, rect.x + 8, rect.y + 8.5, a.fg3));
|
|
473
|
+
frame.lines.forEach((line, i) => titleChildren.push(text(ctx, rect.x + (presentation?.icon ? 22 : 0), rect.y + (i + .5) * 17, line, {
|
|
474
|
+
anchor: "start",
|
|
475
|
+
size: 13,
|
|
476
|
+
weight: 600,
|
|
477
|
+
fill: a.fg3
|
|
478
|
+
}, {
|
|
479
|
+
kind: "frame-title",
|
|
480
|
+
id: frame.id
|
|
481
|
+
})));
|
|
482
|
+
(frame.descLines || []).forEach((line, i) => titleChildren.push(text(ctx, rect.x, rect.y + frame.lines.length * 17 + 4 + i * 16 + 8, line, {
|
|
483
|
+
anchor: "start",
|
|
484
|
+
size: 13,
|
|
485
|
+
fill: a.fg3
|
|
486
|
+
}, {
|
|
487
|
+
kind: "frame-description",
|
|
488
|
+
id: frame.id
|
|
489
|
+
})));
|
|
490
|
+
titleLayer.push(linked(ctx, presentation, group(ctx, titleChildren, {
|
|
491
|
+
kind: "frame-title-group",
|
|
492
|
+
id: frame.id
|
|
493
|
+
})));
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
for (const edge of geometry.edges || []) {
|
|
497
|
+
const rendered = edgePath({
|
|
498
|
+
...edge,
|
|
499
|
+
status: modelEdges.get(edge.id)?.status
|
|
500
|
+
}, modelNodes, ctx, a);
|
|
501
|
+
if (rendered) edgeLayer.push(rendered);
|
|
502
|
+
if (edge.labelRect && edge.labelLines?.length) {
|
|
503
|
+
const r = edge.labelRect, children = [ctx.rect(r.x, r.y, r.w, r.h, {
|
|
504
|
+
fill: a.surface,
|
|
505
|
+
rx: 3
|
|
506
|
+
})];
|
|
507
|
+
const icon = modelEdges.get(edge.id)?.icon;
|
|
508
|
+
if (icon) children.push(drawIcon(ctx, icon, r.x + 13, r.y + r.h / 2, a.fg3));
|
|
509
|
+
edge.labelLines.forEach((line, i) => children.push(text(ctx, r.x + r.w / 2 + (icon ? 11 : 0), r.y + r.h / 2 + (i - (edge.labelLines.length - 1) / 2) * 16, line, {
|
|
510
|
+
anchor: "middle",
|
|
511
|
+
size: 12,
|
|
512
|
+
fill: a.fg3
|
|
513
|
+
}, { kind: "edge-label" })));
|
|
514
|
+
edgeLabelLayer.push(group(ctx, children, {
|
|
515
|
+
kind: "edge-label-group",
|
|
516
|
+
from: edge.from,
|
|
517
|
+
to: edge.to
|
|
518
|
+
}));
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
for (const n of geometry.nodes || []) {
|
|
522
|
+
const item = modelNodes.get(n.id);
|
|
523
|
+
if (item) nodeLayer.push(linked(ctx, item, drawNode(ctx, {
|
|
524
|
+
node: item,
|
|
525
|
+
flowchart: model.type === "flowchart",
|
|
526
|
+
titleLines: n.lines,
|
|
527
|
+
descLines: n.descLines
|
|
528
|
+
}, n, a)));
|
|
529
|
+
}
|
|
530
|
+
const children = [
|
|
531
|
+
defs(ctx, a),
|
|
532
|
+
...framesLayer,
|
|
533
|
+
group(ctx, edgeLayer, { kind: "edges" }),
|
|
534
|
+
group(ctx, nodeLayer, { kind: "nodes" }),
|
|
535
|
+
group(ctx, edgeLabelLayer, { kind: "edge-labels" }),
|
|
536
|
+
group(ctx, titleLayer, { kind: "frame-titles" })
|
|
537
|
+
];
|
|
538
|
+
return {
|
|
539
|
+
width: geometry.width,
|
|
540
|
+
height: geometry.height,
|
|
541
|
+
children,
|
|
542
|
+
...info.title ? { title: info.title } : {}
|
|
543
|
+
};
|
|
544
|
+
}
|
|
545
|
+
var implementations = Object.fromEntries(["flowchart", "stateDiagram-v2"].map((kind) => [kind, {
|
|
546
|
+
optionMode: "raw",
|
|
547
|
+
acceptsPresentation: true,
|
|
548
|
+
honoredConfig: ["flowchart.inheritDir"],
|
|
549
|
+
parse: (body, info) => parseGraph(body, info),
|
|
550
|
+
layout: (model, options, info) => layoutGraph(model, options, info),
|
|
551
|
+
scene
|
|
552
|
+
}]));
|
|
553
|
+
export { graph_exports, implementations };
|